Fix for HotDropWorldSVC.java not working

This commit is contained in:
RePixelatedMC
2023-11-17 12:17:46 +01:00
parent 15a90edb03
commit 74e87a7fae
@@ -5,6 +5,10 @@ import static java.nio.file.StandardWatchEventKinds.*;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; 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.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
@@ -16,20 +20,21 @@ import com.volmit.iris.util.scheduling.Looper;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class HotDropWorldSVC extends Looper implements IrisService { public class HotDropWorldSVC implements IrisService {
private WatchService watchService; private WatchService watchService;
private JavaPlugin plugin; private JavaPlugin plugin;
public Looper ticker;
@Override @Override
public void onEnable() { public void onEnable() {
this.plugin = Iris.instance; // Assuming Iris.instance is your plugin instance Iris.info("hotDropSVC");
this.plugin = Iris.instance;
initializeWatchService(); initializeWatchService();
} }
@Override @Override
public void onDisable() { public void onDisable() {
ticker.interrupt();
} }
private void initializeWatchService() { private void initializeWatchService() {
@@ -37,12 +42,17 @@ public class HotDropWorldSVC extends Looper implements IrisService {
this.watchService = FileSystems.getDefault().newWatchService(); this.watchService = FileSystems.getDefault().newWatchService();
Path path = Paths.get(Bukkit.getWorldContainer().getAbsolutePath()); Path path = Paths.get(Bukkit.getWorldContainer().getAbsolutePath());
path.register(watchService, ENTRY_CREATE); path.register(watchService, ENTRY_CREATE);
this.startLoop();
ticker.start();
} catch (Exception e) { } catch (Exception e) {
Iris.reportError(e); Iris.reportError(e);
e.printStackTrace(); e.printStackTrace();
} }
} }
public void startLoop() {
final JavaPlugin finalPlugin = this.plugin;
ticker = new Looper() {
@Override @Override
protected long loop() { protected long loop() {
WatchKey key; WatchKey key;
@@ -64,7 +74,7 @@ public class HotDropWorldSVC extends Looper implements IrisService {
String version = getVersionFromIrisFolder(irisFolder); String version = getVersionFromIrisFolder(irisFolder);
if (Bukkit.getWorld(worldName) == null && isPackValid(worldName, version)) { if (Bukkit.getWorld(worldName) == null && isPackValid(worldName, version)) {
Bukkit.getScheduler().runTask(this.plugin, () -> WorldHandlerSFG.LoadWorld(worldName)); Bukkit.getScheduler().runTask(finalPlugin, () -> WorldHandlerSFG.LoadWorld(worldName));
} }
} }
} }
@@ -79,6 +89,8 @@ public class HotDropWorldSVC extends Looper implements IrisService {
return 1000; return 1000;
} }
};
}
private String getVersionFromIrisFolder(File irisFolder) { private String getVersionFromIrisFolder(File irisFolder) {
File versionFile = new File(irisFolder, "some_version_file.json"); File versionFile = new File(irisFolder, "some_version_file.json");