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 697078ad6..44ced0dab 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 @@ -6,11 +6,13 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.stream.Collectors; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -33,8 +35,10 @@ 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.Vote; import nautilus.game.arcade.managers.voting.VotingManager; import nautilus.game.arcade.managers.voting.types.GameVote; +import nautilus.game.arcade.managers.voting.types.MapVote; public class GameCreationManager implements Listener { @@ -65,16 +69,6 @@ public class GameCreationManager implements Listener Manager.registerEvents(this); } - public String GetLastMap() - { - return _lastMap; - } - - public void SetLastMap(String file) - { - _lastMap = file; - } - @EventHandler public void NextGame(UpdateEvent event) { @@ -171,7 +165,20 @@ public class GameCreationManager implements Listener if (_votingManager.getFinishedVote() != null) { - gameType = ((GameVote) _votingManager.getFinishedVote()).getWinner(); + Vote vote = _votingManager.getFinishedVote(); + + if (vote instanceof GameVote) + { + GameVote gameVote = ((GameVote) _votingManager.getFinishedVote()); + + gameType = gameVote.getWinner(); + MapPref = gameVote.getWinningMap().getName(); + } + else if (vote instanceof MapVote) + { + MapPref = ((MapVote) vote).getWinner().getName(); + } + _votingManager.deactivate(); } else if (_votingManager.isVoteInProgress()) @@ -197,7 +204,7 @@ public class GameCreationManager implements Listener //Pick Game if (gameType == null) { - // If voting is enabled + // If game voting is enabled if (Manager.GetServerConfig().GameVoting) { List typesToVote = new ArrayList<>(Manager.GetGameList()); @@ -214,7 +221,28 @@ public class GameCreationManager implements Listener typesToVote.remove(UtilMath.r(typesToVote.size())); } - _votingManager.callVote(new GameVote(Manager, typesToVote)); + Map> mapsToVote = new HashMap<>(); + + typesToVote.forEach(votingGameType -> + { + // Load the maps for this game type + loadMaps(votingGameType, votingGameType.getGameClass()); + + List votingGameMaps = _maps.values().stream() + .flatMap(Collection::stream) + .collect(Collectors.toList()); + + // While there are more than 5 maps, remove a random one + while (votingGameMaps.size() > VotingManager.MAPS_TO_VOTE_ON) + { + votingGameMaps.remove(UtilMath.r(votingGameMaps.size())); + } + + // Merge map names from all sources together + mapsToVote.put(votingGameType, votingGameMaps); + }); + + _votingManager.callVote(new GameVote(Manager, typesToVote, mapsToVote)); return; } else @@ -237,6 +265,20 @@ public class GameCreationManager implements Listener return; } + Class gameClass = gameType.getGameClass(); + + // If map voting and ONLY map voting is enabled + if (Manager.GetServerConfig().MapVoting && !Manager.GetServerConfig().GameVoting) + { + loadMaps(gameType, gameClass); + + // Apply the same logic as game voting and merge all those names together + _votingManager.callVote(new MapVote(Manager, _maps.values().stream() + .flatMap(Collection::stream) + .collect(Collectors.toList()))); + return; + } + //Reset Changes Manager.GetCreature().SetDisableCustomDrops(false); Manager.GetDamage().resetConfiguration(); @@ -252,7 +294,6 @@ public class GameCreationManager implements Listener _lastGames.add(0, gameType); boolean setVars = false; - Class gameClass = gameType.getGameClass(); try { @@ -335,6 +376,8 @@ public class GameCreationManager implements Listener if (MapPref != null) { + MapPref = MapPref.replace(" ", ""); + System.out.println("Map Preference: " + MapPref); Map> matches = new HashMap<>(); @@ -352,7 +395,7 @@ public class GameCreationManager implements Listener if (MapSource == null || entryType == MapSource) { matchList.add(map); - System.out.print("Map Preference: " + map); + System.out.print("Map Preference Found: " + map); } } }); @@ -395,6 +438,11 @@ public class GameCreationManager implements Listener selectedMap = UtilAlg.Random(_maps.get(gameType)); + if (selectedMap == null) + { + continue; + } + // Not the last map if (!selectedMap.equals(_lastMap)) { 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 21a129f25..1301c3c5d 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 @@ -186,8 +186,7 @@ public class GameManager implements Listener if (prepTime > 0) Manager.GetGame().PrepareTime = prepTime; - if (!finished) - return true; + return !finished; } return false; } @@ -196,37 +195,41 @@ public class GameManager implements Listener 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 (game == null || game.GetState() != GameState.Prepare) + { return; + } + + if (isInTutorial(true)) + { + return; + } double percentage = (double) (System.currentTimeMillis() - game.GetStateTime()) / game.PrepareTime; - for (Player player : UtilServer.getPlayers()) - UtilTextBottom.displayProgress("Game Start", percentage, - UtilTime.MakeStr(Math.max(0, game.PrepareTime - (System.currentTimeMillis() - game.GetStateTime()))), player); + UtilTextBottom.displayProgress("Game Start", percentage, UtilTime.MakeStr(Math.max(0, game.PrepareTime - (System.currentTimeMillis() - game.GetStateTime()))), UtilServer.getPlayers()); } @EventHandler public void updateGameTutorials(UpdateEvent event) { if (event.getType() != UpdateType.TICK) + { return; + } Game game = Manager.GetGame(); - if (game == null) + if (game == null || game.GetState() != GameState.Prepare) + { return; - - if (game.GetState() != GameState.Prepare) - return; - + } if (game.EnableTutorials) { @@ -247,10 +250,16 @@ public class GameManager implements Listener public void StateUpdate(UpdateEvent event) { if (event.getType() != UpdateType.SEC) + { return; + } Game game = Manager.GetGame(); - if (game == null) return; + + if (game == null) + { + return; + } switch (game.GetState()) { @@ -262,8 +271,10 @@ public class GameManager implements Listener } break; case Recruit: + int validPlayers = Manager.getValidPlayersForGameStart().size(); + //Stop Countdown! - if (game.GetCountdown() != -1 && Manager.getValidPlayersForGameStart().size() < Manager.GetPlayerMin() && !game.GetCountdownForce()) + if (game.GetCountdown() != -1 && validPlayers < Manager.GetPlayerMin() && !game.GetCountdownForce()) { game.SetCountdown(-1); Manager.GetLobby().DisplayWaiting(); @@ -271,11 +282,15 @@ public class GameManager implements Listener if (Manager.IsGameAutoStart()) { - if (Manager.getValidPlayersForGameStart().size() >= Manager.GetPlayerFull()) + if (validPlayers >= Manager.GetPlayerFull()) { StateCountdown(game, 10, false); } - else if (Manager.getValidPlayersForGameStart().size() >= Manager.GetPlayerMin()) + else if (validPlayers >= Manager.GetPlayerFull() * 0.75D) + { + StateCountdown(game, 30, false); + } + else if (validPlayers >= Manager.GetPlayerMin()) { StateCountdown(game, 60, false); } @@ -301,15 +316,17 @@ public class GameManager implements Listener { int players = game.GetPlayers(true).size(); - if (players < 2 || game.PlaySoundGameStart) + if (game.PlaySoundGameStart) { - for (Player player : UtilServer.getPlayers()) + for (Player player : UtilServer.getPlayersCollection()) + { 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.Announce(C.cWhiteB + game.GetName() + " ended, not enough players!"); game.SetState(GameState.Dead); } else 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 63666d709..ccbd67c57 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 @@ -592,36 +592,27 @@ public abstract class LobbyManager implements Listener } @EventHandler - public void InventoryUpdate(UpdateEvent event) + public void inventoryUpdate(UpdateEvent event) { - if (!_manager.IsHotbarInventory()) + if (event.getType() != UpdateType.SEC || !_manager.IsHotbarInventory()) { return; } - if (event.getType() != UpdateType.FAST) + Game game = _manager.GetGame(); + + if (game != null && game.GetState() != GameState.Recruit && game.GadgetsDisabled) { return; } - if (_manager.GetGame() == null) - { - return; - } - - if (_manager.GetGame().GetState() != GameState.Recruit && _manager.GetGame().GadgetsDisabled) - { - return; - } - - for (Player player : UtilServer.getPlayers()) + for (Player player : UtilServer.getPlayersCollection()) { if (player.getOpenInventory().getType() != InventoryType.CRAFTING) { continue; } - //Cosmetic Menu _manager.getCosmeticManager().giveInterfaceItem(player); _manager.getBoosterManager().giveInterfaceItem(player); _manager.getTitles().giveBookIfNotExists(player, false); 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 index 505caaec5..2915b32f9 100644 --- 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 @@ -89,7 +89,6 @@ public abstract class Vote _voteData.put(player, new VoteData<>(value, getRankWeight(_manager.GetClients().Get(player).getPrimaryGroup()))); } - player.closeInventory(); _winnerCache = null; } 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 index dd482d33e..ffdb4dac0 100644 --- 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 @@ -2,6 +2,7 @@ package nautilus.game.arcade.managers.voting; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -94,7 +95,7 @@ public class VotingManager extends ListenerComponent @EventHandler public void playerInteract(PlayerInteractEvent event) { - if (!isVoteInProgress()) + if (event.getAction() == Action.PHYSICAL || !isVoteInProgress()) { return; } @@ -107,7 +108,12 @@ public class VotingManager extends ListenerComponent return; } - _shop.openPageForPlayer(player, new VotingPage<>(_currentVote.getManager(), _shop, player, _currentVote)); + openVotePage(player, _currentVote); + } + + public void openVotePage(Player player, Vote vote) + { + _shop.openPageForPlayer(player, new VotingPage<>(_currentVote.getManager(), _shop, player, vote)); } @EventHandler @@ -129,7 +135,7 @@ public class VotingManager extends ListenerComponent secondary = temp; } - UtilTextBottom.display(primary + "Use " + secondary + C.Bold + "/vote" + primary + " to pick the next " + secondary + C.Bold + _currentVote.getName(), UtilServer.getPlayers()); + UtilTextBottom.display(primary + "Click the " + secondary + C.Bold + "Paper" + primary + " to pick the next " + secondary + C.Bold + _currentVote.getName(), UtilServer.getPlayers()); _colourTick = !_colourTick; } else if (event.getType() == UpdateType.SEC) 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 index 55db5287b..fb41344bc 100644 --- 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 @@ -1,6 +1,9 @@ package nautilus.game.arcade.managers.voting.types; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -18,22 +21,90 @@ import nautilus.game.arcade.managers.voting.Vote; public class GameVote extends Vote { - public GameVote(ArcadeManager manager, List values) + private final Map _mapVotes; + + private VotableMap _winningMap; + + public GameVote(ArcadeManager manager, List values, Map> gameMaps) { 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); + + if (gameMaps.isEmpty()) + { + _mapVotes = Collections.emptyMap(); + } + else + { + _mapVotes = new HashMap<>(); + + gameMaps.forEach((gameType, maps) -> + { + _mapVotes.put(gameType, new MapVote(manager, maps)); + }); + } + } + + @Override + public void vote(Player player, GameType value) + { + super.vote(player, value); + + if (_mapVotes.isEmpty()) + { + player.closeInventory(); + } + else if (value != null) + { + MapVote mapVote = _mapVotes.get(value); + + if (mapVote != null) + { + getManager().GetGameCreationManager().getVotingManager().openVotePage(player, mapVote); + } + else + { + player.closeInventory(); + } + } + } + + @Override + public GameType getWinner() + { + GameType winner = super.getWinner(); + MapVote mapVote = _mapVotes.get(winner); + + if (mapVote != null) + { + _winningMap = mapVote.getWinner(); + } + + return winner; } @Override public void onEnd() { - Bukkit.broadcastMessage(C.cGreenB + getWinner().getName() + C.cWhiteB + " won the " + getName() + " Vote!"); + String message = C.cGreenB + getWinner().getName() + C.cWhiteB; + + if (_winningMap != null) + { + message += " and map " + C.cGreenB + _winningMap.getDisplayName() + C.cWhiteB; + } + + Bukkit.broadcastMessage(message + " won the vote!"); for (Player player : UtilServer.getPlayersCollection()) { player.playSound(player.getLocation(), Sound.NOTE_PIANO, 1, 1); } } + + public VotableMap getWinningMap() + { + return _winningMap; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/types/MapVote.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/types/MapVote.java new file mode 100644 index 000000000..92a3717f6 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/types/MapVote.java @@ -0,0 +1,49 @@ +package nautilus.game.arcade.managers.voting.types; + +import java.util.List; +import java.util.stream.Collectors; + +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.managers.voting.Vote; + +public class MapVote extends Vote +{ + + public MapVote(ArcadeManager manager, List maps) + { + super(manager, "Map", new ItemBuilder(Material.PAPER) + .setTitle(C.cGreenB + "Vote for the next Map") + .addLore("", "Click to vote on the next", "map that's going to be played!") + .build(), maps.stream() + .map(VotableMap::new) + .collect(Collectors.toList())); + } + + @Override + public void vote(Player player, VotableMap value) + { + super.vote(player, value); + + player.closeInventory(); + } + + @Override + public void onEnd() + { + Bukkit.broadcastMessage(C.cGreenB + getWinner().getDisplayName() + C.cWhiteB + " won the 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/types/VotableMap.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/types/VotableMap.java new file mode 100644 index 000000000..8e67327b4 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/types/VotableMap.java @@ -0,0 +1,43 @@ +package nautilus.game.arcade.managers.voting.types; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import nautilus.game.arcade.managers.voting.Voteable; + +public class VotableMap implements Voteable +{ + + private final String _name; + private final ItemStack _itemStack; + + public VotableMap(String name) + { + _name = name; + _itemStack = new ItemStack(Material.PAPER); + } + + @Override + public String getName() + { + return _name; + } + + public String getDisplayName() + { + String[] split = getName().split("_"); + + if (split.length == 1) + { + return getName(); + } + + return split[1]; + } + + @Override + public ItemStack getItemStack() + { + return _itemStack; + } +} 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 index 64176d182..8d0ef0b14 100644 --- 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 @@ -12,6 +12,7 @@ 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; +import nautilus.game.arcade.managers.voting.types.VotableMap; public class VotingPage extends ShopPageBase { @@ -41,22 +42,32 @@ public class VotingPage extends ShopPageBase { _vote.vote(player, voteable); playAcceptSound(player); - player.sendMessage(F.main("Game", "You voted for " + F.name(voteable.getName()) + ".")); + player.sendMessage(F.main("Game", "You voted for " + F.name(fName) + ".")); }); } }