From 790d13d1d756e33b0379dd6bd6ff92b89a1500fd Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 30 Apr 2018 21:48:21 +0100 Subject: [PATCH] Death Tag --- .../arcade/game/games/deathtag/DeathTag.java | 292 +++++++++--------- 1 file changed, 151 insertions(+), 141 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/deathtag/DeathTag.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/deathtag/DeathTag.java index 17d500440..8c08326ff 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/deathtag/DeathTag.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/deathtag/DeathTag.java @@ -1,15 +1,31 @@ package nautilus.game.arcade.game.games.deathtag; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.ItemFrame; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; + import mineplex.core.Managers; import mineplex.core.common.util.C; import mineplex.core.common.util.F; -import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; 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; @@ -26,69 +42,51 @@ import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.NullKit; import nautilus.game.arcade.stats.ComeAtMeBroStatTracker; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.ItemFrame; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - public class DeathTag extends SoloGame { + + private static final String[] DESCRIPTION = + { + C.cGreen + "Run" + C.Reset + " from the " + C.cRed + "Undead!", + "If you die, you become " + C.cRed + "Undead!", + C.cYellow + "Last Runner" + C.Reset + " alive wins!" + }; + private GameTeam _runners; private GameTeam _chasers; - private NautHashMap _deathLocation = new NautHashMap(); + private final Map _deathLocation = new HashMap<>(); + private List _lights; private int _currentSpeed = -1; - - private ArrayList _lights = new ArrayList(); - public DeathTag(ArcadeManager manager) + public DeathTag(ArcadeManager manager) { - super(manager, GameType.DeathTag, + super(manager, GameType.DeathTag, new Kit[] + { + new KitRunnerBasher(manager), + new KitRunnerArcher(manager), + new KitRunnerTraitor(manager), + new NullKit(manager), + new KitAlphaChaser(manager), + new KitChaser(manager), + }, DESCRIPTION); - new Kit[] - { - new KitRunnerBasher(manager), - new KitRunnerArcher(manager), - new KitRunnerTraitor(manager), - new NullKit(manager), - new KitAlphaChaser(manager), - new KitChaser(manager), - }, - - new String[] - { - "Run from the Undead!", - "If you die, you become Undead!", - "The last Runner alive wins!" - }); - - this.StrictAntiHack = true; - - this.DeathOut = false; - this.HungerSet = 20; + StrictAntiHack = true; + DeathOut = false; + HungerSet = 20; + PrepareFreeze = false; + PlayerGameMode = GameMode.ADVENTURE; + SplitKitXP = true; new CompassModule() .setGiveCompassToAlive(true) .register(this); - this.PrepareFreeze = false; - this.PlayerGameMode = GameMode.ADVENTURE; - - SplitKitXP = true; - - registerStatTrackers(new ComeAtMeBroStatTracker(this)); + registerStatTrackers( + new ComeAtMeBroStatTracker(this) + ); registerChatStats( Kills, @@ -96,19 +94,11 @@ public class DeathTag extends SoloGame KDRatio ); } - + @Override public void ParseData() { - _lights = this.WorldData.GetCustomLocs("89"); - - for (Location loc : _lights) - { - if (Math.random() > 0.5) - loc.getBlock().setType(Material.GOLD_BLOCK); - else - loc.getBlock().setTypeIdAndData(35, (byte)15, false); - } + _lights = WorldData.GetCustomLocs("89"); } @Override @@ -121,12 +111,16 @@ public class DeathTag extends SoloGame if (team.GetColor() == ChatColor.RED) { if (kit.GetName().contains("ZOMBIE")) + { team.GetRestrictedKits().add(kit); + } } else { if (kit.GetName().contains("Chaser")) + { team.GetRestrictedKits().add(kit); + } } } } @@ -134,57 +128,63 @@ public class DeathTag extends SoloGame @Override @EventHandler - public void CustomTeamGeneration(GameStateChangeEvent event) + public void CustomTeamGeneration(GameStateChangeEvent event) { if (event.GetState() != GameState.Recruit) + { return; + } - _runners = this.GetTeamList().get(0); + _runners = GetTeamList().get(0); _runners.SetName("Runners"); //Undead Team - _chasers = new GameTeam(this, "Chasers", ChatColor.RED, _runners.GetSpawns()); + _chasers = new GameTeam(this, "Chasers", ChatColor.RED, _runners.GetSpawns()); _chasers.SetVisible(false); - GetTeamList().add(_chasers); + AddTeam(_chasers); RestrictKits(); } @Override - public GameTeam ChooseTeam(Player player) + public GameTeam ChooseTeam(Player player) { return _runners; } - - @EventHandler - public void UpdateLights(UpdateEvent event) - { - if (!IsLive()) - return; - if (event.getType() != UpdateType.SEC) - return; - - for (Location loc : _lights) + @EventHandler + public void updateLights(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC || !InProgress()) { - if (loc.getBlock().getType() == Material.GOLD_BLOCK) - loc.getBlock().setTypeIdAndData(35, (byte)15, false); + return; + } + + for (Location location : _lights) + { + Material material = location.getBlock().getType(); + + if (material == Material.GOLD_BLOCK) + { + location.getBlock().setTypeIdAndData(35, (byte) 15, false); + } else - loc.getBlock().setType(Material.GOLD_BLOCK); + { + location.getBlock().setType(Material.GOLD_BLOCK); + } } } - + @EventHandler public void UpdateSpeed(UpdateEvent event) { - if (!IsLive()) + if (event.getType() != UpdateType.SLOW || !IsLive()) + { return; + } - if (event.getType() != UpdateType.SLOW) - return; - - double ratio = (double)_chasers.GetPlayers(false).size() / (double)GetPlayers(false).size(); + double ratio = (double) _chasers.GetPlayers(false).size() / (double) GetPlayers(false).size(); if (_currentSpeed == -1 && ratio > 0.25) { @@ -204,76 +204,80 @@ public class DeathTag extends SoloGame } @EventHandler - public void ApplyConditions(UpdateEvent event) + public void applyConditions(UpdateEvent event) { - if (!IsLive()) - return; - - if (event.getType() != UpdateType.FAST) + if (event.getType() != UpdateType.SLOW || !IsLive()) + { return; + } if (_currentSpeed >= 0) + { for (Player player : _runners.GetPlayers(false)) { Manager.GetCondition().Factory().Speed("Runner", player, player, 1.9, _currentSpeed, false, false, true); } + } for (Player player : _chasers.GetPlayers(false)) { Manager.GetCondition().Factory().Regen("Undying", player, player, 1.9, 4, false, false, false); if (_currentSpeed < 0) + { Manager.GetCondition().Factory().Speed("Haste", player, player, 1.9, 0, false, false, true); + } } } - + @EventHandler - public void onPlayerInteractEntity(PlayerInteractEntityEvent event) + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { - if(event.getRightClicked() instanceof ItemFrame) + if (event.getRightClicked() instanceof ItemFrame) { event.setCancelled(true); } } @EventHandler - public void UpdateChasers(UpdateEvent event) + public void updateChasers(UpdateEvent event) { - if (!IsLive()) - return; - - if (event.getType() != UpdateType.FAST) + if (event.getType() != UpdateType.FAST || !IsLive()) + { return; + } int req = 1 + (int) ((System.currentTimeMillis() - GetStateTime()) / 30000); while (_chasers.GetPlayers(true).size() < req && _runners.GetPlayers(true).size() > 0) { Player player = _runners.GetPlayers(true).get(UtilMath.r(_runners.GetPlayers(true).size())); - SetChaser(player, true); + setChaser(player, true); } } @EventHandler - public void PlayerDeath(PlayerDeathEvent event) + public void playerDeath(PlayerDeathEvent event) { if (_runners.HasPlayer(event.getEntity())) { _deathLocation.put(event.getEntity(), event.getEntity().getLocation()); - SetChaser(event.getEntity(), false); + setChaser(event.getEntity(), false); } } - public void SetChaser(Player player, boolean forced) + private void setChaser(Player player, boolean forced) { //Set them as OUT! - if (GetTeam(player) != null) + if (IsPlaying(player)) + { GetTeam(player).SetPlacement(player, PlayerState.OUT); + } SetPlayerTeam(player, _chasers, true); //Kit - Kit newKit = GetKits()[5]; //Normal + Kit newKit = GetKits()[5]; //Normal if (forced) { newKit = GetKits()[4]; //Alpha @@ -285,13 +289,12 @@ public class DeathTag extends SoloGame //Refresh VisibilityManager vm = Managers.require(VisibilityManager.class); Bukkit.getOnlinePlayers().forEach(pl -> vm.refreshVisibility(pl, player)); - + if (forced) { AddGems(player, 10, "Forced Chaser", false, false); - Announce(F.main("Game", F.elem(_runners.GetColor() + player.getName()) + " has become an " + - F.elem(_chasers.GetColor() + newKit.GetName()) + ".")); + Announce(F.main("Game", F.elem(_runners.GetColor() + player.getName()) + " has become an " + F.elem(_chasers.GetColor() + newKit.GetName()) + ".")); player.getWorld().strikeLightningEffect(player.getLocation()); } @@ -310,22 +313,23 @@ public class DeathTag extends SoloGame player.eject(); if (_deathLocation.containsKey(player)) + { player.teleport(_deathLocation.remove(player)); + } else + { player.teleport(_chasers.GetSpawn()); + } } //Re-Give Kit - Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() + Manager.runSyncLater(() -> { - public void run() - { - GetKit(player).ApplyKit(player); + GetKit(player).ApplyKit(player); - //Refresh on Spawn - VisibilityManager vm = Managers.require(VisibilityManager.class); - Bukkit.getOnlinePlayers().forEach(pl -> vm.refreshVisibility(pl, player)); - } + //Refresh on Spawn + VisibilityManager vm = Managers.require(VisibilityManager.class); + Bukkit.getOnlinePlayers().forEach(pl -> vm.refreshVisibility(pl, player)); }, 0); } @@ -333,27 +337,38 @@ public class DeathTag extends SoloGame public void EndCheck() { if (!IsLive()) + { return; - + } + if (_runners.GetPlayers(true).size() <= 1) { - ArrayList places = _runners.GetPlacements(true); + List places = _runners.GetPlacements(true); if (places.size() >= 1) + { AddGems(places.get(0), 15, "1st Place", false, false); + } if (places.size() >= 2) + { AddGems(places.get(1), 10, "2nd Place", false, false); + } if (places.size() >= 3) + { AddGems(places.get(2), 5, "3rd Place", false, false); + } for (Player player : GetPlayers(false)) + { if (player.isOnline()) + { AddGems(player, 10, "Participation", false, false); + } + } AnnounceEnd(places); - SetState(GameState.End); } } @@ -362,22 +377,18 @@ public class DeathTag extends SoloGame @EventHandler public void ScoreboardUpdate(UpdateEvent event) { - if (event.getType() != UpdateType.FAST) + if (event.getType() != UpdateType.FAST || _runners == null || _chasers == null) + { return; - - if (_runners == null || _chasers == null) - return; - - //Wipe Last - Scoreboard.reset(); + } Scoreboard.writeNewLine(); - - Scoreboard.write(_runners.GetPlayers(true).size() + " " +_runners.GetColor() + " Runners"); - + + Scoreboard.write(_runners.GetPlayers(true).size() + " " + _runners.GetColor() + " Runners"); + Scoreboard.writeNewLine(); - - Scoreboard.write(_chasers.GetPlayers(true).size() + " " +_chasers.GetColor() + " Chasers"); + + Scoreboard.write(_chasers.GetPlayers(true).size() + " " + _chasers.GetColor() + " Chasers"); Scoreboard.draw(); } @@ -385,12 +396,7 @@ public class DeathTag extends SoloGame @Override public boolean CanJoinTeam(GameTeam team) { - if (team.GetColor() == ChatColor.RED) - { - return team.GetSize() < 1 + UtilServer.getPlayers().length/8; - } - - return true; + return team.GetColor() != ChatColor.RED || team.GetSize() < 1 + UtilServer.getPlayers().length / 8; } @Override @@ -403,7 +409,7 @@ public class DeathTag extends SoloGame return 0; } - + @Override public List getWinners() { @@ -412,14 +418,18 @@ public class DeathTag extends SoloGame List places = _runners.GetPlayers(true); if (places.isEmpty() || !places.get(0).isOnline()) - return Arrays.asList(); + { + return Collections.emptyList(); + } else - return Arrays.asList(places.get(0)); + { + return Collections.singletonList(places.get(0)); + } } - else - return null; + + return null; } - + @Override public List getLosers() { @@ -427,7 +437,7 @@ public class DeathTag extends SoloGame { return _chasers.GetPlayers(true); } - else - return null; + + return null; } }