From 4e1a05e9bdb4ac72d4baf7a640fda424f74fdf98 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Sat, 26 Jul 2014 10:40:49 -0700 Subject: [PATCH] Fixed whitelist issue with tournament mode. --- .../nautilus/game/arcade/ArcadeManager.java | 217 ++++++++++-------- 1 file changed, 125 insertions(+), 92 deletions(-) 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 8d763e5e9..81c2bf03f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -19,6 +19,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Material; +import org.bukkit.OfflinePlayer; import org.bukkit.craftbukkit.v1_7_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer; import org.bukkit.entity.Player; @@ -76,11 +77,11 @@ import mineplex.core.timing.TimingManager; public class ArcadeManager extends MiniPlugin implements IRelation { - //Modules + // Modules private AntiStack _antistack; private BlockRestore _blockRestore; private Blood _blood; - private Chat _chat; + private Chat _chat; private CoreClientManager _clientManager; private DisguiseManager _disguiseManager; private DonationManager _donationManager; @@ -92,10 +93,10 @@ public class ArcadeManager extends MiniPlugin implements IRelation private FireworkHandler _firework; private ProjectileManager _projectileManager; - private Portal _portal; + private Portal _portal; private ArcadeShop _arcadeShop; - - //Managers + + // Managers private GameFactory _gameFactory; private GameCreationManager _gameCreationManager; private GameGemManager _gameGemManager; @@ -104,27 +105,30 @@ public class ArcadeManager extends MiniPlugin implements IRelation private GameStatsManager _gameStatsManager; private GameWorldManager _gameWorldManager; private ServerStatusManager _serverStatusManager; - + private StatsManager _statsManager; private ClassManager _classManager; private SkillFactory _skillFactory; private ClassShopManager _classShopManager; private ClassCombatShop _classShop; - + private EloManager _eloManager; - + private MiscManager _miscManager; - - //Observers + + // Observers private HashSet _specList = new HashSet(); - //Server Games + // Server Games private GameServerConfig _serverConfig; - - //Games + + // Games private Game _game; - public ArcadeManager(Arcade plugin, ServerStatusManager serverStatusManager, GameServerConfig serverConfig, CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager, DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, AntiStack antistack, Portal portal, PacketHandler packetHandler, PreferencesManager preferences, String webAddress) + public ArcadeManager(Arcade plugin, ServerStatusManager serverStatusManager, GameServerConfig serverConfig, + CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager, + DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, AntiStack antistack, + Portal portal, PacketHandler packetHandler, PreferencesManager preferences, String webAddress) { super("Game Manager", plugin); @@ -134,9 +138,9 @@ public class ArcadeManager extends MiniPlugin implements IRelation AntiHack.Instance.SetEnabled(false); Bukkit.getServer().setWhitelist(true); } - - //Modules - _antistack = antistack; + + // Modules + _antistack = antistack; _blockRestore = new BlockRestore(plugin); @@ -145,7 +149,9 @@ public class ArcadeManager extends MiniPlugin implements IRelation _explosionManager = new Explosion(plugin, _blockRestore); _explosionManager.SetDebris(false); - if (serverConfig.GameList.contains(GameType.ChampionsDominate) || serverConfig.GameList.contains(GameType.ChampionsTDM) || serverConfig.GameList.contains(GameType.ChampionsMOBA)) + if (serverConfig.GameList.contains(GameType.ChampionsDominate) + || serverConfig.GameList.contains(GameType.ChampionsTDM) + || serverConfig.GameList.contains(GameType.ChampionsMOBA)) { _conditionManager = new SkillConditionManager(plugin); } @@ -169,33 +175,39 @@ public class ArcadeManager extends MiniPlugin implements IRelation _firework = new FireworkHandler(); _fire = new Fire(plugin, _conditionManager, damageManager); - + _projectileManager = new ProjectileManager(plugin); - if (serverConfig.GameList.contains(GameType.ChampionsDominate) || serverConfig.GameList.contains(GameType.ChampionsTDM) || serverConfig.GameList.contains(GameType.ChampionsMOBA)) + if (serverConfig.GameList.contains(GameType.ChampionsDominate) + || serverConfig.GameList.contains(GameType.ChampionsTDM) + || serverConfig.GameList.contains(GameType.ChampionsMOBA)) { Energy energy = new Energy(plugin); - ItemFactory itemFactory = new ItemFactory(_plugin, _blockRestore, _conditionManager, damageManager, energy, _fire, _projectileManager, webAddress); - _skillFactory = new SkillFactory(plugin, damageManager, this, _damageManager.GetCombatManager(), _conditionManager, _projectileManager, _blockRestore, _fire, new Movement(plugin), teleport, energy, webAddress); - _classManager = new ClassManager(plugin, clientManager, donationManager, _skillFactory, itemFactory, webAddress); - + ItemFactory itemFactory = new ItemFactory(_plugin, _blockRestore, _conditionManager, damageManager, energy, + _fire, _projectileManager, webAddress); + _skillFactory = new SkillFactory(plugin, damageManager, this, _damageManager.GetCombatManager(), + _conditionManager, _projectileManager, _blockRestore, _fire, new Movement(plugin), teleport, + energy, webAddress); + _classManager = new ClassManager(plugin, clientManager, donationManager, _skillFactory, itemFactory, + webAddress); + _classShopManager = new ClassShopManager(_plugin, _classManager, _skillFactory, itemFactory); _classShop = new ClassCombatShop(_classShopManager, clientManager, donationManager, webAddress); - + _eloManager = new EloManager(_plugin); } - - //_statsManager = new StatsManager(plugin); - + + // _statsManager = new StatsManager(plugin); + _portal = portal; - //Shop + // Shop _arcadeShop = new ArcadeShop(this, clientManager, donationManager); - //Game Factory + // Game Factory _gameFactory = new GameFactory(this); - //Managers + // Managers new GameChatManager(this); _gameCreationManager = new GameCreationManager(this); _gameGemManager = new GameGemManager(this); @@ -208,14 +220,14 @@ public class ArcadeManager extends MiniPlugin implements IRelation _miscManager = new MiscManager(this); new IdleManager(this); - //Game Addons + // Game Addons new CompassAddon(plugin, this); new SoupAddon(plugin, this); new TeamArmorAddon(plugin, this); } @Override - public void AddCommands() + public void AddCommands() { AddCommand(new GameCommand(this)); AddCommand(new WriteCommand(this)); @@ -285,7 +297,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation { return _eloManager; } - + public Explosion GetExplosion() { return _explosionManager; @@ -320,7 +332,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation { return _arcadeShop; } - + public GameStatsManager GetStats() { return _gameStatsManager; @@ -328,7 +340,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation public GameCreationManager GetGameCreationManager() { - return _gameCreationManager; + return _gameCreationManager; } public GameFactory GetGameFactory() @@ -355,7 +367,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation { return _statsManager; } - + public ChatColor GetColor(Player player) { if (_game == null) @@ -369,7 +381,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation } @Override - public boolean CanHurt(String a, String b) + public boolean CanHurt(String a, String b) { return CanHurt(UtilPlayer.searchExact(a), UtilPlayer.searchExact(b)); } @@ -385,7 +397,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation if (!_game.DamagePvP) return false; - //Self Damage + // Self Damage if (pA.equals(pB)) return _game.DamageSelf; @@ -420,8 +432,9 @@ public class ArcadeManager extends MiniPlugin implements IRelation @EventHandler public void MessageMOTD(ServerListPingEvent event) - { - 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 (_game == null || _game.GetState() == GameState.Recruit) { @@ -459,7 +472,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation event.setQuitMessage(null); } - public Game GetGame() + public Game GetGame() { return _game; } @@ -483,9 +496,12 @@ public class ArcadeManager extends MiniPlugin implements IRelation { if (_game != null && !_game.GiveClock) return; - - player.getInventory().setItem(8, ItemStackFactory.Instance.CreateStack(Material.WATCH, (byte)0, 1, (short)0, C.cGreen + "Return to Hub", - new String[] {"", ChatColor.RESET + "Click while holding this", ChatColor.RESET + "to return to the Hub."})); + + player.getInventory().setItem( + 8, + ItemStackFactory.Instance.CreateStack(Material.WATCH, (byte) 0, 1, (short) 0, C.cGreen + + "Return to Hub", new String[] { "", ChatColor.RESET + "Click while holding this", + ChatColor.RESET + "to return to the Hub." })); } @EventHandler @@ -493,41 +509,55 @@ public class ArcadeManager extends MiniPlugin implements IRelation { if (Bukkit.getServer().hasWhitelist()) { - if (_clientManager.Get(event.getPlayer().getName()).GetRank().Has(event.getPlayer(), Rank.MODERATOR, false)) - { + if (_clientManager.Get(event.getPlayer().getName()).GetRank().Has(event.getPlayer(), Rank.MODERATOR, false)) + { event.allow(); event.setResult(PlayerLoginEvent.Result.ALLOWED); - + if (_serverConfig.Tournament) { event.getPlayer().setOp(true); } - } - else - { - event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server Whitelisted!"); - } - - return; + } + else + { + for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) + { + if (player.getName().equalsIgnoreCase(event.getPlayer().getName())) + { + event.allow(); + event.setResult(PlayerLoginEvent.Result.ALLOWED); + return; + } + } + + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server Whitelisted!"); + } + + return; } - + // Reserved Slot Check if (Bukkit.getOnlinePlayers().length >= Bukkit.getServer().getMaxPlayers()) { if (_serverStatusManager.getCurrentServerName().contains("BETA")) { - if (_clientManager.Get(event.getPlayer().getName()).GetRank().Has(event.getPlayer(), Rank.HELPER, false)) + if (_clientManager.Get(event.getPlayer().getName()).GetRank() + .Has(event.getPlayer(), Rank.HELPER, false)) { event.allow(); event.setResult(PlayerLoginEvent.Result.ALLOWED); return; } } - else if (_clientManager.Get(event.getPlayer().getName()).GetRank().Has(event.getPlayer(), Rank.ULTRA, false) || _donationManager.Get(event.getPlayer().getName()).OwnsUnknownPackage(_serverConfig.ServerType + " ULTRA")) + else if (_clientManager.Get(event.getPlayer().getName()).GetRank() + .Has(event.getPlayer(), Rank.ULTRA, false) + || _donationManager.Get(event.getPlayer().getName()).OwnsUnknownPackage( + _serverConfig.ServerType + " ULTRA")) { event.allow(); event.setResult(PlayerLoginEvent.Result.ALLOWED); - + return; } @@ -535,9 +565,9 @@ public class ArcadeManager extends MiniPlugin implements IRelation } } - public boolean IsAlive(Player player) + public boolean IsAlive(Player player) { - if (_game == null) + if (_game == null) return false; return _game.IsAlive(player); @@ -549,16 +579,16 @@ public class ArcadeManager extends MiniPlugin implements IRelation player.setAllowFlight(false); UtilInv.Clear(player); - ((CraftEntity)player).getHandle().getDataWatcher().watch(0, Byte.valueOf((byte) 0)); + ((CraftEntity) player).getHandle().getDataWatcher().watch(0, Byte.valueOf((byte) 0)); player.setSprinting(false); - + player.setFoodLevel(20); - player.setSaturation(3f); + player.setSaturation(3f); player.setExhaustion(0f); player.setMaxHealth(20); - player.setHealth(player.getMaxHealth()); + player.setHealth(player.getMaxHealth()); player.setFireTicks(0); player.setFallDistance(0); @@ -566,11 +596,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation player.setLevel(0); player.setExp(0f); - ((CraftPlayer)player).getHandle().spectating = false; - ((CraftPlayer)player).getHandle().k = true; - + ((CraftPlayer) player).getHandle().spectating = false; + ((CraftPlayer) player).getHandle().k = true; + // Arrows go bye bye. - ((CraftPlayer)player).getHandle().p(0); + ((CraftPlayer) player).getHandle().p(0); GetCondition().EndCondition(player, ConditionType.CLOAK, null); @@ -582,8 +612,10 @@ public class ArcadeManager extends MiniPlugin implements IRelation public ArrayList LoadFiles(String gameName) { TimingManager.start("ArcadeManager LoadFiles"); - File folder = new File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "maps" + File.separatorChar + gameName); - if (!folder.exists()) folder.mkdirs(); + File folder = new File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + + "maps" + File.separatorChar + gameName); + if (!folder.exists()) + folder.mkdirs(); ArrayList maps = new ArrayList(); @@ -599,19 +631,19 @@ public class ArcadeManager extends MiniPlugin implements IRelation if (name.length() < 5) continue; - name = name.substring(name.length()-4, name.length()); + name = name.substring(name.length() - 4, name.length()); if (file.getName().equals(".zip")) continue; - maps.add(file.getName().substring(0, file.getName().length()-4)); + maps.add(file.getName().substring(0, file.getName().length() - 4)); } for (String map : maps) System.out.println("Found Map: " + map); TimingManager.stop("ArcadeManager LoadFiles"); - + return maps; } @@ -657,14 +689,14 @@ public class ArcadeManager extends MiniPlugin implements IRelation if (_game == null) event.setCancelled(true); } - + @EventHandler public void MobSpawn(CreatureSpawnEvent event) { if (_game == null) event.setCancelled(true); } - + @EventHandler public void SkillTrigger(SkillTriggerEvent event) { @@ -673,7 +705,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation event.SetCancelled(true); } } - + @EventHandler public void ItemTrigger(ItemTriggerEvent event) { @@ -689,35 +721,35 @@ public class ArcadeManager extends MiniPlugin implements IRelation if (event.getMessage().equalsIgnoreCase("/spec")) { event.setCancelled(true); - + if (_game != null && _game.InProgress()) { UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot toggle Spectator during games.")); return; } - + if (!_specList.remove(event.getPlayer())) { _specList.add(event.getPlayer()); - + UtilPlayer.message(event.getPlayer(), F.main("Game", "You are now a Spectator!")); } else { UtilPlayer.message(event.getPlayer(), F.main("Game", "You are no longer a Spectator!")); } - - //Clean + + // Clean if (_game != null) { - //Remove Data + // Remove Data _game.RemoveTeamPreference(event.getPlayer()); _game.GetPlayerKits().remove(event.getPlayer()); _game.GetPlayerGems().remove(event.getPlayer()); - - //Leave Team + + // Leave Team GameTeam team = _game.GetTeam(event.getPlayer()); - + if (team != null) { team.RemovePlayer(event.getPlayer()); @@ -725,23 +757,23 @@ public class ArcadeManager extends MiniPlugin implements IRelation } } } - + @EventHandler public void ObserverQuit(PlayerQuitEvent event) { _specList.remove(event.getPlayer()); } - + public boolean IsObserver(Player player) { return _specList.contains(player); } - + public boolean IsTournamentServer() { return _serverConfig.Tournament; } - + @EventHandler public void ObserverQuit(GameStateChangeEvent event) { @@ -750,10 +782,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation _skillFactory.ResetAll(); } } - + @EventHandler public void TeleportLog(PlayerTeleportEvent event) { - System.out.println("Teleporting: " + event.getPlayer().getName() + " to " + event.getTo().getWorld().getWorldFolder().getName()); + System.out.println("Teleporting: " + event.getPlayer().getName() + " to " + + event.getTo().getWorld().getWorldFolder().getName()); } }