diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 7b18f77c4..46919bae0 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -150,6 +150,7 @@ import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam.PlayerState; import nautilus.game.arcade.game.games.event.EventModule; import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; +import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.managers.GameAchievementManager; import nautilus.game.arcade.managers.GameCreationManager; import nautilus.game.arcade.managers.GameFlagManager; @@ -226,7 +227,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation private LobbyManager _gameLobbyManager; private GamePlayerManager _gamePlayerManager; private GameWorldManager _gameWorldManager; - private GameHostManager _gameHostManager; + private final GameHostManager _gameHostManager; private GameChatManager _gameChatManager; private ServerStatusManager _serverStatusManager; private InventoryManager _inventoryManager; @@ -271,11 +272,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation private final Titles _titles; public ArcadeManager(Arcade plugin, ServerStatusManager serverStatusManager, GameServerConfig serverConfig, - CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager, - StatsManager statsManager, IncognitoManager incognitoManager, AchievementManager achievementManager, DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, Chat chat, - Portal portal, PreferencesManager preferences, InventoryManager inventoryManager, PacketHandler packetHandler, - CosmeticManager cosmeticManager, ProjectileManager projectileManager, PetManager petManager, HologramManager hologramManager, PollManager pollManager, - NpcManager npcManager, CustomDataManager customDataManager, Punish punish, EloManager eloManager, ThankManager thankManager, BoosterManager boosterManager) + CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager, + StatsManager statsManager, IncognitoManager incognitoManager, AchievementManager achievementManager, DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, Chat chat, + Portal portal, PreferencesManager preferences, InventoryManager inventoryManager, PacketHandler packetHandler, + CosmeticManager cosmeticManager, ProjectileManager projectileManager, PetManager petManager, HologramManager hologramManager, PollManager pollManager, + NpcManager npcManager, CustomDataManager customDataManager, Punish punish, EloManager eloManager, ThankManager thankManager, BoosterManager boosterManager) { super("Game Manager", plugin); @@ -504,10 +505,10 @@ public class ArcadeManager extends MiniPlugin implements IRelation .register(ArcadeScoreboardLine.SERVER_VALUE) .recalculate(); - scoreboard.get(ArcadeScoreboardLine.PLAYERS_NAME).write(C.cYellow + C.Bold + "Players"); - scoreboard.get(ArcadeScoreboardLine.KIT_NAME).write(C.cGray + C.Bold + "Kit"); - scoreboard.get(ArcadeScoreboardLine.SERVER_NAME).write(C.cAqua + C.Bold + "Server"); - scoreboard.get(ArcadeScoreboardLine.SERVER_VALUE).write(_plugin.getConfig().getString("serverstatus.name")); + scoreboard.get(ArcadeScoreboardLine.PLAYERS_NAME).write(C.cYellowB + "Players"); + scoreboard.get(ArcadeScoreboardLine.KIT_NAME).write(C.cGrayB + "Kit"); + scoreboard.get(ArcadeScoreboardLine.SERVER_NAME).write(C.cAquaB + "Server"); + scoreboard.get(ArcadeScoreboardLine.SERVER_VALUE).write(UtilServer.getServerName()); } @Override @@ -515,18 +516,32 @@ public class ArcadeManager extends MiniPlugin implements IRelation { if (GetGame() != null) { - if (GetGame().GetCountdown() > 0) - scoreboard.setSidebarName(C.Bold + "§lStarting in " + C.cGreen + "§l" + GetGame().GetCountdown() + (GetGame().GetCountdown() == 1 ? " Second" : " Seconds")); - else if (GetGame().GetCountdown() == 0) - scoreboard.setSidebarName(ChatColor.WHITE + "§lIn Progress..."); + int countdown = GetGame().GetCountdown(); + + if (countdown > 0) + { + scoreboard.setSidebarName(C.Bold + "Starting in " + C.cGreenB + countdown + " Second" + (countdown == 1 ? "" : "s")); + } + else if (countdown == 0) + { + scoreboard.setSidebarName(C.cGreenB + "In Progress..."); + } else if (GetGame().GetState() == GameState.Recruit) - scoreboard.setSidebarName(ChatColor.GREEN + "§l" + "Waiting for players"); + { + scoreboard.setSidebarName(C.cGreenB + "Waiting for players"); + } else if (GetGame().GetState() == GameState.Loading) - scoreboard.setSidebarName(ChatColor.GREEN + "§l" + "Loading..."); + { + scoreboard.setSidebarName(C.cGreenB + "Loading..."); + } + } + else if (_gameCreationManager.getVotingManager().isVoteInProgress()) + { + scoreboard.setSidebarName(C.cGreenB + "Voting ends in " + _gameCreationManager.getVotingManager().getCurrentVote().getTimer()); } else { - scoreboard.setSidebarName(ChatColor.GREEN + "§l" + "Waiting for game"); + scoreboard.setSidebarName(C.cGreenB + "No Game"); } scoreboard.get(ArcadeScoreboardLine.PLAYERS_VALUE).write(getValidPlayersForGameStart().size() + "/" + GetPlayerFull()); @@ -541,30 +556,28 @@ public class ArcadeManager extends MiniPlugin implements IRelation scoreboard.get(ArcadeScoreboardLine.GEM_VALUE).write(donationManager.Get(scoreboard.getOwner()).getBalance(GlobalCurrency.GEM)); } + ChatColor teamColor = ChatColor.GRAY; + String kitName = "None"; + if (GetGame() != null) { - ChatColor teamColor = null; - String kitName = "None"; + Kit kit = GetGame().GetKit(scoreboard.getOwner()); + GameTeam team = GetGame().GetTeam(scoreboard.getOwner()); - if (GetGame().GetTeam(scoreboard.getOwner()) != null) + if (kit != null) { - teamColor = GetGame().GetTeam(scoreboard.getOwner()).GetColor(); + kitName = kit.GetName() + ""; } - if (GetGame().GetKit(scoreboard.getOwner()) != null) + if (team != null) { - kitName = GetGame().GetKit(scoreboard.getOwner()).GetName() + ""; + teamColor = team.GetColor(); } - - if (teamColor == null) - { - teamColor = ChatColor.GRAY; - } - - scoreboard.get(ArcadeScoreboardLine.KIT_NAME).write(teamColor + C.Bold + "Kit"); - scoreboard.get(ArcadeScoreboardLine.KIT_VALUE).write(kitName); } + scoreboard.get(ArcadeScoreboardLine.KIT_NAME).write(teamColor + C.Bold + "Kit"); + scoreboard.get(ArcadeScoreboardLine.KIT_VALUE).write(kitName); + if (GetGame() instanceof MinecraftLeague) { if (!scoreboard.isRegistered(ArcadeScoreboardLine.DIVISION_SPACER)) @@ -606,7 +619,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation generatePermissions(); } - + private void generatePermissions() { PermissionGroup.PLAYER.setPermission(Perm.RETURN_TO_HUB_COMMAND, true, true); @@ -629,7 +642,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation { PermissionGroup.ADMIN.setPermission(Perm.AUTO_OP, true, true); PermissionGroup.QAM.setPermission(Perm.AUTO_OP, false, true); - } else + } + else { PermissionGroup.LT.setPermission(Perm.AUTO_OP, true, true); } @@ -985,8 +999,14 @@ public class ArcadeManager extends MiniPlugin implements IRelation { event.setMaxPlayers(_serverConfig.MaxPlayers); + if (UtilServer.isTestServer(false)) + { + event.setMotd(ChatColor.GOLD + "Private Mineplex Test Server"); + return; + } + //MPS - if (_gameHostManager != null && _gameHostManager.isPrivateServer()) + if (_gameHostManager.isPrivateServer()) { if (_gameHostManager.isHostExpired()) { @@ -1001,39 +1021,30 @@ public class ArcadeManager extends MiniPlugin implements IRelation } } - String extrainformation = "|" + _serverConfig.ServerType + "|" + (_game == null ? "Unknown" : _game.GetName()) - + "|" + ((_game == null || _game.WorldData == null) ? "Unknown" : _game.WorldData.MapName); + String extrainformation = "|" + _serverConfig.ServerType + "|" + (_game == null ? "Unknown" : _game.GetName()) + "|" + ((_game == null || _game.WorldData == null) ? "Unknown" : _game.WorldData.MapName); if (_gameHostManager.isPrivateServer() && _gameHostManager.hasPermission(Perm.FEATURED_SERVER)) { extrainformation += "|HostRank." + _gameHostManager.getHostRank().name(); } - //Always Joinable - /*if (_game != null && _game.JoinInProgress) + + if (_game == null || _game.GetState() == GameState.Recruit) { - event.setMotd(ChatColor.GREEN + "Recruiting" + extrainformation); - } - //Recruiting - else */if (_game == null || _game.GetState() == GameState.Recruit) - { - if (_game != null && _game.GetCountdown() != -1) - { - event.setMotd(ChatColor.GREEN + "Starting in " + _game.GetCountdown() + " Seconds" + extrainformation); + if (_game != null && _game.GetCountdown() != -1) + { + event.setMotd(ChatColor.GREEN + "Starting in " + _game.GetCountdown() + " Seconds" + extrainformation); + } + else + { + event.setMotd(ChatColor.GREEN + "Recruiting" + extrainformation); + } } + //In Progress else { - event.setMotd(ChatColor.GREEN + "Recruiting" + extrainformation); + event.setMotd(ChatColor.YELLOW + "In Progress" + extrainformation); } } - //In Progress - else - { - event.setMotd(ChatColor.YELLOW + "In Progress" + extrainformation); - } - - if (UtilServer.isTestServer(false)) - event.setMotd(ChatColor.GOLD + "Private Mineplex Test Server"); - } @EventHandler public void onClickCompassPartyIcon(PartySelectServerEvent event) @@ -1187,7 +1198,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation if (_clientManager.Get(event.getPlayer()).hasPermission(Perm.AUTO_OP)) { event.getPlayer().setOp(true); - } else + } + else { event.getPlayer().setOp(false); } @@ -1960,7 +1972,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation if (!GetGame().WorldBoneMeal && event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getItemInHand().getType() == Material.INK_SACK && - player.getItemInHand().getData().getData() == (byte)15) + player.getItemInHand().getData().getData() == (byte) 15) { event.setCancelled(true); @@ -2013,7 +2025,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation { return _titles; } - + public QuestManager getQuestManager() { return _questManager; 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 ddff23dfa..62194eb58 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java @@ -1,11 +1,12 @@ package nautilus.game.arcade; import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; import mineplex.core.common.MinecraftVersion; import mineplex.core.common.Pair; -import mineplex.core.game.GameCategory; import mineplex.core.game.GameDisplay; +import mineplex.core.itemstack.ItemBuilder; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.games.alieninvasion.AlienInvasion; @@ -106,8 +107,9 @@ 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 nautilus.game.arcade.managers.voting.Voteable; -public enum GameType +public enum GameType implements Voteable { //Mini BaconBrawl(BaconBrawl.class, GameDisplay.BaconBrawl), @@ -260,7 +262,7 @@ public enum GameType new GameMode(UltimateOITQ.class, GameType.Quiver, "Ultimate OITQ"), new GameMode(Countdown.class, GameType.HideSeek, "Countdown"), new GameMode(SmashDom.class, GameType.ChampionsDominate, "Smash Dominate"), - new GameMode(SuperPaintstrike.class, GameType.MineStrike, "Super Paintstrike", new Pair[] + new GameMode(SuperPaintstrike.class, GameType.MineStrike, "Super Paintstrike", new Pair[] { //Pair.create(MinecraftVersion.Version1_8, "http://file.mineplex.com/ResMinestrike.zip"), //Pair.create(MinecraftVersion.Version1_9, "http://file.mineplex.com/ResMinestrike19.zip") @@ -368,7 +370,7 @@ public enum GameType return this._display; } - public String GetName() + public String getName() { return _display.getName(); } @@ -388,25 +390,12 @@ public enum GameType return _display.getMaterialData(); } - public GameCategory getGameCategory() + @Override + public ItemStack getItemStack() { - return _display.getGameCategory(); + return new ItemBuilder(GetMaterial(), GetMaterialData()).build(); } - public String GetKitGameName(Game game) - { - if (hasGamemodes()) - { - return getModeGameType(game.getClass())._display.getKitGameName(); - } - return _display.getKitGameName(); - } - - public boolean isUsingGameModes() - { - return _gameMaps; - } - public GameMode getGameMode(Class game) { for (GameMode mode : getGameModes()) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/SetCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/SetCommand.java index fe716f1c9..24ebf4fd9 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/SetCommand.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/SetCommand.java @@ -13,6 +13,8 @@ import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; + import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameMode; import nautilus.game.arcade.GameType; @@ -37,9 +39,6 @@ public class SetCommand extends CommandBase return; } - if (Plugin.GetGame() == null) - return; - if (args.length == 0) { caller.sendMessage(F.help(String.format("/game set [%s(gamemode)] [%s(mapsource)] [%s(mapname)]", MODE_PREFIX, SOURCE_PREFIX, MAP_PREFIX), "Set the current game or next game", ChatColor.DARK_RED)); @@ -178,7 +177,7 @@ public class SetCommand extends CommandBase } Plugin.GetGame().setGame(matches.get(0), caller, true); - if (Plugin.getPlugin().getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing")) + if (UtilServer.isTestServer()) { Plugin.GetGameList().clear(); Plugin.GetGameList().add(matches.get(0)); @@ -260,7 +259,7 @@ public class SetCommand extends CommandBase { input = input.toLowerCase(); - List allMapNames = source.stream().flatMap(type -> Plugin.LoadFiles(type.GetName()).stream()).collect(Collectors.toList()); + List allMapNames = source.stream().flatMap(type -> Plugin.LoadFiles(type.getName()).stream()).collect(Collectors.toList()); List matches = new ArrayList<>(); 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 4c2f8309d..700b62ae4 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 @@ -422,7 +422,7 @@ public abstract class Game extends ListenerComponent implements Lifetimed _lifetime.register(this); // Player List - UtilTabTitle.broadcastHeaderAndFooter(C.cGold + C.Bold + gameType.GetName(), "Visit " + C.cGreen + "www.mineplex.com" + UtilTabTitle.broadcastHeaderAndFooter(C.cGold + C.Bold + gameType.getName(), "Visit " + C.cGreen + "www.mineplex.com" + ChatColor.RESET + " for News, Forums and Shop"); // Game @@ -439,7 +439,7 @@ public abstract class Game extends ListenerComponent implements Lifetimed _files = new HashMap<>(); for (GameType type : GetWorldHostNames()) { - _files.put(type, Manager.LoadFiles(type.GetName())); + _files.put(type, Manager.LoadFiles(type.getName())); } if (Manager.GetGameCreationManager().MapPref != null) { @@ -607,7 +607,7 @@ public abstract class Game extends ListenerComponent implements Lifetimed public String GetName() { - return _gameType.GetName(); + return _gameType.getName(); } public GameType[] GetWorldHostNames() @@ -1861,12 +1861,12 @@ public abstract class Game extends ListenerComponent implements Lifetimed SetState(GameState.Dead); if (inform) - Announce(C.cAqua + C.Bold + caller.getName() + " has changed game to " + gameType.GetName() + "."); + Announce(C.cAqua + C.Bold + caller.getName() + " has changed game to " + gameType.getName() + "."); } else { if (inform) - Announce(C.cAqua + C.Bold + caller.getName() + " set next game to " + gameType.GetName() + "."); + Announce(C.cAqua + C.Bold + caller.getName() + " set next game to " + gameType.getName() + "."); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameServerConfig.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameServerConfig.java index 617588f8f..3ea1199cd 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameServerConfig.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameServerConfig.java @@ -47,6 +47,9 @@ public class GameServerConfig public boolean PublicServer = true; public boolean PlayerServerWhitelist = false; + + public boolean GameVoting = true; + public boolean MapVoting = true; public boolean IsValid() { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/item/items/CakeSheep.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/item/items/CakeSheep.java index 6649eba8f..f180baf4f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/item/items/CakeSheep.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/item/items/CakeSheep.java @@ -118,10 +118,10 @@ public class CakeSheep extends CakeSpecialItem implements Listener } long left = start + EXPLOSION_TIME - System.currentTimeMillis(); + Location sheepLocation = sheep.getLocation(); if (left <= 0) { - Location sheepLocation = sheep.getLocation(); Map blocks = UtilBlock.getInRadius(sheepLocation, EXPLOSION_RADIUS); Collection placedBlocks = _game.getCakePlayerModule().getPlacedBlocks(); @@ -189,7 +189,7 @@ public class CakeSheep extends CakeSpecialItem implements Listener if (tick % 6 == 0) { - location.getWorld().playSound(location, Sound.SHEEP_IDLE, 2, 0.8F); + location.getWorld().playSound(sheepLocation, Sound.SHEEP_IDLE, 2, 0.8F); } tick++; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/ChooseMapPage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/ChooseMapPage.java index 2677821a2..1836ee1ad 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/ChooseMapPage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/ChooseMapPage.java @@ -27,10 +27,10 @@ public class ChooseMapPage extends BasePage addBackToSetGamePage(); int slot = 9; - String loadMaps = _gameType.GetName(); + String loadMaps = _gameType.getName(); if(_gameType.getMapSource() != null) { - loadMaps = _gameType.getMapSource()[0].GetName(); + loadMaps = _gameType.getMapSource()[0].getName(); } for(String cur : getPlugin().LoadFiles(loadMaps)) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/EditRotationPage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/EditRotationPage.java index 065e65789..5bad0badd 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/EditRotationPage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/EditRotationPage.java @@ -64,7 +64,7 @@ public class EditRotationPage extends BasePage private void addGameButton(int slot, final GameType type, boolean enabled) { - String titleString = ChatColor.RESET + (enabled ? C.cGreen : C.cRed) + ChatColor.BOLD + type.GetName(); + String titleString = ChatColor.RESET + (enabled ? C.cGreen : C.cRed) + ChatColor.BOLD + type.getName(); String infoString = ChatColor.RESET + C.cGray + (enabled ? "Click to Disable" : "Click to Enable"); String[] lore = new String[]{infoString}; if (_manager.hasWarning().contains(type)) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/GameVotingPage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/GameVotingPage.java index dfe284b4a..64b0f1500 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/GameVotingPage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/GameVotingPage.java @@ -75,7 +75,7 @@ public class GameVotingPage extends BasePage private void addPickHighestButton(int slot) { - ShopItem item = new ShopItem(Material.DIAMOND_BLOCK, (byte)0, "§b§lSelect Highest Voted Game", new String[]{"§7Game: §e" + getHighestVoted().GetName()}, 1, false, false); + ShopItem item = new ShopItem(Material.DIAMOND_BLOCK, (byte)0, "§b§lSelect Highest Voted Game", new String[]{"§7Game: §e" + getHighestVoted().getName()}, 1, false, false); addButton(slot, item, (player, clickType) -> { if (!_manager.isHost(player)) //Double Check... @@ -166,7 +166,7 @@ public class GameVotingPage extends BasePage } String curVotes = "§7Votes: §e" + votes; - ShopItem item = new ShopItem(type.GetMaterial(), type.GetMaterialData(), type.GetName(), new String[]{click, curVotes}, 1, false, false); + ShopItem item = new ShopItem(type.GetMaterial(), type.GetMaterialData(), type.getName(), new String[]{click, curVotes}, 1, false, false); if (votes >= 1) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/SetGamePage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/SetGamePage.java index 2bf7d5510..3dd86a775 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/SetGamePage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/SetGamePage.java @@ -79,7 +79,7 @@ public class SetGamePage extends BasePage lore.add("§c§lWARNING: §fThis game was rejected!"); } - ShopItem shopItem = new ShopItem(type.GetMaterial(), type.GetMaterialData(), type.GetName(), lore.toArray(new String[lore.size()]), 1, false, false); + ShopItem shopItem = new ShopItem(type.GetMaterial(), type.GetMaterialData(), type.getName(), lore.toArray(new String[lore.size()]), 1, false, false); addButton(slot, shopItem, (player, clickType) -> { if (clickType == ClickType.LEFT) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java index 9446072c6..a72f6d73e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java @@ -1,23 +1,5 @@ package nautilus.game.arcade.managers; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilTime; -import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.common.timing.TimingManager; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.minecraft.game.core.combat.CombatManager.AttackReason; -import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.GameMode; -import nautilus.game.arcade.GameType; -import nautilus.game.arcade.game.Game; -import nautilus.game.arcade.game.Game.GameState; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - import java.lang.reflect.Array; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -29,35 +11,61 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import mineplex.core.common.timing.TimingManager; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilTime; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.combat.CombatManager.AttackReason; + +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameMode; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.game.Game; +import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.managers.voting.VotingManager; +import nautilus.game.arcade.managers.voting.types.GameVote; + public class GameCreationManager implements Listener { - ArcadeManager Manager; - - private ArrayList _ended = new ArrayList(); - + + final ArcadeManager Manager; + private final VotingManager _votingManager; + + private final List _ended = new ArrayList<>(); + private GameType _nextGame = null; - + private String _lastMap = ""; private GameMode _lastMode = null; - private ArrayList _lastGames = new ArrayList(); + private final List _lastGames = new ArrayList<>(); public String MapPref = null; public GameType MapSource = null; public GameMode ModePref = null; - + public GameCreationManager(ArcadeManager manager) { Manager = manager; - - Manager.getPluginManager().registerEvents(this, Manager.getPlugin()); + _votingManager = new VotingManager(manager); + + Manager.registerEvents(this); } - + public String GetLastMap() { return _lastMap; } - public void SetLastMap(String file) + public void SetLastMap(String file) { _lastMap = file; } @@ -65,92 +73,160 @@ public class GameCreationManager implements Listener @EventHandler public void NextGame(UpdateEvent event) { - if (event.getType() != UpdateType.FAST) + if (event.getType() != UpdateType.FAST || Manager.GetGameList().isEmpty()) + { return; - - if (Manager.GetGameList().isEmpty()) - return; - + } + while (_lastGames.size() > Manager.GetGameList().size() - 1) - _lastGames.remove(_lastGames.size()-1); - + { + _lastGames.remove(_lastGames.size() - 1); + } + if (Manager.GetGame() == null && _ended.isEmpty()) { - CreateGame(null); + createGame(); } //Archive Game - if (Manager.GetGame() != null) - { - if (Manager.GetGame().GetState() == GameState.Dead) - { - Manager.GetGame().disable(); - //Schedule Cleanup - _ended.add(Manager.GetGame()); + if (Manager.GetGame() != null && Manager.GetGame().GetState() == GameState.Dead) + { + Manager.GetGame().disable(); + _votingManager.deactivate(); - //Lobby Display - Manager.GetLobby().DisplayLast(Manager.GetGame()); + //Schedule Cleanup + _ended.add(Manager.GetGame()); - Manager.SetGame(null); - } + //Lobby Display + Manager.GetLobby().DisplayLast(Manager.GetGame()); + + Manager.SetGame(null); } //Clean Archived Games Iterator gameIterator = _ended.iterator(); while (gameIterator.hasNext()) - { + { Game game = gameIterator.next(); - + TimingManager.start("GameCreationManager - Attempting Removal - " + game.GetName()); - + //Cleaned if (game.WorldData == null || game.WorldData.World == null) { - gameIterator.remove(); + gameIterator.remove(); } else { boolean removedPlayers = false; + if (UtilTime.elapsed(game.GetStateTime(), 20000)) { - TimingManager.start("GameCreationManager - Kick Players - " + game.GetName()); - - for (Player player : game.WorldData.World.getPlayers()) + TimingManager.start("GameCreationManager - Kick Players - " + game.GetName()); + + for (Player player : game.WorldData.World.getPlayers()) { System.out.println("Kicking [" + player.getName() + "] with Validity [" + player.isValid() + "] with Online [" + player.isOnline() + "]"); - + player.remove(); - player.kickPlayer("Dead World"); + player.kickPlayer("Dead World"); } - + removedPlayers = true; - + TimingManager.stop("GameCreationManager - Kick Players - " + game.GetName()); } - + //Clean if (removedPlayers || game.WorldData.World.getPlayers().isEmpty()) { if (game.WorldData.World.getPlayers().isEmpty()) + { System.out.println("World Player Count [" + game.WorldData.World.getPlayers().size() + "]"); - + } + TimingManager.start("GameCreationManager - Uninit World - " + game.GetName()); - + game.WorldData.Uninitialize(); game.WorldData = null; gameIterator.remove(); TimingManager.stop("GameCreationManager - Uninit World - " + game.GetName()); - }; + } } - + TimingManager.stop("GameCreationManager - Attempting Removal - " + game.GetName()); } } - private void CreateGame(GameType gameType) + private void createGame() { + GameType gameType = null; + + if (_votingManager.getFinishedVote() != null) + { + gameType = ((GameVote) _votingManager.getFinishedVote()).getWinner(); + _votingManager.deactivate(); + } + else if (_votingManager.isVoteInProgress()) + { + return; + } + else + { + System.out.println(_nextGame == null ? "Next Game = null" : "Next Game = " + _nextGame.getName()); + System.out.println("Map Pref = " + MapPref); + System.out.println("Gamemode Pref = " + ModePref); + } + + //Chosen Game + if (_nextGame != null) + { + gameType = _nextGame; + _nextGame = null; + + System.out.println("Staff Selected GameType: " + gameType); + } + + //Pick Game + if (gameType == null) + { + // If voting is enabled + if (Manager.GetServerConfig().GameVoting) + { + List typesToVote = new ArrayList<>(Manager.GetGameList()); + + // Don't let the game that was just played appear + if (!_lastGames.isEmpty()) + { + typesToVote.remove(_lastGames.get(0)); + } + + // While there are more than 3 games, remove a random one + while (typesToVote.size() > VotingManager.GAMES_TO_VOTE_ON) + { + typesToVote.remove(UtilMath.r(typesToVote.size())); + } + + _votingManager.callVote(new GameVote(Manager, typesToVote)); + return; + } + else + { + for (int i = 0; i < 50; i++) + { + gameType = UtilAlg.Random(Manager.GetGameList()); + ModePref = randomGameMode(gameType); + + if (!_lastGames.contains(gameType)) + { + break; + } + } + } + } + //Reset Changes Manager.GetCreature().SetDisableCustomDrops(false); Manager.GetDamage().resetConfiguration(); @@ -160,45 +236,18 @@ public class GameCreationManager implements Listener Manager.GetDamage().GetCombatManager().setUseWeaponName(AttackReason.CustomWeaponName); ItemStackFactory.Instance.SetUseCustomNames(false); - System.out.println(_nextGame == null ? "Next Game = null" : "Next Game = " + _nextGame.GetName()); - System.out.println(MapPref == null ? "Map Pref = null" : "Map Pref = " + MapPref); - - System.out.println(ModePref == null ? "Gamemode Pref = null" : "Gamemode Pref = " + ModePref); - - //Chosen Game - if (_nextGame != null) - { - gameType = _nextGame; - _nextGame = null; - - System.out.println("Staff Selected GameType: " + gameType); - } - - //Pick Game - if (gameType == null) - { - for (int i=0 ; i<50 ; i++) - { - gameType = Manager.GetGameList().get(UtilMath.r(Manager.GetGameList().size())); - ModePref = randomGameMode(gameType); - - if (!_lastGames.contains(gameType)) - break; - } - } - //Champions Manager.toggleChampionsModules(gameType); - + _lastGames.add(0, gameType); - + boolean setVars = false; - + try { GameMode mode = null; Class gameClass = gameType.getGameClass(); - + if (ModePref != null) { for (GameMode modes : gameType.getGameModes()) @@ -213,17 +262,17 @@ public class GameCreationManager implements Listener } } } - + if (gameClass == null) { - gameClass = gameType.getGameModes()[UtilMath.r(gameType.getGameModes().length)].getGameClass(); + gameClass = UtilMath.randomElement(gameType.getGameModes()).getGameClass(); } - + ModePref = null; - + Game game = gameClass.getConstructor(ArcadeManager.class).newInstance(Manager); - - if (setVars && mode != null) + + if (setVars) { modifyGameConfiguration(gameClass, mode, game); } @@ -232,7 +281,7 @@ public class GameCreationManager implements Listener } catch (NoSuchMethodException ex) { - System.err.println("Is the constructor for " + gameType.GetName() + " using only one argument?"); + System.err.println("Is the constructor for " + gameType.getName() + " using only one argument?"); ex.printStackTrace(); return; } @@ -260,27 +309,27 @@ public class GameCreationManager implements Listener Manager.GetGame().getLifetime().start(GameState.Loading); TimingManager.stop("registerEvents"); } - + private GameMode randomGameMode(GameType type) { ArrayList modes = Manager.GetServerConfig().GameModeList; if (modes.size() == 0) return null; - + GameMode[] gameModes = type.getGameModes(); - + String mode = modes.get(UtilMath.r(modes.size())); - + int i = 0; while ((_lastMode == null || mode.equalsIgnoreCase(_lastMode.getName())) && !containsMode(gameModes, mode) && i != 25) { mode = modes.get(UtilMath.r(modes.size())); i++; } - + return getMode(gameModes, mode); } - + private boolean containsMode(GameMode[] modes, String mode) { for (GameMode otherMode : modes) @@ -308,15 +357,20 @@ public class GameCreationManager implements Listener public void SetNextGameType(GameType type) { _nextGame = type; + + if (_votingManager.isVoteInProgress()) + { + _votingManager.deactivate(); + } } @SuppressWarnings("unchecked") private void modifyGameConfiguration(Class gameClass, GameMode mode, Game game) { ArrayList> classes = new ArrayList<>(); - + Class superClass = gameClass; - while(superClass != Game.class) + while (superClass != Game.class) { classes.add(superClass); superClass = (Class) superClass.getSuperclass(); @@ -344,12 +398,12 @@ public class GameCreationManager implements Listener Field f = getField(clazz, var); if (f == null) continue; - + processList(clazz, game, var, value.contains(":") ? value.split("\\:") : new String[] - { - value - }, - add, remove, !List.class.isAssignableFrom(f.getType())); + { + value + }, + add, remove, !List.class.isAssignableFrom(f.getType())); } else if (value.contains("[")) { @@ -359,7 +413,7 @@ public class GameCreationManager implements Listener Map varMap = new HashMap<>(); String[] values = value.contains(":") ? value.split(":") : new String[] - { value }; + {value}; for (String keyValueSet : values) { @@ -380,7 +434,7 @@ public class GameCreationManager implements Listener @SuppressWarnings("unchecked") private void processMap(Class clazz, Game game, String var, - Map map) + Map map) { Field f = getField(clazz, var); if (f == null) @@ -415,7 +469,7 @@ public class GameCreationManager implements Listener @SuppressWarnings("unchecked") private void processList(Class clazz, Game game, String var, String[] value, - boolean add, boolean remove, boolean array) + boolean add, boolean remove, boolean array) { Field f = getField(clazz, var); if (f == null) @@ -430,7 +484,7 @@ public class GameCreationManager implements Listener f.set(game, Array.newInstance(f.getType().getComponentType(), value.length)); for (int i = 0; i < value.length; i++) { - ((Object[])f.get(game))[i] = parseValue(f.getType().getComponentType(), value[i], game); + ((Object[]) f.get(game))[i] = parseValue(f.getType().getComponentType(), value[i], game); } } else @@ -438,7 +492,7 @@ public class GameCreationManager implements Listener ParameterizedType type = (ParameterizedType) f.getGenericType(); Type generic = type.getActualTypeArguments()[0]; Class genericClazz = Class.forName(generic.getTypeName()); - + ArrayList currentList = (ArrayList) f.get(game); if (!add && !remove) { @@ -563,4 +617,9 @@ public class GameCreationManager implements Listener } return f; } + + public VotingManager getVotingManager() + { + return _votingManager; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java index c810a2f33..7ef20a245 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java @@ -1344,7 +1344,7 @@ public class GameFlagManager implements Listener if (Manager.GetGame().GetType().getResourcePackUrls(Manager.GetGame()) == null || Manager.GetGame().GetType().getResourcePackUrls(Manager.GetGame()).length == 0) return; - UtilTextMiddle.display(C.cGold + C.Bold + Manager.GetGame().GetType().GetName(), "Make sure you accept the Resource Pack", 20, 120, 20, event.getPlayer()); + UtilTextMiddle.display(C.cGold + C.Bold + Manager.GetGame().GetType().getName(), "Make sure you accept the Resource Pack", 20, 120, 20, event.getPlayer()); } @EventHandler diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameHostManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameHostManager.java index d7c02f7c7..29bfa2ed3 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameHostManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameHostManager.java @@ -153,7 +153,7 @@ public class GameHostManager implements Listener _games.add(GameType.Barbarians); _games.add(GameType.SmashDomination); - _games.sort(Comparator.comparing(GameType::GetName)); + _games.sort(Comparator.comparing(GameType::getName)); //Config Defaults if (Manager.GetHost() != null && Manager.GetHost().length() > 0) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java index dd71ce734..21a129f25 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java @@ -63,15 +63,15 @@ public class GameManager implements Listener { if (event.getType() != UpdateType.FASTEST) return; - + if (Manager.GetGame() != null && !Manager.GetGame().InProgress()) { ChatColor col = ChatColor.RED; - if (_colorId == 1) col = ChatColor.YELLOW; - else if (_colorId == 2) col = ChatColor.GREEN; - else if (_colorId == 3) col = ChatColor.AQUA; - _colorId = (_colorId+1)%4; - + if (_colorId == 1) col = ChatColor.YELLOW; + else if (_colorId == 2) col = ChatColor.GREEN; + else if (_colorId == 3) col = ChatColor.AQUA; + _colorId = (_colorId + 1) % 4; + String text = col + C.Bold + "US.MINEPLEX.COM EU.MINEPLEX.COM"; double health = 1; @@ -80,7 +80,7 @@ public class GameManager implements Listener if (Manager.GetGame().GetCountdown() >= 0 && Manager.GetGame().GetCountdown() <= 10) health = 1 - Manager.GetGame().GetCountdown() / 10d; } - + //Display IP UtilTextTop.displayProgress(text, health, UtilServer.getPlayers()); @@ -99,7 +99,7 @@ public class GameManager implements Listener } } } - + //Name Dragons Appropriately for (Gadget mount : Manager.getCosmeticManager().getGadgetManager().getGadgets(GadgetType.MOUNT)) { @@ -109,132 +109,132 @@ public class GameManager implements Listener ((MountDragon) mount).setHealthPercent(health); } } - + for (Gadget gadget : Manager.getCosmeticManager().getGadgetManager().getGadgets(GadgetType.MORPH)) { if (gadget instanceof MorphWither) { - ((MorphWither)gadget).setWitherData(text, health); + ((MorphWither) gadget).setWitherData(text, health); } } } } - + public boolean isInTutorial(boolean checkForTimer) { if (Manager.GetGame() == null || Manager.GetGame().GetState() != GameState.Prepare) return false; Game game = Manager.GetGame(); - + boolean tutorialSet = false; - for(GameTeam team : game.GetTeamList()) + for (GameTeam team : game.GetTeamList()) { - if(team.getTutorial() != null) + if (team.getTutorial() != null) tutorialSet = true; } - if(!tutorialSet) + if (!tutorialSet) { game.addTutorials(); } boolean finished = true; - if(game.EnableTutorials) + if (game.EnableTutorials) { - for(Player player : UtilServer.getPlayers()) + for (Player player : UtilServer.getPlayers()) { - if(player.getWorld() == Manager.GetLobby().getSpawn().getWorld()) + if (player.getWorld() == Manager.GetLobby().getSpawn().getWorld()) return true; } long prepTime = 0; - for(GameTeam team : game.GetTeamList()) + for (GameTeam team : game.GetTeamList()) { long timeUsage = 0; - if(team.getTutorial() != null) + if (team.getTutorial() != null) { - if(!team.getTutorial().hasStarted()) + if (!team.getTutorial().hasStarted()) { team.getTutorial().setTeam(team); - team.getTutorial().start(); + team.getTutorial().start(); timeUsage = team.getTutorial().StartAfterTutorial; timeUsage = timeUsage + (team.getTutorial().TimeBetweenPhase * team.getTutorial().getPhases().length); - if(team.getTutorial().CustomEnding) + if (team.getTutorial().CustomEnding) timeUsage = timeUsage + team.getTutorial().CustomEndingTime; - - for(TutorialPhase phase : team.getTutorial().getPhases()) + + for (TutorialPhase phase : team.getTutorial().getPhases()) { - for(TutorialText text : phase.getText()) + for (TutorialText text : phase.getText()) { timeUsage = timeUsage + (text.getStayTime() * 50); } } } - if(!team.getTutorial().hasEnded()) + if (!team.getTutorial().hasEnded()) { finished = false; - if(checkForTimer) + if (checkForTimer) { - if(team.getTutorial().ShowPrepareTimer) + if (team.getTutorial().ShowPrepareTimer) finished = true; else finished = false; } } } - if(prepTime <= timeUsage) + if (prepTime <= timeUsage) prepTime = timeUsage; } - if(prepTime > 0) + if (prepTime > 0) Manager.GetGame().PrepareTime = prepTime; - - if(!finished) + + if (!finished) return true; - } + } return false; } - + @EventHandler public void DisplayPrepareTime(UpdateEvent event) { if (event.getType() != UpdateType.TICK) return; - + if (Manager.GetGame() == null || Manager.GetGame().GetState() != GameState.Prepare) return; Game game = Manager.GetGame(); - - if(isInTutorial(true)) + + if (isInTutorial(true)) return; double percentage = (double) (System.currentTimeMillis() - game.GetStateTime()) / game.PrepareTime; - + for (Player player : UtilServer.getPlayers()) - UtilTextBottom.displayProgress("Game Start", percentage, + UtilTextBottom.displayProgress("Game Start", percentage, UtilTime.MakeStr(Math.max(0, game.PrepareTime - (System.currentTimeMillis() - game.GetStateTime()))), player); } - + @EventHandler public void updateGameTutorials(UpdateEvent event) { - if(event.getType() != UpdateType.TICK) + if (event.getType() != UpdateType.TICK) return; - + Game game = Manager.GetGame(); - - if(game == null) + + if (game == null) return; - - if(game.GetState() != GameState.Prepare) + + if (game.GetState() != GameState.Prepare) return; - - - if(game.EnableTutorials) + + + if (game.EnableTutorials) { - for(GameTeam team : game.GetTeamList()) + for (GameTeam team : game.GetTeamList()) { - if(team.getTutorial() != null) + if (team.getTutorial() != null) { - if(!team.getTutorial().hasEnded() && team.getTutorial().hasStarted()) + if (!team.getTutorial().hasEnded() && team.getTutorial().hasStarted()) { team.getTutorial().onTick(team.getTutorial().tick()); } @@ -250,92 +250,101 @@ public class GameManager implements Listener return; Game game = Manager.GetGame(); - if (game == null) return; + if (game == null) return; - if (game.GetState() == GameState.Loading) + switch (game.GetState()) { - if (UtilTime.elapsed(game.GetStateTime(), 30000)) - { - System.out.println("Game Load Expired."); - game.SetState(GameState.Dead); - } - } - else if (game.GetState() == GameState.Recruit) - { - //Stop Countdown! - if (game.GetCountdown() != -1 && - Manager.getValidPlayersForGameStart().size() < Manager.GetPlayerMin() && - !game.GetCountdownForce()) - { - game.SetCountdown(-1); - Manager.GetLobby().DisplayWaiting(); - } - - if (Manager.IsGameAutoStart()) - { - if (Manager.getValidPlayersForGameStart().size() >= Manager.GetPlayerFull()) - StateCountdown(game, 20, false); - - else if (Manager.getValidPlayersForGameStart().size() >= Manager.GetPlayerMin()) - StateCountdown(game, 60, false); - - else if (game.GetCountdown() != -1) - StateCountdown(game, -1, false); - } - else if (game.GetCountdown() != -1) - { - StateCountdown(game, -1, false); - } - } - else if (game.GetState() == GameState.Prepare) - { - if(isInTutorial(false)) - return; - - if (game.CanStartPrepareCountdown()) - { - if (UtilTime.elapsed(game.GetStateTime(), game.PrepareTime)) + case Loading: + if (UtilTime.elapsed(game.GetStateTime(), 30000)) { - int players = game.GetPlayers(true).size(); - - if (players < 2 || game.PlaySoundGameStart) - { - for (Player player : UtilServer.getPlayers()) - player.playSound(player.getLocation(), Sound.NOTE_PLING, 2f, 2f); - } + System.out.println("Game Load Expired."); + game.SetState(GameState.Dead); + } + break; + case Recruit: + //Stop Countdown! + if (game.GetCountdown() != -1 && Manager.getValidPlayersForGameStart().size() < Manager.GetPlayerMin() && !game.GetCountdownForce()) + { + game.SetCountdown(-1); + Manager.GetLobby().DisplayWaiting(); + } - if (players < 2) + if (Manager.IsGameAutoStart()) + { + if (Manager.getValidPlayersForGameStart().size() >= Manager.GetPlayerFull()) { - game.Announce(C.cWhite + C.Bold + game.GetName() + " ended, not enough players!"); - game.SetState(GameState.Dead); + StateCountdown(game, 10, false); + } + else if (Manager.getValidPlayersForGameStart().size() >= Manager.GetPlayerMin()) + { + StateCountdown(game, 60, false); + } + else if (game.GetCountdown() != -1) + { + StateCountdown(game, -1, false); + } + } + else if (game.GetCountdown() != -1) + { + StateCountdown(game, -1, false); + } + break; + case Prepare: + if (isInTutorial(false)) + { + return; + } + + if (game.CanStartPrepareCountdown()) + { + if (UtilTime.elapsed(game.GetStateTime(), game.PrepareTime)) + { + int players = game.GetPlayers(true).size(); + + if (players < 2 || game.PlaySoundGameStart) + { + for (Player player : UtilServer.getPlayers()) + player.playSound(player.getLocation(), Sound.NOTE_PLING, 2f, 2f); + } + + if (players < 2) + { + game.Announce(C.cWhite + C.Bold + game.GetName() + " ended, not enough players!"); + game.SetState(GameState.Dead); + } + else + { + game.SetState(GameState.Live); + } } else { - game.SetState(GameState.Live); + for (Player player : UtilServer.getPlayersCollection()) + { + player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1f, 1f); + } } } - else + break; + case Live: + { + if (game.GameTimeout != -1 && UtilTime.elapsed(game.GetStateTime(), game.GameTimeout) && Manager.IsGameTimeout()) { - for (Player player : UtilServer.getPlayers()) - player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1f, 1f); + game.HandleTimeout(); } - } - } - else if (game.GetState() == GameState.Live) - { - if (game.GameTimeout != -1 && UtilTime.elapsed(game.GetStateTime(), game.GameTimeout) && Manager.IsGameTimeout()) - { - game.HandleTimeout(); - } - } - else if (game.GetState() == GameState.End) - { - WinEffectGadget winEffectGadget = game.WinEffectManager.getWinEffect(); - if (UtilTime.elapsed(game.GetStateTime(), winEffectGadget == null ? 10000 : winEffectGadget.getLength())) + break; + } + case End: { - game.WinEffectManager.end(); - game.SetState(GameState.Dead); + WinEffectGadget winEffectGadget = game.WinEffectManager.getWinEffect(); + + if (UtilTime.elapsed(game.GetStateTime(), winEffectGadget == null ? 10000 : winEffectGadget.getLength())) + { + game.WinEffectManager.end(); + game.SetState(GameState.Dead); + } + break; } } } @@ -390,8 +399,12 @@ public class GameManager implements Listener } if (game.GetCountdown() > 0 && game.GetCountdown() <= 10) - for (Player player : UtilServer.getPlayers()) + { + for (Player player : UtilServer.getPlayersCollection()) + { player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 1f); + } + } //Countdown Ended if (game.GetCountdown() == 0) @@ -418,9 +431,9 @@ public class GameManager implements Listener if (Manager.GetGame() != null && Manager.GetGame().GetState() != GameState.Recruit && event.getReason() == RestartTriggerEvent.RestartReason.UPDATE) event.setCancelled(true); } - + @EventHandler - public void KitRegister(GameStateChangeEvent event) + public void KitRegister(GameStateChangeEvent event) { if (event.GetState() != event.GetGame().KitRegisterState) return; @@ -429,7 +442,7 @@ public class GameManager implements Listener } @EventHandler(priority = EventPriority.HIGH) - public void KitDeregister(GameStateChangeEvent event) + public void KitDeregister(GameStateChangeEvent event) { if (event.GetState() != GameState.End) return; @@ -494,14 +507,14 @@ public class GameManager implements Listener return; final ArrayList players = game.GetPlayers(true); - + //Prepare Players - for (int i=0 ; i 0 || game.GetState() != GameState.Recruit) { UtilPlayer.message(event.getPlayer(), F.main("Carl", "You can't use my spinner at the moment!")); event.setCancelled(true); } - } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GamePlayerManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GamePlayerManager.java index 24d517577..202395545 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GamePlayerManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GamePlayerManager.java @@ -1,7 +1,5 @@ package nautilus.game.arcade.managers; -import java.util.ArrayList; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -83,7 +81,7 @@ public class GamePlayerManager implements Listener //Player List UtilTabTitle.setHeaderAndFooter(player, - Manager.GetGame() != null ? C.cGold + C.Bold + Manager.GetGame().GetType().GetName() : " ", + Manager.GetGame() != null ? C.cGold + C.Bold + Manager.GetGame().GetType().getName() : " ", "Visit " + C.cGreen + "www.mineplex.com" + ChatColor.RESET + " for News, Forums and Shop"); //Lobby Spawn diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameStatManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameStatManager.java index f9b20dc52..8c3273ba7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameStatManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameStatManager.java @@ -150,9 +150,9 @@ public class GameStatManager implements Listener int loss = UtilMath.r(50); int play = wins+loss; - Manager.GetStatsManager().incrementStat(player, type.GetName() + ".Wins", wins); - Manager.GetStatsManager().incrementStat(player, type.GetName() + ".Losses", loss); - Manager.GetStatsManager().incrementStat(player, type.GetName() + ".GamesPlayed", play); + Manager.GetStatsManager().incrementStat(player, type.getName() + ".Wins", wins); + Manager.GetStatsManager().incrementStat(player, type.getName() + ".Losses", loss); + Manager.GetStatsManager().incrementStat(player, type.getName() + ".GamesPlayed", play); } event.getPlayer().sendMessage("Gave Stats: " + player.getName()); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/lobby/LobbyManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/lobby/LobbyManager.java index 219b715de..5e3e71d80 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/lobby/LobbyManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/lobby/LobbyManager.java @@ -361,7 +361,7 @@ public abstract class LobbyManager implements Listener } } - public void UpdateFirework() + private void UpdateFirework() { if (UtilTime.elapsed(_fireworkStart, 10000)) { @@ -375,6 +375,16 @@ public abstract class LobbyManager implements Listener { //Start Fireworks RegisterFireworks(game.WinnerTeam); + + _manager.getMineplexGameManager().clearKitNPCs(); + + //Remove Old Ents + getTeams().keySet().forEach(Entity::remove); + getTeams().clear(); + + //Remove Blocks + getTeamBlocks().forEach(Block::setType); + getTeamBlocks().clear(); } public void DisplayNext(Game game) @@ -390,8 +400,6 @@ public abstract class LobbyManager implements Listener writeGameLine(_manager.GetGame().GetMode(), 1, 159, (byte) 1); } - _manager.getMineplexGameManager().clearKitNPCs(); - UtilServer.getPlayersCollection().forEach(this::equipActiveKit); DisplayWaiting(); @@ -403,14 +411,6 @@ public abstract class LobbyManager implements Listener writeKitLine("Select", 0, 159, (byte) 15); writeKitLine("Kit", 1, 159, (byte) 4); - //Remove Old Ents - getTeams().keySet().forEach(Entity::remove); - getTeams().clear(); - - //Remove Blocks - getTeamBlocks().forEach(Block::setType); - getTeamBlocks().clear(); - //Smash if (game.HideTeamSheep) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/Vote.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/Vote.java new file mode 100644 index 000000000..505caaec5 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/Vote.java @@ -0,0 +1,185 @@ +package nautilus.game.arcade.managers.voting; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.account.permissions.PermissionGroup; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilServer; + +import nautilus.game.arcade.ArcadeManager; + +public abstract class Vote +{ + + public static class VoteData + { + private final T _value; + private final double _rankWeight; + + VoteData(T value, double rankWeight) + { + _value = value; + _rankWeight = rankWeight; + } + + public T getValue() + { + return _value; + } + } + + private static final int VOTE_TIME = 30; + + private static double getRankWeight(PermissionGroup group) + { + switch (group) + { + case PLAYER: + return 1.0; + case ULTRA: + return 1.1; + case HERO: + return 1.2; + case LEGEND: + return 1.3; + case TITAN: + return 1.4; + default: + return 1.5; + } + } + + private final ArcadeManager _manager; + private final String _name; + private final ItemStack _itemStack; + private final List _values; + private final Map> _voteData; + + private int _timer; + private T _winnerCache; + + public Vote(ArcadeManager manager, String name, ItemStack itemStack, List values) + { + _manager = manager; + _name = name; + _itemStack = itemStack; + _values = values; + _voteData = new ConcurrentHashMap<>(); + _timer = VOTE_TIME; + } + + public abstract void onEnd(); + + public void vote(Player player, T value) + { + if (value == null) + { + _voteData.remove(player); + } + else + { + _voteData.put(player, new VoteData<>(value, getRankWeight(_manager.GetClients().Get(player).getPrimaryGroup()))); + } + + player.closeInventory(); + _winnerCache = null; + } + + public void removeVote(Player player) + { + vote(player, null); + } + + public T getWinner() + { + if (_winnerCache != null) + { + return _winnerCache; + } + + Map results = new HashMap<>(_values.size()); + + _voteData.values().forEach(voteData -> results.put(voteData.getValue(), results.getOrDefault(voteData.getValue(), 0D) + voteData._rankWeight)); + + List winners = new ArrayList<>(_values.size()); + double winningVotes = -1; + + for (Entry entry : results.entrySet()) + { + T value = entry.getKey(); + double votes = entry.getValue(); + + if (votes == winningVotes) + { + winners.add(value); + } + else if (votes > winningVotes) + { + winners.clear(); + winners.add(value); + winningVotes = votes; + } + } + + if (winners.size() == 1) + { + _winnerCache = winners.get(0); + } + else if (winners.isEmpty()) + { + _winnerCache = UtilAlg.Random(_values); + } + else + { + _winnerCache = UtilAlg.Random(winners); + } + + return _winnerCache; + } + + public VoteData getPlayerVote(Player player) + { + return _voteData.get(player); + } + + public ArcadeManager getManager() + { + return _manager; + } + + public String getName() + { + return _name; + } + + public ItemStack getItemStack() + { + return _itemStack; + } + + public List getValues() + { + return _values; + } + + public boolean decrementTimer() + { + int voted = _voteData.size(); + int validPlayers = _manager.getValidPlayersForGameStart().size(); + + return validPlayers != 0 && (voted >= _manager.GetPlayerFull() && voted == validPlayers || --_timer == 0); + } + + public int getTimer() + { + return _timer; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/Voteable.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/Voteable.java new file mode 100644 index 000000000..290463f69 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/Voteable.java @@ -0,0 +1,12 @@ +package nautilus.game.arcade.managers.voting; + +import org.bukkit.inventory.ItemStack; + +public interface Voteable +{ + + String getName(); + + ItemStack getItemStack(); + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/VotingManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/VotingManager.java new file mode 100644 index 000000000..dd482d33e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/VotingManager.java @@ -0,0 +1,158 @@ +package nautilus.game.arcade.managers.voting; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextBottom; +import mineplex.core.lifetimes.ListenerComponent; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.managers.voting.ui.VotingPage; +import nautilus.game.arcade.managers.voting.ui.VotingShop; + +public class VotingManager extends ListenerComponent +{ + + public static final int GAMES_TO_VOTE_ON = 3; + public static final int MAPS_TO_VOTE_ON = 5; + + private final VotingShop _shop; + + private Vote _currentVote, _finishedVote; + private boolean _colourTick; + + public VotingManager(ArcadeManager manager) + { + _shop = new VotingShop(manager, manager.GetClients(), manager.GetDonation()); + } + + public void callVote(Vote vote) + { + _currentVote = vote; + + for (Player player : UtilServer.getPlayersCollection()) + { + player.getInventory().setItem(0, _currentVote.getItemStack()); + } + + activate(); + } + + @Override + public void deactivate() + { + super.deactivate(); + + if (_currentVote != null) + { + ItemStack remove = _currentVote.getItemStack(); + for (Player player : UtilServer.getPlayersCollection()) + { + player.getInventory().remove(remove); + } + + _currentVote.onEnd(); + _currentVote = null; + _finishedVote = null; + } + } + + @EventHandler + public void playerJoin(PlayerJoinEvent event) + { + if (!isVoteInProgress()) + { + return; + } + + Player player = event.getPlayer(); + + player.getInventory().setItem(0, _currentVote.getItemStack()); + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + if (!isVoteInProgress()) + { + return; + } + + Player player = event.getPlayer(); + + _currentVote.removeVote(player); + } + + @EventHandler + public void playerInteract(PlayerInteractEvent event) + { + if (!isVoteInProgress()) + { + return; + } + + Player player = event.getPlayer(); + ItemStack itemStack = player.getItemInHand(); + + if (itemStack == null || !itemStack.equals(_currentVote.getItemStack())) + { + return; + } + + _shop.openPageForPlayer(player, new VotingPage<>(_currentVote.getManager(), _shop, player, _currentVote)); + } + + @EventHandler + public void informPlayers(UpdateEvent event) + { + if (!isVoteInProgress() || _finishedVote != null) + { + return; + } + + if (event.getType() == UpdateType.TWOSEC) + { + String primary = C.cGold, secondary = C.cYellow; + + if (_colourTick) + { + String temp = primary; + primary = secondary; + secondary = temp; + } + + UtilTextBottom.display(primary + "Use " + secondary + C.Bold + "/vote" + primary + " to pick the next " + secondary + C.Bold + _currentVote.getName(), UtilServer.getPlayers()); + _colourTick = !_colourTick; + } + else if (event.getType() == UpdateType.SEC) + { + if (_currentVote.decrementTimer()) + { + _finishedVote = _currentVote; + } + } + } + + public Vote getFinishedVote() + { + return _finishedVote; + } + + public Vote getCurrentVote() + { + return _currentVote; + } + + public boolean isVoteInProgress() + { + return _currentVote != null; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/types/GameVote.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/types/GameVote.java new file mode 100644 index 000000000..55db5287b --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/types/GameVote.java @@ -0,0 +1,39 @@ +package nautilus.game.arcade.managers.voting.types; + +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilServer; +import mineplex.core.itemstack.ItemBuilder; + +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.managers.voting.Vote; + +public class GameVote extends Vote +{ + + public GameVote(ArcadeManager manager, List values) + { + super(manager, "Game", new ItemBuilder(Material.PAPER) + .setTitle(C.cGreenB + "Vote for the next Game") + .addLore("", "Click to vote on the next", "game that's going to be played!") + .build(), values); + } + + @Override + public void onEnd() + { + Bukkit.broadcastMessage(C.cGreenB + getWinner().getName() + C.cWhiteB + " won the " + getName() + " Vote!"); + + for (Player player : UtilServer.getPlayersCollection()) + { + player.playSound(player.getLocation(), Sound.NOTE_PIANO, 1, 1); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/ui/VotingPage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/ui/VotingPage.java new file mode 100644 index 000000000..64176d182 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/ui/VotingPage.java @@ -0,0 +1,63 @@ +package nautilus.game.arcade.managers.voting.ui; + +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.shop.page.ShopPageBase; + +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.managers.voting.Vote; +import nautilus.game.arcade.managers.voting.Vote.VoteData; +import nautilus.game.arcade.managers.voting.Voteable; + +public class VotingPage extends ShopPageBase +{ + + private final Vote _vote; + + public VotingPage(ArcadeManager plugin, VotingShop shop, Player player, Vote vote) + { + super(plugin, shop, plugin.GetClients(), plugin.GetDonation(), "Pick The Next " + vote.getName() + "!", player, 27); + + _vote = vote; + + buildPage(); + } + + @Override + protected void buildPage() + { + int slot = 12; + VoteData playerVote = _vote.getPlayerVote(getPlayer()); + + addButton(10, new ItemBuilder(Material.COAL) + .setTitle(C.cPurpleB + "Random " + _vote.getName()) + .addLore("Leave " + _vote.getName() + " voting up to chance", "with a random selection.") + .setGlow(playerVote == null) + .build(), (player, clickType) -> + { + _vote.removeVote(player); + playRemoveSound(player); + }); + + String lowerName = _vote.getName().toLowerCase(); + + for (T voteable : _vote.getValues()) + { + ItemBuilder builder = new ItemBuilder(voteable.getItemStack()) + .setTitle(C.cGreenB + voteable.getName()) + .addLore("", "Click to vote for " + voteable.getName(), "to be the next " + lowerName + "!") + .setGlow(playerVote != null && playerVote.getValue().equals(voteable)); + + addButton(slot++, builder.build(), (player, clickType) -> + { + _vote.vote(player, voteable); + playAcceptSound(player); + player.sendMessage(F.main("Game", "You voted for " + F.name(voteable.getName()) + ".")); + }); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/ui/VotingShop.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/ui/VotingShop.java new file mode 100644 index 000000000..e887f9c57 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/ui/VotingShop.java @@ -0,0 +1,26 @@ +package nautilus.game.arcade.managers.voting.ui; + +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; + +import nautilus.game.arcade.ArcadeManager; + +public class VotingShop extends ShopBase +{ + + public VotingShop(ArcadeManager plugin, CoreClientManager clientManager, DonationManager donationManager) + { + super(plugin, clientManager, donationManager, "Voting"); + } + + @Override + protected ShopPageBase> buildPagesFor(Player player) + { + return null; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java index 31fe41def..6671b6a70 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java @@ -217,7 +217,7 @@ public class WorldData { if (Folder == null) { - Folder = "Game" + Id + "_" + GetGame().GetName() + "_" + GetFile(); + Folder = "Game" + Id + "_" + GetGame().getName() + "_" + GetFile(); } return Folder; } @@ -232,7 +232,7 @@ public class WorldData TimingManager.stop("UnzipWorld creating folders"); TimingManager.start("UnzipWorld UnzipToDirectory"); - ZipUtil.UnzipToDirectory("../../update/maps/" + GetGame().GetName() + "/" + GetFile() + ".zip", folder); + ZipUtil.UnzipToDirectory("../../update/maps/" + GetGame().getName() + "/" + GetFile() + ".zip", folder); TimingManager.stop("UnzipWorld UnzipToDirectory"); }