Allow the hub clock to exist when the game is null

This commit is contained in:
Sam 2018-07-06 17:14:30 +01:00 committed by Alexander Meech
parent 2644066dcb
commit 04dc72fa77
3 changed files with 33 additions and 49 deletions

View File

@ -161,6 +161,7 @@ import nautilus.game.arcade.managers.GameRewardManager;
import nautilus.game.arcade.managers.GameSpectatorManager; import nautilus.game.arcade.managers.GameSpectatorManager;
import nautilus.game.arcade.managers.GameStatManager; import nautilus.game.arcade.managers.GameStatManager;
import nautilus.game.arcade.managers.GameWorldManager; import nautilus.game.arcade.managers.GameWorldManager;
import nautilus.game.arcade.managers.HubClockManager;
import nautilus.game.arcade.managers.IdleManager; import nautilus.game.arcade.managers.IdleManager;
import nautilus.game.arcade.managers.NextBestGameManager; import nautilus.game.arcade.managers.NextBestGameManager;
import nautilus.game.arcade.managers.ServerUptimeManager; import nautilus.game.arcade.managers.ServerUptimeManager;
@ -615,6 +616,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_winStreakManager = require(WinStreakManager.class); _winStreakManager = require(WinStreakManager.class);
_mineplexGameManager = require(MineplexGameManager.class); _mineplexGameManager = require(MineplexGameManager.class);
if (IsHotbarHubClock())
{
new HubClockManager(this);
}
new AdminCommands(); new AdminCommands();
generatePermissions(); generatePermissions();

View File

@ -92,7 +92,6 @@ import nautilus.game.arcade.events.PlayerPrepareTeleportEvent;
import nautilus.game.arcade.events.PlayerStateChangeEvent; import nautilus.game.arcade.events.PlayerStateChangeEvent;
import nautilus.game.arcade.game.GameTeam.PlayerState; import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.modules.AntiExpOrbModule; import nautilus.game.arcade.game.modules.AntiExpOrbModule;
import nautilus.game.arcade.game.modules.HubClockModule;
import nautilus.game.arcade.game.modules.Module; import nautilus.game.arcade.game.modules.Module;
import nautilus.game.arcade.game.modules.gamesummary.GameSummaryModule; import nautilus.game.arcade.game.modules.gamesummary.GameSummaryModule;
import nautilus.game.arcade.game.team.GameTeamModule; import nautilus.game.arcade.game.team.GameTeamModule;
@ -195,7 +194,7 @@ public abstract class Game extends ListenerComponent implements Lifetimed
public boolean UseCustomScoreboard = false; public boolean UseCustomScoreboard = false;
// Loaded from Map Config // Loaded from Map Config
public WorldData WorldData = null; public WorldData WorldData;
// Game Help // Game Help
private int _helpIndex = 0; private int _helpIndex = 0;
@ -427,7 +426,6 @@ public abstract class Game extends ListenerComponent implements Lifetimed
// Scoreboard // Scoreboard
Scoreboard = new GameScoreboard(this); Scoreboard = new GameScoreboard(this);
WorldData = new WorldData(this);
// Stat Trackers // Stat Trackers
registerStatTrackers( registerStatTrackers(
@ -480,12 +478,6 @@ public abstract class Game extends ListenerComponent implements Lifetimed
_teamModule = new GameTeamModule(); _teamModule = new GameTeamModule();
_teamModule.register(this); _teamModule.register(this);
if (getArcadeManager().IsHotbarHubClock())
{
new HubClockModule()
.register(this);
}
registerDebugCommand("kit", Perm.DEBUG_COMMANDS, PermissionGroup.ADMIN, (caller, args) -> registerDebugCommand("kit", Perm.DEBUG_COMMANDS, PermissionGroup.ADMIN, (caller, args) ->
{ {
String kit = Arrays.stream(args).collect(Collectors.joining(" ")); String kit = Arrays.stream(args).collect(Collectors.joining(" "));

View File

@ -1,13 +1,11 @@
package nautilus.game.arcade.game.modules; package nautilus.game.arcade.managers;
import java.util.Arrays;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
@ -21,46 +19,37 @@ import mineplex.core.portal.GenericServer;
import mineplex.core.portal.Intent; import mineplex.core.portal.Intent;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerStateChangeEvent; import nautilus.game.arcade.events.PlayerStateChangeEvent;
import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.managers.GameSpectatorManager;
public class HubClockModule extends Module public class HubClockManager implements Listener
{ {
private static final int HUB_CLOCK_SLOT = 8; private static final int HUB_CLOCK_SLOT = 8;
private static final ItemStack HUB_CLOCK_ITEM = ItemStackFactory.Instance.CreateStack(Material.WATCH, (byte) 0, 1, (short) 0, private static final ItemStack HUB_CLOCK_ITEM = ItemStackFactory.Instance.CreateStack(Material.WATCH, (byte) 0, 1, (short) 0,
C.cGreen + "Return to Hub", C.cGreen + "Return to Hub",
new String[]{"", ChatColor.RESET + "Click while holding this", ChatColor.RESET + "to return to the Hub."}); new String[]{"", ChatColor.RESET + "Click while holding this", ChatColor.RESET + "to return to the Hub."});
public HubClockModule() private final ArcadeManager _manager;
{
Player[] players = UtilServer.getPlayers();
if (players.length > 0) public HubClockManager(ArcadeManager manager)
{ {
Arrays.stream(players).forEach(this::giveClock); _manager = manager;
}
UtilServer.getPlayersCollection().forEach(this::giveClock);
manager.registerEvents(this);
} }
public void giveClock(Player player) public void giveClock(Player player)
{ {
if (getGame() != null && !getGame().GiveClock)
{
return;
}
player.getInventory().setItem(HUB_CLOCK_SLOT, HUB_CLOCK_ITEM); player.getInventory().setItem(HUB_CLOCK_SLOT, HUB_CLOCK_ITEM);
} }
public void removeClock(Player player) public void removeClock(Player player)
{ {
if (!player.getInventory().getItem(HUB_CLOCK_SLOT).equals(HUB_CLOCK_ITEM))
{
return;
}
player.getInventory().remove(HUB_CLOCK_ITEM); player.getInventory().remove(HUB_CLOCK_ITEM);
} }
@ -73,24 +62,24 @@ public class HubClockModule extends Module
@EventHandler @EventHandler
public void giveOnNextLobby(GameStateChangeEvent event) public void giveOnNextLobby(GameStateChangeEvent event)
{ {
if (event.GetState() != Game.GameState.Recruit) if (event.GetState() != GameState.Recruit || !canGiveClock())
{ {
return; return;
} }
Arrays.stream(UtilServer.getPlayers()).forEach(this::giveClock); UtilServer.getPlayersCollection().forEach(this::giveClock);
} }
@EventHandler @EventHandler
public void giveOnDeath(PlayerStateChangeEvent event) public void giveOnDeath(PlayerStateChangeEvent event)
{ {
// Only handle when the player is now out // Only handle when the player is now out
if (event.GetState() != GameTeam.PlayerState.OUT) if (event.GetState() != PlayerState.OUT || !canGiveClock())
{ {
return; return;
} }
getGame().getArcadeManager().runSyncLater(() -> giveClock(event.GetPlayer()), GameSpectatorManager.ITEM_GIVE_DELAY); _manager.runSyncLater(() -> giveClock(event.GetPlayer()), GameSpectatorManager.ITEM_GIVE_DELAY);
} }
@EventHandler @EventHandler
@ -98,7 +87,7 @@ public class HubClockModule extends Module
{ {
// Only handle when the player is now in. // Only handle when the player is now in.
// This should make MS not have a persistent clock after round end // This should make MS not have a persistent clock after round end
if (event.GetState() != GameTeam.PlayerState.IN) if (event.GetState() != PlayerState.IN || !canGiveClock())
{ {
return; return;
} }
@ -127,13 +116,8 @@ public class HubClockModule extends Module
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.getItemInHand() == null)
{
return;
}
// Only allow this exact clock to be used. // Only allow this exact clock to be used.
if (!player.getItemInHand().equals(HUB_CLOCK_ITEM)) if (HUB_CLOCK_ITEM.equals(player.getItemInHand()))
{ {
return; return;
} }
@ -145,9 +129,11 @@ public class HubClockModule extends Module
} }
// Send to server // Send to server
getGame() _manager.GetPortal().sendPlayerToGenericServer(event.getPlayer(), GenericServer.HUB, Intent.PLAYER_REQUEST);
.getArcadeManager() }
.GetPortal()
.sendPlayerToGenericServer(event.getPlayer(), GenericServer.HUB, Intent.PLAYER_REQUEST); private boolean canGiveClock()
{
return _manager.GetGame() == null || _manager.GetGame().GetState() == GameState.Recruit || _manager.GetGame().GiveClock;
} }
} }