Skip to content

Commit

Permalink
Add permanent option to /swa revoltimmunity command.
Browse files Browse the repository at this point in the history
Closes #322.
  • Loading branch information
LlmDl committed Nov 23, 2021
1 parent 5cdad31 commit a7b6e92
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
case "nation":
return getTownyStartingWith(args[2], "n");
case "alltowns":
return Arrays.asList("0","1","2","3","4","5","6");
return Arrays.asList("0","1","2","3","4","5","6","permanent");
}
}

if (args.length == 4) {
if (args[1].equalsIgnoreCase("town") || args[1].equalsIgnoreCase("nation"))
return Arrays.asList("0","1","2","3","4","5","6");
return Arrays.asList("0","1","2","3","4","5","6","permanent");
}
case "siege":
if (args.length == 2)
Expand Down Expand Up @@ -483,27 +483,34 @@ private void parseSiegeWarRevoltImmunityCommand(CommandSender sender, String[] a
}

try {
if (args[0].equalsIgnoreCase("alltowns"))
if (args[0].equalsIgnoreCase("alltowns") && !args[1].equalsIgnoreCase("permanent"))
Integer.parseInt(args[1]);
else
else if (!args[0].equalsIgnoreCase("alltowns") && !args[2].equalsIgnoreCase("permanent"))
Integer.parseInt(args[2]);
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
Messaging.sendMsg(sender, Translation.of("msg_error_must_be_num"));
showRevoltImmunityHelp(sender);
return;
}

String timeDuration;
if (args.length >= 3 && args[0].equalsIgnoreCase("town")) {
//town {townname} {hours}
Town town = TownyUniverse.getInstance().getTown(args[1]);
if (town == null) {
Messaging.sendErrorMsg(sender, Translation.of("msg_err_not_registered_1", args[1]));
return;
}
long durationMillis = (long)(Long.parseLong(args[2]) * TimeMgmt.ONE_HOUR_IN_MILLIS);
TownMetaDataController.setRevoltImmunityEndTime(town, System.currentTimeMillis() + durationMillis);
TownyMessaging.sendPrefixedTownMessage(town, Translation.of("msg_set_revolt_immunities_town", args[1], args[2]));
Messaging.sendMsg(sender, Translation.of("msg_set_revolt_immunities_town", args[1], args[2]));

if (args[2].equalsIgnoreCase("permanent")) {
TownMetaDataController.setRevoltImmunityEndTime(town, -1L);
timeDuration = Translation.of("msg_permanent");
} else {
TownMetaDataController.setRevoltImmunityEndTime(town, System.currentTimeMillis() + (long)(Long.parseLong(args[2]) * TimeMgmt.ONE_HOUR_IN_MILLIS));
timeDuration = Long.parseLong(args[2]) + com.palmergames.bukkit.towny.object.Translation.of("msg_hours");
}
TownyMessaging.sendPrefixedTownMessage(town, Translation.of("msg_set_revolt_immunities_town", town, timeDuration));
Messaging.sendMsg(sender, Translation.of("msg_set_revolt_immunities_town", town, timeDuration));

} else if (args.length >= 3 && args[0].equalsIgnoreCase("nation")) {
//nation {nationname} {hours}
Expand All @@ -512,20 +519,35 @@ private void parseSiegeWarRevoltImmunityCommand(CommandSender sender, String[] a
Messaging.sendErrorMsg(sender, Translation.of("msg_err_not_registered_1", args[1]));
return;
}
long durationMillis = (long)(Long.parseLong(args[2]) * TimeMgmt.ONE_HOUR_IN_MILLIS);
long endTime;
if (args[2].equalsIgnoreCase("permanent")) {
endTime = -1l;
timeDuration = Translation.of("msg_permanent");
} else {
endTime = System.currentTimeMillis() + (long)(Long.parseLong(args[2]) * TimeMgmt.ONE_HOUR_IN_MILLIS);
timeDuration = Long.parseLong(args[2]) + com.palmergames.bukkit.towny.object.Translation.of("msg_hours");
}

for (Town town : nation.getTowns()) {
TownMetaDataController.setRevoltImmunityEndTime(town, System.currentTimeMillis() + durationMillis);
TownMetaDataController.setRevoltImmunityEndTime(town, endTime);
}
TownyMessaging.sendPrefixedNationMessage(nation, Translation.of("msg_set_revolt_immunities_nation", args[1], args[2]));
Messaging.sendMsg(sender, Translation.of("msg_set_revolt_immunities_nation", args[1], args[2]));
TownyMessaging.sendPrefixedNationMessage(nation, Translation.of("msg_set_revolt_immunities_nation", nation, timeDuration));
Messaging.sendMsg(sender, Translation.of("msg_set_revolt_immunities_nation", nation, timeDuration));

} else if (args[0].equalsIgnoreCase("alltowns")) {
//all towns
long durationMillis = (long)(Long.parseLong(args[1]) * TimeMgmt.ONE_HOUR_IN_MILLIS);
long endTime;
if (args[1].equalsIgnoreCase("permanent")) {
endTime = -1l;
timeDuration = Translation.of("msg_permanent");
} else {
endTime = System.currentTimeMillis() + (long)(Long.parseLong(args[1]) * TimeMgmt.ONE_HOUR_IN_MILLIS);
timeDuration = Long.parseLong(args[1]) + com.palmergames.bukkit.towny.object.Translation.of("msg_hours");
}
for (Town town : new ArrayList<>(TownyUniverse.getInstance().getTowns())) {
TownMetaDataController.setRevoltImmunityEndTime(town, System.currentTimeMillis() + durationMillis);
TownMetaDataController.setRevoltImmunityEndTime(town, endTime);
}
Messaging.sendGlobalMessage(Translation.of("msg_set_revolt_immunities_all", args[1]));
Messaging.sendGlobalMessage(Translation.of("msg_set_revolt_immunities_all", timeDuration));

} else {
showRevoltImmunityHelp(sender);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,13 @@ public void onTownStatusScreen(TownStatusScreenEvent event) {
}

//Revolt Immunity Timer: 71.8 hours
if (SiegeWarSettings.getRevoltSiegesEnabled() && System.currentTimeMillis() < TownMetaDataController.getRevoltImmunityEndTime(town)) {
String time = TimeMgmt.getFormattedTimeValue(TownMetaDataController.getRevoltImmunityEndTime(town)- System.currentTimeMillis());
long immunity = TownMetaDataController.getRevoltImmunityEndTime(town);
if (SiegeWarSettings.getRevoltSiegesEnabled() && immunity == -1l || System.currentTimeMillis() < immunity) {
String time = immunity == -1l ? Translation.of("msg_permanent") : TimeMgmt.getFormattedTimeValue(immunity- System.currentTimeMillis());
out.add(Translation.of("status_town_revolt_immunity_timer", time));
}

long immunity = TownMetaDataController.getSiegeImmunityEndTime(town);
immunity = TownMetaDataController.getSiegeImmunityEndTime(town);
if (SiegeController.hasSiege(town)) {
Siege siege = SiegeController.getSiege(town);
SiegeStatus siegeStatus= siege.getStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public static void processStartSiegeRequest(Player player,
if(!TownOccupationController.isTownOccupied(targetTown))
throw new TownyException(Translation.of("msg_err_cannot_start_revolt_siege_as_town_is_unoccupied"));

if (System.currentTimeMillis() < TownMetaDataController.getRevoltImmunityEndTime(targetTown))
long immunity = TownMetaDataController.getRevoltImmunityEndTime(targetTown);
if (immunity == -1L)
throw new TownyException(Translation.of("msg_err_siege_war_revolt_immunity_permanent"));
if (System.currentTimeMillis() < immunity)
throw new TownyException(Translation.of("msg_err_siege_war_revolt_immunity_active"));

Nation occupierNation = TownOccupationController.getTownOccupier(targetTown);
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,6 @@ msg_err_siegecamp_too_close_to_another_siegecamp: 'SiegeCamp too lose to another
msg_err_too_soon_since_your_last_siegecamp: 'It has been too soon since you last tried to make a SiegeCamp on this town!'
msg_err_your_siegecamp_failed_you_must_wait_x: 'Your SiegeCamp failed to score enough points, you may not attempt another siege for %s.'
attackers_scored_points_towards_siege_camp_x_of_x: '%s has scored points towards their SiegeCamp session: %s/%s.'
attacker_has_begun_a_siegecamp_session: '%s has begun a SiegeCamp session against %s. If successful a Siege will begin! The attackers must score %s points within %s minutes.'
attacker_has_begun_a_siegecamp_session: '%s has begun a SiegeCamp session against %s. If successful a Siege will begin! The attackers must score %s points within %s minutes.'

msg_err_siege_war_revolt_immunity_permanent: "&cYour town has permanent revolt immunity. It cannot revolt."
4 changes: 3 additions & 1 deletion src/main/resources/french.yml
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,6 @@ msg_err_siegecamp_too_close_to_another_siegecamp: 'SiegeCamp too lose to another
msg_err_too_soon_since_your_last_siegecamp: 'It has been too soon since you last tried to make a SiegeCamp on this town!'
msg_err_your_siegecamp_failed_you_must_wait_x: 'Your SiegeCamp failed to score enough points, you may not attempt another siege for %s.'
attackers_scored_points_towards_siege_camp_x_of_x: '%s has scored points towards their SiegeCamp session: %s/%s.'
attacker_has_begun_a_siegecamp_session: '%s has begun a SiegeCamp session against %s. If successful a Siege will begin! The attackers must score %s points within %s minutes.'
attacker_has_begun_a_siegecamp_session: '%s has begun a SiegeCamp session against %s. If successful a Siege will begin! The attackers must score %s points within %s minutes.'

msg_err_siege_war_revolt_immunity_permanent: "&cYour town has permanent revolt immunity. It cannot revolt."

0 comments on commit a7b6e92

Please sign in to comment.