package nautilus.game.arcade.managers; import java.util.HashSet; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilGear; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.game.Game.GameState; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; public class GameHostManager implements Listener { ArcadeManager Manager; private Player _host; private long _serverStartTime = System.currentTimeMillis(); private long _serverExpireTime = 43200000; private long _lastOnline = System.currentTimeMillis(); private long _expireTime = 300000; private HashSet _whitelist = new HashSet(); private HashSet _blacklist = new HashSet(); public GameHostManager(ArcadeManager manager) { Manager = manager; Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin()); } /* @EventHandler public void updateHost(UpdateEvent event) { if (event.getType() != UpdateType.FAST) return; //No Host - Not MPS if (Manager.GetHost() == null || Manager.GetHost().length() == 0) return; //Host Update if (_host != null) { giveHostItem(); _lastOnline = System.currentTimeMillis(); } } @EventHandler public void hostJoin(PlayerJoinEvent event) { if (Manager.GetHost() == null || Manager.GetHost().length() == 0) return; if (Manager.GetHost().equals(event.getPlayer().getName())) { System.out.println("Game Host Joined."); _host = event.getPlayer(); } } @EventHandler public void hostQuit(PlayerQuitEvent event) { if (Manager.GetHost() == null || Manager.GetHost().length() == 0) return; if (Manager.GetHost().equals(event.getPlayer().getName())) { System.out.println("Game Host Quit."); _host = null; } } public boolean isHostExpired() { if (Manager.GetHost() == null || Manager.GetHost().length() == 0) return false; return UtilTime.elapsed(_lastOnline, _expireTime) || UtilTime.elapsed(_serverStartTime, _serverExpireTime); } private void giveHostItem() { if (Manager.GetGame() == null) return; if (_host == null) return; if (UtilGear.isMat(_host.getInventory().getItem(5), Material.BOOK_AND_QUILL)) return; _host.getInventory().setItem(5, ItemStackFactory.Instance.CreateStack(Material.BOOK_AND_QUILL, (byte)0, 1, C.cGreen + C.Bold + "/menu")); } public HashSet getWhitelist() { return _whitelist; } public HashSet getBlacklist() { return _blacklist; } @EventHandler public void menuCommand(PlayerCommandPreprocessEvent event) { if (_host == null || !event.getPlayer().equals(_host)) return; if (!event.getMessage().toLowerCase().startsWith("/menu")) return; openMenu(); } @EventHandler public void menuInteract(PlayerInteractEvent event) { if (_host == null || !event.getPlayer().equals(_host)) return; if (!UtilGear.isMat(_host.getItemInHand(), Material.BOOK_AND_QUILL)) return; openMenu(); } private void openMenu() { if (_host == null) return; //XXX OPEN GUI HERE } @EventHandler public void whitelistCommand(PlayerCommandPreprocessEvent event) { if (_host == null || !event.getPlayer().equals(_host)) return; if (!event.getMessage().toLowerCase().startsWith("/whitelist ")) return; String[] args = event.getMessage().split(" "); for (int i=1 ; i