diff --git a/src/main/java/com/graywolf336/jail/JailIO.java b/src/main/java/com/graywolf336/jail/JailIO.java index 706a7db..6097757 100644 --- a/src/main/java/com/graywolf336/jail/JailIO.java +++ b/src/main/java/com/graywolf336/jail/JailIO.java @@ -405,4 +405,26 @@ public class JailIO { break; } } + + /** + * Removes a jail from the storage system. + * + * @param name of the jail to remove. + */ + public void removeJail(String name) { + switch(storage) { + case 1: + case 2: + break; + default: + flat.set("jails." + name, null); + + try { + flat.save(new File(pl.getDataFolder(), "data.yml")); + } catch (IOException e) { + pl.getLogger().severe("Unable to remove the jail " + name + " from the storage: " + e.getMessage()); + } + break; + } + } } diff --git a/src/main/java/com/graywolf336/jail/JailManager.java b/src/main/java/com/graywolf336/jail/JailManager.java index 2018e84..25bdeff 100644 --- a/src/main/java/com/graywolf336/jail/JailManager.java +++ b/src/main/java/com/graywolf336/jail/JailManager.java @@ -73,6 +73,16 @@ public class JailManager { if(n) plugin.getJailIO().saveJail(jail); } + /** + * Removes a {@link Jail}. + * + * @param name of the jail to remove + */ + public void removeJail(String name) { + this.jails.remove(name); + plugin.getJailIO().removeJail(name); + } + /** * Gets a jail by the given name. * diff --git a/src/main/java/com/graywolf336/jail/command/JailHandler.java b/src/main/java/com/graywolf336/jail/command/JailHandler.java index bc694b7..9434e42 100644 --- a/src/main/java/com/graywolf336/jail/command/JailHandler.java +++ b/src/main/java/com/graywolf336/jail/command/JailHandler.java @@ -18,6 +18,7 @@ import com.graywolf336.jail.command.subcommands.JailCommand; import com.graywolf336.jail.command.subcommands.JailCreateCommand; import com.graywolf336.jail.command.subcommands.JailDeleteCellCommand; import com.graywolf336.jail.command.subcommands.JailDeleteCellsCommand; +import com.graywolf336.jail.command.subcommands.JailDeleteCommand; import com.graywolf336.jail.command.subcommands.JailListCellsCommand; import com.graywolf336.jail.command.subcommands.JailListCommand; import com.graywolf336.jail.command.subcommands.JailMuteCommand; @@ -172,6 +173,7 @@ public class JailHandler { load(JailCreateCommand.class); load(JailDeleteCellCommand.class); load(JailDeleteCellsCommand.class); + load(JailDeleteCommand.class); load(JailListCellsCommand.class); load(JailListCommand.class); load(JailMuteCommand.class); diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailDeleteCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailDeleteCommand.java new file mode 100644 index 0000000..860b803 --- /dev/null +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailDeleteCommand.java @@ -0,0 +1,38 @@ +package com.graywolf336.jail.command.subcommands; + +import org.bukkit.command.CommandSender; + +import com.graywolf336.jail.JailManager; +import com.graywolf336.jail.command.Command; +import com.graywolf336.jail.command.CommandInfo; +import com.graywolf336.jail.enums.LangString; + +@CommandInfo( + maxArgs = 1, + minimumArgs = 1, + needsPlayer = false, + pattern = "delete|d", + permission = "jail.command.jaildelete", + usage = "/jail delete " + ) +public class JailDeleteCommand implements Command { + public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception { + //Check if the jail name provided is a valid jail + if(jm.isValidJail(args[1])) { + //check if the jail doesn't contain prisoners + if(jm.getJail(args[1]).getAllPrisoners().size() == 0) { + //There are no prisoners, so we can delete it + jm.removeJail(args[1]); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILREMOVED, args[1])); + }else { + //The jail has prisoners, they need to release them first + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILREMOVALUNSUCCESSFUL, args[1])); + } + }else { + //No jail found by the provided name + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1])); + } + + return true; + } +} diff --git a/src/main/java/com/graywolf336/jail/enums/LangString.java b/src/main/java/com/graywolf336/jail/enums/LangString.java index 77aa961..212a214 100644 --- a/src/main/java/com/graywolf336/jail/enums/LangString.java +++ b/src/main/java/com/graywolf336/jail/enums/LangString.java @@ -114,6 +114,8 @@ public enum LangString { CELLREMOVED ("general"), /** The simple word jailing to be put in other parts. */ JAILING ("jailing"), + /** THe message sent to the sender when they try to remove a jail but there are still prisoners in there. */ + JAILREMOVALUNSUCCESSFUL ("general"), /** The message sent whenever a jail is successfully removed. */ JAILREMOVED ("general"), /** Message sent when doing something that requires a cell but the given name of a cell doesn't exist. */ diff --git a/src/main/resources/en.yml b/src/main/resources/en.yml index fba1ffc..c30e4b2 100644 --- a/src/main/resources/en.yml +++ b/src/main/resources/en.yml @@ -12,6 +12,7 @@ language: cellremovalunsuccessful: '&cThe removal of cell %0% from jail %1% was unsuccessful because there is a prisoner in there still. Release or transfer before trying to remove the cell again.' cellremoved: '&9Cell %0% has been successfully removed from the jail %1%.' jailing: '&9jailing' + jailremovalunsuccessful: '&cThe removal of the jail %0% was unsuccessful because there are prisoners in there, please release or transfer them first.' jailremoved: '&9Jail %0% has been successfully removed.' nocell: '&cNo cell found by the name of %0% in the jail %1%.' nocells: '&cNo cells found in the jail %0%.'