Skip to content

Commit

Permalink
Merge pull request #32 from Warriorrrr/swa-fix
Browse files Browse the repository at this point in the history
Fix setCaptured and setPlundered.
  • Loading branch information
Goosius1 authored Jan 15, 2021
2 parents 723072c + 4d717a7 commit 3eb7b7d
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class SiegeWarAdminCommand implements CommandExecutor, TabCompleter {

private static final List<String> siegewaradminTabCompletes = Arrays.asList("immunity","reload","siege","town");
private static final List<String> siegewaradminImmunityTabCompletes = Arrays.asList("town","nation","alltowns");
private static final List<String> siegewaradminSiegeTabCompletes = Arrays.asList("setpoints","end");
private static final List<String> siegewaradminTownTabCompletes = Arrays.asList("setcaptured","setplundered");
private static final List<String> siegewaradminSiegeTabCompletes = Arrays.asList("setpoints","end","setplundered");
private static final List<String> siegewaradminTownTabCompletes = Arrays.asList("setcaptured");

public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {

Expand Down Expand Up @@ -68,6 +68,8 @@ public List<String> 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)
Expand All @@ -77,7 +79,7 @@ public List<String> 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)
Expand Down Expand Up @@ -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":
Expand All @@ -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
Expand All @@ -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;
}
Expand Down

0 comments on commit 3eb7b7d

Please sign in to comment.