-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
567 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* This file is part of spark. | ||
* | ||
* Copyright (c) lucko (Luck) <[email protected]> | ||
* Copyright (c) contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.lucko.spark.bukkit; | ||
|
||
import org.bukkit.scheduler.BukkitScheduler; | ||
|
||
/** | ||
* Interface for the server scheduler on Bukkit servers. | ||
*/ | ||
public interface BukkitSparkScheduler { | ||
|
||
/** | ||
* Executes the given {@link Runnable} asynchronously using the plugins scheduler. | ||
* | ||
* @param task the task | ||
*/ | ||
void executeAsync(Runnable task); | ||
|
||
/** | ||
* Executes the given {@link Runnable} on the server/client main thread. | ||
* | ||
* @param task the task | ||
*/ | ||
void executeSync(Runnable task); | ||
|
||
/** | ||
* Uses the {@link BukkitScheduler} for async and sync operations. | ||
*/ | ||
@SuppressWarnings("deprecation") | ||
final class Basic implements BukkitSparkScheduler { | ||
private final BukkitSparkPlugin plugin; | ||
|
||
public Basic(BukkitSparkPlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public void executeAsync(Runnable task) { | ||
this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, task); | ||
} | ||
|
||
@Override | ||
public void executeSync(Runnable task) { | ||
this.plugin.getServer().getScheduler().runTask(this.plugin, task); | ||
} | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
spark-bukkit/src/main/java/me/lucko/spark/bukkit/folia/FoliaScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* This file is part of spark. | ||
* | ||
* Copyright (c) lucko (Luck) <[email protected]> | ||
* Copyright (c) contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.lucko.spark.bukkit.folia; | ||
|
||
import me.lucko.spark.bukkit.BukkitSparkPlugin; | ||
import me.lucko.spark.bukkit.BukkitSparkScheduler; | ||
|
||
import io.papermc.paper.threadedregions.scheduler.AsyncScheduler; | ||
import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; | ||
|
||
/** | ||
* Uses the {@link AsyncScheduler} for async operations, | ||
* and the {@link GlobalRegionScheduler} for sync operations. | ||
*/ | ||
public final class FoliaScheduler implements BukkitSparkScheduler { | ||
private final BukkitSparkPlugin plugin; | ||
|
||
public FoliaScheduler(BukkitSparkPlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public void executeAsync(Runnable task) { | ||
this.plugin.getServer().getAsyncScheduler().runNow(this.plugin, t -> task.run()); | ||
} | ||
|
||
@Override | ||
public void executeSync(Runnable task) { | ||
this.plugin.getServer().getGlobalRegionScheduler().execute(this.plugin, task); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
spark-bukkit/src/main/java/me/lucko/spark/bukkit/folia/FoliaSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* This file is part of spark. | ||
* | ||
* Copyright (c) lucko (Luck) <[email protected]> | ||
* Copyright (c) contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.lucko.spark.bukkit.folia; | ||
|
||
/** | ||
* Compatibility util for Paper's threaded regions "Folia" project. | ||
*/ | ||
public enum FoliaSupport { | ||
; | ||
|
||
public static final boolean IS_ACTIVE; | ||
|
||
static { | ||
boolean active = false; | ||
try { | ||
Class.forName("io.papermc.paper.threadedregions.scheduler.RegionScheduler"); | ||
active = true; | ||
} catch (ClassNotFoundException e) { | ||
// ignore | ||
} | ||
IS_ACTIVE = active; | ||
} | ||
|
||
} |
Oops, something went wrong.