diff --git a/src/main/java/com/volmit/iris/core/commands/CommandIris.java b/src/main/java/com/volmit/iris/core/commands/CommandIris.java index b2b5cc4ad..5e8cbae78 100644 --- a/src/main/java/com/volmit/iris/core/commands/CommandIris.java +++ b/src/main/java/com/volmit/iris/core/commands/CommandIris.java @@ -38,10 +38,12 @@ import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.jobs.QueueJob; +import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.World; import java.io.File; +import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -96,6 +98,37 @@ public class CommandIris implements DecreeExecutor { sender().sendMessage(C.GREEN + "Successfully created your world!"); } + @Decree(description = "Remove an Iris world", aliases = {"del", "rm"}, 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 && world.getWorldFolder().delete()) { + sender().sendMessage(C.GREEN + "Successfully removed world folder"); + } else { + sender().sendMessage(C.RED + "Failed to remove world folder"); + } + } + @Decree(description = "Print version information") public void version() { sender().sendMessage(C.GREEN + "Iris v" + Iris.instance.getDescription().getVersion() + " by Volmit Software"); diff --git a/src/main/java/com/volmit/iris/core/tools/IrisCreator.java b/src/main/java/com/volmit/iris/core/tools/IrisCreator.java index f6d2244f2..d4e418514 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisCreator.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisCreator.java @@ -231,4 +231,18 @@ public class IrisCreator { } } } + + public static boolean removeFromBukkitYml(String name) throws IOException { + YamlConfiguration yml = YamlConfiguration.loadConfiguration(BUKKIT_YML); + ConfigurationSection section = yml.getConfigurationSection("worlds"); + if (section == null) { + return false; + } + section.set(name, null); + if (section.getValues(false).keySet().stream().noneMatch(k -> section.get(k) != null)) { + yml.set("worlds", null); + } + yml.save(BUKKIT_YML); + return true; + } } diff --git a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java index ece0c942d..c2da5a844 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java @@ -36,6 +36,7 @@ import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import java.io.File; +import java.io.IOException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; @@ -221,7 +222,6 @@ public class IrisToolbelt { new VolmitSender(j, Iris.instance.getTag()).sendMessage("You have been evacuated from this world. " + m); j.teleport(i.getSpawnLocation()); } - return true; } } @@ -248,4 +248,8 @@ public class IrisToolbelt { if(e == null) {return;} e.getEngine().getMantle().getMantle().remove(x, y - world.getMinHeight(), z, of); } + + public static boolean removeWorld(World world) throws IOException { + return IrisCreator.removeFromBukkitYml(world.getName()); + } }