From 1e1fa6ce19f237bb7a4f4d44dc907c02eeef7d4c Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 7 Jul 2018 23:15:46 +0100 Subject: [PATCH] After QA testing --- .../mineplex/core/mission/MissionManager.java | 2 +- .../mission/commands/ViewMissionsCommand.java | 2 +- .../personalServer/PersonalServerManager.java | 4 +- .../nautilus/game/arcade/ArcadeManager.java | 11 +++++- .../arcade/events/PlayerStateChangeEvent.java | 38 ++++++++++--------- .../src/nautilus/game/arcade/game/Game.java | 5 ++- .../games/cakewars/shop/CakeShopModule.java | 20 ++++++++-- .../games/cakewars/shop/CakeTeamItem.java | 2 +- .../games/cakewars/team/CakeTeamModule.java | 2 +- .../games/cakewars/ui/CakeResourcePage.java | 2 +- .../cakewars/ui/CakeResourceStarPage.java | 2 +- .../game/arcade/game/team/GameTeamModule.java | 4 +- .../game/arcade/managers/GameManager.java | 13 ++++++- .../game/arcade/managers/HubClockManager.java | 30 ++++++++------- .../arcade/managers/NextBestGameManager.java | 4 +- .../arcade/managers/voting/VotingManager.java | 10 ++--- .../managers/voting/event/VoteStartEvent.java | 35 +++++++++++++++++ .../managers/voting/types/GameVote.java | 6 +++ 18 files changed, 136 insertions(+), 56 deletions(-) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/event/VoteStartEvent.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/mission/MissionManager.java b/Plugins/Mineplex.Core/src/mineplex/core/mission/MissionManager.java index fbf003eca..a7c77eb6e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/mission/MissionManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/mission/MissionManager.java @@ -357,7 +357,7 @@ public class MissionManager extends MiniDbClientPlugin private boolean canInform(int currentProgress, int amount, int requiredProgress, double requirement) { - int progressToGet = (int) (requiredProgress * requirement); + int progressToGet = (int) Math.ceil(requiredProgress * requirement); return currentProgress + amount >= progressToGet && currentProgress < progressToGet; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/mission/commands/ViewMissionsCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/mission/commands/ViewMissionsCommand.java index faaa9f0b7..79ed1cab7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/mission/commands/ViewMissionsCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/mission/commands/ViewMissionsCommand.java @@ -11,7 +11,7 @@ public class ViewMissionsCommand extends CommandBase public ViewMissionsCommand(MissionManager plugin) { - super(plugin, Perm.VIEW_MISSION_COMMAND, "missions"); + super(plugin, Perm.VIEW_MISSION_COMMAND, "missions", "mission"); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java index 2d4cbf8f9..51123be30 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java @@ -150,7 +150,7 @@ public class PersonalServerManager extends MiniPlugin } final ServerGroup serverGroup = new ServerGroup("COM-" + community.getId(), "COM-" + community.getName(), "COM-" + community.getId(), ram, cpu, 1, 0, UtilMath.random.nextInt(250) + 19999, "", true, "Lobby_MCS.zip", "Arcade.jar", "plugins/Arcade/", 15, 20, - true, false, false, community.getFavoriteGame().name(), "", "", "Community", true, false, false, true, false, false, true, false, false, false, false, false, false, true, true, true, true, false, false, "", _us ? Region.US : Region.EU, "", "", "", ""); + true, false, false, community.getFavoriteGame().name(), "", "", "Community", true, false, false, true, false, false, true, false, false, false, false, false, false, true, true, true, false, false, false, "", _us ? Region.US : Region.EU, "", "", "", ""); _repository.updateServerGroup(serverGroup); runSync(() -> @@ -183,7 +183,7 @@ public class PersonalServerManager extends MiniPlugin } final ServerGroup serverGroup = new ServerGroup(serverName, serverName, host.getName(), ram, cpu, 1, 0, UtilMath.random.nextInt(250) + 19999, "", true, "Lobby_MPS.zip", "Arcade.jar", "plugins/Arcade/", minPlayers, maxPlayers, - true, false, false, games, "", "", "Player", true, event, false, true, false, true, true, false, false, false, false, false, false, true, true, true, true, false, false, "", _us ? Region.US : Region.EU, "", "", "", ""); + true, false, false, games, "", "", "Player", true, event, false, true, false, true, true, false, false, false, false, false, false, true, true, true, false, false, false, "", _us ? Region.US : Region.EU, "", "", "", ""); getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), () -> { 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 bf2225ac4..afd933334 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -169,6 +169,7 @@ import nautilus.game.arcade.managers.chat.GameChatManager; import nautilus.game.arcade.managers.lobby.LobbyManager; import nautilus.game.arcade.managers.lobby.current.NewGameLobbyManager; import nautilus.game.arcade.managers.lobby.legacy.LegacyGameLobbyManager; +import nautilus.game.arcade.managers.voting.event.VoteStartEvent; public class ArcadeManager extends MiniPlugin implements IRelation { @@ -557,7 +558,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation scoreboard.get(ArcadeScoreboardLine.GEM_VALUE).write(donationManager.Get(scoreboard.getOwner()).getBalance(GlobalCurrency.GEM)); } - ChatColor teamColor = ChatColor.GRAY; + ChatColor teamColor = ChatColor.GOLD; String kitName = "None"; if (GetGame() != null) @@ -1654,6 +1655,14 @@ public class ArcadeManager extends MiniPlugin implements IRelation } } + @EventHandler + public void onVote(VoteStartEvent event) + { + getTitles().forceEnable(); + getCosmeticManager().setActive(true); + getCosmeticManager().setHideParticles(false); + } + @EventHandler public void disableGadget(PlayerJoinEvent event) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/events/PlayerStateChangeEvent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/events/PlayerStateChangeEvent.java index 6c6cdc906..1e15b372d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/events/PlayerStateChangeEvent.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/events/PlayerStateChangeEvent.java @@ -4,41 +4,45 @@ import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam.PlayerState; import org.bukkit.entity.Player; -import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; -public class PlayerStateChangeEvent extends Event +public class PlayerStateChangeEvent extends PlayerEvent { - private static final HandlerList handlers = new HandlerList(); - private Game _game; - private Player _player; - private PlayerState _state; + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + public static HandlerList getHandlerList() + { + return HANDLER_LIST; + } + + private final Game _game; + private final PlayerState _state; public PlayerStateChangeEvent(Game game, Player player, PlayerState state) { + super(player); + _game = game; - _player = player; _state = state; } - + + @Override public HandlerList getHandlers() { - return handlers; + return HANDLER_LIST; } - - public static HandlerList getHandlerList() - { - return handlers; - } - + public Game GetGame() { return _game; } - + + @Deprecated public Player GetPlayer() { - return _player; + return getPlayer(); } public PlayerState GetState() 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 0304155f7..a3f377063 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 @@ -1161,13 +1161,14 @@ public abstract class Game extends ListenerComponent implements Lifetimed GameTeam team = GetTeam(player); if (team == null) + { return false; + } team.SetPlayerState(player, state); // Event - PlayerStateChangeEvent playerStateEvent = new PlayerStateChangeEvent(this, player, PlayerState.OUT); - UtilServer.getServer().getPluginManager().callEvent(playerStateEvent); + UtilServer.CallEvent(new PlayerStateChangeEvent(this, player, state)); return true; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeShopModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeShopModule.java index a13a7828f..e69eb0056 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeShopModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeShopModule.java @@ -37,6 +37,7 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.newnpc.NPC; import mineplex.core.newnpc.NewNPCManager; import mineplex.core.newnpc.SimpleNPC; +import mineplex.core.newnpc.event.NPCInteractEvent; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -233,6 +234,7 @@ public class CakeShopModule extends CakeModule } Block block = event.getClickedBlock(); + Player player = event.getPlayer(); if (block == null || block.getType() != Material.BARRIER) { @@ -240,20 +242,30 @@ public class CakeShopModule extends CakeModule } event.setCancelled(true); + openShop(player, event.getAction(), block.getLocation()); + } - Location location = block.getLocation(); + // Why do we need this? 1.8 clients sometimes ignore the block, and instead say they hit the entity. + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void entityInteract(NPCInteractEvent event) + { + openShop(event.getPlayer(), event.isLeftClick() ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK, event.getNpc().getEntity().getLocation()); + } + private void openShop(Player player, Action action, Location location) + { for (Entry entry : _npcs.entrySet()) { - if (UtilMath.offset2dSquared(entry.getKey().getEntity().getLocation(), location) > 1) + Location npcLocation = entry.getKey().getEntity().getLocation(); + + if (location.getBlockX() != npcLocation.getBlockX() || location.getBlockZ() != npcLocation.getBlockZ()) { continue; } - Player player = event.getPlayer(); CakeResource resource = entry.getValue(); - if (UtilPlayer.isSpectator(player) || event.getAction() == Action.LEFT_CLICK_BLOCK && UtilItem.isSword(player.getItemInHand()) || !Recharge.Instance.use(player, "Interact Shop", 500, false, false)) + if (UtilPlayer.isSpectator(player) || (action == Action.LEFT_CLICK_BLOCK && UtilItem.isSword(player.getItemInHand())) || !Recharge.Instance.use(player, "Interact Shop", 500, false, false)) { return; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeTeamItem.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeTeamItem.java index 0f41d3916..e9d345d0a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeTeamItem.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeTeamItem.java @@ -58,7 +58,7 @@ public enum CakeTeamItem implements CakeItem new ItemStack(Material.DIAMOND_SWORD), "Gives your entire team %s.", Pair.create("Sharpness I", 8), - Pair.create("Haste II", 12) + Pair.create("Sharpness II", 12) ) { @Override diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeamModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeamModule.java index ddecfe79d..5e90b1910 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeamModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeamModule.java @@ -493,7 +493,7 @@ public class CakeTeamModule extends CakeModule CakeTeam cakeTeam = _teams.get(team); - if (!cakeTeam.canRespawn()) + if (cakeTeam == null || !cakeTeam.canRespawn()) { return; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/ui/CakeResourcePage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/ui/CakeResourcePage.java index da9a14fd4..23787673e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/ui/CakeResourcePage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/ui/CakeResourcePage.java @@ -90,7 +90,7 @@ public class CakeResourcePage extends ShopPageBase giveClock(event.GetPlayer()), GameSpectatorManager.ITEM_GIVE_DELAY); + UtilServer.getPlayersCollection().forEach(this::giveClock); } @EventHandler - public void removeOnRespawn(PlayerStateChangeEvent event) + public void giveOnDeath(PlayerStateChangeEvent event) { - // Only handle when the player is now in. - // This should make MS not have a persistent clock after round end - if (event.GetState() != PlayerState.IN || !canGiveClock()) + if (!canGiveClock()) { return; } - removeClock(event.GetPlayer()); + // Only handle when the player is now out + if (event.GetState() == PlayerState.OUT) + { + _manager.runSyncLater(() -> giveClock(event.getPlayer()), GameSpectatorManager.ITEM_GIVE_DELAY); + } + // Fix for MineStrike + else + { + removeClock(event.getPlayer()); + } } @EventHandler @@ -117,7 +119,7 @@ public class HubClockManager implements Listener Player player = event.getPlayer(); // Only allow this exact clock to be used. - if (HUB_CLOCK_ITEM.equals(player.getItemInHand())) + if (!HUB_CLOCK_ITEM.equals(player.getItemInHand())) { return; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/NextBestGameManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/NextBestGameManager.java index a9017b473..729bcc0f9 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/NextBestGameManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/NextBestGameManager.java @@ -406,8 +406,10 @@ public class NextBestGameManager implements Listener private void handle(Player player) { - if (getGame().IsAlive(player)) + if (getGame() != null && getGame().IsAlive(player)) + { return; + } Party party = _partyManager.getPartyByPlayer(player); 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 6e666f050..9cf80d8b5 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 @@ -28,6 +28,8 @@ import mineplex.core.updater.event.UpdateEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.managers.voting.command.MapRatingsCommand; +import nautilus.game.arcade.managers.voting.event.VoteStartEvent; +import nautilus.game.arcade.managers.voting.types.MapVote; import nautilus.game.arcade.managers.voting.ui.VotingPage; import nautilus.game.arcade.managers.voting.ui.VotingShop; @@ -94,6 +96,8 @@ public class VotingManager extends ListenerComponent implements Lifetimed activate(); _lifetime.start(); + + UtilServer.CallEvent(new VoteStartEvent(vote)); } @Override @@ -116,11 +120,7 @@ public class VotingManager extends ListenerComponent implements Lifetimed UtilPlayer.closeInventoryIfOpen(player); } - // false when /game set has been used during a vote - if (_manager.GetGameCreationManager().getNextGameType() == null) - { - _currentVote.onEnd(); - } + _currentVote.onEnd(); _currentVote = null; _finishedVote = null; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/event/VoteStartEvent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/event/VoteStartEvent.java new file mode 100644 index 000000000..750b2f15e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/event/VoteStartEvent.java @@ -0,0 +1,35 @@ +package nautilus.game.arcade.managers.voting.event; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import nautilus.game.arcade.managers.voting.Vote; + +public class VoteStartEvent extends Event +{ + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + public static HandlerList getHandlerList() + { + return HANDLER_LIST; + } + + private final Vote _vote; + + public VoteStartEvent(Vote vote) + { + _vote = vote; + } + + public Vote getVote() + { + return _vote; + } + + @Override + public HandlerList getHandlers() + { + return HANDLER_LIST; + } +} 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 74409c53a..90b79fdb0 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 @@ -86,6 +86,12 @@ public class GameVote extends Vote @Override public void onEnd() { + // true when /game set has been used during a vote + if (getManager().GetGameCreationManager().getNextGameType() != null) + { + return; + } + String message = C.cGreenB + getWinner().getName() + C.cWhiteB; if (_winningMapVote != null)