From 51c7caca8cd3b432d57861742828bed19e5a3961 Mon Sep 17 00:00:00 2001 From: drfiveminusmint Date: Sun, 26 May 2024 12:35:45 -0400 Subject: [PATCH] Use Siege Broadcast system --- .../warfare/features/siege/SiegeCommand.java | 16 +++++++++++++++- .../features/siege/SiegeLeaderListener.java | 16 +++++++++++----- .../siege/events/SiegeBroadcastEvent.java | 5 ++++- .../features/siege/tasks/SiegeProgressTask.java | 11 +++++++++-- .../resources/localisation/mcwlang_en.properties | 2 ++ 5 files changed, 41 insertions(+), 9 deletions(-) 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 afb9391..3838a74 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 @@ -97,7 +97,19 @@ private boolean cancelCommand(CommandSender commandSender, String[] args) { if (!region.equalsIgnoreCase(siege.getName())) continue; - cancelSiege(siege); + if((commandSender instanceof Player)) { + if (siege.getPlayer().equals((Player) commandSender) || commandSender.hasPermission("movecraft.siege.cancel.other")) { + cancelSiege(siege); + } else { + commandSender.sendMessage(I18nSupport.getInternationalisedString("Insufficient Permissions")); + } + } else { + if (commandSender.hasPermission("movecraft.siege.cancel.other")) { + cancelSiege(siege); + } else { + commandSender.sendMessage(I18nSupport.getInternationalisedString("Insufficient Permissions")); + } + } return true; } return false; @@ -181,6 +193,8 @@ private boolean infoCommand(CommandSender commandSender, String[] args) { + militaryTimeIntToString(siege.getConfig().getScheduleEnd()) + " UTC"); commandSender.sendMessage(I18nSupport.getInternationalisedString("Siege - Duration") + ChatColor.WHITE + secondsIntToString(siege.getConfig().getDuration())); + commandSender.sendMessage(I18nSupport.getInternationalisedString("Siege - Sudden Death Duration") + ChatColor.WHITE + + secondsIntToString(siege.getConfig().getSuddenDeathDuration())); return true; } diff --git a/src/main/java/net/countercraft/movecraft/warfare/features/siege/SiegeLeaderListener.java b/src/main/java/net/countercraft/movecraft/warfare/features/siege/SiegeLeaderListener.java index 8d8f9dc..63461ad 100644 --- a/src/main/java/net/countercraft/movecraft/warfare/features/siege/SiegeLeaderListener.java +++ b/src/main/java/net/countercraft/movecraft/warfare/features/siege/SiegeLeaderListener.java @@ -84,8 +84,11 @@ private void processCraftRemoval(Craft leaderCraft) { Siege currentSiege = getSiegeByLeader(player); if (currentSiege == null) return; if (currentSiege.leaderIsInControl()) { - Bukkit.getServer().broadcastMessage(String.format(I18nSupport.getInternationalisedString("Siege - Lost Control"), - player.getDisplayName(), currentSiege.getName())); + String broadcast = String.format(I18nSupport.getInternationalisedString("Siege - Lost Control"), + player.getDisplayName(), currentSiege.getName()); + Bukkit.getServer().broadcastMessage(broadcast); + SiegeBroadcastEvent event = new SiegeBroadcastEvent(currentSiege, broadcast, SiegeBroadcastEvent.Type.LOSE_CONTROL); + Bukkit.getServer().getPluginManager().callEvent(event); currentSiege.setLeaderInControl(false); if (currentSiege.isSuddenDeathActive()) endSiege(currentSiege); @@ -103,8 +106,11 @@ private boolean processCraftMovement(Craft leaderCraft, Player player, Siege cur return true; } } else if (!currentSiege.leaderIsInControl()) { - Bukkit.getServer().broadcastMessage(String.format(I18nSupport.getInternationalisedString("Siege - Gained Control"), - player.getDisplayName(), currentSiege.getName(), leaderCraft.getType().getStringProperty(CraftType.NAME), leaderCraft.getOrigBlockCount(), leaderCraft.getHitBox().getMidPoint().toString())); + String broadcast = String.format(I18nSupport.getInternationalisedString("Siege - Gained Control"), + player.getDisplayName(), currentSiege.getName(), leaderCraft.getType().getStringProperty(CraftType.NAME), leaderCraft.getOrigBlockCount(), leaderCraft.getHitBox().getMidPoint().toString()); + Bukkit.getServer().broadcastMessage(broadcast); + SiegeBroadcastEvent event = new SiegeBroadcastEvent(currentSiege, broadcast, SiegeBroadcastEvent.Type.GAIN_CONTROL); + Bukkit.getServer().getPluginManager().callEvent(event); currentSiege.setLeaderInControl(true); } return false; @@ -129,7 +135,7 @@ private void endSiege(Siege siege) { .replaceAll("%l", playerName)); } - SiegeBroadcastEvent event = new SiegeBroadcastEvent(siege, broadcast, SiegeBroadcastEvent.Type.CANCEL); + SiegeBroadcastEvent event = new SiegeBroadcastEvent(siege, broadcast, SiegeBroadcastEvent.Type.LOSE); Bukkit.getServer().getPluginManager().callEvent(event); } diff --git a/src/main/java/net/countercraft/movecraft/warfare/features/siege/events/SiegeBroadcastEvent.java b/src/main/java/net/countercraft/movecraft/warfare/features/siege/events/SiegeBroadcastEvent.java index 416e017..41cf698 100644 --- a/src/main/java/net/countercraft/movecraft/warfare/features/siege/events/SiegeBroadcastEvent.java +++ b/src/main/java/net/countercraft/movecraft/warfare/features/siege/events/SiegeBroadcastEvent.java @@ -16,7 +16,10 @@ public enum Type { PROGRESS_NOT_IN_BOX, WIN, LOSE, - CANCEL + CANCEL, + SUDDEN_DEATH, + GAIN_CONTROL, + LOSE_CONTROL } private static final HandlerList HANDLERS = new HandlerList(); private final String broadcast; diff --git a/src/main/java/net/countercraft/movecraft/warfare/features/siege/tasks/SiegeProgressTask.java b/src/main/java/net/countercraft/movecraft/warfare/features/siege/tasks/SiegeProgressTask.java index ad80851..b037d8e 100644 --- a/src/main/java/net/countercraft/movecraft/warfare/features/siege/tasks/SiegeProgressTask.java +++ b/src/main/java/net/countercraft/movecraft/warfare/features/siege/tasks/SiegeProgressTask.java @@ -6,6 +6,7 @@ import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; +import org.bukkit.Sound; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,11 +45,17 @@ public void run() { // Check if it's time to begin sudden death if (!siege.isSuddenDeathActive() && timeLeft < siege.getConfig().getSuddenDeathDuration()) { - Bukkit.getServer().broadcastMessage(String.format(I18nSupport.getInternationalisedString("Siege - Sudden Death"), - siege.getName(), (timeLeft+2)/60)); + String broadcast = String.format(I18nSupport.getInternationalisedString("Siege - Sudden Death"), + siege.getName(), (timeLeft+2)/60); + Bukkit.getServer().broadcastMessage(broadcast); + SiegeBroadcastEvent event = new SiegeBroadcastEvent(siege, broadcast, SiegeBroadcastEvent.Type.SUDDEN_DEATH); + Bukkit.getServer().getPluginManager().callEvent(event); if (!siege.leaderIsInControl()) { endSiege(); } else { + for (Player p : Bukkit.getOnlinePlayers()) { + p.playSound(p.getLocation(), Sound.ENTITY_WITHER_DEATH, 1, 0.25F); + } siege.setSuddenDeathActive(true); } } diff --git a/src/main/resources/localisation/mcwlang_en.properties b/src/main/resources/localisation/mcwlang_en.properties index 84cc44c..53360d8 100644 --- a/src/main/resources/localisation/mcwlang_en.properties +++ b/src/main/resources/localisation/mcwlang_en.properties @@ -32,6 +32,7 @@ Siege\ -\ Day\ of\ Week=Day of week\: Siege\ -\ Start\ Time=Start time\: Siege\ -\ End\ Time=End time\: Siege\ -\ Duration=Duration\: +Siege\ -\ Sudden\ Death\ Duration=Sudden Death Duration\: Siege\ -\ Flagship\ In\ Box=The Siege of %s is under way. The Siege Flagship is a(n) %s of size %d under the command of %s at %d, %d, %d. Siege will end Siege\ -\ Flagship\ Not\ In\ Box=The Siege of %s is under way. The Siege Leader, %s, is not in command of a Flagship within the Siege Region\! If they are still not when the duration expires, the siege will fail\! Siege will end in Siege\ -\ Siege\ Success=The Siege of %s has succeeded\! The forces of %s have been victorious\! @@ -43,6 +44,7 @@ Siege\ -\ Siege\ Not\ Configured=Siege is not configured on this server. Siege\ -\ No\ Argument=No argument specified, valid arguments include begin, info, and list. Siege\ -\ Invalid\ Argument=Invalid argument specified, valid arguments include begin, info, and list. Siege\ -\ Specify\ Region=You need to supply a siege region. +Siege\ -\ No\ Siege\ Underway=No siege is currently underway. Siege\ -\ Siege\ About\ To\ Begin=%s is preparing to siege %s\! All players wishing to participate in the defense should head there immediately\! Siege will begin Siege\ -\ Log\ Siege\ Start=Siege: %s commenced by %s for a cost of %d. Siege\ -\ Must\ Be\ Player=You need to be a player to siege.