From 58ae09ebd4c9af901974d286468a38f792bb75ee Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 31 Aug 2015 11:32:18 +0200 Subject: [PATCH] saving Project for pulling. --- .../arcade/game/games/event/EventGame.java | 131 +++++++++++++++++- .../arcade/game/games/event/EventModule.java | 60 ++++---- 2 files changed, 159 insertions(+), 32 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/event/EventGame.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/event/EventGame.java index 05d1c8508..681dd16c4 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/event/EventGame.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/event/EventGame.java @@ -1,9 +1,12 @@ package nautilus.game.arcade.game.games.event; +import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; @@ -11,7 +14,9 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTime; import mineplex.core.disguise.disguises.DisguiseBase; import mineplex.core.disguise.disguises.DisguiseBat; import mineplex.core.disguise.disguises.DisguiseChicken; @@ -26,21 +31,28 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.core.visibility.VisibilityManager; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.Game; -import nautilus.game.arcade.game.SoloGame; -import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.games.event.kits.KitPlayer; +import nautilus.game.arcade.game.games.skywars.TeamSkywars.TeamColors; import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.managers.GameHostManager; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.Effect; import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.BlockFace; +import org.bukkit.block.Sign; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockRedstoneEvent; +import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.EntityDeathEvent; @@ -65,6 +77,8 @@ public class EventGame extends Game private boolean _allowAllGadgets = false; private HashSet _gadgetWhitelist = new HashSet(); + + private HashMap _functionSigns; public EventGame(ArcadeManager manager) { @@ -110,9 +124,45 @@ public class EventGame extends Game this.GameTimeout = -1; _mps = manager.GetGameHostManager(); + _functionSigns = new HashMap<>(); this.CreatureAllow = true; } + + @EventHandler + public void registerSigns(GameStateChangeEvent event) + { + if(event.GetState() != GameState.Live) + return; + + for(Location loc : WorldData.GetDataLocs("RED")) + { + for(int i = -5; i < 5; i++) + { + Location temp = loc.clone().add(0, i, 0); + if(temp.getBlock().getType() == Material.SIGN_POST || temp.getBlock().getType() == Material.WALL_SIGN) + { + if(!_functionSigns.containsKey((Sign) temp.getBlock().getState())) + { + _functionSigns.put((Sign) temp.getBlock().getState(), System.currentTimeMillis()); + } + } + } + } + } + + @EventHandler + public void signPlace(SignChangeEvent event) + { + if(!IsLive()) + return; + + if(!Manager.GetGameHostManager().isAdmin(event.getPlayer(), true)) + return; + + if(event.getLine(0).startsWith("[") && event.getLine(0).endsWith("]")) + _functionSigns.put((Sign) event.getBlock().getState(), System.currentTimeMillis()); + } //Before GamePlayerManager puts onto Spec! @EventHandler(priority = EventPriority.LOW) @@ -464,4 +514,81 @@ public class EventGame extends Game return losers; } + @EventHandler + public void signCheck(BlockRedstoneEvent event) + { + if(event.getBlock().getType() != Material.SIGN_POST && event.getBlock().getType() != Material.WALL_SIGN) + return; + + useSign(((Sign) event.getBlock().getState()).getLines()); + } + + @EventHandler + public void signClock(UpdateEvent event) + { + if(event.getType() != UpdateType.SEC) + return; + + for(Sign sign : _functionSigns.keySet()) + { + if(sign.getBlock().getRelative(BlockFace.DOWN).getType() != Material.IRON_BLOCK) + continue; + + Sign cooldown = null; + + for(BlockFace face : BlockFace.values()) + { + if(face == BlockFace.UP) + continue; + + if(sign.getBlock().getRelative(BlockFace.DOWN).getRelative(face).getType() == Material.WALL_SIGN) + { + cooldown = (Sign) sign.getBlock().getRelative(BlockFace.DOWN).getRelative(face).getState(); + break; + } + } + + if(cooldown == null) + continue; + + if(!UtilTime.elapsed(_functionSigns.get(sign), Long.parseLong(cooldown.getLine(0)) * 1000)) + continue; + + _functionSigns.put(sign, System.currentTimeMillis()); + useSign(sign.getLines()); + } + } + + public void useSign(String[] args) + { + String command = args[0]; + String playerName = args[1]; + + command.replace("[", "").replaceAll("]", ""); + if(command.contentEquals("BC")) + { + String message = args[1]; + for(int i = 2; i <= 3; i++) + message += " " + args[i]; + + String colored = ChatColor.translateAlternateColorCodes('&', message); + this.Announce(F.main("Event", colored), true); + } + + + Player player = Bukkit.getPlayer(playerName); + if(player == null) + return; + + String[] vars = new String[args.length - 1]; + vars[0] = args[0]; + vars[1] = args[2]; + vars[2] = args[3]; + + if(command.contentEquals("MOB")) + { + Manager.GetEventModule().commandMob(player, vars); + } + } + } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/event/EventModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/event/EventModule.java index 537e6589c..90d0c4f29 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/event/EventModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/event/EventModule.java @@ -54,7 +54,7 @@ import org.bukkit.potion.PotionEffectType; public class EventModule extends MiniPlugin { - public ArcadeManager Manager; + private ArcadeManager Manager; private NautHashMap _potionEffectsDuration = new NautHashMap<>(); private NautHashMap _potionEffectsMult = new NautHashMap<>(); @@ -110,7 +110,7 @@ public class EventModule extends MiniPlugin event.setCancelled(true); } - private void commandHelp(Player player) + public void commandHelp(Player player) { UtilPlayer.message(player, F.main("Event", "Displaying Commands;")); @@ -151,7 +151,7 @@ public class EventModule extends MiniPlugin UtilPlayer.message(player, F.value("/e effect clear", "")); } - private void commandHelpSettings(Player player) + public void commandHelpSettings(Player player) { UtilPlayer.message(player, F.main("Event", "Displaying Settings Commands;")); UtilPlayer.message(player, F.value("/e damage all", "Toggles All Damage")); @@ -181,7 +181,7 @@ public class EventModule extends MiniPlugin //Command Handler @EventHandler(priority = EventPriority.LOWEST) - private void commandHandler(PlayerCommandPreprocessEvent event) + public void commandHandler(PlayerCommandPreprocessEvent event) { if (!Manager.GetGame().InProgress()) return; @@ -366,7 +366,7 @@ public class EventModule extends MiniPlugin } } - private void listSettings(Player player) + public void listSettings(Player player) { UtilPlayer.message(player, F.value("Damage All", F.tf(Manager.GetGame().Damage))); UtilPlayer.message(player, F.value("Damage PvP", F.tf(Manager.GetGame().DamagePvP))); @@ -389,28 +389,28 @@ public class EventModule extends MiniPlugin UtilPlayer.message(player, F.value("Mob griefing", F.tf(_mobGriefing))); } - private void commandBlockBreakInCreative(Player player, String[] args) + public void commandBlockBreakInCreative(Player player, String[] args) { Manager.GetGame().BlockBreakCreative = !Manager.GetGame().BlockBreakCreative; UtilPlayer.message(player, F.main("Settings", "BlockBreakCreative: " + F.tf(Manager.GetGame().BlockBreakCreative))); } - private void commandBlockPlaceInCreative(Player player, String[] args) + public void commandBlockPlaceInCreative(Player player, String[] args) { Manager.GetGame().BlockPlaceCreative = !Manager.GetGame().BlockPlaceCreative; UtilPlayer.message(player, F.main("Settings", "BlockPlaceCreative: " + F.tf(Manager.GetGame().BlockPlaceCreative))); } - private void commandMobGriefing(Player player, String[] args) + public void commandMobGriefing(Player player, String[] args) { _mobGriefing = !_mobGriefing; UtilPlayer.message(player, F.main("Settings", "Mob Griefing: " + F.tf(_mobGriefing))); } - private void commandBlockPlace(Player player, String[] args, boolean whitelist, String command) + public void commandBlockPlace(Player player, String[] args, boolean whitelist, String command) { try { @@ -471,7 +471,7 @@ public class EventModule extends MiniPlugin commandHelpSettings(player); } - private void commandBlockBreak(Player player, String[] args, boolean whitelist, String command) + public void commandBlockBreak(Player player, String[] args, boolean whitelist, String command) { try { @@ -532,7 +532,7 @@ public class EventModule extends MiniPlugin commandHelpSettings(player); } - private void commandHealth(Player player, String[] args) + public void commandHealth(Player player, String[] args) { try { @@ -563,7 +563,7 @@ public class EventModule extends MiniPlugin commandHelpSettings(player); } - private void commandHunger(Player player, String[] args) + public void commandHunger(Player player, String[] args) { try { @@ -594,7 +594,7 @@ public class EventModule extends MiniPlugin commandHelpSettings(player); } - private void commandTime(Player player, String[] args) + public void commandTime(Player player, String[] args) { try { @@ -626,7 +626,7 @@ public class EventModule extends MiniPlugin } //Teleport Command (To, Here, All) - private void commandTeleport(Player player, String[] args) + public void commandTeleport(Player player, String[] args) { if (args.length >= 3 && args[1].equalsIgnoreCase("here")) { @@ -668,7 +668,7 @@ public class EventModule extends MiniPlugin } //Gadget Commands (Global & Individual) - private void commandGadget(Player player, String[] args) + public void commandGadget(Player player, String[] args) { if(!(Manager.GetGame() instanceof EventGame)) { UtilPlayer.message(player, F.main("Inventory", "You can only enable/disable gadgets in the Event game!")); @@ -780,7 +780,7 @@ public class EventModule extends MiniPlugin } //Silence - private void commandSilence(Player player, String[] args) + public void commandSilence(Player player, String[] args) { try { @@ -813,7 +813,7 @@ public class EventModule extends MiniPlugin } //Gamemode (Self and Others) - private void commandAdmin(Player player, String[] args) + public void commandAdmin(Player player, String[] args) { Player target = player; @@ -835,7 +835,7 @@ public class EventModule extends MiniPlugin } //Gamemode (Self and Others) - private void commandGamemode(Player player, String[] args) + public void commandGamemode(Player player, String[] args) { Player target = player; @@ -857,7 +857,7 @@ public class EventModule extends MiniPlugin } //Forcefield - private void commandForcefieldRadius(Player player, String[] args) + public void commandForcefieldRadius(Player player, String[] args) { if(!(Manager.GetGame() instanceof EventGame)) { @@ -889,7 +889,7 @@ public class EventModule extends MiniPlugin } //Give - private void commandGive(Player player, String[] args) + public void commandGive(Player player, String[] args) { String[] newArgs = new String[args.length-1]; @@ -900,7 +900,7 @@ public class EventModule extends MiniPlugin } //Spec - private void commandSpectators(Player player, String[] args) + public void commandSpectators(Player player, String[] args) { Manager.GetGame().JoinInProgress = !Manager.GetGame().JoinInProgress; @@ -908,7 +908,7 @@ public class EventModule extends MiniPlugin } //Deathout - private void commandDeathout(Player player, String[] args) + public void commandDeathout(Player player, String[] args) { Manager.GetGame().DeathOut = !Manager.GetGame().DeathOut; @@ -916,7 +916,7 @@ public class EventModule extends MiniPlugin } //QuitOut - private void commandQuitOut(Player player, String[] args) + public void commandQuitOut(Player player, String[] args) { Manager.GetGame().QuitOut = !Manager.GetGame().QuitOut; @@ -924,7 +924,7 @@ public class EventModule extends MiniPlugin } //Double Jump - private void commandDoubleJump(Player player, String[] args) + public void commandDoubleJump(Player player, String[] args) { if(!(Manager.GetGame() instanceof EventGame)) { @@ -942,7 +942,7 @@ public class EventModule extends MiniPlugin } //Scoreboard - private void commandScoreboard(Player player, String[] args) + public void commandScoreboard(Player player, String[] args) { if(!(Manager.GetGame() instanceof EventGame)) { @@ -1016,7 +1016,7 @@ public class EventModule extends MiniPlugin } //Whitelist - private void commandWhitelist(Player player, String[] args) + public void commandWhitelist(Player player, String[] args) { //On and Off if (args.length >= 2) @@ -1056,7 +1056,7 @@ public class EventModule extends MiniPlugin } //Mob - private void commandMob(Player caller, String[] args) + public void commandMob(Player caller, String[] args) { if (args.length == 1) { @@ -1444,7 +1444,7 @@ public class EventModule extends MiniPlugin } } - private void commandMobKill(Player caller, String[] args) + public void commandMobKill(Player caller, String[] args) { if (args.length < 3) { @@ -1490,7 +1490,7 @@ public class EventModule extends MiniPlugin UtilPlayer.message(caller, F.main("Creature", "Killed " + target + ". " + count + " Removed.")); } - private void commandKit(Player caller, String[] args) + public void commandKit(Player caller, String[] args) { if(!(Manager.GetGame() instanceof EventGame)) { @@ -1533,7 +1533,7 @@ public class EventModule extends MiniPlugin commandHelp(caller); } - private void commandEffect(Player caller, String[] args) + public void commandEffect(Player caller, String[] args) { //Clear if (args.length >= 3 && args[2].equalsIgnoreCase("clear"))