From 50044816859659c10394bc29504505ff62f387b3 Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Sat, 4 Nov 2023 20:04:05 +0100 Subject: [PATCH] - Fixed /iris remove for real this time lol - Changed it back to /iris instead of /iris worldmanager for easier access --- .../iris/core/commands/CommandIris.java | 66 +++++++++++++++++++ .../core/commands/CommandWorldManager.java | 45 ------------- .../com/volmit/iris/core/service/EditSVC.java | 4 +- 3 files changed, 69 insertions(+), 46 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/core/commands/CommandIris.java b/core/src/main/java/com/volmit/iris/core/commands/CommandIris.java index daba86596..dc9e2df82 100644 --- a/core/src/main/java/com/volmit/iris/core/commands/CommandIris.java +++ b/core/src/main/java/com/volmit/iris/core/commands/CommandIris.java @@ -22,9 +22,11 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisBenchmarking; +import com.volmit.iris.core.tools.IrisCreator; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.IrisDimension; +import com.volmit.iris.engine.object.IrisWorld; import com.volmit.iris.engine.platform.PlatformChunkGenerator; import com.volmit.iris.engine.safeguard.UtilsSFG; import com.volmit.iris.util.collection.KList; @@ -36,6 +38,7 @@ import com.volmit.iris.util.decree.annotations.Param; import com.volmit.iris.util.decree.specialhandlers.NullablePlayerHandler; import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.Form; +import com.volmit.iris.util.mantle.MantleChunk; import com.volmit.iris.util.parallel.BurstExecutor; import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.plugin.VolmitSender; @@ -49,9 +52,11 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import java.io.File; +import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import static com.volmit.iris.core.service.EditSVC.deletingWorld; import static com.volmit.iris.core.tools.IrisBenchmarking.inProgress; import static com.volmit.iris.engine.safeguard.IrisSafeguard.unstablemode; import static com.volmit.iris.engine.safeguard.ServerBootSFG.incompatiblePlugins; @@ -211,6 +216,67 @@ public class CommandIris implements DecreeExecutor { Iris.service(StudioSVC.class).open(sender(), 1337, "overworld"); } + @Decree(description = "Remove an Iris world", aliases = {"del", "rm", "delete"}, sync = true) + public void remove( + @Param(description = "The world to remove") + World world, + @Param(description = "Whether to also remove the folder (if set to false, just does not load the world)", defaultValue = "true") + boolean delete + ) { + if (!IrisToolbelt.isIrisWorld(world)) { + sender().sendMessage(C.RED + "This is not an Iris world. Iris worlds: " + String.join(", ", Bukkit.getServer().getWorlds().stream().filter(IrisToolbelt::isIrisWorld).map(World::getName).toList())); + return; + } + sender().sendMessage(C.GREEN + "Removing world: " + world.getName()); + try { + if (IrisToolbelt.removeWorld(world)) { + sender().sendMessage(C.GREEN + "Successfully removed " + world.getName() + " from bukkit.yml"); + } else { + sender().sendMessage(C.YELLOW + "Looks like the world was already removed from bukkit.yml"); + } + } catch (IOException e) { + sender().sendMessage(C.RED + "Failed to save bukkit.yml because of " + e.getMessage()); + e.printStackTrace(); + } + IrisToolbelt.evacuate(world, "Deleting world"); + deletingWorld = true; + Bukkit.unloadWorld(world, false); + int retries = 10; + if (delete) { + if (deleteDirectory(world.getWorldFolder())) { + sender().sendMessage(C.GREEN + "Successfully removed world folder"); + } else { + while(true){ + if (deleteDirectory(world.getWorldFolder())){ + sender().sendMessage(C.GREEN + "Successfully removed world folder"); + break; + } + sender().sendMessage(C.GREEN + "DEBUG1"); + retries--; + if (retries == 0){ + sender().sendMessage(C.RED + "Failed to remove world folder"); + break; + } + J.sleep(2000); + } + } + } + deletingWorld = false; + } + + public static boolean deleteDirectory(File dir) { + if (dir.isDirectory()) { + File[] children = dir.listFiles(); + for (int i = 0; i < children.length; i++) { + boolean success = deleteDirectory(children[i]); + if (!success) { + return false; + } + } + } + return dir.delete(); + } + @Decree(description = "Set aura spins") public void aura( @Param(description = "The h color value", defaultValue = "-20") diff --git a/core/src/main/java/com/volmit/iris/core/commands/CommandWorldManager.java b/core/src/main/java/com/volmit/iris/core/commands/CommandWorldManager.java index 7fd039764..1f82ea3d9 100644 --- a/core/src/main/java/com/volmit/iris/core/commands/CommandWorldManager.java +++ b/core/src/main/java/com/volmit/iris/core/commands/CommandWorldManager.java @@ -147,51 +147,6 @@ public class CommandWorldManager implements DecreeExecutor { sender().sendMessage(C.GREEN + "Evacuating world" + world.getName()); IrisToolbelt.evacuate(world); } - @Decree(description = "Remove an Iris world", aliases = {"del", "rm", "delete"}, sync = true) - public void remove( - @Param(description = "The world to remove") - World world, - @Param(description = "Whether to also remove the folder (if set to false, just does not load the world)", defaultValue = "true") - boolean delete - ) { - if (!IrisToolbelt.isIrisWorld(world)) { - sender().sendMessage(C.RED + "This is not an Iris world. Iris worlds: " + String.join(", ", Bukkit.getServer().getWorlds().stream().filter(IrisToolbelt::isIrisWorld).map(World::getName).toList())); - return; - } - sender().sendMessage(C.GREEN + "Removing world: " + world.getName()); - try { - if (IrisToolbelt.removeWorld(world)) { - sender().sendMessage(C.GREEN + "Successfully removed " + world.getName() + " from bukkit.yml"); - } else { - sender().sendMessage(C.YELLOW + "Looks like the world was already removed from bukkit.yml"); - } - } catch (IOException e) { - sender().sendMessage(C.RED + "Failed to save bukkit.yml because of " + e.getMessage()); - e.printStackTrace(); - } - IrisToolbelt.evacuate(world, "Deleting world"); - Bukkit.unloadWorld(world, false); - if (delete) { - if (deleteDirectory(world.getWorldFolder())) { - sender().sendMessage(C.GREEN + "Successfully removed world folder"); - } else { - sender().sendMessage(C.RED + "Failed to remove world folder"); - } - } - - } - public static boolean deleteDirectory(File dir) { - if (dir.isDirectory()) { - File[] children = dir.listFiles(); - for (int i = 0; i < children.length; i++) { - boolean success = deleteDirectory(children[i]); - if (!success) { - return false; - } - } - } - return dir.delete(); - } boolean doesWorldExist(String worldName) { File worldContainer = Bukkit.getWorldContainer(); diff --git a/core/src/main/java/com/volmit/iris/core/service/EditSVC.java b/core/src/main/java/com/volmit/iris/core/service/EditSVC.java index 834b1712a..dc944f1f2 100644 --- a/core/src/main/java/com/volmit/iris/core/service/EditSVC.java +++ b/core/src/main/java/com/volmit/iris/core/service/EditSVC.java @@ -33,6 +33,7 @@ import org.bukkit.event.world.WorldUnloadEvent; public class EditSVC implements IrisService { private KMap editors; + public static boolean deletingWorld = false; @Override public void onEnable() { @@ -71,11 +72,12 @@ public class EditSVC implements IrisService { @EventHandler public void on(WorldUnloadEvent e) { - if (editors.containsKey(e.getWorld())) { + if (editors.containsKey(e.getWorld()) && !deletingWorld) { editors.remove(e.getWorld()).close(); } } + public void update() { for (World i : editors.k()) { if (M.ms() - editors.get(i).last() > 1000) {