diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/skin/SkinData.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/skin/SkinData.java index 910849f06..28a189da6 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/skin/SkinData.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/skin/SkinData.java @@ -62,7 +62,8 @@ public class SkinData public final static SkinData HAUNTED_CHEST = new SkinData("eyJ0aW1lc3RhbXAiOjE0NzUyNTUzOTE3OTcsInByb2ZpbGVJZCI6IjlmY2FlZDhiMTRiNTRmN2ZhNjRjYjYwNDBlNzA1MjcyIiwicHJvZmlsZU5hbWUiOiJMQ2FzdHIxIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9lZWM5MmU4ODNiOGFjODI0MDU5YTk5NGM5NTNjNTQ0NDQ0Yjk3ZWFkZDdhNWFjNGY3ZTZhOTUxOGQ5YTkxMSJ9fX0=", "GqycEQvWoZeXDLAJ6ricUx3coA4Y6AswL0GV1KebetoTkd9XNtkJJ9eUf6ViwpSgmL0H89sdMjghThHKczUEmjaFeNl2Z9cwGnR1WOK3KpD+v8C7f10l2DNd7z8s1clJfkVay/5KkgNMneu+ZStF8mCt+uyOSfZX4toLRBba6ZDaz4RlmcNt3e6h+dCaB/npbrWxddX7YZWsAMEKxmMKrG/Rm1Gx7ZOchmd4l6+pypA3Vrjoc0LVjqDV/TsePiNxV9LWFB7Rc6YGkIyz2+z5m168iLnn4+qMMXOYndwH7RGcTLEJDPRfNjawuPNcRlYZ6bf30S540MQdC0dJbRLu0uT9CAyi1vjxezdKjGJZSiY5WmtWrhkiRRtCMr9fGxBRNxPDdf5bs7IgWClFgafkGFZKZjLlOV8qtlMrPQSduPtGBCM64veJchSMFS6MfxgE2O/+4EZ246ZN1bdV6KiLRDIzFmy9PBn2o6MNtcdFc/G5XdD7aCTwuGD6sbG2T97Aiai56CN1vYsc6yXUfeZafSm6qviXAx3zTEd1aw1oAZLj3PAt0uZRHggsBEKvwPVKsgHsOVFj5vu0BfHFbdaSdhL3GFotk06Ilr5cLxOrTwqoVNp/hiIJ8pu7T0AEWy1pMYD1+RszsTjJ76l305cQ3UHvinjnbXllsFQIIVE899s="); public final static SkinData WITCH = new SkinData("eyJ0aW1lc3RhbXAiOjE0NzM5OTEyMTE1NDQsInByb2ZpbGVJZCI6IjlmY2FlZDhiMTRiNTRmN2ZhNjRjYjYwNDBlNzA1MjcyIiwicHJvZmlsZU5hbWUiOiJMQ2FzdHIxIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS81NDg1ZDZlMTBhNmNmMmY3Mzg2NmZhMGRiNjEzOWQ5NWViZDM0ZGZiMGY0YzAxMmRkM2YzYWYxMWQ5ZjQxYyJ9fX0=", "cojkGLflVWxwnhDXmHMke7crkeA78iUYOWY7H3YvMJFD+VZi9E7vUahLTTx5ELH+PvcaHJerSDmuV+Nasc3K2n6zlXXb0B7RB/ose/kdPxHAIJee7IbZX0iFNDn6irUSOS4wOYF/BwaqG3HmpoSxV52SGMs6kqTer2Rjg3X+XwYFFiDHAR/gwhfXLzrM1iBc171vgu6T+kx65iBHa/YB/V/mj8FSxwM0f5IsLpgAEdxDL9PvEKQWgWeZ1CAqEXlGnjPkd9oGzW0TgDz2MksBbYZ2kmn/S53kK9vCrVB7egZPS4VBtKpq1P7Jeu8rtgjnAKVFQJZ2lMHnVRuvGTd8JKoPHarUPpU2LURUMaCtHzSv9v/4gjkafnDhqxG4TTcr5hxFV+ho72HQchoeaUXzIO+Yo71zrVqkrS0hw6OtgMIBlvaGaEUsFvGiCZePBEiHojO43AKqJcJAVeT2RAzHcAaBAO79ACGjNKw/oj02rOurLha9i+99bKui96Eg7SS/nPchbmu5YQ9nSpkW+JeYXnBzGGzNG4y02VWgz15L718+8161zXobhuK07qlY9i1nipFbEJedqG0cfS+AUzauETFvS9nMtxhtftYPCIxm40GQj6e77asNCAEElGssaUGKO3bjm348+oF9tR/eBOYWJQ8kL46IQLDRoop7UhG4ewY="); public final static SkinData TURKEY = new SkinData("eyJ0aW1lc3RhbXAiOjE0NzU3NzM2MTc5MDQsInByb2ZpbGVJZCI6IjlmY2FlZDhiMTRiNTRmN2ZhNjRjYjYwNDBlNzA1MjcyIiwicHJvZmlsZU5hbWUiOiJMQ2FzdHIxIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8xYzdmYjczMTRkNmY1ZTMzNmVjN2ViNTI1ZGM0ODMzOWNhMjI4ZDk3ODU1MDM3ZDZhNDIwOGZjNzYwNDc1NiJ9fX0=", "eZWi1LOD8ke7MCUAfhspBCnyfCoGM8suFLKtbW6b27CURoRBG3eKIfwLYYeMp3ObjoZ8gCB90s28Qyw5XMzwvvowy9W/b5cYC0OzQ8+GR7tDZoWc28tGqGBM8cmDJIFQgZdceBIIr2lXeAvEJfLbyrus46hPjk8YTiQW2DsBq88BhKIy6Igb1rGqJ1goVERF07b6+/yMdLKCaT8OZFzKLXfo5rY5gr6HLnvsQiNL9aTrl74agXn1GUcP+QVNe7/c9lYmv5vLCBst1YiIPq27NZASZ++Fwyv6+PRlaFZZYtMHVd4UZeYPl7ak1Cdi/1sUcRpkBbJM8AHIrqq0iuXxrLbc6ldQ2cYQKHg9ljIpW/EZanuf6Wgm/LK1JnxXne9GUb/xPzB1EnZ95i8/u9WJa+NixEcfc3pAzDPYncIR8lishFwyBRta6BCG76U3UY2lQr3YD/48AJ49r7+WVU0gOP/h2SDSdAZHEdvkpVJ0w/xA+SevJ7Y7xA5EJ655YMQ0F8f3WUFTf1pFklE5E+fwkMVCWOPw7UMy558IcRSpdWAPPyf8sc7CpDqRk37/vXWRDa+7YBfgskK6B2eXowrzThUOBx+AmDTF3Rv8ZSr1Un0FWGi+GQ5ny7W9dJBMomzyMUbzz9stsCml5XB+6xLP2MD+9lO1bHipKS6qkhtZChE="); - + + // Comments this out for now, so it doesn't load the player profile // A better way to do this would check for the properties when getting the skull or the skin // Might change on the next version diff --git a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java index 136d324ab..787e73a59 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java @@ -56,7 +56,8 @@ public enum GameDisplay SurvivalGamesTeams("Survival Games Teams", "Survival Games", Material.IRON_SWORD, (byte)0, GameCategory.TEAM_VARIANT, 23), Tug("Tug of Wool", Material.WHEAT, (byte)0, GameCategory.ARCADE, 44), TurfWars("Turf Wars", Material.STAINED_CLAY, (byte)14, GameCategory.ARCADE, 45), - UHC("Ultra Hardcore", Material.GOLDEN_APPLE, (byte)0, GameCategory.SURVIVAL, 46), + UHC("Ultra Hardcore", Material.GOLDEN_APPLE, (byte)0, GameCategory.TEAM_VARIANT, 46), + UHCSolo("Ultra Hardcore Solo", "Ultra Hardcore", Material.GOLDEN_APPLE, (byte)0, GameCategory.SURVIVAL, 46), WitherAssault("Wither Assault", Material.SKULL_ITEM, (byte)1, GameCategory.ARCADE, 47), Wizards("Wizards", Material.BLAZE_ROD, (byte)0, GameCategory.SURVIVAL, 48), ZombieSurvival("Zombie Survival", Material.SKULL_ITEM, (byte)2, GameCategory.SURVIVAL, 49), diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java index 41613e265..90f50857e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java @@ -1,9 +1,12 @@ package nautilus.game.arcade; +import org.bukkit.Material; + import mineplex.core.common.MinecraftVersion; import mineplex.core.common.Pair; import mineplex.core.game.GameCategory; import mineplex.core.game.GameDisplay; + import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.games.baconbrawl.BaconBrawl; import nautilus.game.arcade.game.games.barbarians.Barbarians; @@ -99,18 +102,16 @@ import nautilus.game.arcade.game.games.survivalgames.modes.UHCSurvivalgames; import nautilus.game.arcade.game.games.tug.Tug; import nautilus.game.arcade.game.games.turfforts.TurfForts; import nautilus.game.arcade.game.games.typewars.TypeWars; -import nautilus.game.arcade.game.games.uhc.UHC; +import nautilus.game.arcade.game.games.uhc.UHCSolo; +import nautilus.game.arcade.game.games.uhc.UHCTeams; import nautilus.game.arcade.game.games.uhc.modes.Assassins; import nautilus.game.arcade.game.games.uhc.modes.BloodDiamonds; -import nautilus.game.arcade.game.games.uhc.modes.CutClean; import nautilus.game.arcade.game.games.uhc.modes.GodBattles; import nautilus.game.arcade.game.games.valentines.Valentines; import nautilus.game.arcade.game.games.wither.WitherGame; import nautilus.game.arcade.game.games.wizards.Wizards; import nautilus.game.arcade.game.games.zombiesurvival.ZombieSurvival; -import org.bukkit.Material; - public enum GameType { //Mini @@ -183,7 +184,8 @@ public enum GameType SurvivalGamesTeams(TeamSurvivalGames.class, GameDisplay.SurvivalGamesTeams, new GameType[]{GameType.SurvivalGames}, false), Tug(Tug.class, GameDisplay.Tug), TurfWars(TurfForts.class, GameDisplay.TurfWars), - UHC(UHC.class, GameDisplay.UHC), + UHC(UHCTeams.class, GameDisplay.UHC), + UHCSolo(UHCSolo.class, GameDisplay.UHCSolo, new GameType[] { GameType.UHC }, false), WitherAssault(WitherGame.class, GameDisplay.WitherAssault), Wizards(Wizards.class, GameDisplay.Wizards, new Pair[] { @@ -228,7 +230,6 @@ public enum GameType new GameMode(SkySmash.class, GameType.Skywars, "Sky Smash"), new GameMode(TeamBuild.class, GameType.Build, "Team Master Builders"), new GameMode(DukesOfDecoration.class, GameType.Build, "Dukes Of Decoration"), - new GameMode(CutClean.class, GameType.UHC, "Cut Clean"), new GameMode(GodBattles.class, GameType.UHC, "God Battles"), new GameMode(BloodDiamonds.class, GameType.UHC, "Blood Diamonds"), new GameMode(Assassins.class, GameType.UHC, "Assassins"), diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index cea5b206a..19dab9f47 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -36,7 +36,9 @@ import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingPlaceEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.scoreboard.NameTagVisibility; @@ -61,6 +63,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTabTitle; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.elo.EloPlayer; import mineplex.core.elo.EloTeam; @@ -298,6 +301,9 @@ public abstract class Game implements Listener public boolean SpeedMeasurement = false; + // Rejoining the game + public long RejoinTime = 120000; + // Chat Stats public final ChatStatData Kills = new ChatStatData("Kills", "Kills", true); public final ChatStatData Assists = new ChatStatData("Assists", "Assists", true); @@ -380,6 +386,11 @@ public abstract class Game implements Listener private HashMap>> _playerPastLocs = new HashMap<>(); private Set _debugCommands = new HashSet<>(); + public NautHashMap RejoinTimes = new NautHashMap(); + public NautHashMap RejoinTeam = new NautHashMap(); + public NautHashMap RejoinKit = new NautHashMap(); + public NautHashMap RejoinHealth = new NautHashMap(); + public Game(ArcadeManager manager, GameType gameType, Kit[] kits, String[] gameDesc) { Manager = manager; @@ -2412,4 +2423,148 @@ public abstract class Game implements Listener { return clazz.cast(_modules.get(clazz)); } + + /* + * All code related to rejoining games. + * Moved here from TeamGame + */ + + @EventHandler(priority = EventPriority.LOW) + public void PlayerQuit(PlayerQuitEvent event) + { + if (!InProgress()) + return; + + Player player = event.getPlayer(); + + GameTeam team = GetTeam(player); + if (team == null) return; + + if (!team.IsAlive(player)) + return; + + if (player.isDead()) + return; + + if (player.getWorld().getName().equalsIgnoreCase("world")) + return; + + if (!QuitOut) + { + //Store + RejoinTimes.put(player.getName(), System.currentTimeMillis()); + RejoinTeam.put(player.getName(), team); + + if (GetKit(player) != null) + RejoinKit.put(player.getName(), GetKit(player)); + + RejoinHealth.put(player.getName(), player.getHealth()); + + if (!GetLocationStore().containsKey(player.getName())) + { + GetLocationStore().put(player.getName(), player.getLocation()); + } + + //Announcement + Announce(team.GetColor() + C.Bold + player.getName() + " has disconnected! " + UtilTime.convert(RejoinTime, 0, TimeUnit.MINUTES) + " minutes to rejoin.", false); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void PlayerLoginAllow(PlayerLoginEvent event) + { + if (!InProgress() || QuitOut) + return; + + //Rejoined + GameTeam team = RejoinTeam.remove(event.getPlayer().getName()); + if (team != null && RejoinTimes.remove(event.getPlayer().getName()) != null) + { + team.AddPlayer(event.getPlayer(), true); + Announce(team.GetColor() + C.Bold + event.getPlayer().getName() + " has reconnected!", false); + + + Kit kit = RejoinKit.remove(event.getPlayer().getName()); + if (kit != null) + _playerKit.put(event.getPlayer(), kit); + } + } + + //Do this on Join, not Login, otherwise player no get heal. + @EventHandler (priority = EventPriority.MONITOR) + public void playerRejoinGame(PlayerJoinEvent event) + { + if (!InProgress() || QuitOut) + return; + + Player player = event.getPlayer(); + + if (RejoinHealth.containsKey(player.getName())) + { + double health = RejoinHealth.remove(player.getName()); + if (health > 0) + { + getArcadeManager().runSyncLater(() -> + { + player.setHealth(health); + }, 1L); + } + } + } + + @EventHandler + public void PlayerRejoinExpire(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC || QuitOut) + return; + + Iterator rejoinIterator = RejoinTimes.keySet().iterator(); + + while (rejoinIterator.hasNext()) + { + String name = rejoinIterator.next(); + + if (!UtilTime.elapsed(RejoinTimes.get(name), RejoinTime)) + continue; + + rejoinIterator.remove(); + + //Get Team (By Name) + GameTeam team = RejoinTeam.remove(name); + if (team != null) + Announce(team.GetColor() + C.Bold + name + " did not reconnect in time!", false); + + RejoinKit.remove(name); + RejoinHealth.remove(name); + } + } + + @EventHandler + public void RejoinCommand(PlayerCommandPreprocessEvent event) + { + if (!QuitOut && event.getPlayer().isOp() && event.getMessage().startsWith("/allowrejoin")) + { + String[] toks = event.getMessage().split(" "); + + if (toks.length <= 1) + { + event.getPlayer().sendMessage("Missing Param!"); + } + else + { + RejoinTimes.put(toks[1], System.currentTimeMillis()); + event.getPlayer().sendMessage("Allowed " + toks[1] + " to rejoin!"); + } + + event.setCancelled(true); + } + } + + protected void removePlayerFromRejoin(String name) + { + RejoinTimes.remove(name); + RejoinKit.remove(name); + RejoinTeam.remove(name); + RejoinHealth.remove(name); + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/TeamGame.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/TeamGame.java index 2130c1f7d..66754b7d4 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/TeamGame.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/TeamGame.java @@ -25,15 +25,8 @@ import java.util.List; public abstract class TeamGame extends Game { - public long RejoinTime = 120000; - protected ArrayList _places = new ArrayList(); - public NautHashMap RejoinTimes = new NautHashMap(); - public NautHashMap RejoinTeam = new NautHashMap(); - public NautHashMap RejoinKit = new NautHashMap(); - public NautHashMap RejoinHealth = new NautHashMap(); - public TeamGame(ArcadeManager manager, GameType gameType, Kit[] kits, String[] gameDesc) { super(manager, gameType, kits, gameDesc); @@ -74,137 +67,6 @@ public abstract class TeamGame extends Game return; team.RemovePlayer(player); - - if (player.isDead()) - return; - - if (player.getWorld().getName().equalsIgnoreCase("world")) - return; - - if (!QuitOut) - { - //Store - RejoinTimes.put(player.getName(), System.currentTimeMillis()); - RejoinTeam.put(player.getName(), team); - - if (GetKit(player) != null) - RejoinKit.put(player.getName(), GetKit(player)); - - RejoinHealth.put(player.getName(), player.getHealth()); - - if (!GetLocationStore().containsKey(player.getName())) - { - GetLocationStore().put(player.getName(), player.getLocation()); - } - - //Announcement - Announce(team.GetColor() + C.Bold + player.getName() + " has disconnected! " + UtilTime.convert(RejoinTime, 0, TimeUnit.MINUTES) + " minutes to rejoin.", false); - } - } - - @EventHandler(priority = EventPriority.LOWEST) - public void PlayerLoginAllow(PlayerLoginEvent event) - { - if (!InProgress() || QuitOut) - return; - - //Rejoined - GameTeam team = RejoinTeam.remove(event.getPlayer().getName()); - if (team != null && RejoinTimes.remove(event.getPlayer().getName()) != null) - { - team.AddPlayer(event.getPlayer(), true); - Announce(team.GetColor() + C.Bold + event.getPlayer().getName() + " has reconnected!", false); - - - Kit kit = RejoinKit.remove(event.getPlayer().getName()); - if (kit != null) - _playerKit.put(event.getPlayer(), kit); - -// final Player player = event.getPlayer(); -// Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), new Runnable() -// { -// @Override -// public void run() -// { -// if (RejoinHealth.containsKey(player.getName())) -// { -// double health = RejoinHealth.remove(player.getName()); -// player.setHealth(health); -// player.sendMessage("DEBUG: restored hp to " + health); -// } -// } -// }, 20); - } - } - - //Do this on Join, not Login, otherwise player no get heal. - @EventHandler (priority = EventPriority.MONITOR) - public void playerRejoinGame(PlayerJoinEvent event) - { - if (!InProgress() || QuitOut) - return; - - Player player = event.getPlayer(); - - if (RejoinHealth.containsKey(player.getName())) - { - double health = RejoinHealth.remove(player.getName()); - if (health > 0) - { - getArcadeManager().runSyncLater(() -> - { - player.setHealth(health); - }, 1L); - } - } - } - - @EventHandler - public void PlayerRejoinExpire(UpdateEvent event) - { - if (event.getType() != UpdateType.SEC || QuitOut) - return; - - Iterator rejoinIterator = RejoinTimes.keySet().iterator(); - - while (rejoinIterator.hasNext()) - { - String name = rejoinIterator.next(); - - if (!UtilTime.elapsed(RejoinTimes.get(name), RejoinTime)) - continue; - - rejoinIterator.remove(); - - //Get Team (By Name) - GameTeam team = RejoinTeam.remove(name); - if (team != null) - Announce(team.GetColor() + C.Bold + name + " did not reconnect in time!", false); - - RejoinKit.remove(name); - RejoinHealth.remove(name); - } - } - - @EventHandler - public void RejoinCommand(PlayerCommandPreprocessEvent event) - { - if (!QuitOut && event.getPlayer().isOp() && event.getMessage().startsWith("/allowrejoin")) - { - String[] toks = event.getMessage().split(" "); - - if (toks.length <= 1) - { - event.getPlayer().sendMessage("Missing Param!"); - } - else - { - RejoinTimes.put(toks[1], System.currentTimeMillis()); - event.getPlayer().sendMessage("Allowed " + toks[1] + " to rejoin!"); - } - - event.setCancelled(true); - } } public void EndCheck() @@ -312,12 +174,4 @@ public abstract class TeamGame extends Game return players; } - - protected void removePlayerFromRejoin(String name) - { - RejoinTimes.remove(name); - RejoinKit.remove(name); - RejoinTeam.remove(name); - RejoinHealth.remove(name); - } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/KitUHC.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/KitUHC.java index 8f9f70b7e..bdc3070f5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/KitUHC.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/KitUHC.java @@ -22,8 +22,16 @@ public class KitUHC extends ProgressingKit }; + private static final ItemStack[] PLAYER_ITEMS = { + new ItemStack(Material.STONE_SWORD), + new ItemStack(Material.STONE_PICKAXE), + new ItemStack(Material.STONE_AXE), + new ItemStack(Material.STONE_SPADE), + new ItemStack(Material.APPLE, 3), + }; + private static final ItemStack IN_HAND = new ItemStack(Material.GOLD_SWORD); - + public KitUHC(ArcadeManager manager) { super(manager, "UHC Player", "uhcplayer", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND); @@ -33,6 +41,6 @@ public class KitUHC extends ProgressingKit @Override public void GiveItems(Player player) { - + player.getInventory().addItem(PLAYER_ITEMS); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java index 310b7feaf..6802ee6e7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java @@ -1,6 +1,62 @@ package nautilus.game.arcade.game.games.uhc; -import mineplex.core.account.CoreClient; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; +import java.util.stream.Collectors; + +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.World.Environment; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Ghast; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Monster; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.PrepareItemCraftEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerPortalEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; +import org.bukkit.event.world.ChunkUnloadEvent; +import org.bukkit.inventory.CraftingInventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapelessRecipe; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; + import mineplex.core.boosters.event.BoosterItemGiveEvent; import mineplex.core.common.Pair; import mineplex.core.common.Rank; @@ -9,7 +65,6 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilParser; @@ -33,84 +88,22 @@ import nautilus.game.arcade.events.PlayerPrepareTeleportEvent; import nautilus.game.arcade.game.DebugCommand; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; -import nautilus.game.arcade.game.TeamGame; import nautilus.game.arcade.game.modules.AntiExpOrbModule; +import nautilus.game.arcade.game.modules.CutCleanModule; import nautilus.game.arcade.game.modules.OreVeinEditorModule; import nautilus.game.arcade.game.modules.PlayerHeadModule; import nautilus.game.arcade.game.modules.SafezoneModule; -import nautilus.game.arcade.game.modules.TeamModule; import nautilus.game.arcade.game.modules.combatlog.CombatLogModule; import nautilus.game.arcade.game.modules.combatlog.CombatLogNPC; import nautilus.game.arcade.game.modules.combatlog.CombatLogNPCExpiredEvent; import nautilus.game.arcade.game.modules.combatlog.CombatLogNPCKilledEvent; import nautilus.game.arcade.game.modules.combatlog.CombatLogNPCPreSpawnEvent; -import nautilus.game.arcade.game.modules.compass.CompassEntry; import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.kit.Kit; - import net.minecraft.server.v1_8_R3.MinecraftServer; import net.minecraft.server.v1_8_R3.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.World; -import org.bukkit.World.Environment; -import org.bukkit.WorldBorder; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Ghast; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Monster; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.PrepareItemCraftEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerPortalEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.event.world.ChunkUnloadEvent; -import org.bukkit.inventory.CraftingInventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.ShapelessRecipe; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; - -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class UHC extends TeamGame +public abstract class UHC extends Game { private static int _gamesRun = 0; @@ -119,122 +112,133 @@ public class UHC extends TeamGame // The number of minutes after which PVP should be enabled public static final int SAFE_TIME_IN_MINUTES = 11; - // This is the region in which nothing can be done (block placing, flowing, etc) + // The number of minutes after which Deathmatch should start. + public static final int MINING_TIME_IN_MINUTES = 20; + + // This is the region in which nothing can be done (block placing, flowing, + // etc) public static final int SAFE_REGION = 36; + // The maximum/starting arena size + public static final int MAX_ARENA_SIZE = 1000; + + // The deathmatch arena size + public static final int DEATHMATCH_ARENA_SIZE = 100; + + // The time for the border to shrink to 0 during deathmatch. + public static final int DEATHMATCH_TIME_SECONDS = 600; + + // The pre-deathmatch teleporting time + public static final int PRE_DEATHMATCH_TIME_SECONDS = 11; + // The amount of damage to give from hitting the world border public static final int WORLD_BORDER_DAMAGE = 5; + // The amount of damage to give from hitting the world border + public static final int WORLD_BORDER_TIME = 5; + // The number of ticks to delay before teleporting each player public static final long DELAY_BETWEEN_PLAYER_TELEPORT = 5L; + // The max Y value that a player can have in order to have night vision. + public static final long NIGHT_VISION_MAX_Y = 54; + + // The rate that an apple will drop when breaking a leaves block + public static final double APPLE_DROP_RATE = 0.1; + // The number of minutes passed in this game - private int _minutesSinceStart = 0; + private int _minutesSinceStart; // The Objective representing the tab list health display private Objective _healthObjective; - + // The number of players which have been teleported private int _teleportedPlayers = -1; // The total number of players to teleport - private int _totalPlayers = 0; + private int _totalPlayers; // Whether players are teleporting currently private volatile boolean _isTeleporting = false; // Border - private int _secondsSinceStart; - private Map _borderPositions = new HashMap<>(); - private double _currentBorder = 1000; - private double _previousBorder = 1000; - private long _borderStartedMoving; + private UHCBorder _border; - private boolean _hasPvpStarted = false; + // Freeze manager + private UHCFreezer _freezer; + + // Pre-deathmatch + private int _secondsSincePreDeathmatch; + + // Pvp + private boolean _hasPvpStarted; public UHC(ArcadeManager manager) { this(manager, GameType.UHC); - registerChatStats( - Kills, - Assists, - BlankLine, - DamageTaken, - DamageDealt - ); + registerChatStats(Kills, Assists, BlankLine, DamageTaken, DamageDealt); - new OreVeinEditorModule() - .removeNonAirVeins() - .register(this); - new AntiExpOrbModule() - .register(this); + new OreVeinEditorModule().removeNonAirVeins().register(this); + new AntiExpOrbModule().register(this); } public UHC(ArcadeManager manager, GameType type) { - super(manager, type, - new Kit[] - { - new KitUHC(manager) - }, + super(manager, type, new Kit[] { new KitUHC(manager) }, - new String[] - { - "10 minutes of no PvP", "Only Golden Apples restore health", "Ores can only be found in caves", - "Borders shrink over time", "Last player/team alive wins!" - }); + new String[] { "10 minutes of no PvP", "Only Golden Apples restore health", "Ores can only be found in caves", "Borders shrink over time", "Last player/team alive wins!" }); _gamesRun++; - this.HideTeamSheep = true; + HideTeamSheep = true; - this.StrictAntiHack = true; + StrictAntiHack = true; - this.GameTimeout = 10800000; + GameTimeout = 10800000; - this.DamagePvP = false; + DamagePvP = false; - this.DeathDropItems = true; + DeathDropItems = true; - this.ItemDrop = true; - this.ItemPickup = true; + ItemDrop = true; + ItemPickup = true; - this.BlockBreak = true; - this.BlockPlace = true; + BlockBreak = true; + BlockPlace = true; - this.InventoryOpenBlock = true; - this.InventoryOpenChest = true; - this.InventoryClick = true; + InventoryOpenBlock = true; + InventoryOpenChest = true; + InventoryClick = true; - this.DeathOut = true; - this.QuitOut = false; + DeathOut = true; + QuitOut = false; - this.CreatureAllow = true; + CreatureAllow = true; - this.AnnounceStay = false; + AnnounceStay = false; - this.DeathMessages = false; + DeathMessages = false; - this.SoupEnabled = false; + SoupEnabled = false; - this.WorldBoundaryKill = false; + WorldBoundaryKill = false; - this.GemBoosterEnabled = false; - this.GemDoubleEnabled = false; - this.GemHunterEnabled = false; + GemBoosterEnabled = false; + GemDoubleEnabled = false; + GemHunterEnabled = false; - this.WorldBoneMeal = true; + WorldBoneMeal = true; - this.DontAllowOverfill = true; + DontAllowOverfill = true; - this.GadgetsDisabled = true; + GadgetsDisabled = true; WorldTimeSet = -1; - this.WorldLeavesDecay = true; - this.WorldBlockGrow = true; - this.WorldSoilTrample = true; - this.WorldBoneMeal = true; - this.WorldChunkUnload = true; + WorldLeavesDecay = true; + WorldBlockGrow = true; + WorldSoilTrample = true; + WorldBoneMeal = true; + WorldChunkUnload = true; CraftRecipes(); @@ -250,16 +254,21 @@ public class UHC extends TeamGame _healthObjective = Scoreboard.getScoreboard().registerNewObjective("Health", "health"); _healthObjective.setDisplaySlot(DisplaySlot.PLAYER_LIST); - new TeamModule().register(this); + // World Border + _border = new UHCBorder(this, MAX_ARENA_SIZE); + + // Player Freezer + _freezer = new UHCFreezer(this); + new PlayerHeadModule().register(this); - new SafezoneModule() - .filter(location -> - location.getX() <= SAFE_REGION && location.getX() >= -SAFE_REGION && - location.getZ() <= SAFE_REGION && location.getZ() >= -SAFE_REGION) - .register(this); - new CompassModule() - .setGiveCompass(false) - .register(this); + new SafezoneModule().filter(location -> location.getX() <= SAFE_REGION && location.getX() >= -SAFE_REGION && location.getZ() <= SAFE_REGION && location.getZ() >= -SAFE_REGION).register(this); + new CompassModule().setGiveCompass(false).register(this); + + new CutCleanModule().associateBlockDrop(Material.GOLD_ORE, new ItemBuilder(Material.GOLD_INGOT).build()).associateBlockDrop(Material.IRON_ORE, new ItemBuilder(Material.IRON_INGOT).build()) + .associateBlockDrop(Material.GRAVEL, new ItemStack(Material.FLINT)).associateMobDrop(Material.RAW_BEEF, new ItemBuilder(Material.COOKED_BEEF).build()).associateMobDrop( + Material.RAW_CHICKEN, new ItemBuilder(Material.COOKED_CHICKEN).build()).associateMobDrop(Material.RAW_FISH, new ItemBuilder(Material.COOKED_FISH).build()).associateMobDrop( + Material.PORK, new ItemBuilder(Material.GRILLED_PORK).build()).associateMobDrop(Material.RABBIT, new ItemBuilder(Material.COOKED_RABBIT).build()).associateMobDrop( + Material.MUTTON, new ItemBuilder(Material.COOKED_MUTTON).build()).register(this); registerDebugCommand(new DebugCommand("startpvp", Rank.ADMIN) { @@ -291,10 +300,8 @@ public class UHC extends TeamGame { UtilPlayer.message(caller, F.main("Debug", "Loaded worlds:")); UtilPlayer.message(caller, F.desc("Bukkit Worlds", Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.joining(", ")))); - UtilPlayer.message(caller, F.desc("NMS Worlds", MinecraftServer.getServer().worlds.stream() - .map(net.minecraft.server.v1_8_R3.WorldServer::getWorldData) - .map(net.minecraft.server.v1_8_R3.WorldData::getName) - .collect(Collectors.joining(", ")))); + UtilPlayer.message(caller, F.desc("NMS Worlds", MinecraftServer.getServer().worlds.stream().map(net.minecraft.server.v1_8_R3.WorldServer::getWorldData).map( + net.minecraft.server.v1_8_R3.WorldData::getName).collect(Collectors.joining(", ")))); return; } if (args[0].equals("info")) @@ -310,7 +317,8 @@ public class UHC extends TeamGame } else if (worldName.startsWith("n:")) { - WorldServer world = MinecraftServer.getServer().worlds.stream().filter(ws -> ws.getWorldData().getName().replace(" ", "").equals(worldName.substring(2))).findAny().orElse(null); + WorldServer world = MinecraftServer.getServer().worlds.stream().filter(ws -> ws.getWorldData().getName().replace(" ", "").equals(worldName.substring(2))).findAny().orElse( + null); if (world != null) { targetWorld = world.getWorld(); @@ -329,7 +337,8 @@ public class UHC extends TeamGame UtilPlayer.message(caller, F.main("Debug", "World info for " + targetWorld.getName())); UtilPlayer.message(caller, F.desc("Chunks", String.valueOf(chunks.length))); UtilPlayer.message(caller, F.desc("Entities", String.valueOf(targetWorld.getEntities().size()))); - UtilPlayer.message(caller, F.desc("Tile Entities", String.valueOf(Arrays.stream(chunks).map(Chunk::getTileEntities).map(Arrays::asList).flatMap(Collection::stream).count()))); + UtilPlayer.message(caller, F.desc("Tile Entities", String.valueOf(Arrays.stream(chunks).map(Chunk::getTileEntities).map(Arrays::asList).flatMap(Collection::stream) + .count()))); UtilPlayer.message(caller, F.desc("View Distance", String.valueOf(nmsWorld.spigotConfig.viewDistance))); UtilPlayer.message(caller, F.desc("Unload queue size", String.valueOf(nmsWorld.chunkProviderServer.unloadQueue.size()))); } @@ -357,7 +366,8 @@ public class UHC extends TeamGame } else if (worldName.startsWith("n:")) { - WorldServer world = MinecraftServer.getServer().worlds.stream().filter(ws -> ws.getWorldData().getName().replace(" ", "").equals(worldName.substring(2))).findAny().orElse(null); + WorldServer world = MinecraftServer.getServer().worlds.stream().filter(ws -> ws.getWorldData().getName().replace(" ", "").equals(worldName.substring(2))).findAny().orElse( + null); if (world != null) { targetWorld = world.getWorld(); @@ -439,8 +449,18 @@ public class UHC extends TeamGame } } }); - } + registerDebugCommand(new DebugCommand("dm", Rank.ADMIN) + { + @Override + public void Execute(Player caller, String[] args) + { + _minutesSinceStart = MINING_TIME_IN_MINUTES + 1; + startPreDeathmatch(); + UtilPlayer.message(caller, F.main("Debug", "Starting deathmatch")); + } + }); + } @Override public void recruit() @@ -449,39 +469,50 @@ public class UHC extends TeamGame Location spawn = GetRandomSpawn(WorldData.World.getSpawnLocation(), true); WorldData.World.setSpawnLocation(spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ()); - WorldServer worldServer = ((CraftWorld) WorldData.World).getHandle(); + setViewDistance(VIEW_DISTANCE); - // Update view distance - worldServer.spigotConfig.viewDistance = VIEW_DISTANCE; - worldServer.getPlayerChunkMap().a(VIEW_DISTANCE); + SetState(GameState.Recruit); + } + public void createSpawns() + { // Wipe Spawns - for (GameTeam team : this.GetTeamList()) + for (GameTeam team : GetTeamList()) { team.GetSpawns().clear(); } + double border = _border.getMaxCords(); + // Solo Game - if (this._teamList.size() == 1) + if (FillTeamsInOrderToCount == -1) { + Bukkit.broadcastMessage("Using Solo Game spawning"); getArcadeManager().runSyncTimer(new BukkitRunnable() { + @Override public void run() { - if (GetTeamList().get(0).GetSpawns().size() < GetPlayers(true).size()) + GameTeam gameTeam = GetTeamList().get(0); + List players = GetPlayers(true); + + if (gameTeam.GetSpawns().size() < Manager.GetPlayerFull()) { + Bukkit.broadcastMessage("Attempting to add spawn!"); + Location loc = GetRandomSpawn(null, false); - // Dynamically scale distance requirement based on how many teams need to fit - double dist = (2 * _currentBorder) / (Math.sqrt(GetPlayers(true).size()) + 3); + // Dynamically scale distance requirement based on how + // many teams need to fit + double dist = (2 * border) / (Math.sqrt(players.size()) + 3); // Ensure distance between Teams - 500 Attempts for (int i = 0; i < 500; i++) { boolean clash = false; - for (Location otherSpawn : GetTeamList().get(0).GetSpawns()) + for (Location otherSpawn : gameTeam.GetSpawns()) { if (UtilMath.offset(loc, otherSpawn) < dist) { @@ -496,31 +527,35 @@ public class UHC extends TeamGame loc = GetRandomSpawn(null, false); } - GetTeamList().get(0).GetSpawns().add(loc); + Bukkit.broadcastMessage("Added!"); + gameTeam.GetSpawns().add(loc); } else { cancel(); - SetState(GameState.Recruit); } } }, 0L, 1L); } else { + Bukkit.broadcastMessage("Using Team Game spawning"); getArcadeManager().runSyncTimer(new BukkitRunnable() { + AtomicInteger currentTeamId = new AtomicInteger(); + double border = _border.getMaxCords(); @Override public void run() { - GameTeam team = _teamList.get(currentTeamId.get()); + GameTeam team = GetTeamList().get(currentTeamId.get()); Location loc = GetRandomSpawn(null, false); - // Dynamically scale distance requirement based on how many teams need to fit - double dist = (2 * _currentBorder) / (Math.sqrt(GetTeamList().size()) + 3); + // Dynamically scale distance requirement based on how many + // teams need to fit + double dist = (2 * border) / (Math.sqrt(GetTeamList().size()) + 3); // Ensure distance between Teams - 500 Attempts for (int i = 0; i < 500; i++) @@ -552,10 +587,9 @@ public class UHC extends TeamGame currentTeamId.getAndIncrement(); - if (currentTeamId.get() >= _teamList.size()) + if (currentTeamId.get() >= GetTeamList().size()) { cancel(); - SetState(GameState.Recruit); } } }, 0L, 1L); @@ -565,21 +599,16 @@ public class UHC extends TeamGame @Override public void ParseData() { - int i = 0; - - for (double border : buildBorders(1000, 1000, 32)) - { - _borderPositions.put(i++ * 4, border); - } - - WorldBorder border = WorldData.World.getWorldBorder(); - border.setCenter(0, 0); - border.setSize(_currentBorder * 2); - border.setDamageBuffer(-99); - border.setWarningDistance(-99); - border.setWarningTime(-99); + WorldData.MinX = -MAX_ARENA_SIZE; + WorldData.MinZ = -MAX_ARENA_SIZE; + WorldData.MaxX = MAX_ARENA_SIZE; + WorldData.MaxZ = MAX_ARENA_SIZE; WorldData.World.getEntities().forEach(Entity::remove); + + _border.prepare(); + + createSpawns(); } @Override @@ -588,39 +617,10 @@ public class UHC extends TeamGame return true; } - @EventHandler - public void onSecond(UpdateEvent event) - { - if (event.getType() != UpdateType.SEC) - { - return; - } - - if (!IsLive()) - { - return; - } - - _previousBorder = _currentBorder; - - // We half the number so this only activates every 2nd second. - if (_borderPositions.containsKey(_secondsSinceStart)) - { - _currentBorder = _borderPositions.get(_secondsSinceStart); - - _borderStartedMoving = System.currentTimeMillis(); - - WorldBorder border = WorldData.World.getWorldBorder(); - border.setSize(_currentBorder * 2, 1); - } - - _secondsSinceStart++; - } - @EventHandler public void outsideBorder(UpdateEvent event) { - if (!IsLive()) + if (!IsLive() || !TeleportsDisqualify) { return; } @@ -630,16 +630,7 @@ public class UHC extends TeamGame return; } - // The distance between the old border and the new - double distanceMovedSince = _currentBorder - _previousBorder; - - // Multiply that distance depending on how long its been since it moved. - long timeSinceMoved = System.currentTimeMillis() - _borderStartedMoving; - double percentageBorderMoved = Math.min(timeSinceMoved, 1000D) / 1000D; - - distanceMovedSince *= percentageBorderMoved; - - double border = (_previousBorder - 0.3D) + distanceMovedSince; + double border = _border.getMaxCords(); for (Player player : UtilServer.getPlayers()) { @@ -654,13 +645,11 @@ public class UHC extends TeamGame while (bottom.getVehicle() != null) bottom = bottom.getVehicle(); - UtilAction - .velocity(bottom, UtilAlg.getTrajectory2d(loc, GetSpectatorLocation()), 1.2, true, 0.4, 0, 10, true); + UtilAction.velocity(bottom, UtilAlg.getTrajectory2d(loc, GetSpectatorLocation()), 1.2, true, 0.4, 0, 10, true); if (Manager.IsAlive(player)) { - Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.CUSTOM, WORLD_BORDER_DAMAGE, false, false, false, - "Nether Field", "Vaporize"); + Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.CUSTOM, WORLD_BORDER_DAMAGE, false, false, false, "Nether Field", "Vaporize"); player.getWorld().playSound(loc, Sound.NOTE_BASS, 2f, 1f); player.getWorld().playSound(loc, Sound.NOTE_BASS, 2f, 1f); @@ -683,19 +672,20 @@ public class UHC extends TeamGame // Bump Players Back In if (loc.getX() > border || loc.getX() < -border || loc.getZ() > border || loc.getZ() < -border) { - // Can't use recharge on entities; blame bad design (mapping by name instead of uuid) -// if (Recharge.Instance.use(ent, "Hit by Border", 1000, false, false)) + // Can't use recharge on entities; blame bad design (mapping + // by name instead of uuid) + // if (Recharge.Instance.use(ent, "Hit by Border", 1000, + // false, false)) { Entity bottom = ent; while (bottom.getVehicle() != null) bottom = bottom.getVehicle(); - UtilAction - .velocity(bottom, UtilAlg.getTrajectory2d(loc, GetSpectatorLocation()), 1.2, true, 0.4, 0, 10, true); + UtilAction.velocity(bottom, UtilAlg.getTrajectory2d(loc, GetSpectatorLocation()), 1.2, true, 0.4, 0, 10, true); - // If nothing else has damaged the NPC, then lastDamageCause will be null - Manager.GetDamage().NewDamageEvent(ent, null, null, DamageCause.CUSTOM, WORLD_BORDER_DAMAGE, false, false, false, - "Nether Field", "Vaporize"); + // If nothing else has damaged the NPC, then + // lastDamageCause will be null + Manager.GetDamage().NewDamageEvent(ent, null, null, DamageCause.CUSTOM, WORLD_BORDER_DAMAGE, false, false, false, "Nether Field", "Vaporize"); ent.getWorld().playSound(loc, Sound.NOTE_BASS, 2f, 1f); ent.getWorld().playSound(loc, Sound.NOTE_BASS, 2f, 1f); @@ -705,20 +695,6 @@ public class UHC extends TeamGame } } - private List buildBorders(int seconds, double border, double leaveRemaining) - { - double totalNumber = Math.pow(seconds, 1.9D) + (seconds * 50); - - List borders = new ArrayList<>(); - - for (int i = 0; i <= seconds; i++) - { - borders.add(border - ((border - leaveRemaining) * (((Math.pow(i, 1.9D) + (i * 50))) / totalNumber))); - } - - return borders; - } - @EventHandler public void endPortalTransfer(final PlayerPortalEvent event) { @@ -745,9 +721,17 @@ public class UHC extends TeamGame { startPvp(); } + else if (_minutesSinceStart < MINING_TIME_IN_MINUTES) + { + UtilTextMiddle.display(null, C.cRed + "Deathmatch in " + (MINING_TIME_IN_MINUTES - _minutesSinceStart) + " minutes.", 5, 80, 5); + } + else if (_minutesSinceStart == MINING_TIME_IN_MINUTES) + { + startPreDeathmatch(); + } } - private void startPvp() + public void startPvp() { if (_hasPvpStarted) return; @@ -758,13 +742,95 @@ public class UHC extends TeamGame for (Player player : UtilServer.getPlayers()) player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1f, 1f); - this.DamagePvP = true; - this.RejoinTime = 300000; // 5 minutes - getModule(CompassModule.class) - .setGiveCompass(true); - new CombatLogModule() - .setCombatLogTime((int) RejoinTime) - .register(this); + DamagePvP = true; + RejoinTime = 300000; // 5 minutes + getModule(CompassModule.class).setGiveCompass(true); + new CombatLogModule().setCombatLogTime((int) RejoinTime).register(this); + } + + public void startPreDeathmatch() + { + Announce(C.cRedB + "Deathmatch is starting... Players are being teleported!", false); + + // Freeze all players + for (Player player : GetPlayers(true)) + { + _freezer.freeze(player); + } + + // Toggle temporary game settings + TeleportsDisqualify = false; + Damage = false; + + // Set the border + _border.setSize(DEATHMATCH_ARENA_SIZE, 0); + + // Recreate spawns + createSpawns(); + + // Delayed to allow time for all spawns to be generated + getArcadeManager().runSyncLater(new BukkitRunnable() + { + + @Override + public void run() + { + // Teleport players, depending on how many players are alive + // this could + // cause some issues. + for (GameTeam gameTeam : GetTeamList()) + { + Bukkit.broadcastMessage("Total of " + gameTeam.GetSpawns().size() + " spawns to chose from " + gameTeam.GetName()); + gameTeam.SpawnTeleport(); + } + + for (Player player : UtilServer.getPlayers()) + { + if (!IsAlive(player)) + { + player.teleport(SpectatorSpawn); + } + } + } + }, 20L); + } + + public void startDeathmatch() + { + Announce(C.cRedB + "Fight!", false); + + // Unfreeze all players + _freezer.unfreeze(); + + // Toggle temporary game settings + TeleportsDisqualify = true; + Damage = true; + + // Set the border + _border.setSize(0, DEATHMATCH_TIME_SECONDS); + } + + @EventHandler + public void deathmatchTimer(UpdateEvent event) + { + // Checks to see if it is pre-deathmatch + if (event.getType() != UpdateType.SEC || TeleportsDisqualify) + { + return; + } + + _secondsSincePreDeathmatch++; + + if (_secondsSincePreDeathmatch < PRE_DEATHMATCH_TIME_SECONDS) + { + int seconds = PRE_DEATHMATCH_TIME_SECONDS - _secondsSincePreDeathmatch; + + Announce(C.cRedB + "Deathmatch starting in " + seconds + " second" + (seconds == 1 ? "" : "s"), false); + } + else if (_secondsSincePreDeathmatch == PRE_DEATHMATCH_TIME_SECONDS) + { + startDeathmatch(); + } } @EventHandler @@ -784,9 +850,8 @@ public class UHC extends TeamGame if (npc.getLastDamager() instanceof Player) { Player killer = (Player) npc.getLastDamager(); - Announce(npc.getPlayerInfo().getTeamColor() + C.Bold + npc.getPlayerInfo().getName() - + C.cGray + C.Bold + " was killed by " + getArcadeManager().GetColor(killer) - + C.Bold + npc.getLastDamager().getName() + C.cGray + C.Bold + " while logged out."); + Announce(npc.getPlayerInfo().getTeamColor() + C.Bold + npc.getPlayerInfo().getName() + C.cGray + C.Bold + " was killed by " + getArcadeManager().GetColor(killer) + C.Bold + npc + .getLastDamager().getName() + C.cGray + C.Bold + " while logged out."); } else { @@ -795,15 +860,10 @@ public class UHC extends TeamGame { cause = npc.getLastDamager().getName(); } - Announce(npc.getPlayerInfo().getTeamColor() + C.Bold + npc.getPlayerInfo().getName() - + C.cGray + C.Bold + " was killed by " + cause + " while logged out."); + Announce(npc.getPlayerInfo().getTeamColor() + C.Bold + npc.getPlayerInfo().getName() + C.cGray + C.Bold + " was killed by " + cause + " while logged out."); } - ItemStack stack = new ItemBuilder(Material.SKULL_ITEM) - .setData((byte) 3) - .setTitle(npc.getPlayerInfo().getTeamColor() + npc.getPlayerInfo().getName() + "'s Head") - .setPlayerHead(npc.getPlayerInfo().getName()) - .build(); + ItemStack stack = PlayerHeadModule.getGoldenHead(); npc.getNPC().getWorld().dropItemNaturally(npc.getNPC().getLocation(), stack); @@ -822,11 +882,8 @@ public class UHC extends TeamGame { CombatLogNPC npc = event.getNpc(); - ItemStack stack = new ItemBuilder(Material.SKULL_ITEM) - .setData((byte) 3) - .setTitle(npc.getPlayerInfo().getTeamColor() + npc.getPlayerInfo().getName() + "'s Head") - .setPlayerHead(npc.getPlayerInfo().getName()) - .build(); + ItemStack stack = new ItemBuilder(Material.SKULL_ITEM).setData((byte) 3).setTitle(npc.getPlayerInfo().getTeamColor() + npc.getPlayerInfo().getName() + "'s Head").setPlayerHead(npc + .getPlayerInfo().getName()).build(); npc.getNPC().getWorld().dropItemNaturally(npc.getNPC().getLocation(), stack); @@ -899,7 +956,8 @@ public class UHC extends TeamGame @EventHandler(priority = EventPriority.MONITOR) public void on(PlayerKickEvent event) { - // Don't kick players while teleporting. Probably NCP trying to kick for fly or something + // Don't kick players while teleporting. Probably NCP trying to kick for + // fly or something if (_isTeleporting) { event.setCancelled(true); @@ -941,14 +999,14 @@ public class UHC extends TeamGame player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 30 * 20, 128), true); player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 30 * 20, 128), true); - game.ValidateKit(player, game.GetTeam(player)); if (game.GetKit(player) != null) game.GetKit(player).ApplyKit(player); - } + _border.setSize(MAX_ARENA_SIZE / 2, MINING_TIME_IN_MINUTES * 60); + Announce(C.cGreen + C.Bold + "Please wait, you will be teleported soon", false); _totalPlayers = players.size(); @@ -964,8 +1022,7 @@ public class UHC extends TeamGame if (_teleportedPlayers >= players.size()) { Announce(C.cGreen + C.Bold + "The game will start in 5 seconds", false); - Manager.runSyncLater(() -> - { + Manager.runSyncLater(() -> { try { for (Player player : players) @@ -987,12 +1044,13 @@ public class UHC extends TeamGame } teleportedLocations.clear(); - } finally + } + finally { game.AnnounceGame(); game.StartPrepareCountdown(); - //Event + // Event GamePrepareCountdownCommence gamePrepareCountdownCommence = new GamePrepareCountdownCommence(game); UtilServer.getServer().getPluginManager().callEvent(gamePrepareCountdownCommence); @@ -1006,14 +1064,17 @@ public class UHC extends TeamGame Player player = players.get(_teleportedPlayers); GameTeam team = game.GetTeam(player); - // This could happen if the player left (and rejoined) while teleporting + // This could happen if the player left (and rejoined) while + // teleporting // Team maps based on player as a key if (team != null) { + Bukkit.broadcastMessage(team.GetSpawns().size() + " spawns for " + player.getName() + " in team " + team.GetName()); + // Save where they teleported teleportedLocations.put(player.getUniqueId(), team.SpawnTeleport(player)); - //Event + // Event PlayerPrepareTeleportEvent playerStateEvent = new PlayerPrepareTeleportEvent(game, player); UtilServer.getServer().getPluginManager().callEvent(playerStateEvent); } @@ -1024,7 +1085,7 @@ public class UHC extends TeamGame } }, 5 * 20L, DELAY_BETWEEN_PLAYER_TELEPORT); - //Spectators Move + // Spectators Move for (Player player : UtilServer.getPlayers()) { if (Manager.GetGame().IsAlive(player)) @@ -1032,6 +1093,7 @@ public class UHC extends TeamGame Manager.addSpectator(player, true); } + } @Override @@ -1042,19 +1104,17 @@ public class UHC extends TeamGame return SpectatorSpawn; } - SpectatorSpawn = WorldData.World.getSpawnLocation(); - - SpectatorSpawn.add(0, 10, 0); + SpectatorSpawn = new Location(WorldData.World, 0, 60, 0); SpectatorSpawn = SpectatorSpawn.getBlock().getLocation().add(0.5, 0.1, 0.5); - while (SpectatorSpawn.getBlock().getTypeId() != 0 || SpectatorSpawn.getBlock().getRelative(BlockFace.UP).getTypeId() != 0) + while (SpectatorSpawn.getBlock().getType() != Material.AIR || SpectatorSpawn.getBlock().getRelative(BlockFace.UP).getType() != Material.AIR) SpectatorSpawn.add(0, 1, 0); return SpectatorSpawn; } - private Location GetRandomSpawn(Location around, boolean sameChunk) + public Location GetRandomSpawn(Location around, boolean sameChunk) { int tries = 0; @@ -1074,9 +1134,12 @@ public class UHC extends TeamGame if (around == null) { - // Return a int from 0 - 1800, then remove 900 so its a int from -900 to 900 - int x = (int) (UtilMath.r((int) (1.8 * _currentBorder)) - (0.9 * _currentBorder)); - int z = (int) (UtilMath.r((int) (1.8 * _currentBorder)) - (0.9 * _currentBorder)); + double currentBorder = _border.getMaxCords(); + + // Return a int from 0 - 1800, then remove 900 so its a int from + // -900 to 900 + int x = (int) (UtilMath.r((int) (1.8 * currentBorder)) - (0.9 * currentBorder)); + int z = (int) (UtilMath.r((int) (1.8 * currentBorder)) - (0.9 * currentBorder)); targetBlock = UtilBlock.getHighest(WorldData.World, x, z, null); } @@ -1096,8 +1159,7 @@ public class UHC extends TeamGame } else { - targetBlock = UtilBlock.getHighest(WorldData.World, around.getBlockX() - 4 + UtilMath.r(tries < 10 ? 8 : 30), around.getBlockZ() - 4 - + UtilMath.r(tries < 10 ? 8 : 30), null); + targetBlock = UtilBlock.getHighest(WorldData.World, around.getBlockX() - 4 + UtilMath.r(tries < 10 ? 8 : 30), around.getBlockZ() - 4 + UtilMath.r(tries < 10 ? 8 : 30), null); } } @@ -1176,8 +1238,7 @@ public class UHC extends TeamGame // Simple if (killer != null) { - Announce(Manager.GetColor(dead) + C.Bold + dead.getName() + C.cGray + C.Bold + " was killed by " - + Manager.GetColor(killer) + C.Bold + killer.getName() + C.cGray + C.Bold + "."); + Announce(Manager.GetColor(dead) + C.Bold + dead.getName() + C.cGray + C.Bold + " was killed by " + Manager.GetColor(killer) + C.Bold + killer.getName() + C.cGray + C.Bold + "."); } else { @@ -1188,8 +1249,7 @@ public class UHC extends TeamGame else { - Announce(Manager.GetColor(dead) + C.Bold + dead.getName() + C.cGray + C.Bold + " was killed by " - + log.GetAttackers().getFirst().GetName() + "."); + Announce(Manager.GetColor(dead) + C.Bold + dead.getName() + C.cGray + C.Bold + " was killed by " + log.GetAttackers().getFirst().GetName() + "."); } } } @@ -1283,8 +1343,7 @@ public class UHC extends TeamGame { if (event.getBlock().getType() == Material.OBSIDIAN) { - UtilPlayer.message(event.getPlayer(), - F.main("Game", "You cannot place " + F.elem("Obsidian") + " in the " + F.elem("Nether") + ".")); + UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot place " + F.elem("Obsidian") + " in the " + F.elem("Nether") + ".")); event.setCancelled(true); } } @@ -1324,12 +1383,63 @@ public class UHC extends TeamGame event.setCancelled(false); } + @EventHandler + public void nightVision(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + { + return; + } + + for (Player player : GetPlayers(true)) + { + if (player.getLocation().getY() <= NIGHT_VISION_MAX_Y) + { + player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0)); + } + else + { + player.removePotionEffect(PotionEffectType.NIGHT_VISION); + } + } + } + + @EventHandler + public void appleDrop(BlockBreakEvent event) + { + Block block = event.getBlock(); + + if (block.getType() != Material.LEAVES) + { + return; + } + + if (Math.random() < APPLE_DROP_RATE) + { + block.getWorld().dropItemNaturally(block.getLocation().add(0.5, 0.5, 0.5), new ItemStack(Material.APPLE)); + } + } + + @EventHandler + public void stopPoison(EntityDamageEvent event) + { + if (event.getCause() != DamageCause.POISON || !(event.getEntity() instanceof LivingEntity)) + { + return; + } + + ((LivingEntity) event.getEntity()).removePotionEffect(PotionEffectType.POISON); + event.setCancelled(true); + } + @Override public void EndCheck() { if (!IsLive()) return; + boolean end = false; + // Solo if (GetTeamList().size() == 1) { @@ -1353,15 +1463,14 @@ public class UHC extends TeamGame for (Player player : GetPlayers(false)) if (player.isOnline()) AddGems(player, 10, "Participation", false, false); - - // End - SetState(GameState.End); + + end = true; } } else { // Online Teams - List teamsAlive = this.GetTeamList().stream().filter(team -> team.GetPlayers(true).size() > 0).collect(Collectors.toList()); + List teamsAlive = GetTeamList().stream().filter(team -> team.GetPlayers(true).size() > 0).collect(Collectors.toList()); // Offline Player Team if (teamsAlive.size() > 1) @@ -1386,9 +1495,18 @@ public class UHC extends TeamGame { AnnounceEnd(teamsAlive.get(0)); } - SetState(GameState.End); + + end = true; } } + + if (end) + { + _border.stop(); + + // End + SetState(GameState.End); + } } @Override @@ -1406,7 +1524,7 @@ public class UHC extends TeamGame { if (GetPlayers(true).size() < 8) { - Scoreboard.writeGroup(GetPlayers(true), player -> Pair.create(player.getName(), (int) Math.ceil(player.getHealth())), true); + Scoreboard.writeGroup(GetPlayers(true), player -> Pair.create(GetTeam(player).GetColor() + player.getName(), (int) Math.ceil(player.getHealth())), true); } else { @@ -1433,7 +1551,8 @@ public class UHC extends TeamGame if (GetState() == GameState.Prepare) { int players = _teleportedPlayers + 1; - if (players > _totalPlayers) players = _totalPlayers; + if (players > _totalPlayers) + players = _totalPlayers; Scoreboard.write("Teleporting Players (" + players + "/" + _totalPlayers + ")"); } else if (GetState() == GameState.Live) @@ -1445,9 +1564,11 @@ public class UHC extends TeamGame Scoreboard.write("Finished"); } + double currentBorder = _border.getMaxCords(); + Scoreboard.writeNewLine(); Scoreboard.write(C.cYellow + C.Bold + "Borders"); - Scoreboard.write("-" + (int) _currentBorder + " to " + "+" + (int) _currentBorder); + Scoreboard.write("-" + (int) currentBorder + " to " + "+" + (int) currentBorder); Scoreboard.draw(); @@ -1457,63 +1578,32 @@ public class UHC extends TeamGame } } - @Override - public boolean CanJoinTeam(GameTeam team) - { - return team.GetSize() < 2; - } - - // Ensure 2 players per team - @Override - public GameTeam ChooseTeam(Player player) - { - GameTeam team = null; - - // Random Team - for (GameTeam gameTeam : _teamList) - { - if (gameTeam.GetSize() == 1) - return gameTeam; - - if (team == null || gameTeam.GetSize() < team.GetSize()) - { - team = gameTeam; - } - } - - return team; - } - - @EventHandler - public void TeamRename(GameStateChangeEvent event) - { - if (event.GetState() != GameState.Live) - return; - - for (GameTeam team : GetTeamList()) - { - // Big Team - if (team.GetSize() > 2) - { - team.SetName("Team " + team.GetName()); - continue; - } - - String name = ""; - - for (int i = 0; i < team.GetPlayers(false).size(); i++) - { - Player player = team.GetPlayers(false).get(i); - - name += player.getName(); - - if (i < team.GetPlayers(false).size() - 1) - name += " & "; - } - - team.SetName(name); - } - } + // @Override + // public boolean CanJoinTeam(GameTeam team) + // { + // return team.GetSize() < 2; + // } + // + // // Ensure 2 players per team + // @Override + // public GameTeam ChooseTeam(Player player) + // { + // GameTeam team = null; + // + // // Random Team + // for (GameTeam gameTeam : GetTeamList()) + // { + // if (gameTeam.GetSize() == 1) + // return gameTeam; + // + // if (team == null || gameTeam.GetSize() < team.GetSize()) + // { + // team = gameTeam; + // } + // } + // + // return team; + // } @Override public double GetKillsGems(Player killer, Player killed, boolean assist) @@ -1530,44 +1620,58 @@ public class UHC extends TeamGame return 200; } - @EventHandler - public void damageCancel(EntityDamageEvent event) + // @EventHandler + // public void damageCancel(EntityDamageEvent event) + // { + // if (!IsLive()) + // event.setCancelled(true); + // + // // Damagee + // Player damagee = null; + // if (event.getEntity() instanceof Player) + // { + // damagee = (Player) event.getEntity(); + // + // // Dead + // if (!IsAlive(damagee)) + // event.setCancelled(true); + // } + // + // // Damager + // LivingEntity damagerEnt = UtilEvent.GetDamagerEntity(event, true); + // + // if (damagerEnt instanceof Player) + // { + // // PvP + // if (!DamagePvP && damagee != null) + // event.setCancelled(true); + // + // Player damager = (Player) damagerEnt; + // + // // Dead + // if (!IsAlive(damager)) + // event.setCancelled(true); + // + // // Same Team + // if (damagee != null) + // if (GetTeam(damager) != null && GetTeam(damagee) != null && + // GetTeam(damager).equals(GetTeam(damagee))) + // { + // event.setCancelled(true); + // } + // } + // } + + public void setViewDistance(int chunks) { - if (!IsLive()) - event.setCancelled(true); + WorldServer worldServer = ((CraftWorld) WorldData.World).getHandle(); + + worldServer.spigotConfig.viewDistance = VIEW_DISTANCE; + worldServer.getPlayerChunkMap().a(VIEW_DISTANCE); + } - // Damagee - Player damagee = null; - if (event.getEntity() instanceof Player) - { - damagee = (Player) event.getEntity(); - - // Dead - if (!IsAlive(damagee)) - event.setCancelled(true); - } - - // Damager - LivingEntity damagerEnt = UtilEvent.GetDamagerEntity(event, true); - - if (damagerEnt instanceof Player) - { - // PvP - if (!DamagePvP && damagee != null) - event.setCancelled(true); - - Player damager = (Player) damagerEnt; - - // Dead - if (!IsAlive(damager)) - event.setCancelled(true); - - // Same Team - if (damagee != null) - if (GetTeam(damager) != null && GetTeam(damagee) != null && GetTeam(damager).equals(GetTeam(damagee))) - { - event.setCancelled(true); - } - } + public UHCBorder getBorder() + { + return _border; } } \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHCBorder.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHCBorder.java new file mode 100644 index 000000000..2855c0a0d --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHCBorder.java @@ -0,0 +1,57 @@ +package nautilus.game.arcade.game.games.uhc; + +import org.bukkit.WorldBorder; + +public class UHCBorder +{ + + private static final int WARNING_TIME = 20; + + private UHC _host; + private int _startingSize; + + private WorldBorder _worldBorder; + + public UHCBorder(UHC host, int startingSize) + { + _host = host; + _startingSize = startingSize; + } + + public void prepare() + { + _worldBorder = _host.WorldData.World.getWorldBorder(); + + _worldBorder.setCenter(0, 0); + _worldBorder.setWarningTime(WARNING_TIME); + + setSize(_startingSize, 0); + } + + public void setSize(double size, long seconds) + { + _worldBorder.setSize(size * 2, seconds); + } + + public void stop() + { + _worldBorder.setSize(_worldBorder.getSize()); + _worldBorder.setSize(99999); + } + + public double getSize() + { + if (_worldBorder == null) + { + return _startingSize; + } + + return _worldBorder.getSize(); + } + + public double getMaxCords() + { + return getSize() / 2; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHCFreezer.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHCFreezer.java new file mode 100644 index 000000000..c4116a390 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHCFreezer.java @@ -0,0 +1,64 @@ +package nautilus.game.arcade.game.games.uhc; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.plugin.java.JavaPlugin; + +public class UHCFreezer implements Listener +{ + + private UHC _host; + + private Set _frozenPlayers = new HashSet<>(); + + public UHCFreezer(UHC host) + { + _host = host; + + JavaPlugin plugin = host.Manager.getPlugin(); + + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + public void freeze(Player player) + { + _frozenPlayers.add(player.getUniqueId()); + } + + public void unfreeze(Player player) + { + _frozenPlayers.remove(player.getUniqueId()); + } + + public void unfreeze() + { + _frozenPlayers.clear(); + } + + @EventHandler + public void onMove(PlayerMoveEvent event) + { + if (!_host.IsLive() || !_frozenPlayers.contains(event.getPlayer().getUniqueId())) + { + return; + } + + Location from = event.getFrom(); + Location to = event.getTo(); + + if (from.getX() == to.getX() && from.getZ() == to.getZ()) + { + return; + } + + event.setTo(from); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHCSolo.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHCSolo.java new file mode 100644 index 000000000..1795606d1 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHCSolo.java @@ -0,0 +1,86 @@ +package nautilus.game.arcade.game.games.uhc; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.GameTeam; + +public class UHCSolo extends UHC +{ + + public UHCSolo(ArcadeManager manager) + { + this(manager, GameType.UHCSolo); + } + + public UHCSolo(ArcadeManager manager, GameType type) + { + super(manager, type); + + DamageTeamSelf = true; + SpawnNearAllies = false; + } + + @EventHandler + public void playerTeamGeneration(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Recruit) + { + return; + } + + _teamList = new ArrayList<>(Arrays.asList(_teamList.get(0))); + + for (GameTeam team : _teamList) + { + team.SetName("Players"); + team.SetColor(ChatColor.YELLOW); + } + } + + @Override + public List getWinners() + { + if (GetState().ordinal() >= GameState.End.ordinal()) + { + List places = GetTeamList().get(0).GetPlacements(true); + + if (places.isEmpty() || !places.get(0).isOnline()) + return Arrays.asList(); + else + return Arrays.asList(places.get(0)); + } + else + return null; + } + + @Override + public List getLosers() + { + List winners = getWinners(); + + if (winners == null) + return null; + + List losers = GetTeamList().get(0).GetPlayers(false); + + losers.removeAll(winners); + + return losers; + } + + @Override + public String GetMode() + { + return "UHC Solo"; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHCTeams.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHCTeams.java new file mode 100644 index 000000000..49b1d4d9b --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHCTeams.java @@ -0,0 +1,125 @@ +package nautilus.game.arcade.game.games.uhc; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerQuitEvent; + +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.modules.TeamModule; + +public class UHCTeams extends UHC +{ + + public UHCTeams(ArcadeManager manager) + { + this(manager, GameType.UHC); + } + + public UHCTeams(ArcadeManager manager, GameType type) + { + super(manager, type); + + FillTeamsInOrderToCount = 2; + DamageTeamSelf = false; + DontAllowOverfill = true; + + // NEVER EVER EVER USE THIS!!!!! + //TeamMode = true; + + // Load the Team Module + new TeamModule().register(this); + } + + @EventHandler(priority = EventPriority.LOW) + public void PlayerQuit(PlayerQuitEvent event) + { + if (!InProgress()) + return; + + Player player = event.getPlayer(); + + GameTeam team = GetTeam(player); + if (team == null) return; + + if (!team.IsAlive(player)) + return; + + team.RemovePlayer(player); + } + + @EventHandler + public void TeamRename(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Live) + { + return; + } + + for (GameTeam team : GetTeamList()) + { + // Big Team + if (team.GetSize() > 2) + { + team.SetName("Team " + team.GetName()); + continue; + } + + String name = ""; + List players = team.GetPlayers(false); + + for (int i = 0; i < players.size(); i++) + { + Player player = players.get(i); + + name += player.getName(); + + if (i < players.size() - 1) + { + name += " & "; + } + } + + team.SetName(name); + } + } + + @Override + public List getWinners() + { + if (WinnerTeam == null) + return null; + + return WinnerTeam.GetPlayers(false); + } + + @Override + public List getLosers() + { + if (WinnerTeam == null) + return null; + + List players = new ArrayList<>(); + + for (GameTeam team : GetTeamList()) + { + if (team != WinnerTeam) + players.addAll(team.GetPlayers(false)); + } + + return players; + } + + @Override + public String GetMode() + { + return "UHC Teams"; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/Assassins.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/Assassins.java index a5ec141d0..34d732d6c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/Assassins.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/Assassins.java @@ -12,17 +12,19 @@ import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.itemstack.ItemStackFactory; + import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; -import nautilus.game.arcade.game.games.uhc.UHC; +import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.game.games.uhc.UHCSolo; /** * Assassins gamemode for UHC * * @author xXVevzZXx */ -public class Assassins extends UHC +public class Assassins extends UHCSolo { private HashMap _assassins; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/BloodDiamonds.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/BloodDiamonds.java index 609ed8c9e..32daf6400 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/BloodDiamonds.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/BloodDiamonds.java @@ -8,14 +8,14 @@ import org.bukkit.event.block.BlockBreakEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; -import nautilus.game.arcade.game.games.uhc.UHC; +import nautilus.game.arcade.game.games.uhc.UHCSolo; /** * BloodDiamonds gamemode for UHC * * @author xXVevzZXx */ -public class BloodDiamonds extends UHC +public class BloodDiamonds extends UHCSolo { private HashMap _oreDamage; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/CutClean.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/CutClean.java deleted file mode 100644 index 470fb1a6e..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/CutClean.java +++ /dev/null @@ -1,68 +0,0 @@ -package nautilus.game.arcade.game.games.uhc.modes; - -import mineplex.core.itemstack.ItemBuilder; -import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.GameType; -import nautilus.game.arcade.game.games.uhc.UHC; -import nautilus.game.arcade.game.modules.CutCleanModule; -import nautilus.game.arcade.game.modules.ItemGiverModule; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -/* - * The CutClean variant of UHC - * - * This is identical to UHC however iron and gold ore will immediately smelt - * and mob drops will be immediately cooked - */ -public class CutClean extends UHC -{ - // The amount of steak to give at the start of the game - private static final int STEAK_AMOUNT = 15; - - public CutClean(ArcadeManager manager) - { - super(manager, GameType.Brawl); - - new CutCleanModule() - .associateBlockDrop( - Material.GOLD_ORE, - new ItemBuilder(Material.GOLD_INGOT).build() - ) - .associateBlockDrop( - Material.IRON_ORE, - new ItemBuilder(Material.IRON_INGOT).build() - ) - .associateMobDrop( - Material.RAW_BEEF, - new ItemBuilder(Material.COOKED_BEEF).build() - ) - .associateMobDrop( - Material.RAW_CHICKEN, - new ItemBuilder(Material.COOKED_CHICKEN).build() - ) - .associateMobDrop( - Material.RAW_FISH, - new ItemBuilder(Material.COOKED_FISH).build() - ) - .associateMobDrop( - Material.PORK, - new ItemBuilder(Material.GRILLED_PORK).build() - ) - .associateMobDrop( - Material.RABBIT, - new ItemBuilder(Material.COOKED_RABBIT).build() - ) - .register(this); - - new ItemGiverModule() - .withItem(new ItemStack(Material.COOKED_BEEF, STEAK_AMOUNT)) - .register(this); - } - - @Override - public String GetMode() - { - return "Cut Clean"; - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/GodBattles.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/GodBattles.java index f722a0a7b..1f566abf0 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/GodBattles.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/GodBattles.java @@ -1,28 +1,31 @@ package nautilus.game.arcade.game.games.uhc.modes; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilItem; -import mineplex.core.common.util.UtilMath; -import mineplex.core.itemstack.ItemBuilder; -import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.GameType; -import nautilus.game.arcade.game.games.uhc.UHC; -import nautilus.game.arcade.game.modules.CutCleanModule; -import nautilus.game.arcade.game.modules.ItemGiverModule; -import nautilus.game.arcade.game.modules.OreVeinEditorModule; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.inventory.ItemStack; - import java.util.List; import java.util.Set; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.inventory.ItemStack; + +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilMath; +import mineplex.core.itemstack.ItemBuilder; + +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.game.games.uhc.UHCSolo; +import nautilus.game.arcade.game.modules.CutCleanModule; +import nautilus.game.arcade.game.modules.ItemGiverModule; +import nautilus.game.arcade.game.modules.OreVeinEditorModule; + /** * GodBattles gamemode for UHC */ -public class GodBattles extends UHC +public class GodBattles extends UHCSolo { // The set of materials which will be considered as an ore private static final Set ORE_MATERIALS = Sets.newHashSet( diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/PlayerHeadModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/PlayerHeadModule.java index 3553a357c..4ce7f88c1 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/PlayerHeadModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/PlayerHeadModule.java @@ -1,11 +1,5 @@ package nautilus.game.arcade.game.modules; -import mineplex.core.common.util.C; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.itemstack.ItemBuilder; -import mineplex.core.itemstack.ItemStackFactory; -import nautilus.game.arcade.game.GameTeam; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -20,11 +14,18 @@ import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ShapedRecipe; -import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.material.MaterialData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.itemstack.ItemStackFactory; + +import nautilus.game.arcade.game.GameTeam; + public class PlayerHeadModule extends Module { private boolean _disableCraftingRegularApples = true; @@ -36,7 +37,7 @@ public class PlayerHeadModule extends Module ShapedRecipe headApple2 = new ShapedRecipe(new ItemStack(Material.GOLDEN_APPLE, 1)); headApple2.shape("GGG", "GHG", "GGG"); headApple2.setIngredient('G', Material.GOLD_INGOT); - headApple2.setIngredient('H', new MaterialData(Material.SKULL_ITEM, (byte) 3)); + headApple2.setIngredient('H', new MaterialData(Material.SKULL_ITEM, (byte) 2)); UtilServer.getServer().addRecipe(headApple2); } @@ -69,7 +70,7 @@ public class PlayerHeadModule extends Module if (event.getItem().getItemStack().getType() == Material.SKULL_ITEM) { UtilPlayer.message(event.getPlayer(), " "); - UtilPlayer.message(event.getPlayer(), C.cGreen + C.Bold + "You picked up a Player Head!"); + UtilPlayer.message(event.getPlayer(), C.cGreen + C.Bold + "You picked up a Golden Head!"); UtilPlayer.message(event.getPlayer(), C.cWhite + "Craft a Golden Head Apple with it for ultimate healing."); UtilPlayer.message(event.getPlayer(), C.cWhite + "Use the recipe for Golden Apple, but Head replaces Apple."); UtilPlayer.message(event.getPlayer(), " "); @@ -86,15 +87,7 @@ public class PlayerHeadModule extends Module if (team == null) return; - // Skull Drop - ItemStack stack = new ItemBuilder(Material.SKULL_ITEM) - .setData((short) 3) - .setAmount(1) - .setTitle(team.GetColor() + player.getName() + "'s Head") - .setPlayerHead(player.getName()) - .build(); - - event.getDrops().add(stack); + event.getDrops().add(getGoldenHead()); } @EventHandler @@ -164,4 +157,13 @@ public class PlayerHeadModule extends Module return; } } + + public static final ItemStack getGoldenHead() + { + return new ItemBuilder(Material.SKULL_ITEM) + .setData((short) 2) + .setAmount(1) + .setTitle(C.cGoldB + "Golden Head") + .build(); + } }