Skip to content

Commit

Permalink
fix plugin not registering properly on spigot
Browse files Browse the repository at this point in the history
  • Loading branch information
granny committed Jun 21, 2024
1 parent a5e8d19 commit e577a90
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
16 changes: 2 additions & 14 deletions bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapBukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions bukkit/src/main/java/net/pl3x/map/bukkit/util/SchedulerUtil.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit e577a90

Please sign in to comment.