diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java index d8052c50b..2ac418c9b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java @@ -282,15 +282,18 @@ public class Moba extends TeamGame setKits(_kits); // Store player data - for (Player player : GetPlayers(true)) - { - _playerData.add(new MobaPlayer(player)); - MobaUtil.setTeamEntity(player, GetTeam(player)); - } + GetPlayers(true).forEach(this::setupPlayerData); + // Make sure to cleanup cleanupLobby(); } + public void setupPlayerData(Player player) + { + _playerData.add(new MobaPlayer(player)); + MobaUtil.setTeamEntity(player, GetTeam(player)); + } + @EventHandler public void preventOverfill(PlayerPrepareTeleportEvent event) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/MobaClassic.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/MobaClassic.java index 1d0cf535b..853488d6d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/MobaClassic.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/MobaClassic.java @@ -10,7 +10,6 @@ import nautilus.game.arcade.game.games.moba.general.HotJoiningManager; import nautilus.game.arcade.game.games.moba.prepare.PrepareManager; import nautilus.game.arcade.game.games.moba.prepare.PrepareSelection; import nautilus.game.arcade.game.modules.CustomScoreboardModule; -import nautilus.game.arcade.game.modules.GameStatisticsModule; import nautilus.game.arcade.scoreboard.GameScoreboard; import org.bukkit.ChatColor; import org.bukkit.entity.LivingEntity; @@ -98,7 +97,7 @@ public class MobaClassic extends Moba { suffix = C.cYellow + " Unknown"; } - else if (mobaPlayer.getKit() == null) + else if (mobaPlayer == null || mobaPlayer.getKit() == null) { suffix = C.cYellow + " Selecting"; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/buff/BuffManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/buff/BuffManager.java index 66ce3aba8..c89e1fe11 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/buff/BuffManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/buff/BuffManager.java @@ -4,6 +4,8 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTime; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game.GameState; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -36,25 +38,7 @@ public class BuffManager implements Listener _buffs.get(buff.getEntity()).add(buff); buff.apply(); } - - public boolean hasBuff(LivingEntity entity, Class> clazz) - { - if (!_buffs.containsKey(entity)) - { - return false; - } - - for (Buff buff : _buffs.get(entity)) - { - if (buff.getClass().equals(clazz)) - { - return true; - } - } - - return false; - } - + @EventHandler public void update(UpdateEvent event) { @@ -91,4 +75,15 @@ public class BuffManager implements Listener } } } + + @EventHandler + public void end(GameStateChangeEvent event) + { + if (event.GetState() != GameState.End) + { + return; + } + + _buffs.forEach((livingEntity, buffs) -> buffs.forEach(Buff::expire)); + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/general/HotJoiningManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/general/HotJoiningManager.java index cd02401a9..f413cd84b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/general/HotJoiningManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/general/HotJoiningManager.java @@ -1,21 +1,26 @@ package nautilus.game.arcade.game.games.moba.general; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilTime; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.games.moba.Moba; +import nautilus.game.arcade.game.games.moba.kit.HeroSkill; import nautilus.game.arcade.game.games.moba.progression.MobaExperienceCalculateEvent; import nautilus.game.arcade.game.games.moba.structure.tower.Tower; import nautilus.game.arcade.kit.Kit; +import nautilus.game.arcade.kit.Perk; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import java.util.ArrayList; import java.util.List; +import java.util.UUID; public class HotJoiningManager implements Listener { @@ -23,18 +28,22 @@ public class HotJoiningManager implements Listener private static final int HOT_JOIN_EXP_REWARD = 100; private final Moba _host; + private final List _pending; private final List _hotJoined; + private final List _played; public HotJoiningManager(Moba host) { _host = host; + _pending = new ArrayList<>(); _hotJoined = new ArrayList<>(); + _played = new ArrayList<>(8); } - @EventHandler(priority = EventPriority.MONITOR) - public void playerJoin(PlayerJoinEvent event) + @EventHandler(priority = EventPriority.LOWEST) + public void playerLogin(PlayerLoginEvent event) { - if (!_host.IsLive()) + if (!_host.IsLive() || !_host.getArcadeManager().IsRewardStats()) { return; } @@ -42,11 +51,36 @@ public class HotJoiningManager implements Listener Player player = event.getPlayer(); GameTeam team = _host.ChooseTeam(player); - if (team == null || _host.getArcadeManager().isVanished(player)) + if (team == null || team.GetSize() >= 4) { return; } + _pending.add(player); + team.AddPlayer(player, true); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void playerJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + + if (!_pending.remove(player)) + { + return; + } + + GameTeam team = _host.GetTeam(player); + + if (_host.getArcadeManager().isVanished(player)) + { + if (team != null) + { + team.RemovePlayer(player); + } + return; + } + for (Tower tower : _host.getTowerManager().getTowers()) { // If the team's second tower is dead @@ -57,16 +91,34 @@ public class HotJoiningManager implements Listener } } - team.AddPlayer(player, true); + boolean played = _played.contains(player.getUniqueId()); + team.SpawnTeleport(player); - _hotJoined.add(player); + + if (!played) + { + _hotJoined.add(player); + } + + _host.setupPlayerData(player); _host.getArcadeManager().runSyncLater(() -> { Kit kit = _host.getFirstKit(player); - player.sendMessage(F.main("Game", "Thanks for choosing to join a game in progress! If you stay until the end of the game you will earn an additional " + HOT_JOIN_EXP_REWARD + " experience points")); + if (!played) + { + player.sendMessage(F.main("Game", "Thanks for choosing to join a game in progress! If you stay until the end of the game you will were an additional " + F.elem(HOT_JOIN_EXP_REWARD) + " " + F.greenElem("Heroes of GWEN Role") + " experience.")); + } _host.SetKit(player, kit, true); + + Perk perk = kit.GetPerks()[kit.GetPerks().length - 1]; + + // Put Ultimates on cooldown + if (perk instanceof HeroSkill) + { + ((HeroSkill) perk).useSkill(player); + } }, 1); } @@ -74,9 +126,21 @@ public class HotJoiningManager implements Listener public void playerQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); + _pending.remove(player); _hotJoined.remove(player); } + @EventHandler + public void live(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Prepare) + { + return; + } + + _host.GetPlayers(true).forEach(player -> _played.add(player.getUniqueId())); + } + @EventHandler public void expCalculate(MobaExperienceCalculateEvent event) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/devon/SkillInfinity.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/devon/SkillInfinity.java index 6097e9a28..753b4d324 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/devon/SkillInfinity.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/devon/SkillInfinity.java @@ -50,7 +50,7 @@ public class SkillInfinity extends HeroSkill @EventHandler public void interact(PlayerInteractEvent event) { - if (!isSkillItem(event) || _active.contains(event.getPlayer())) + if (!isSkillItem(event)) { return; } @@ -66,13 +66,11 @@ public class SkillInfinity extends HeroSkill // Give 1 arrow just incase the player didn't have one _kit.giveAmmo(player, 1); bow.addEnchantment(Enchantment.ARROW_INFINITE, 1); - _active.add(player); broadcast(player); useActiveSkill(() -> { bow.removeEnchantment(Enchantment.ARROW_INFINITE); - _active.remove(player); }, player, 7000); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShop.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShop.java index 6b8b00e34..224ee61bc 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShop.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShop.java @@ -26,7 +26,6 @@ import nautilus.game.arcade.game.games.moba.shop.hunter.MobaHunterShop; import nautilus.game.arcade.game.games.moba.shop.mage.MobaMageShop; import nautilus.game.arcade.game.games.moba.shop.warrior.MobaWarriorShop; import nautilus.game.arcade.game.games.moba.util.MobaConstants; -import nautilus.game.arcade.kit.Kit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; @@ -249,6 +248,7 @@ public class MobaShop implements Listener public List getOwnedItems(Player player) { + _upgrades.putIfAbsent(player, new ArrayList<>()); return _upgrades.get(player); } @@ -329,20 +329,6 @@ public class MobaShop implements Listener Handle MobaItem events */ - @EventHandler - public void prepare(GameStateChangeEvent event) - { - if (event.GetState() != GameState.Prepare) - { - return; - } - - for (Player player : _host.GetPlayers(true)) - { - _upgrades.put(player, new ArrayList<>()); - } - } - @EventHandler public void ammoGive(AmmoGiveEvent event) {