diff --git a/core/src/main/java/com/volmit/iris/core/service/HotDropWorldSVC.java b/core/src/main/java/com/volmit/iris/core/service/HotDropWorldSVC.java index 88bab482b..c16ea949a 100644 --- a/core/src/main/java/com/volmit/iris/core/service/HotDropWorldSVC.java +++ b/core/src/main/java/com/volmit/iris/core/service/HotDropWorldSVC.java @@ -5,6 +5,10 @@ import static java.nio.file.StandardWatchEventKinds.*; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonParseException; @@ -16,20 +20,21 @@ import com.volmit.iris.util.scheduling.Looper; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; -public class HotDropWorldSVC extends Looper implements IrisService { +public class HotDropWorldSVC implements IrisService { private WatchService watchService; private JavaPlugin plugin; + public Looper ticker; @Override public void onEnable() { - this.plugin = Iris.instance; // Assuming Iris.instance is your plugin instance + Iris.info("hotDropSVC"); + this.plugin = Iris.instance; initializeWatchService(); - } @Override public void onDisable() { - + ticker.interrupt(); } private void initializeWatchService() { @@ -37,47 +42,54 @@ public class HotDropWorldSVC extends Looper implements IrisService { this.watchService = FileSystems.getDefault().newWatchService(); Path path = Paths.get(Bukkit.getWorldContainer().getAbsolutePath()); path.register(watchService, ENTRY_CREATE); + this.startLoop(); + ticker.start(); } catch (Exception e) { Iris.reportError(e); e.printStackTrace(); } } - @Override - protected long loop() { - WatchKey key; - try { - key = watchService.poll(); - if (key != null) { - for (WatchEvent event : key.pollEvents()) { - WatchEvent.Kind kind = event.kind(); + public void startLoop() { + final JavaPlugin finalPlugin = this.plugin; + ticker = new Looper() { + @Override + protected long loop() { + WatchKey key; + try { + key = watchService.poll(); + if (key != null) { + for (WatchEvent event : key.pollEvents()) { + WatchEvent.Kind kind = event.kind(); - if (kind == ENTRY_CREATE) { - WatchEvent ev = (WatchEvent) event; - Path filename = ev.context(); + if (kind == ENTRY_CREATE) { + WatchEvent ev = (WatchEvent) event; + Path filename = ev.context(); - File newDir = new File(Bukkit.getWorldContainer(), filename.toString()); - File irisFolder = new File(newDir, "iris"); - if (irisFolder.exists() && irisFolder.isDirectory()) { - Iris.info("World HotDrop Detected!"); - String worldName = newDir.getName(); - String version = getVersionFromIrisFolder(irisFolder); + File newDir = new File(Bukkit.getWorldContainer(), filename.toString()); + File irisFolder = new File(newDir, "iris"); + if (irisFolder.exists() && irisFolder.isDirectory()) { + Iris.info("World HotDrop Detected!"); + String worldName = newDir.getName(); + String version = getVersionFromIrisFolder(irisFolder); - if (Bukkit.getWorld(worldName) == null && isPackValid(worldName, version)) { - Bukkit.getScheduler().runTask(this.plugin, () -> WorldHandlerSFG.LoadWorld(worldName)); + if (Bukkit.getWorld(worldName) == null && isPackValid(worldName, version)) { + Bukkit.getScheduler().runTask(finalPlugin, () -> WorldHandlerSFG.LoadWorld(worldName)); + } + } } } + key.reset(); } + } catch (Throwable e) { + Iris.reportError(e); + e.printStackTrace(); + return -1; } - key.reset(); - } - } catch (Throwable e) { - Iris.reportError(e); - e.printStackTrace(); - return -1; - } - return 1000; + return 1000; + } + }; } private String getVersionFromIrisFolder(File irisFolder) {