From e23eee62e0c508f17c2e53a602cecf01a971be1e Mon Sep 17 00:00:00 2001 From: Euphyllia Bierque Date: Sat, 2 Mar 2024 14:21:23 +0100 Subject: [PATCH] Energie pour Folia et Spigot --- buildSrc/src/main/kotlin/CommonConfig.kt | 1 + worldedit-bukkit/build.gradle.kts | 2 ++ .../worldedit/bukkit/BukkitBlockCommandSender.java | 12 +++++++----- .../worldedit/bukkit/BukkitServerInterface.java | 13 ++++++++++++- .../com/sk89q/worldedit/bukkit/WorldEditPlugin.java | 12 +++++++++++- worldedit-bukkit/src/main/resources/plugin.yml | 3 ++- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/buildSrc/src/main/kotlin/CommonConfig.kt b/buildSrc/src/main/kotlin/CommonConfig.kt index ba0f6bde87..3618881fec 100644 --- a/buildSrc/src/main/kotlin/CommonConfig.kt +++ b/buildSrc/src/main/kotlin/CommonConfig.kt @@ -25,6 +25,7 @@ fun Project.applyCommonConfiguration() { snapshotsOnly() } } + maven { url = uri("https://jitpack.io") } } configurations.all { diff --git a/worldedit-bukkit/build.gradle.kts b/worldedit-bukkit/build.gradle.kts index 9f8a9dc15a..2c31e76715 100644 --- a/worldedit-bukkit/build.gradle.kts +++ b/worldedit-bukkit/build.gradle.kts @@ -61,6 +61,7 @@ dependencies { "implementation"("org.bstats:bstats-bukkit:2.2.1") "implementation"("it.unimi.dsi:fastutil") "testImplementation"("org.mockito:mockito-core:1.9.0-rc1") + "implementation"("com.github.Euphillya:Energie:26cdee42f4") project.project(":worldedit-bukkit:adapters").subprojects.forEach { "adapters"(project(it.path)) @@ -91,6 +92,7 @@ tasks.named("shadowJar") { include(dependency("io.papermc:paperlib")) include(dependency("it.unimi.dsi:fastutil")) include(dependency("com.sk89q.lib:jlibnoise")) + include(dependency("com.github.Euphillya:Energie")) exclude(dependency("$group:$name")) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java index 12840c4dd7..001c3ede21 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java @@ -28,6 +28,8 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter; import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import fr.euphyllia.energie.Energie; +import fr.euphyllia.energie.model.SchedulerType; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; @@ -156,11 +158,11 @@ public boolean isActive() { updateActive(); } else { // we should update it eventually - Bukkit.getScheduler().callSyncMethod(plugin, - () -> { - updateActive(); - return null; - }); + WorldEditPlugin.getEnergieTask().getScheduler(Energie.SchedulerSoft.MINECRAFT).execute( + SchedulerType.GLOBAL, schedulerTaskInter -> { + updateActive(); + } + ); } return active; } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index d30b8e494c..ab1259a35c 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -37,6 +37,8 @@ import com.sk89q.worldedit.util.lifecycle.Lifecycled; import com.sk89q.worldedit.world.DataFixer; import com.sk89q.worldedit.world.registry.Registries; +import fr.euphyllia.energie.Energie; +import fr.euphyllia.energie.model.SchedulerType; import io.papermc.lib.PaperLib; import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; @@ -51,6 +53,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nullable; @@ -121,7 +124,15 @@ public void reload() { @Override public int schedule(long delay, long period, Runnable task) { - return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period); + AtomicInteger taskId = new AtomicInteger(0); + WorldEditPlugin.getEnergieTask().getScheduler(Energie.SchedulerSoft.MINECRAFT) + .runAtFixedRate(SchedulerType.GLOBAL, delay, period, schedulerTaskInter -> { + task.run(); + if (schedulerTaskInter != null) { + taskId.set(schedulerTaskInter.getTaskId()); + } + }); + return taskId.get(); } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index b338b2498f..928665f08d 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -58,6 +58,7 @@ import com.sk89q.worldedit.world.item.ItemCategory; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.weather.WeatherTypes; +import fr.euphyllia.energie.Energie; import io.papermc.lib.PaperLib; import org.apache.logging.log4j.Logger; import org.bstats.bukkit.Metrics; @@ -116,6 +117,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { public static final String CUI_PLUGIN_CHANNEL = "worldedit:cui"; private static WorldEditPlugin INSTANCE; private static final int BSTATS_PLUGIN_ID = 3328; + private static fr.euphyllia.energie.Energie energieTask; // Euphyllia private final SimpleLifecycled adapter = SimpleLifecycled.invalid(); @@ -154,6 +156,7 @@ public void onEnable() { // Catch bad things being done by naughty plugins that include // WorldEdit's classes ClassSourceValidator verifier = new ClassSourceValidator(this); + energieTask = new Energie(this); // Euphyllia verifier.reportMismatches(ImmutableList.of(World.class, CommandManager.class, EditSession.class, Actor.class)); WorldEdit.getInstance().getEventBus().post(new PlatformsRegisteredEvent()); @@ -321,7 +324,8 @@ public void onDisable() { if (config != null) { config.unload(); } - this.getServer().getScheduler().cancelTasks(this); + getEnergieTask().getScheduler(Energie.SchedulerSoft.MINECRAFT).cancelAllTask(); + getEnergieTask().getScheduler(Energie.SchedulerSoft.NATIVE).cancelAllTask(); } /** @@ -569,4 +573,10 @@ public void onAsyncTabComplete(com.destroystokyo.paper.event.server.AsyncTabComp event.setHandled(true); } } + + // Euphyllia start + public static Energie getEnergieTask() { + return energieTask; + } + // Euphyllia end } diff --git a/worldedit-bukkit/src/main/resources/plugin.yml b/worldedit-bukkit/src/main/resources/plugin.yml index aa19044bb0..ec7574ab7a 100644 --- a/worldedit-bukkit/src/main/resources/plugin.yml +++ b/worldedit-bukkit/src/main/resources/plugin.yml @@ -5,4 +5,5 @@ load: STARTUP api-version: 1.13 softdepend: [Vault] author: EngineHub -website: https://enginehub.org/worldedit \ No newline at end of file +website: https://enginehub.org/worldedit +folia-supported: true \ No newline at end of file