From 4460f2e651311840cc3fa53249c73f02fc0ebe83 Mon Sep 17 00:00:00 2001 From: CoderTim Date: Mon, 21 Jul 2014 16:29:15 -0400 Subject: [PATCH 1/5] Prevent fully powered-up Sneaky Assassin players from using additional power-ups --- .../sneakyassassins/powerups/ArmorPowerUp.java | 12 ++++++++++-- .../games/sneakyassassins/powerups/PowerUp.java | 2 +- .../sneakyassassins/powerups/PowerUpManager.java | 14 ++++++++------ .../sneakyassassins/powerups/WeaponPowerUp.java | 6 ++++-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/ArmorPowerUp.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/ArmorPowerUp.java index 3034531e2..bcfb42874 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/ArmorPowerUp.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/ArmorPowerUp.java @@ -37,12 +37,20 @@ public class ArmorPowerUp extends PowerUp } @Override - public void powerUpPlayer(Player player) + public boolean powerUpPlayer(Player player) { - if(powerUpArmor(player) || powerUpArmor(player)) + if (powerUpArmor(player) || powerUpArmor(player)) + { player.sendMessage("Your armor was upgraded!"); + + return true; + } else + { player.sendMessage("Your armor is already fully upgraded!"); + + return false; + } } private boolean powerUpArmor(Player player) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUp.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUp.java index 4a9b83296..30d68ccb1 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUp.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUp.java @@ -108,5 +108,5 @@ public abstract class PowerUp getPowerUpManager().removePowerUp(this); } - public abstract void powerUpPlayer(Player player); + public abstract boolean powerUpPlayer(Player player); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUpManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUpManager.java index 60455149e..71c0acbeb 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUpManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUpManager.java @@ -145,21 +145,23 @@ public class PowerUpManager implements Listener event.setCancelled(true); } - @EventHandler - public void onPlayerPickUpPowerUp(PlayerPickupItemEvent event) + @EventHandler(ignoreCancelled = true) + public void onPlayerPickUpPowerUp(final PlayerPickupItemEvent event) { if (getGame().GetTeam(event.getPlayer()) != null) { - PowerUp powerUp = getPowerUpByItem(event.getItem()); + final PowerUp powerUp = getPowerUpByItem(event.getItem()); if (powerUp != null) { event.setCancelled(true); - powerUp.powerUpPlayer(event.getPlayer()); - powerUp.remove(); + if (powerUp.powerUpPlayer(event.getPlayer())) + { + powerUp.remove(); - schedulePowerUpSpawn(10); + schedulePowerUpSpawn(10); + } } } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/WeaponPowerUp.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/WeaponPowerUp.java index 95ab59acb..e9d8ee03d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/WeaponPowerUp.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/WeaponPowerUp.java @@ -22,7 +22,7 @@ public class WeaponPowerUp extends PowerUp } @Override - public void powerUpPlayer(Player player) + public boolean powerUpPlayer(Player player) { for (int swordType = 0; swordType < SWORD_PROGRESSION.size(); swordType++) { @@ -35,10 +35,12 @@ public class WeaponPowerUp extends PowerUp player.sendMessage("You sword was upgraded!"); - return; + return true; } } player.sendMessage("Your sword is already fully upgraded!"); + + return false; } } From a6a274069cb1547e31219d3521c7815d365a4537 Mon Sep 17 00:00:00 2001 From: CoderTim Date: Mon, 21 Jul 2014 17:26:45 -0400 Subject: [PATCH 2/5] Prevent power-up message spam when player is fully powered-up --- .../powerups/PowerUpManager.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUpManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUpManager.java index 71c0acbeb..3d125d21f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUpManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUpManager.java @@ -22,6 +22,7 @@ public class PowerUpManager implements Listener private final List _powerUps = new ArrayList<>(); private Location _lastLocation = null; private int _nextSpawnCountdown = -1; + private final Map _powerUpPickUpCooldown = new HashMap<>(); public PowerUpManager(Game game, Random random, List spawnLocations) { @@ -156,11 +157,28 @@ public class PowerUpManager implements Listener { event.setCancelled(true); - if (powerUp.powerUpPlayer(event.getPlayer())) + if (_powerUpPickUpCooldown.get(event.getPlayer().getUniqueId()) != powerUp) { - powerUp.remove(); + if (powerUp.powerUpPlayer(event.getPlayer())) + { + powerUp.remove(); - schedulePowerUpSpawn(10); + schedulePowerUpSpawn(10); + } + else + { + _powerUpPickUpCooldown.put(event.getPlayer().getUniqueId(), powerUp); + + Bukkit.getScheduler().runTaskLater(getPlugin(), new Runnable() + { + @Override + public void run() + { + if (_powerUpPickUpCooldown.get(event.getPlayer().getUniqueId()) == powerUp) + _powerUpPickUpCooldown.remove(event.getPlayer().getUniqueId()); + } + }, 2000); + } } } } From d7037f1619570a75884308cd0edea7473bdbf344 Mon Sep 17 00:00:00 2001 From: Peter Miller Date: Tue, 22 Jul 2014 22:18:29 -0400 Subject: [PATCH 3/5] Breaking up "/news" commands (like "/npc" sub-commands) using multicommandbase. --- .../mineplex/hub/commands/NewsAddCommand.java | 71 ++++++ .../mineplex/hub/commands/NewsCommand.java | 208 +----------------- .../hub/commands/NewsConfirmCommand.java | 45 ++++ .../hub/commands/NewsDeleteCommand.java | 59 +++++ .../hub/commands/NewsListCommand.java | 66 ++++++ .../mineplex/hub/commands/NewsSetCommand.java | 81 +++++++ .../src/mineplex/hub/modules/NewsManager.java | 19 ++ 7 files changed, 351 insertions(+), 198 deletions(-) create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsAddCommand.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsConfirmCommand.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsDeleteCommand.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsListCommand.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsSetCommand.java diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsAddCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsAddCommand.java new file mode 100644 index 000000000..455218794 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsAddCommand.java @@ -0,0 +1,71 @@ +package mineplex.hub.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.hub.HubManager; +import mineplex.hub.modules.NewsManager; + +public class NewsAddCommand extends CommandBase +{ + public NewsAddCommand(HubManager plugin) + { + super(plugin, Rank.ADMIN, "add"); + } + + @Override + public void Execute(final Player caller, final String[] args) + { + if (args == null || args.length == 0 || args.length > 128) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!")); + return; + } + else + { + NewsManager newsMang = Plugin.GetNewsManager(); + + String newsEntry = ""; + for (int i = 0; i < args.length; i++) + { + newsEntry += args[i] + " "; + } + newsEntry = newsEntry.substring(0, newsEntry.length() - 1); + + // Check for 256 character length for MySQL! + if (newsEntry.length() > 256) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news entry is too long [> 256 characters]!")); + return; + } + + newsMang.AddNewsEntry(newsEntry, new Callback() + { + public void run(Boolean success) + { + if (success) + { + String newsEntry = ""; + for (int i = 0; i < args.length; i++) + { + newsEntry += args[i] + " "; + } + newsEntry = newsEntry.substring(0, newsEntry.length() - 1); + + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "The news entry: " + C.cGold + newsEntry + C.cGray + " has been added to the database!")); + } + else + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "There was an error adding the news entry to the database!")); + } + } + }); + return; + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java index 71067f06a..dd1e33d77 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java @@ -1,215 +1,27 @@ package mineplex.hub.commands; -import java.util.HashMap; -import java.util.Iterator; - import org.bukkit.entity.Player; -import mineplex.core.command.CommandBase; +import mineplex.core.command.MultiCommandBase; import mineplex.core.common.Rank; -import mineplex.core.common.util.C; -import mineplex.core.common.util.Callback; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; import mineplex.hub.HubManager; -import mineplex.hub.modules.NewsManager; -public class NewsCommand extends CommandBase +public class NewsCommand extends MultiCommandBase { public NewsCommand(HubManager plugin) { super(plugin, Rank.ADMIN, "news"); + + AddCommand(new NewsAddCommand(plugin)); + AddCommand(new NewsDeleteCommand(plugin)); + AddCommand(new NewsConfirmCommand(plugin)); + AddCommand(new NewsListCommand(plugin)); + AddCommand(new NewsSetCommand(plugin)); } @Override - public void Execute(final Player caller, final String[] args) + protected void Help(Player caller, String args[]) { - final NewsManager newsMang = Plugin.GetNewsManager(); - - if (args == null || args.length == 0) - { - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!")); - - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "Available news arguments for this command:")); - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news list" + C.cGray + " - Lists (numbered) stored news messages from database.")); - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news add " + C.cGray + " - Adds specified news entry string to database at end of table.")); - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news delete #" + C.cGray + " - Removes specified (numbered) news entry string from database.")); - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news set # " + C.cGray + " - Updates specified (numbered) news entry string in database.")); - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "*Please Note: " + C.cGray + "Updates to server news entries from the database are on a 4 minute refresh cycle!")); - return; - } - else if (args.length == 1 && args[0].equalsIgnoreCase("list")) - { - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "Current server news messages:")); - - newsMang.RetriveNewsEntries(new Callback>() - { - public void run(final HashMap newsEntries) - { - // Order newsEntries set or its output by newsPosition, not hash order... - newsMang.RetrieveMaxNewsPosition(new Callback() - { - public void run(Integer maxPosition) - { - String[] newsStrings = new String[maxPosition]; - for (Iterator iterator = newsEntries.keySet().iterator(); iterator.hasNext();) - { - String newsPosition = iterator.next(); - newsStrings[Integer.parseInt(newsPosition) - 1] = newsEntries.get(newsPosition); - } - - for (int i = 0; i < newsStrings.length; i++) - { - UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.GetName() + "> \", color:blue, \"extra\":[{\"text\":\"[DELETE] \", color:red, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news ¢¤₦₣¡₨₥ " + (i + 1) + "\"}, \"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Deletes News Entry " + (i + 1) + " : " + newsStrings[i] + "\"}}, {\"text\":\"News " + (i + 1) + "\", color:gold}, {\"text\":\" : \", color:gray}, {\"text\":\"" + newsStrings[i] + "\", color:white}]}"); - } - } - }); - } - }); - return; - } - else if (args.length >= 2 && args.length <= 128) - { - if (args[0].equals("¢¤₦₣¡₨₥") && args.length == 2) - { - int newsPosition; - try - { - newsPosition = Integer.parseInt(args[1]); - } - catch (Exception exception) - { - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!")); - return; - } - - UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.GetName() + "> \", color:blue, \"extra\":[{\"text\":\"[CONFIRM] \", color:green, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news delete " + newsPosition + "\"}, \"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Are you absolutely sure???\"}}, {\"text\":\"News Entry " + newsPosition + "\", color:gold}, {\"text\":\" deletion?\", color:gray}]}"); - return; - } - else if (args[0].equalsIgnoreCase("delete") && args.length == 2) - { - final int newsPosition; - try - { - newsPosition = Integer.parseInt(args[1]); - } - catch (Exception exception) - { - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!")); - return; - } - newsMang.DeleteNewsEntry(newsPosition, new Callback() - { - public void run(Boolean success) - { - if (success) - { - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "The news entry at position " + C.cGold + newsPosition + C.cGray + " has been deleted!")); - } - else - { - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "There was an error deleting the news entry; likely the specified news position was invalid!")); - } - } - }); - return; - } - else if (args[0].equalsIgnoreCase("add")) - { - String newsEntry = ""; - for (int i = 1; i < args.length; i++) - { - newsEntry += args[i] + " "; - } - newsEntry = newsEntry.substring(0, newsEntry.length() - 1); - - // Check for 256 character length for MySQL! - if (newsEntry.length() > 256) - { - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news entry is too long [> 256 characters]!")); - return; - } - - newsMang.AddNewsEntry(newsEntry, new Callback() - { - public void run(Boolean success) - { - if (success) - { - String newsEntry = ""; - for (int i = 1; i < args.length; i++) - { - newsEntry += args[i] + " "; - } - newsEntry = newsEntry.substring(0, newsEntry.length() - 1); - - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "The news entry: " + C.cGold + newsEntry + C.cGray + " has been added to the database!")); - } - else - { - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "There was an error adding the news entry to the database!")); - } - } - }); - return; - } - else if (args[0].equalsIgnoreCase("set") && args.length >= 3) - { - final int newsPosition; - String newsEntry = ""; - for (int i = 2; i < args.length; i++) - { - newsEntry += args[i] + " "; - } - newsEntry = newsEntry.substring(0, newsEntry.length() - 1); - - // Check for 256 character length for MySQL! - if (newsEntry.length() > 256) - { - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news entry is too long [> 256 characters]!")); - return; - } - - try - { - newsPosition = Integer.parseInt(args[1]); - } - catch (Exception exception) - { - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!")); - return; - } - newsMang.SetNewsEntry(newsEntry, newsPosition, new Callback() - { - public void run(Boolean success) - { - if (success) - { - String newsEntry = ""; - for (int i = 2; i < args.length; i++) - { - newsEntry += args[i] + " "; - } - newsEntry = newsEntry.substring(0, newsEntry.length() - 1); - - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "The news entry at position " + C.cGold + newsPosition + C.cGray + " has been updated to: " + C.cGold + newsEntry + C.cGray + "!")); - } - else - { - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "There was an error updating the news entry; likely the specified news position was invalid!")); - } - } - }); - return; - } - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!")); - return; - } - else - { - UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!")); - return; - } + Plugin.GetNewsManager().Help(caller); } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsConfirmCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsConfirmCommand.java new file mode 100644 index 000000000..337da8a8c --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsConfirmCommand.java @@ -0,0 +1,45 @@ +package mineplex.hub.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.hub.HubManager; + +public class NewsConfirmCommand extends CommandBase +{ + public NewsConfirmCommand(HubManager plugin) + { + super(plugin, Rank.ADMIN, "¢¤₦₣¡₨₥"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args == null || args.length == 0 || args.length > 1) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!")); + return; + } + else + { + int newsPosition; + try + { + newsPosition = Integer.parseInt(args[0]); + } + catch (Exception exception) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!")); + return; + } + + UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.GetName() + "> \", color:blue, \"extra\":[{\"text\":\"[CONFIRM] \", color:green, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news delete " + newsPosition + "\"}, \"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Are you absolutely sure???\"}}, {\"text\":\"News Entry " + newsPosition + "\", color:gold}, {\"text\":\" deletion?\", color:gray}]}"); + return; + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsDeleteCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsDeleteCommand.java new file mode 100644 index 000000000..039de916f --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsDeleteCommand.java @@ -0,0 +1,59 @@ +package mineplex.hub.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.hub.HubManager; +import mineplex.hub.modules.NewsManager; + +public class NewsDeleteCommand extends CommandBase +{ + public NewsDeleteCommand(HubManager plugin) + { + super(plugin, Rank.ADMIN, "delete"); + } + + @Override + public void Execute(final Player caller, String[] args) + { + if (args == null || args.length == 0 || args.length > 1) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!")); + return; + } + else + { + NewsManager newsMang = Plugin.GetNewsManager(); + final int newsPosition; + try + { + newsPosition = Integer.parseInt(args[0]); + } + catch (Exception exception) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!")); + return; + } + newsMang.DeleteNewsEntry(newsPosition, new Callback() + { + public void run(Boolean success) + { + if (success) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "The news entry at position " + C.cGold + newsPosition + C.cGray + " has been deleted!")); + } + else + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "There was an error deleting the news entry; likely the specified news position was invalid!")); + } + } + }); + return; + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsListCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsListCommand.java new file mode 100644 index 000000000..cc53857ab --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsListCommand.java @@ -0,0 +1,66 @@ +package mineplex.hub.commands; + +import java.util.HashMap; +import java.util.Iterator; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.hub.HubManager; +import mineplex.hub.modules.NewsManager; + +public class NewsListCommand extends CommandBase +{ + public NewsListCommand(HubManager plugin) + { + super(plugin, Rank.ADMIN, "list"); + } + + @Override + public void Execute(final Player caller, String[] args) + { + if (args == null || args.length == 0) + { + final NewsManager newsMang = Plugin.GetNewsManager(); + + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "Current server news messages:")); + + newsMang.RetriveNewsEntries(new Callback>() + { + public void run(final HashMap newsEntries) + { + // Order newsEntries set or its output by newsPosition, not hash order... + newsMang.RetrieveMaxNewsPosition(new Callback() + { + public void run(Integer maxPosition) + { + String[] newsStrings = new String[maxPosition]; + for (Iterator iterator = newsEntries.keySet().iterator(); iterator.hasNext();) + { + String newsPosition = iterator.next(); + newsStrings[Integer.parseInt(newsPosition) - 1] = newsEntries.get(newsPosition); + } + + for (int i = 0; i < newsStrings.length; i++) + { + UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.GetName() + "> \", color:blue, \"extra\":[{\"text\":\"[DELETE] \", color:red, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news ¢¤₦₣¡₨₥ " + (i + 1) + "\"}, \"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Deletes News Entry " + (i + 1) + " : " + newsStrings[i] + "\"}}, {\"text\":\"News " + (i + 1) + "\", color:gold}, {\"text\":\" : \", color:gray}, {\"text\":\"" + newsStrings[i] + "\", color:white}]}"); + } + } + }); + } + }); + return; + } + else + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!")); + return; + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsSetCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsSetCommand.java new file mode 100644 index 000000000..ea34f8cd5 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsSetCommand.java @@ -0,0 +1,81 @@ +package mineplex.hub.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.hub.HubManager; +import mineplex.hub.modules.NewsManager; + +public class NewsSetCommand extends CommandBase +{ + public NewsSetCommand(HubManager plugin) + { + super(plugin, Rank.ADMIN, "set"); + } + + @Override + public void Execute(final Player caller, final String[] args) + { + if (args == null || args.length < 2 || args.length > 128) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!")); + return; + } + else + { + NewsManager newsMang = Plugin.GetNewsManager(); + + final int newsPosition; + String newsEntry = ""; + for (int i = 1; i < args.length; i++) + { + newsEntry += args[i] + " "; + } + newsEntry = newsEntry.substring(0, newsEntry.length() - 1); + + // Check for 256 character length for MySQL! + if (newsEntry.length() > 256) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news entry is too long [> 256 characters]!")); + return; + } + + try + { + newsPosition = Integer.parseInt(args[0]); + } + catch (Exception exception) + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!")); + return; + } + newsMang.SetNewsEntry(newsEntry, newsPosition, new Callback() + { + public void run(Boolean success) + { + if (success) + { + String newsEntry = ""; + for (int i = 1; i < args.length; i++) + { + newsEntry += args[i] + " "; + } + newsEntry = newsEntry.substring(0, newsEntry.length() - 1); + + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "The news entry at position " + C.cGold + newsPosition + C.cGray + " has been updated to: " + C.cGold + newsEntry + C.cGray + "!")); + } + else + { + UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "There was an error updating the news entry; likely the specified news position was invalid!")); + } + } + }); + return; + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java index e540d04d0..6d67b4986 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java @@ -9,6 +9,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import mineplex.core.MiniPlugin; +import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; @@ -187,6 +188,24 @@ public class NewsManager extends MiniPlugin }); } + public void Help(Player caller, String message) + { + UtilPlayer.message(caller, F.main(_moduleName, "Available news arguments for this command:")); + UtilPlayer.message(caller, F.help(C.cGold + "/news list", "Lists (numbered) stored news messages from database.", Rank.ADMIN)); + UtilPlayer.message(caller, F.help(C.cGold + "/news add ", "Adds specified news entry string to database at end of table.", Rank.ADMIN)); + UtilPlayer.message(caller, F.help(C.cGold + "/news delete #", "Removes specified (numbered) news entry string from database.", Rank.ADMIN)); + UtilPlayer.message(caller, F.help(C.cGold + "/news set # ", "Updates specified (numbered) news entry string in database.", Rank.ADMIN)); + UtilPlayer.message(caller, F.help("*Please Note:", "Updates to server news entries from the database are on a 4 minute refresh cycle!", Rank.ADMIN)); + + if (message != null) + UtilPlayer.message(caller, F.main(_moduleName, ChatColor.RED + message)); + } + + public void Help(Player caller) + { + Help(caller, null); + } + @EventHandler public void NewsUpdate(UpdateEvent event) { From fe356add41b450325b2dc728dd033c59c2e13987 Mon Sep 17 00:00:00 2001 From: CoderTim Date: Wed, 23 Jul 2014 15:41:47 -0400 Subject: [PATCH 4/5] Restore original blocks when Sneaky Assassin power-up beacon is removed --- .../sneakyassassins/powerups/PowerUp.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUp.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUp.java index 30d68ccb1..65bb6ce6f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUp.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUp.java @@ -16,6 +16,8 @@ public abstract class PowerUp private final Location _location; private Location _effectLocation; private Block _beaconBlock; + private BlockState _originalBeaconBlock; + private BlockState[][] _originalBeaconBase = new BlockState[3][3]; private Item _item; public PowerUp(PowerUpManager powerUpManager, PowerUpType powerUpType, Location location) @@ -39,12 +41,21 @@ public abstract class PowerUp public void activate() { - _beaconBlock = getLocation().getBlock(); + _beaconBlock = getLocation().getBlock().getRelative(BlockFace.DOWN); + + _originalBeaconBlock = _beaconBlock.getState(); _beaconBlock.setType(Material.BEACON); - for (int x = -1; x <= 1; x++) - for (int z = -1; z <= 1; z++) - _beaconBlock.getRelative(x, -1, z).setType(Material.IRON_BLOCK); + for (int x = 0; x < 3; x++) + { + for (int z = 0; z < 3; z++) + { + Block beaconBaseBlock = _beaconBlock.getRelative(x-1, -1, z-1); + + _originalBeaconBase[x][z] = beaconBaseBlock.getState(); + beaconBaseBlock.setType(Material.IRON_BLOCK); + } + } } public void onUpdate(UpdateEvent event) @@ -103,7 +114,11 @@ public abstract class PowerUp _item = null; } - _beaconBlock.setType(Material.AIR); + _originalBeaconBlock.update(true, false); + + for (int x = 0; x < _originalBeaconBase.length; x++) + for (int z = 0; z < _originalBeaconBase[0].length; z++) + _originalBeaconBase[x][z].update(true, false); getPowerUpManager().removePowerUp(this); } From fe463551305765def2793809e34db297bc04beac Mon Sep 17 00:00:00 2001 From: CoderTim Date: Thu, 24 Jul 2014 21:25:59 -0400 Subject: [PATCH 5/5] Added missing description to Sneak Assassin revealer items --- .../sneakyassassins/kits/KitRevealer.java | 12 +++++++- .../powerups/PowerUpManager.java | 2 +- .../game/arcade/kit/perks/PerkRevealer.java | 29 +++++++++---------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/kits/KitRevealer.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/kits/KitRevealer.java index abed8a6b1..25e55c47a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/kits/KitRevealer.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/kits/KitRevealer.java @@ -1,5 +1,7 @@ package nautilus.game.arcade.game.games.sneakyassassins.kits; +import mineplex.core.common.util.*; +import mineplex.core.itemstack.*; import nautilus.game.arcade.*; import nautilus.game.arcade.kit.*; import nautilus.game.arcade.kit.perks.*; @@ -19,6 +21,14 @@ public class KitRevealer extends SneakyAssassinKit { super.GiveItems(player); - player.getInventory().addItem(new ItemStack(Material.EMERALD, 3)); + player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 3, + C.cYellow + C.Bold + "Right-Click" + C.cWhite + C.Bold + " - " + C.cGreen + C.Bold + "Reveal Assassins", + new String[] + { + ChatColor.RESET + "Throw a revealer.", + ChatColor.RESET + "Players within 5 blocks", + ChatColor.RESET + "get revealed for 5 seconds.", + + })); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUpManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUpManager.java index 3d125d21f..4271e28a7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUpManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/powerups/PowerUpManager.java @@ -146,7 +146,7 @@ public class PowerUpManager implements Listener event.setCancelled(true); } - @EventHandler(ignoreCancelled = true) + @EventHandler public void onPlayerPickUpPowerUp(final PlayerPickupItemEvent event) { if (getGame().GetTeam(event.getPlayer()) != null) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkRevealer.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkRevealer.java index 9fbc69cd4..ccf296615 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkRevealer.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkRevealer.java @@ -33,27 +33,24 @@ public class PerkRevealer extends Perk implements IThrown public PerkRevealer() { - super("Revealer", new String[] - { - C.cYellow + "Right-Click" + C.cGray + " with Emerald to " + C.cGreen + "throw Revealer", - }); + super("Revealer", new String[]{C.cYellow + "Right-Click" + C.cGray + " with Emerald to " + C.cGreen + "throw Revealer"}); } @EventHandler public void onPlayerThrowRevealer(PlayerInteractEvent event) { - if(event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) + if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return; - if(event.getPlayer().getItemInHand() == null) + if (event.getPlayer().getItemInHand() == null) return; - if(event.getPlayer().getItemInHand().getType() != Material.EMERALD) + if (event.getPlayer().getItemInHand().getType() != Material.EMERALD) return; Player player = event.getPlayer(); - if(!Kit.HasKit(player)) + if (!Kit.HasKit(player)) return; event.setCancelled(true); @@ -69,15 +66,15 @@ public class PerkRevealer extends Perk implements IThrown @EventHandler public void onUpdate(UpdateEvent event) { - if(event.getType() == UpdateType.SEC) + if (event.getType() == UpdateType.SEC) { - for(Iterator> it = getRevealedPlayers().entrySet().iterator(); it.hasNext();) + for (Iterator> it = getRevealedPlayers().entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = it.next(); - if(!entry.getKey().isOnline()) + if (!entry.getKey().isOnline()) it.remove(); - else if(entry.getValue()._expirationSeconds <= 0) + else if (entry.getValue()._expirationSeconds <= 0) { it.remove(); @@ -119,16 +116,16 @@ public class PerkRevealer extends Perk implements IThrown UtilFirework.playFirework(data.GetThrown().getLocation(), effect); - for(Player player : Manager.GetGame().GetPlayers(true)) + for (Player player : Manager.GetGame().GetPlayers(true)) { - if(player == data.GetThrower()) + if (player == data.GetThrower()) continue; - if(player.getLocation().getWorld() == data.GetThrown().getWorld() && player.getLocation().distanceSquared(data.GetThrown().getLocation()) <= 25) + if (player.getLocation().getWorld() == data.GetThrown().getWorld() && player.getLocation().distanceSquared(data.GetThrown().getLocation()) <= 25) { RevealedPlayerInfo info = getRevealedPlayers().get(player); - if(info == null) + if (info == null) { info = new RevealedPlayerInfo(Manager.GetDisguise().getDisguise(player)); getRevealedPlayers().put(player, info);