diff --git a/src/main/java/net/countercraft/movecraft/warfare/features/siege/SiegeCommand.java b/src/main/java/net/countercraft/movecraft/warfare/features/siege/SiegeCommand.java index 3838a74..93a8d1e 100644 --- a/src/main/java/net/countercraft/movecraft/warfare/features/siege/SiegeCommand.java +++ b/src/main/java/net/countercraft/movecraft/warfare/features/siege/SiegeCommand.java @@ -21,6 +21,8 @@ import org.jetbrains.annotations.Nullable; import java.text.NumberFormat; +import java.time.Duration; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -63,40 +65,26 @@ else if (args[0].equalsIgnoreCase("info")) else if (args[0].equalsIgnoreCase("time")) return timeCommand(commandSender); else if (args[0].equalsIgnoreCase("cancel")) - return cancelCommand(commandSender, args); + return cancelCommand(commandSender); + else if (args[0].equalsIgnoreCase("status")) + return statusCommand(commandSender); commandSender.sendMessage( MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Siege - Invalid Argument")); return true; } - private boolean cancelCommand(CommandSender commandSender, String[] args) { + private boolean cancelCommand(CommandSender commandSender) { if (!commandSender.hasPermission("movecraft.siege.cancel")) { commandSender.sendMessage( MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions")); return true; } - if (args.length <= 1) { - commandSender.sendMessage( - MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Siege - Specify Region")); - return true; - } - - StringBuilder sb = new StringBuilder(); - for (int i = 1; i < args.length; i++) { - if (i > 1) - sb.append(" "); - sb.append(args[i]); - } - String region = sb.toString(); for (Siege siege : MovecraftWarfare.getInstance().getSiegeManager().getSieges()) { if (siege.getStage().get() == Siege.Stage.INACTIVE) continue; - if (!region.equalsIgnoreCase(siege.getName())) - continue; - if((commandSender instanceof Player)) { if (siege.getPlayer().equals((Player) commandSender) || commandSender.hasPermission("movecraft.siege.cancel.other")) { cancelSiege(siege); @@ -112,6 +100,7 @@ private boolean cancelCommand(CommandSender commandSender, String[] args) { } return true; } + commandSender.sendMessage(I18nSupport.getInternationalisedString("Siege - No Siege Active")); return false; } @@ -139,6 +128,11 @@ private void cancelSiege(Siege siege) { } private boolean timeCommand(CommandSender commandSender) { + if (!commandSender.hasPermission("movecraft.siege.time")) { + commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions")); + return true; + } + int militaryTime = getMilitaryTime(); commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + dayToString(getDayOfWeek()) + " - " + String.format("%02d", militaryTime / 100) + ":" + String.format("%02d", militaryTime % 100)); @@ -146,6 +140,11 @@ private boolean timeCommand(CommandSender commandSender) { } private boolean infoCommand(CommandSender commandSender, String[] args) { + if (!commandSender.hasPermission("movecraft.siege.info")) { + commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions")); + return true; + } + if (args.length <= 1) { commandSender.sendMessage( MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Siege - Specify Region")); @@ -225,6 +224,11 @@ private String secondsIntToString(int seconds) { } private boolean listCommand(CommandSender commandSender, String[] args) { + if (!commandSender.hasPermission("movecraft.siege.list")) { + commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions")); + return true; + } + SiegeManager siegeManager = MovecraftWarfare.getInstance().getSiegeManager(); int page; try { @@ -259,6 +263,12 @@ private boolean beginCommand(CommandSender commandSender) { return true; } + if (!commandSender.hasPermission("movecraft.siege.begin")) { + commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + + I18nSupport.getInternationalisedString("Insufficient Permissions")); + return true; + } + SiegeManager siegeManager = MovecraftWarfare.getInstance().getSiegeManager(); Player player = (Player) commandSender; for (Siege siege : siegeManager.getSieges()) { @@ -323,6 +333,62 @@ private boolean beginCommand(CommandSender commandSender) { return true; } + private Boolean statusCommand(CommandSender commandSender) { + if (!commandSender.hasPermission("movecraft.siege.status")) { + commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + + I18nSupport.getInternationalisedString("Insufficient Permissions")); + return true; + } + + for (Siege siege : MovecraftWarfare.getInstance().getSiegeManager().getSieges()) { + if (siege.getStage().get() == Siege.Stage.INACTIVE) + continue; + + Duration timePassed = Duration.between(siege.getStartTime(), LocalDateTime.now()); + + StringBuilder message = new StringBuilder(); + if (siege.getStage().get() == Siege.Stage.PREPARATION) { + long timeLeft = siege.getConfig().getDelayBeforeStart() - timePassed.getSeconds(); + message.append(String.format(I18nSupport.getInternationalisedString("Siege - Siege About To Begin"), + siege.getPlayer().getName(), + siege.getName())); + message.append(SiegeUtils.formatMinutes(timeLeft)); + commandSender.sendMessage(message.toString()); + } + long timeLeft = siege.getConfig().getDuration() - timePassed.getSeconds(); + Craft siegeCraft = CraftManager.getInstance().getCraftByPlayer(siege.getPlayer().getPlayer()); + if (siege.leaderIsInControl()) { + message.append(String.format(I18nSupport.getInternationalisedString("Siege - Flagship In Box"), + siege.getName(), + siegeCraft.getType().getStringProperty(CraftType.NAME), + siegeCraft.getOrigBlockCount(), + siege.getPlayer().getName(), + siegeCraft.getHitBox().getMidPoint().getX(), + siegeCraft.getHitBox().getMidPoint().getY(), + siegeCraft.getHitBox().getMidPoint().getZ())); + message.append(SiegeUtils.formatMinutes(timeLeft)); + } else { + message.append(String.format(I18nSupport.getInternationalisedString("Siege - Flagship Not In Box"), + siege.getName(), + siegeCraft.getType().getStringProperty(CraftType.NAME), + siegeCraft.getOrigBlockCount(), + siege.getPlayer().getName(), + siegeCraft.getHitBox().getMidPoint().getX(), + siegeCraft.getHitBox().getMidPoint().getY(), + siegeCraft.getHitBox().getMidPoint().getZ())); + message.append(SiegeUtils.formatMinutes(timeLeft)); + } + commandSender.sendMessage(message.toString()); + if (siege.isSuddenDeathActive()) { + commandSender.sendMessage(String.format(I18nSupport.getInternationalisedString("Siege - Sudden Death"), siege.getPlayer().getName(), (timeLeft / 60) + 1)); + } + + } + commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + + I18nSupport.getInternationalisedString("Siege - No Siege Underway")); + return true; + } + @Nullable private Siege getSiege(@NotNull Player player, SiegeManager siegeManager) { Set regions = MovecraftWorldGuard.getInstance().getWGUtils().getRegions(player.getLocation()); @@ -397,20 +463,20 @@ private String dayToString(int day) { public List onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { final List tabCompletions = new ArrayList<>(); if (strings.length <= 1) { - tabCompletions.add("info"); - tabCompletions.add("begin"); - tabCompletions.add("list"); - tabCompletions.add("time"); - tabCompletions.add("cancel"); + if (commandSender.hasPermission("movecraft.siege.info")) + tabCompletions.add("info"); + if (commandSender.hasPermission("movecraft.siege.begin")) + tabCompletions.add("begin"); + if (commandSender.hasPermission("movecraft.siege.list")) + tabCompletions.add("list"); + if (commandSender.hasPermission("movecraft.siege.time")) + tabCompletions.add("time"); + if (commandSender.hasPermission("movecraft.siege.cancel")) + tabCompletions.add("cancel"); + if (commandSender.hasPermission("movecraft.siege.status")) + tabCompletions.add("status"); } else if (strings[0].equalsIgnoreCase("info")) { for (Siege siege : MovecraftWarfare.getInstance().getSiegeManager().getSieges()) { - tabCompletions.add(siege.getName()); - } - } else if (strings[0].equalsIgnoreCase("cancel")) { - for (Siege siege : MovecraftWarfare.getInstance().getSiegeManager().getSieges()) { - if (siege.getStage().get() == Siege.Stage.INACTIVE) - continue; - tabCompletions.add(siege.getName()); } } diff --git a/src/main/resources/localisation/mcwlang_en.properties b/src/main/resources/localisation/mcwlang_en.properties index 53360d8..2f8abf3 100644 --- a/src/main/resources/localisation/mcwlang_en.properties +++ b/src/main/resources/localisation/mcwlang_en.properties @@ -55,6 +55,7 @@ Siege\ -\ No\ Configuration\ Found=Could not find a siege configuration for the Siege\ -\ Siege\ Region\ Not\ Found=Siege region not found. Use '/siege list' to find valid siege regions. Siege\ -\ Default\ Siege\ Start\ Cancel\ Reason=Your siege was cancelled by a plugin. Event\ -\ Default\ Cancel\ Reason=Sorry, the performed action was cancelled by a plugin. +Siege\ -\ No\ Siege\ Active=No siege is currently underway. Siege\ -\ No\ Retreat=You are the siege leader, and cannot retreat! Use '/siege cancel' to cancel the siege. Siege\ -\ Gained\ Control=%s has gained control of the %s siege region! Their flagship is a(n) %s of size %d at %s. Siege\ -\ Lost\ Control=%s has lost control of the %s siege region!