From 4d717a77b7ceaad803c3b9eaa2d9660c01c8a68d Mon Sep 17 00:00:00 2001 From: Warrior <50800980+Warriorrrr@users.noreply.github.com> Date: Thu, 14 Jan 2021 18:08:56 +0100 Subject: [PATCH] Fix setCaptured and setPlundered. --- .../command/SiegeWarAdminCommand.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/command/SiegeWarAdminCommand.java b/src/main/java/com/gmail/goosius/siegewar/command/SiegeWarAdminCommand.java index a1b5c4f64..88689ed89 100644 --- a/src/main/java/com/gmail/goosius/siegewar/command/SiegeWarAdminCommand.java +++ b/src/main/java/com/gmail/goosius/siegewar/command/SiegeWarAdminCommand.java @@ -33,8 +33,8 @@ public class SiegeWarAdminCommand implements CommandExecutor, TabCompleter { private static final List siegewaradminTabCompletes = Arrays.asList("immunity","reload","siege","town"); private static final List siegewaradminImmunityTabCompletes = Arrays.asList("town","nation","alltowns"); - private static final List siegewaradminSiegeTabCompletes = Arrays.asList("setpoints","end"); - private static final List siegewaradminTownTabCompletes = Arrays.asList("setcaptured","setplundered"); + private static final List siegewaradminSiegeTabCompletes = Arrays.asList("setpoints","end","setplundered"); + private static final List siegewaradminTownTabCompletes = Arrays.asList("setcaptured"); public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { @@ -68,6 +68,8 @@ public List onTabComplete(CommandSender sender, Command command, String if (args.length == 4 ) { if (args[2].equalsIgnoreCase("addcontrol") || args[2].equalsIgnoreCase("removecontrol")) return getTownyStartingWith(args[3], "r"); + if (args[2].equalsIgnoreCase("setplundered")) + return Arrays.asList("true","false"); } case "town": if (args.length == 2) @@ -77,7 +79,7 @@ public List onTabComplete(CommandSender sender, Command command, String return NameUtil.filterByStart(siegewaradminTownTabCompletes, args[2]); if (args.length == 4) - if (args[2].equalsIgnoreCase("setcaptured") || args[2].equalsIgnoreCase("setplundered")) + if (args[2].equalsIgnoreCase("setcaptured")) return Arrays.asList("true","false"); default: if (args.length == 1) @@ -232,10 +234,14 @@ private void parseSiegeWarSiegeCommand(CommandSender sender, String[] args) { Messaging.sendErrorMsg(sender, Translation.of("msg_err_town_not_registered", args[0])); return; } - if (!SiegeController.hasActiveSiege(town)) { + if (!SiegeController.hasActiveSiege(town) && !args[1].equalsIgnoreCase("setplundered")) { Messaging.sendErrorMsg(sender, Translation.of("msg_err_not_being_sieged", town.getName())); return; } + if (!SiegeController.hasSiege(town) && args[1].equalsIgnoreCase("setplundered")) { + Messaging.sendErrorMsg(sender, Translation.of("msg_err_not_being_sieged", town.getName())); + return; + } switch(args[1].toLowerCase()) { case "setpoints": @@ -261,6 +267,12 @@ private void parseSiegeWarSiegeCommand(CommandSender sender, String[] args) { else AttackerWin.attackerWin(siege, siege.getAttackingNation()); return; + case "setplundered": + Boolean plundered = Boolean.parseBoolean(args[2]); + siege.setTownPlundered(plundered); + SiegeController.saveSiege(siege); + Messaging.sendMsg(sender, Translation.of("msg_swa_set_plunder_success", plundered.toString().toUpperCase(), town.getName())); + return; } } else @@ -280,22 +292,15 @@ private void parseSiegeWarTownCommand(CommandSender sender, String[] args) { } switch (args[1].toLowerCase()) { - case "setplundered": { - Boolean plundered = Boolean.parseBoolean(args[2]); - Siege siege = SiegeController.getSiege(town); - siege.setTownPlundered(plundered); - SiegeController.saveSiege(siege); - Messaging.sendMsg(sender, Translation.of("msg_swa_set_plundered_success", plundered.toString().toUpperCase(), town.getName())); - return; - } case "setcaptured": { Boolean captured = Boolean.parseBoolean(args[2]); town.setConquered(captured); - if (SiegeController.hasActiveSiege(town)) { + if (SiegeController.hasSiege(town)) { Siege siege = SiegeController.getSiege(town); siege.setTownInvaded(captured); SiegeController.saveSiege(siege); } + TownyUniverse.getInstance().getDataSource().saveTown(town); Messaging.sendMsg(sender, Translation.of("msg_swa_set_captured_success", captured.toString().toUpperCase(), town.getName())); return; }