Skip to content

Commit

Permalink
- PR #11, courtesy of Warriorrr.
Browse files Browse the repository at this point in the history
    - Bumps language file to 0.04.
    - Reduces global message spam surrounding peaceful towns.
    - Fix a possible exception when /sw is run with no args.
  - Change command: /swa immunity all towns in nation {nationname}
{hours}
    to: /swa immunity nation {nationname} {hours}
  - Fix global message spam from /swa immunity {town|nation}
sub-commands.
  • Loading branch information
LlmDl committed Jan 7, 2021
1 parent a50f564 commit 06b4829
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.bukkit.command.Command;
Expand All @@ -27,8 +28,7 @@
public class SiegeWarAdminCommand implements CommandExecutor, TabCompleter {

private static final List<String> siegewaradminTabCompletes = Arrays.asList("immunity","reload");
private static final List<String> siegewaradminImmunityTabCompletes = Arrays.asList("town","all");
private static final List<String> siegewaradminImmunityAllTabCompletes = Arrays.asList("towns");
private static final List<String> siegewaradminImmunityTabCompletes = Arrays.asList("town","nation","all");

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

Expand All @@ -41,32 +41,26 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
switch (args[1].toLowerCase()) {
case "town":
return getTownyStartingWith(args[2], "t");
case "nation":
return getTownyStartingWith(args[2], "n");
case "all":
return NameUtil.filterByStart(siegewaradminImmunityAllTabCompletes, args[2]);
return Arrays.asList("towns");
}
}

if (args.length == 4) {
if (args[1].equalsIgnoreCase("town"))
if (args[1].equalsIgnoreCase("town") || args[1].equalsIgnoreCase("nation"))
return Arrays.asList("1","2","3","4","5","6");
if (args[1].equalsIgnoreCase("all") && args[2].equalsIgnoreCase("towns")) {
return Arrays.asList("1","2","3","4","5","6");
if (args[1].equalsIgnoreCase("all")) {
return Arrays.asList("in nation", "1","2","3","4","5","6");
}
}

if (args.length == 6) {
if (args[1].equalsIgnoreCase("all") && args[4].equalsIgnoreCase("nation")) {
return getTownyStartingWith(args[5], "n");
}
}

if (args.length == 7) {
return Arrays.asList("1","2","3","4","5","6");
}


default:
return NameUtil.filterByStart(siegewaradminTabCompletes, args[0]);
if (args.length == 1)
return NameUtil.filterByStart(siegewaradminTabCompletes, args[0]);
else
return Collections.emptyList();
}
}

Expand Down Expand Up @@ -113,10 +107,18 @@ private void showHelp(CommandSender sender) {
sender.sendMessage(ChatTools.formatTitle("/siegewaradmin"));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "reload", Translation.of("admin_help_1")));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "immunity town [town_name] [hours]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "immunity all towns in nation [nation_name] [hours]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "immunity nation [nation_name] [hours]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "immunity all towns [hours]", ""));

}

private void showImmunityHelp(CommandSender sender) {
sender.sendMessage(ChatTools.formatTitle("/swa immunity"));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa immunity", "town [town_name] [hours]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "immunity nation [nation_name] [hours]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa immunity", "all towns [hours]", ""));

}

private void parseSiegeWarReloadCommand(CommandSender sender) {
if (Settings.loadSettingsAndLang()) {
Expand All @@ -128,42 +130,52 @@ private void parseSiegeWarReloadCommand(CommandSender sender) {
}

private void parseSiegeWarImmunityCommand(CommandSender sender, String[] args) {
try {
Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
Messaging.sendMessage(sender, Translation.of("msg_error_must_be_num"));
showImmunityHelp(sender);
return;
}
long durationMillis = (long)(Long.parseLong(args[2]) * TimeMgmt.ONE_HOUR_IN_MILLIS);

if (args.length == 3 && args[0].equalsIgnoreCase("town")) {
//1 town
//town {townname} {hours}
Town town = TownyUniverse.getInstance().getTown(args[1]);
long durationMillis = (long)(Long.parseLong(args[2]) * TimeMgmt.ONE_HOUR_IN_MILLIS);
if (town == null) {
Messaging.sendErrMessage(sender, Translation.of("msg_err_not_registered_1", args[1]));
return;
}
TownMetaDataController.setSiegeImmunityEndTime(town, System.currentTimeMillis() + durationMillis);
TownyMessaging.sendGlobalMessage(Translation.of("msg_set_siege_immunities_town", args[1], args[2]));

} else if (args.length == 6
&& args[0].equalsIgnoreCase("all")
&& args[1].equalsIgnoreCase("towns")
&& args[2].equalsIgnoreCase("in")
&& args[3].equalsIgnoreCase("nation")) {
//All towns in nation
Nation nation = TownyUniverse.getInstance().getNation(args[4]);
long durationMillis = (long)(Long.parseLong(args[5]) * TimeMgmt.ONE_HOUR_IN_MILLIS);
TownyMessaging.sendPrefixedTownMessage(town, Translation.of("msg_set_siege_immunities_town", args[1], args[2]));
Messaging.sendMessage(sender, Translation.of("msg_set_siege_immunities_town", args[1], args[2]));

} else if (args.length == 3 && args[0].equalsIgnoreCase("nation")) {
//nation {nationname} {hours}
Nation nation = TownyUniverse.getInstance().getNation(args[1]);
if (nation == null) {
Messaging.sendErrMessage(sender, Translation.of("msg_err_not_registered_1", args[1]));
return;
}
for(Town town: nation.getTowns()) {
TownMetaDataController.setSiegeImmunityEndTime(town, System.currentTimeMillis() + durationMillis);
}
TownyMessaging.sendGlobalMessage(Translation.of("msg_set_siege_immunities_nation", args[4], args[5]));
TownyMessaging.sendPrefixedNationMessage(nation, Translation.of("msg_set_siege_immunities_nation", args[1], args[2]));
Messaging.sendMessage(sender, Translation.of("msg_set_siege_immunities_nation", args[1], args[2]));

} else if(args.length == 3
&& args[0].equalsIgnoreCase("all")
&& args[1].equalsIgnoreCase("towns")) {
//All towns
long durationMillis = (long)(Long.parseLong(args[2]) * TimeMgmt.ONE_HOUR_IN_MILLIS);
//all towns
for(Town town: new ArrayList<>(TownyUniverse.getInstance().getTowns())) {
TownMetaDataController.setSiegeImmunityEndTime(town, System.currentTimeMillis() + durationMillis);
}
TownyMessaging.sendGlobalMessage(Translation.of("msg_set_siege_immunities_all", args[2]));
} else {

sender.sendMessage(ChatTools.formatTitle("/swa immunity"));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa immunity", "town [town_name] [hours]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa immunity", "all towns in nation [nation_name] [hours]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa immunity", "all towns [hours]", ""));
} }
} else {
showImmunityHelp(sender);
}
}


/**
Expand Down
9 changes: 8 additions & 1 deletion src/main/resources/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@
- Fix PlayerDeaths that weren't directly caused by PVP not counting as deaths that allowed for inventories to be kept.
0.0.5:
- Fix /ta town {name} toggle neutral altering the town's neutral status but not altering the backing metadata.
- Fix Messaging class having the wrong imports.
- Fix Messaging class having the wrong imports.
- PR #11, courtesy of Warriorrr.
- Bumps language file to 0.04.
- Reduces global message spam surrounding peaceful towns.
- Fix a possible exception when /sw is run with no args.
- Change command: /swa immunity all towns in nation {nationname} {hours}
to: /swa immunity nation {nationname} {hours}
- Fix global message spam from /swa immunity {town|nation} sub-commands.
3 changes: 2 additions & 1 deletion src/main/resources/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,5 @@ status_no: '&cNO'
msg_err_no_money: '&cThere is not enough money in the bank.'

#Added in 0.04:
msg_war_siege_peaceful_town_total_switches: '&b%d peaceful town%s %s peacefully switched nations.'
msg_war_siege_peaceful_town_total_switches: '&b%d peaceful town%s %s peacefully switched nations.'
msg_err_not_registered_1: '&c%s is not registered.'

0 comments on commit 06b4829

Please sign in to comment.