diff --git a/bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapBukkit.java b/bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapBukkit.java index 8328dc6e8..8083130b9 100644 --- a/bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapBukkit.java +++ b/bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapBukkit.java @@ -25,13 +25,13 @@ import java.util.UUID; import net.pl3x.map.bukkit.command.BukkitCommandManager; +import net.pl3x.map.bukkit.util.SchedulerUtil; import net.pl3x.map.core.Pl3xMap; import net.pl3x.map.core.event.server.ServerLoadedEvent; import net.pl3x.map.core.network.Network; import net.pl3x.map.core.player.Player; import net.pl3x.map.core.player.PlayerListener; import net.pl3x.map.core.player.PlayerRegistry; -import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.event.EventHandler; @@ -59,12 +59,6 @@ public Pl3xMapBukkit() { @Override public void onEnable() { - try { - Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); - isFolia = true; - } catch (ClassNotFoundException ignored) { - } - this.pl3xmap.enable(); getServer().getPluginManager().registerEvents(this, this); @@ -78,13 +72,7 @@ public void onEnable() { throw new RuntimeException(e); } - if (isFolia) { - Bukkit.getGlobalRegionScheduler().runAtFixedRate(this, timerTask -> - this.pl3xmap.getScheduler().tick(), 20, 1); - } else { - getServer().getScheduler().runTaskTimer(this, () -> - this.pl3xmap.getScheduler().tick(), 20, 1); - } + SchedulerUtil.runTaskTimer(this, this.pl3xmap.getScheduler(), this.getServer().getScheduler()); } @Override diff --git a/bukkit/src/main/java/net/pl3x/map/bukkit/util/SchedulerUtil.java b/bukkit/src/main/java/net/pl3x/map/bukkit/util/SchedulerUtil.java new file mode 100644 index 000000000..0f972e950 --- /dev/null +++ b/bukkit/src/main/java/net/pl3x/map/bukkit/util/SchedulerUtil.java @@ -0,0 +1,28 @@ +package net.pl3x.map.bukkit.util; + +import net.pl3x.map.core.scheduler.Scheduler; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitScheduler; + +public class SchedulerUtil { + private static boolean IS_FOLIA = false; + + static { + try { + Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); + IS_FOLIA = true; + } catch (ClassNotFoundException ignored) { + } + } + + public static void runTaskTimer(Plugin plugin, Scheduler scheduler, BukkitScheduler bukkitScheduler) { + if (IS_FOLIA) { + Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, timerTask -> + scheduler.tick(), 20, 1); + } else { + bukkitScheduler.runTaskTimer(plugin, () -> + scheduler.tick(), 20, 1); + } + } +}