From 2f478e46f3bf2a05063f179828336bcfb49e9220 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 21 Apr 2017 21:53:16 +0100 Subject: [PATCH] Fix various bugs found in testing --- .../arcade/game/games/smash/SuperSmash.java | 53 ++++++++----------- .../game/games/smash/SuperSmashTraining.java | 30 ++++++++--- .../smash/events/SmashActivateEvent.java | 42 +++++++++++++++ .../game/games/smash/perks/SmashUltimate.java | 2 + .../modules/training/TrainingGameModule.java | 5 ++ 5 files changed, 93 insertions(+), 39 deletions(-) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/events/SmashActivateEvent.java diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmash.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmash.java index 3bcdcb304..7e607018e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmash.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmash.java @@ -18,6 +18,7 @@ import nautilus.game.arcade.game.DebugCommand; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam.PlayerState; +import nautilus.game.arcade.game.games.smash.events.SmashActivateEvent; import nautilus.game.arcade.game.games.smash.kits.*; import nautilus.game.arcade.game.games.smash.perks.SmashUltimate; import nautilus.game.arcade.game.modules.compass.CompassModule; @@ -252,12 +253,12 @@ public abstract class SuperSmash extends Game @EventHandler public void triggerSuper(PlayerInteractEvent event) { - if (!IsLive()) + if (!IsLive() || !UtilEvent.isAction(event, UtilEvent.ActionType.R)) { return; } - if (event.getMaterial() != Material.NETHER_STAR) + if (event.getMaterial() != null && event.getMaterial() != Material.NETHER_STAR) { return; } @@ -276,6 +277,15 @@ public abstract class SuperSmash extends Game continue; } + SmashActivateEvent smashActivateEvent = new SmashActivateEvent(player); + + UtilServer.CallEvent(smashActivateEvent); + + if (smashActivateEvent.isCancelled()) + { + return; + } + UtilInv.remove(player, Material.NETHER_STAR, (byte) 0, 1); player.setHealth(player.getMaxHealth()); @@ -547,47 +557,19 @@ public abstract class SuperSmash extends Game @EventHandler(priority = EventPriority.LOWEST) public void abilityDescription(PlayerInteractEvent event) { - if (event.isCancelled()) - { - return; - } - Player player = event.getPlayer(); ItemStack itemStack = player.getItemInHand(); - if (itemStack == null) + if (itemStack == null || itemStack.getItemMeta() == null || itemStack.getItemMeta().getDisplayName() == null || itemStack.getItemMeta().getLore() == null || !displayKitInfo(player)) { return; } - if (itemStack.getItemMeta() == null) + if (itemStack.getType() == Material.WATCH || itemStack.getType() == Material.BED) { return; } - ItemMeta itemMeta = itemStack.getItemMeta(); - - if (itemMeta.getDisplayName() == null) - { - return; - } - - if (itemMeta.getLore() == null) - { - return; - } - - if (GetState() != GameState.Recruit) - { - return; - } - - displayKitInto(player); - event.setCancelled(true); - } - - protected void displayKitInto(Player player) - { for (int i = player.getItemInHand().getItemMeta().getLore().size(); i <= 7; i++) { UtilPlayer.message(player, ""); @@ -606,6 +588,8 @@ public abstract class SuperSmash extends Game UtilPlayer.message(player, ArcadeFormat.Line); player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 2f); + + event.setCancelled(true); } @Override @@ -725,4 +709,9 @@ public abstract class SuperSmash extends Game { return _lives; } + + protected boolean displayKitInfo(Player player) + { + return GetState() == GameState.Recruit; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmashTraining.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmashTraining.java index d4e37452e..a12fd581c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmashTraining.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmashTraining.java @@ -10,6 +10,7 @@ import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.smash.events.SmashActivateEvent; import nautilus.game.arcade.game.modules.training.TrainingBot; import nautilus.game.arcade.game.modules.training.TrainingGameModule; import org.bukkit.ChatColor; @@ -36,6 +37,10 @@ public class SuperSmashTraining extends SuperSmash private Location _borderA; private Location _borderB; + private Function safeFunction = player -> + { + return !UtilAlg.inBoundingBox(player.getLocation(), _borderA, _borderB); + }; private boolean _announceEnd; @@ -49,15 +54,11 @@ public class SuperSmashTraining extends SuperSmash DeathSpectateSecs = 0; PrepareTime = 500; GiveClock = false; - - Function playerFunction = player -> - { - return !UtilAlg.inBoundingBox(player.getLocation(), _borderA, _borderB); - }; + HungerSet = 20; new TrainingGameModule() - .setSkillFunction(playerFunction) - .setDamageFunction(playerFunction) + .setSkillFunction(safeFunction) + .setDamageFunction(safeFunction) .addBot(TrainingBot.class) .register(this); } @@ -156,6 +157,15 @@ public class SuperSmashTraining extends SuperSmash { } + @EventHandler + public void smashActivating(SmashActivateEvent event) + { + if (!safeFunction.apply(event.getPlayer())) + { + event.setCancelled(true); + } + } + @Override public void EndCheck() { @@ -182,6 +192,12 @@ public class SuperSmashTraining extends SuperSmash return (long) (System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(2) + TimeUnit.MINUTES.toMillis(2) * Math.random()); } + @Override + protected boolean displayKitInfo(Player player) + { + return super.displayKitInfo(player) || !safeFunction.apply(player); + } + private void spawnInfoHologram(Location location) { CreatureAllowOverride = true; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/events/SmashActivateEvent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/events/SmashActivateEvent.java new file mode 100644 index 000000000..44b89f7ef --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/events/SmashActivateEvent.java @@ -0,0 +1,42 @@ +package nautilus.game.arcade.game.games.smash.events; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +public class SmashActivateEvent extends PlayerEvent implements Cancellable +{ + + private static final HandlerList HANDLERS = new HandlerList(); + + private boolean _cancelled; + + public SmashActivateEvent(Player who) + { + super(who); + } + + @Override + public boolean isCancelled() + { + return _cancelled; + } + + @Override + public void setCancelled(boolean b) + { + _cancelled = b; + } + + public HandlerList getHandlers() + { + return HANDLERS; + } + + public static HandlerList getHandlerList() + { + return HANDLERS; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/SmashUltimate.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/SmashUltimate.java index 8bddb995c..7fbee53c9 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/SmashUltimate.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/SmashUltimate.java @@ -6,6 +6,8 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import mineplex.core.common.util.UtilServer; +import nautilus.game.arcade.game.games.smash.events.SmashActivateEvent; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/training/TrainingGameModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/training/TrainingGameModule.java index e3c19bf3f..4f83b37f1 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/training/TrainingGameModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/training/TrainingGameModule.java @@ -284,6 +284,11 @@ public class TrainingGameModule extends Module if (!event.isCancelled()) { Recharge.Instance.useForce(player, RETURN_TO_SPAWN_RECHARGE, RETURN_TO_SPAWN_COOLDOWN); + + if (event.GetDamagerEntity(true) instanceof Player) + { + Recharge.Instance.useForce(event.GetDamagerPlayer(true), RETURN_TO_SPAWN_RECHARGE, RETURN_TO_SPAWN_COOLDOWN); + } } if (_damageFunction == null)