From d9a8830e7526beebfd13ba423035bdb3527cbb41 Mon Sep 17 00:00:00 2001 From: Mysticate Date: Sun, 9 Aug 2015 14:34:55 -0400 Subject: [PATCH] Few changes --- .../mineplex/core/itemstack/ItemBuilder.java | 3 +- .../arcade/game/games/evolution/EvoToken.java | 6 +- .../game/games/evolution/Evolution.java | 236 ++++++++++-------- .../games/evolution/evolve/EvolveManager.java | 93 ++++++- 4 files changed, 224 insertions(+), 114 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java index e13338dd1..3a1f090e0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java @@ -308,9 +308,10 @@ public class ItemBuilder return this; } - public void setData(short newData) + public ItemBuilder setData(short newData) { this._data = newData; + return this; } public ItemBuilder setPotion(Potion potion) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/EvoToken.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/EvoToken.java index a0e4f7810..392dbaf0f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/EvoToken.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/EvoToken.java @@ -10,7 +10,7 @@ public class EvoToken implements Comparable public final Player Player; - public int Kills = 0; + public int Level = 0; public EvoToken(Player player) { @@ -20,11 +20,11 @@ public class EvoToken implements Comparable @Override public int compareTo(EvoToken o) { - if (Kills == o.Kills) + if (Level == o.Level) { return 0; } - if (Kills > o.Kills) + if (Level > o.Level) { return -1; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/Evolution.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/Evolution.java index 2dd999be3..155de90d1 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/Evolution.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/Evolution.java @@ -7,21 +7,24 @@ import java.util.Iterator; import mineplex.core.common.util.C; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilGear; +import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.itemstack.ItemBuilder; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; import mineplex.minecraft.game.core.condition.Condition.ConditionType; import mineplex.minecraft.game.core.condition.ConditionActive; -import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; -import nautilus.game.arcade.addons.compass.CompassAttemptTargetEvent; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.SoloGame; -import nautilus.game.arcade.game.games.evolution.events.EvolutionAbilityUseEvent; import nautilus.game.arcade.game.games.evolution.events.EvolutionBeginEvent; import nautilus.game.arcade.game.games.evolution.events.EvolutionEndEvent; import nautilus.game.arcade.game.games.evolution.events.EvolutionPostEvolveEvent; @@ -38,7 +41,6 @@ import nautilus.game.arcade.game.games.evolution.mobs.KitSnowman; import nautilus.game.arcade.game.games.evolution.mobs.KitSpider; import nautilus.game.arcade.game.games.evolution.mobs.KitWolf; import nautilus.game.arcade.kit.Kit; -import nautilus.game.arcade.kit.perks.event.PerkConstructorEvent; import org.bukkit.Location; import org.bukkit.Material; @@ -47,7 +49,8 @@ import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; public class Evolution extends SoloGame @@ -66,6 +69,9 @@ public class Evolution extends SoloGame //Platform location, viewing location. private NautHashMap _evoPlatforms = new NautHashMap(); + private ArrayList _evolutionsAvailable = new ArrayList(); + private ArrayList _attemptingEvolve = new ArrayList(); + public Evolution(ArcadeManager manager) { super(manager, GameType.Evolution, @@ -179,6 +185,8 @@ public class Evolution extends SoloGame } } + + @EventHandler public void showKit(GameStateChangeEvent event) { @@ -212,18 +220,6 @@ public class Evolution extends SoloGame _evolve = new EvolveManager(this, _evoPlatforms); } - @EventHandler - public void tickEvolve(UpdateEvent event) - { - if (!IsLive()) - return; - - if (event.getType() != UpdateType.TICK) - return; - - _evolve.tick(); - } - @Override public boolean HasKit(Player player, Kit kit) { @@ -235,73 +231,23 @@ public class Evolution extends SoloGame return false; } + + //Boolean ending + public void upgradeKit(Player player, boolean give) + { + if (!IsAlive(player)) + return; - @EventHandler(priority = EventPriority.MONITOR) - public void onEvolveDamageRecieve(CustomDamageEvent event) - { - if (!IsLive()) - return; - - if (!(event.GetDamageeEntity() instanceof Player)) - return; - - if (_evolve.isEvolving(event.GetDamageePlayer())) - event.SetCancelled("Player is evolving!"); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onEvolveDamageDeal(CustomDamageEvent event) - { - if (!IsLive()) - return; - - if (!(event.GetDamagerEntity(true) instanceof Player)) - return; - - if (_evolve.isEvolving(event.GetDamagerPlayer(true))) - event.SetCancelled("Player is evolving!"); - } - - @EventHandler - public void onEvolveAbility(EvolutionAbilityUseEvent event) - { - if (!IsLive()) - return; - - if (_evolve.isEvolving(event.getPlayer())) - event.setCancelled(true); - } - - @EventHandler - public void onEvolveCompass(CompassAttemptTargetEvent event) - { - if (!IsLive()) - return; - - if (_evolve.isEvolving(event.getTarget())) - event.setCancelled(true); - } - - @EventHandler - public void onEvolveConstruct(PerkConstructorEvent event) - { - if (!IsLive()) - return; - - if (_evolve.isEvolving(event.getPlayer())) - event.setCancelled(true); - } - - @EventHandler - public void onEvolveMove(PlayerMoveEvent event) - { - if (!IsLive()) - return; - - if (_evolve.isEvolving(event.getPlayer())) - event.getPlayer().teleport(event.getFrom()); - } + EvoKit newKit = _mobKits.get(getScore(player)); + SetKit(player, newKit, false); + + if (give) + { + newKit.upgradeGive(player); + } + } + @EventHandler public void startEvolve(EvolutionBeginEvent event) { @@ -387,37 +333,111 @@ public class Evolution extends SoloGame return; } - EvoToken token = _tokens.get(killer.getName()); + _evolutionsAvailable.add(killer); +// EvoToken token = _tokens.get(killer.getName()); +// +// try +// { +// EvoKit from = _mobKits.get(token.Kills - 1); //Account for the score increase +// EvoKit to = _mobKits.get(token.Kills); +// +// _evolve.addEvolve(killer, from, to); +// } +// catch (IndexOutOfBoundsException ex) +// { +// End(); +// return; +// } + } + + @EventHandler + public void updateAvailableEvolutions(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + return; - try + if (!IsLive()) + return; + + Iterator iterator = _evolutionsAvailable.iterator(); + while (iterator.hasNext()) { - EvoKit from = _mobKits.get(token.Kills - 1); //Account for the score increase - EvoKit to = _mobKits.get(token.Kills); + Player player = iterator.next(); - _evolve.addEvolve(killer, from, to); - } - catch (IndexOutOfBoundsException ex) - { - End(); - return; + if (player == null || !player.isOnline()) + { + iterator.remove(); + return; + } + + if (!IsAlive(player)) + { + iterator.remove(); + return; + } + + if (!_attemptingEvolve.contains(player)) + { + UtilTextMiddle.display("", C.cGreen + C.Bold + "Evolution Available!"); + } + + if (!UtilGear.isMat(player.getInventory().getItem(7), Material.STAINED_CLAY)) + { + player.getInventory().setItem(7, new ItemBuilder(Material.STAINED_CLAY).build()); + } + else + { + //Rainbow effect on the clay + ItemStack item = player.getInventory().getItem(7); + byte data = UtilInv.GetData(item); + + data++; + + if (data > 15) + data = 0; + + item.setDurability(data); + } } } - - //Boolean ending - public void upgradeKit(Player player, boolean give) - { - if (!IsAlive(player)) + + @EventHandler + public void onInteractWithEvolve(PlayerInteractEvent event) + { + if (!UtilEvent.isAction(event, ActionType.R)) return; - - EvoKit newKit = _mobKits.get(getScore(player)); - - SetKit(player, newKit, false); - - if (give) - { - newKit.upgradeGive(player); - } + + if (!IsLive()) + return; + + if (event.getItem().getType() != Material.STAINED_CLAY) + return; + + //Make sure it's the 7 slot + if (event.getPlayer().getInventory().getItem(7) != event.getItem()) + return; + + if (_attemptingEvolve.contains(event.getPlayer())) + return; + + _attemptingEvolve.add(event.getPlayer()); } + + @EventHandler + public void updateAttemptingEvolve(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + return; + + if (!IsLive()) + return; + + Iterator iterator = _attemptingEvolve.iterator(); + while (iterator.hasNext()) + { + Player player = iterator.next(); + } + `} public void increaseScore(Player player) { @@ -427,7 +447,7 @@ public class Evolution extends SoloGame if (!_tokens.containsKey(player.getName())) return; - _tokens.get(player.getName()).Kills++; + _tokens.get(player.getName()).Level++; } public int getScore(Player player) @@ -435,7 +455,7 @@ public class Evolution extends SoloGame if (!IsPlaying(player)) return 0; - return _tokens.get(player.getName()).Kills; + return _tokens.get(player.getName()).Level; } private void End() diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/EvolveManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/EvolveManager.java index 9332480aa..f7bf4613f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/EvolveManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/EvolveManager.java @@ -7,13 +7,25 @@ import java.util.Map.Entry; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.addons.compass.CompassAttemptTargetEvent; import nautilus.game.arcade.game.games.evolution.EvoKit; import nautilus.game.arcade.game.games.evolution.Evolution; +import nautilus.game.arcade.game.games.evolution.events.EvolutionAbilityUseEvent; +import nautilus.game.arcade.kit.perks.event.PerkConstructorEvent; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; -public class EvolveManager +public class EvolveManager implements Listener { /** * @author Mysticate @@ -29,6 +41,8 @@ public class EvolveManager { Host = evolution; _evolveLocs = evolveLocs; + + Bukkit.getPluginManager().registerEvents(this, Host.Manager.getPlugin()); } private PlatformToken getLocation() @@ -57,8 +71,15 @@ public class EvolveManager return _data.get(player.getName()); } - public void tick() + @EventHandler + public void tick(UpdateEvent event) { + if (event.getType() != UpdateType.TICK) + return; + + if (!Host.IsLive()) + return; + Iterator> iterator = _data.entrySet().iterator(); while (iterator.hasNext()) { @@ -92,5 +113,73 @@ public class EvolveManager { data.end(); } + + HandlerList.unregisterAll(this); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onEvolveDamageRecieve(CustomDamageEvent event) + { + if (!Host.IsLive()) + return; + + if (!(event.GetDamageeEntity() instanceof Player)) + return; + + if (isEvolving(event.GetDamageePlayer())) + event.SetCancelled("Player is evolving!"); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onEvolveDamageDeal(CustomDamageEvent event) + { + if (!Host.IsLive()) + return; + + if (!(event.GetDamagerEntity(true) instanceof Player)) + return; + + if (isEvolving(event.GetDamagerPlayer(true))) + event.SetCancelled("Player is evolving!"); + } + + @EventHandler + public void onEvolveAbility(EvolutionAbilityUseEvent event) + { + if (!Host.IsLive()) + return; + + if (isEvolving(event.getPlayer())) + event.setCancelled(true); + } + + @EventHandler + public void onEvolveCompass(CompassAttemptTargetEvent event) + { + if (!Host.IsLive()) + return; + + if (isEvolving(event.getTarget())) + event.setCancelled(true); + } + + @EventHandler + public void onEvolveConstruct(PerkConstructorEvent event) + { + if (!Host.IsLive()) + return; + + if (isEvolving(event.getPlayer())) + event.setCancelled(true); + } + + @EventHandler + public void onEvolveMove(PlayerMoveEvent event) + { + if (!Host.IsLive()) + return; + + if (isEvolving(event.getPlayer())) + event.getPlayer().teleport(event.getFrom()); } }