From 978254c16cc6ee6e15ca91aee84fd71d90985587 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Wed, 18 Sep 2013 05:16:29 -0700 Subject: [PATCH] Fixed dominate start issues. Fixed issue with server status manager and config for server tracker. Changed minekart mob name. Updated Minekart with new server status stuff. Updated Dominate with new server status stuff. --- .../src/mineplex/bungee/Mineplexer.java | 79 ++++++- .../bungee/dynamicServer/DynamicServer.java | 89 ------- .../bungee/lobbyBalancer/LobbyBalancer.java | 186 ++------------- .../src/mineplex/bungee/updater/Updater.java | 193 ---------------- .../core/status/ServerStatusManager.java | 3 + .../src/mineplex/hub/HubManager.java | 2 +- .../src/nautilus/game/core/GamePlugin.java | 3 + .../nautilus/game/core/engine/GameEngine.java | 3 +- .../game/core/engine/TeamGameEngine.java | 50 ++-- .../src/nautilus/game/core/game/Game.java | 70 ++++-- .../dominate/engine/DominateGameEngine.java | 2 +- .../src/nautilus/game/minekart/MineKart.java | 217 ++---------------- .../nautilus/game/minekart/gp/GPResult.java | 8 +- 13 files changed, 179 insertions(+), 726 deletions(-) delete mode 100644 Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/dynamicServer/DynamicServer.java delete mode 100644 Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/updater/Updater.java diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/Mineplexer.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/Mineplexer.java index 422cb0740..5b1f3cd03 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/Mineplexer.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/Mineplexer.java @@ -1,31 +1,90 @@ package mineplex.bungee; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Socket; + import mineplex.bungee.bungeeSigns.BungeeSigns; -import mineplex.bungee.dynamicServer.DynamicServer; +import mineplex.bungee.globalServer.GlobalServer; import mineplex.bungee.lobbyBalancer.LobbyBalancer; import mineplex.bungee.playerCount.PlayerCount; -import mineplex.bungee.updater.Updater; import net.md_5.bungee.api.plugin.Plugin; public class Mineplexer extends Plugin { - private DynamicServer _dynamicServers; + private GlobalServer _dynamicServers; private LobbyBalancer _lobbyBalancer; @Override public void onEnable() { new BungeeSigns(this); - new Updater(this); - _dynamicServers = new DynamicServer(this); + //_dynamicServers = new GlobalServer(this); _lobbyBalancer = new LobbyBalancer(this); new PlayerCount(this); + + /* + Socket socket = null; + DataInputStream dataInputStream = null; + DataOutputStream dataOutputStream = null; + + + try + { + socket = new Socket(); + socket.setSoTimeout(3000); + socket.setTcpNoDelay(true); + socket.setTrafficClass(18); + socket.connect(new InetSocketAddress("192.95.30.130", 4444)); + dataInputStream = new DataInputStream(socket.getInputStream()); + dataOutputStream = new DataOutputStream(socket.getOutputStream()); + + dataOutputStream.writeShort(71); + writeString("defek7", dataOutputStream); + + dataInputStream.read(); + System.out.println(dataInputStream.readByte()); + System.out.println(readString(dataInputStream, 16)); + System.out.println(readString(dataInputStream, 24)); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + */ } - public void ReloadServerLists() - { - _dynamicServers.LoadServers(); - _lobbyBalancer.loadLobbyServers(); - } + protected String readString(DataInputStream dataInputStream, int maxLength) throws IOException + { + short length = dataInputStream.readShort(); + + if (length > maxLength) + { + throw new IOException("Received string length longer than maximum allowed (" + length + " > " + maxLength + ")"); + } + else if (length < 0) + { + throw new IOException("Received string length is less than zero! Weird string!"); + } + else + { + StringBuilder stringBuilder = new StringBuilder(); + + for (int i = 0; i < length; i++) + { + stringBuilder.append(dataInputStream.readChar()); + } + + return stringBuilder.toString(); + } + } + + protected void writeString(String string, DataOutputStream dataOutputStream) throws IOException + { + dataOutputStream.writeShort(string.length()); + dataOutputStream.writeChars(string); + } } diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/dynamicServer/DynamicServer.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/dynamicServer/DynamicServer.java deleted file mode 100644 index 6263418e8..000000000 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/dynamicServer/DynamicServer.java +++ /dev/null @@ -1,89 +0,0 @@ -package mineplex.bungee.dynamicServer; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.InetSocketAddress; - -import net.md_5.bungee.api.plugin.Listener; -import net.md_5.bungee.api.plugin.Plugin; - -public class DynamicServer implements Listener -{ - private Plugin _plugin; - - public DynamicServer(Plugin plugin) - { - _plugin = plugin; - - LoadServers(); - - _plugin.getProxy().getPluginManager().registerListener(_plugin, this); - } - - public void LoadServers() - { - FileInputStream fstream = null; - BufferedReader br = null; - - try - { - File npcFile = new File("servers.dat"); - - if (npcFile.exists()) - { - fstream = new FileInputStream(npcFile); - br = new BufferedReader(new InputStreamReader(fstream)); - - String line = br.readLine(); - - while (line != null) - { - String name = line.split(",")[0]; - String address = line.split(",")[1].split(":")[0]; - Integer port = Integer.parseInt(line.split(",")[1].split(":")[1]); - InetSocketAddress socketAddress = new InetSocketAddress(address, port); - - _plugin.getProxy().getServers().put(name, _plugin.getProxy().constructServerInfo(name, socketAddress, "DynamicServer", false)); - line = br.readLine(); - } - } - else - { - npcFile.createNewFile(); - } - } - catch (Exception e) - { - System.out.println("Error parsing servers file."); - } - finally - { - if (br != null) - { - try - { - br.close(); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - - if (fstream != null) - { - try - { - fstream.close(); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - } - } -} diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java index 5ba8a066c..263ac82e5 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java @@ -1,14 +1,6 @@ package mineplex.bungee.lobbyBalancer; -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.DataOutput; -import java.io.DataOutputStream; -import java.io.IOException; -import java.net.ConnectException; import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketTimeoutException; import java.util.HashMap; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; @@ -21,6 +13,7 @@ import net.md_5.bungee.event.EventHandler; public class LobbyBalancer implements Listener, Runnable { private Plugin _plugin; + private LobbyBalancerRepository _repository; private HashMap _lobbyServers = new HashMap(); private String _bestServer = "Lobby"; @@ -30,11 +23,13 @@ public class LobbyBalancer implements Listener, Runnable public LobbyBalancer(Plugin plugin) { _plugin = plugin; + _repository = new LobbyBalancerRepository(); + _repository.initialize(); loadLobbyServers(); _plugin.getProxy().getPluginManager().registerListener(_plugin, this); - _plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.SECONDS); + _plugin.getProxy().getScheduler().schedule(_plugin, this, 4L, 4L, TimeUnit.SECONDS); } @EventHandler @@ -48,20 +43,10 @@ public class LobbyBalancer implements Listener, Runnable public void run() { + loadLobbyServers(); + synchronized (_serverLock) { - for (String name : _lobbyServers.keySet()) - { - try - { - UpdateServerCount(name); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - String bestServer = null; Entry leastPlayerServer = null; @@ -84,7 +69,7 @@ public class LobbyBalancer implements Listener, Runnable } } - if (_lobbyServers.get(bestServer) > 80) + if (_lobbyServers.containsKey(bestServer) && _lobbyServers.get(bestServer) > 80) { bestServer = leastPlayerServer.getKey(); } @@ -93,163 +78,18 @@ public class LobbyBalancer implements Listener, Runnable } } - protected void UpdateServerCount(String name) throws IOException - { - InetSocketAddress address = _plugin.getProxy().getServerInfo(name).getAddress(); - - Socket socket = null; - DataInputStream dataInputStream = null; - DataOutputStream dataOutputStream = null; - - try - { - socket = new Socket(); - socket.setSoTimeout(3000); - socket.setTcpNoDelay(true); - socket.setTrafficClass(18); - socket.connect(address, 3000); - dataInputStream = new DataInputStream(socket.getInputStream()); - dataOutputStream = new DataOutputStream(socket.getOutputStream()); - - dataOutputStream.writeByte(254); - dataOutputStream.writeByte(1); - dataOutputStream.writeByte(254); - writeString("MC|PingHost", dataOutputStream); - dataOutputStream.writeShort(3 + 2 * address.getAddress().getHostName().length() + 4); - dataOutputStream.writeByte(73); - writeString(address.getAddress().getHostName(), dataOutputStream); - dataOutputStream.writeInt(address.getPort()); - - if (dataInputStream.read() != 255) - { - System.out.println("not 255"); - return; - } - - String var6 = readString(dataInputStream, 256); - - String[] var27; - - if (var6.startsWith("\u00a7") && var6.length() > 1) - { - var27 = var6.substring(1).split("\u0000"); - - synchronized (_serverLock) - { - if (var27[3].contains("Restarting")) - _lobbyServers.put(name, 999); - else - _lobbyServers.put(name, Integer.parseInt(var27[4])); - } - } - } - catch (SocketTimeoutException e) - { - synchronized (_serverLock) - { - _lobbyServers.put(name, 999); - } - } - catch (ConnectException e) - { - synchronized (_serverLock) - { - _lobbyServers.put(name, 999); - } - } - catch (IOException e) - { - System.out.println("[LobbyBalancer IOException] Error pinging " + address.getHostString() + ":" + address.getPort()); - synchronized (_serverLock) - { - _lobbyServers.put(name, 999); - } - throw e; - } - finally - { - try - { - if (dataInputStream != null) - { - dataInputStream.close(); - } - } - catch (Exception exception) - { - ; - } - - try - { - if (dataOutputStream != null) - { - dataOutputStream.close(); - } - } - catch (Exception exception) - { - ; - } - - try - { - if (socket != null) - { - socket.close(); - } - } - catch (Exception exception) - { - ; - } - } - } - - public static void writeString(String par0Str, DataOutput par1DataOutput) throws IOException - { - if (par0Str.length() > 32767) - { - throw new IOException("String too big"); - } - else - { - par1DataOutput.writeShort(par0Str.length()); - par1DataOutput.writeChars(par0Str); - } - } - - public static String readString(DataInput par0DataInput, int par1) throws IOException - { - short var2 = par0DataInput.readShort(); - - if (var2 > par1) - { - throw new IOException("Received string length longer than maximum allowed (" + var2 + " > " + par1 + ")"); - } - else if (var2 < 0) - { - throw new IOException("Received string length is less than zero! Weird string!"); - } - else - { - StringBuilder var3 = new StringBuilder(); - - for (int var4 = 0; var4 < var2; ++var4) - { - var3.append(par0DataInput.readChar()); - } - - return var3.toString(); - } - } - public void loadLobbyServers() { synchronized (_serverLock) { _lobbyServers.clear(); + for (ServerStatusData serverStatusData : _repository.retrieveServerStatuses()) + { + InetSocketAddress socketAddress = new InetSocketAddress(serverStatusData.Address, serverStatusData.Port); + _plugin.getProxy().getServers().put(serverStatusData.Name, _plugin.getProxy().constructServerInfo(serverStatusData.Name, socketAddress, "DynamicServer", false)); + } + for (String key : _plugin.getProxy().getServers().keySet()) { if (key.toUpperCase().contains("LOBBY")) diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/updater/Updater.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/updater/Updater.java deleted file mode 100644 index f837c7bd3..000000000 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/updater/Updater.java +++ /dev/null @@ -1,193 +0,0 @@ -package mineplex.bungee.updater; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FilenameFilter; -import java.io.IOException; -import java.util.HashMap; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.io.FileUtils; - -import mineplex.bungee.Mineplexer; - -public class Updater implements Runnable -{ - private Mineplexer _plugin; - private HashMap _jarMd5Map = new HashMap(); - private File _updateDirectory; - - private boolean _enabled = true; - private boolean _needUpdate = false; - - public Updater(Mineplexer plugin) - { - _plugin = plugin; - _jarMd5Map = new HashMap(); - - getCurrentMd5s(); - - boolean windows = System.getProperty("os.name").startsWith("Windows"); - - _updateDirectory = new File((windows ? "C:" : File.separator + "home" + File.separator + "mineplex") + File.separator + "update" + File.separator + "bungee"); - - _updateDirectory.mkdirs(); - - if (new File("IgnoreUpdates.dat").exists()) - _enabled = false; - - if (_enabled) - _plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.SECONDS); - } - - private void getCurrentMd5s() - { - File currentDir = new File("."); - - FilenameFilter statsFilter = new FilenameFilter() - { - public boolean accept(File paramFile, String paramString) - { - if (paramString.endsWith("dat")) - { - return true; - } - - return false; - } - }; - - for (File f : currentDir.listFiles(statsFilter)) - { - FileInputStream fis = null; - - try - { - fis = new FileInputStream(f); - _jarMd5Map.put(f.getName(), DigestUtils.md5Hex(fis)); - } - catch (Exception ex) - { - System.out.println("Updater: Error parsing dat md5's"); - ex.printStackTrace(); - } - finally - { - if (fis != null) - { - try - { - fis.close(); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - } - } - } - - @Override - public void run() - { - FilenameFilter statsFilter = new FilenameFilter() - { - public boolean accept(File paramFile, String paramString) - { - if (paramString.endsWith("dat")) - { - return true; - } - - return false; - } - }; - - for (File f : _updateDirectory.listFiles(statsFilter)) - { - FileInputStream fis = null; - - try - { - if (_jarMd5Map.containsKey(f.getName())) - { - fis = new FileInputStream(f); - String md5 = DigestUtils.md5Hex(fis); - - if (!md5.equals(_jarMd5Map.get(f.getName()))) - { - _needUpdate = true; - } - } - } - catch (Exception ex) - { - System.out.println("Updater: Error parsing dat md5's"); - ex.printStackTrace(); - } - finally - { - if (fis != null) - { - try - { - fis.close(); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - } - } - - if (_needUpdate) - { - updateFiles(); - } - } - - private void updateFiles() - { - _needUpdate = false; - - boolean windows = System.getProperty("os.name").startsWith("Windows"); - - File updateDir = new File((windows ? "C:" : File.separator + "home" + File.separator + "mineplex") + File.separator + "update" + File.separator + "bungee"); - File currentDir = new File("."); - - updateDir.mkdirs(); - - FilenameFilter statsFilter = new FilenameFilter() - { - public boolean accept(File paramFile, String paramString) - { - if (paramString.endsWith("dat")) - { - return true; - } - - return false; - } - }; - - for (File f : updateDir.listFiles(statsFilter)) - { - try - { - FileUtils.copyFileToDirectory(f, currentDir); - } - catch (Exception ex) - { - System.out.println("Updater: Error updating dats"); - ex.printStackTrace(); - } - } - - getCurrentMd5s(); - _plugin.ReloadServerLists(); - System.out.println("Updater: Updated with new dat files."); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java index 3124e34c3..a865464e6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java @@ -52,6 +52,9 @@ public class ServerStatusManager extends MiniPlugin FileConfiguration yamlConfig = new YamlConfiguration(); File serverTrackerConfig = new File("plugins/ServerTracker/config.yml"); + if (!serverTrackerConfig.exists()) + return; + try { yamlConfig.load(serverTrackerConfig); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 98911bd0c..89839b507 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -232,7 +232,7 @@ public class HubManager extends MiniClientPlugin { if (((LivingEntity)entity).getCustomName().equalsIgnoreCase("play minekart plz")) { - _disguiseManager.disguise(new DisguisePlayer(entity, "Play " + ChatColor.YELLOW + "MineKart")); + _disguiseManager.disguise(new DisguisePlayer(entity, ChatColor.YELLOW + "MineKart")); } else if (((LivingEntity)entity).getCustomName().equalsIgnoreCase("defek7")) _disguiseManager.disguise(new DisguisePlayer(entity, "defek7")); diff --git a/Plugins/Nautilus.Game.Core/src/nautilus/game/core/GamePlugin.java b/Plugins/Nautilus.Game.Core/src/nautilus/game/core/GamePlugin.java index b7a625294..6f0b38ffc 100644 --- a/Plugins/Nautilus.Game.Core/src/nautilus/game/core/GamePlugin.java +++ b/Plugins/Nautilus.Game.Core/src/nautilus/game/core/GamePlugin.java @@ -16,6 +16,7 @@ import me.chiss.Core.MemoryFix.MemoryFix; import me.chiss.Core.Module.ModuleManager; import me.chiss.Core.Modules.*; import mineplex.core.message.MessageManager; +import mineplex.core.monitor.LagMeter; import mineplex.core.movement.Movement; import mineplex.core.npc.NpcManager; import mineplex.core.packethandler.PacketHandler; @@ -27,6 +28,7 @@ import mineplex.core.server.Server; import mineplex.core.server.ServerListener; import mineplex.core.server.ServerTalker; import mineplex.core.spawn.Spawn; +import mineplex.core.status.ServerStatusManager; import mineplex.core.teleport.Teleport; import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; @@ -111,6 +113,7 @@ public abstract class GamePlugin extends JavaPlugin implements IRelation _damage = new DamageManager(this, CombatManager, NpcManager, new DisguiseManager(this, PacketHandler)); _fire = new Fire(this, ConditionManager, _damage); new Punish(this, GetWebServerAddress()); + new ServerStatusManager(this, new LagMeter(this, ClientManager)); SkillManager = new SkillFactory(this, _damage, this, CombatManager, ConditionManager, _throw, _blockRestore, _fire, new Movement(this), _teleport, Energy, GetWebServerAddress()); diff --git a/Plugins/Nautilus.Game.Core/src/nautilus/game/core/engine/GameEngine.java b/Plugins/Nautilus.Game.Core/src/nautilus/game/core/engine/GameEngine.java index 11571b3a3..49af01c7a 100644 --- a/Plugins/Nautilus.Game.Core/src/nautilus/game/core/engine/GameEngine.java +++ b/Plugins/Nautilus.Game.Core/src/nautilus/game/core/engine/GameEngine.java @@ -93,7 +93,7 @@ import net.minecraft.server.v1_6_R2.NBTTagCompound; import net.minecraft.server.v1_6_R2.NBTTagList; import net.minecraft.server.v1_6_R2.NBTTagString; -public abstract class GameEngine, ScoreHandlerType extends IScoreHandler, ArenaType extends IArena, PlayerType extends IGamePlayer> implements IGameEngine, Listener, Runnable, IRelation +public abstract class GameEngine, ScoreHandlerType extends IScoreHandler, ArenaType extends IArena, PlayerType extends IGamePlayer> implements IGameEngine, Listener, IRelation { protected int MaxGames = -1; @@ -161,7 +161,6 @@ public abstract class GameEngine, Portal = new mineplex.core.portal.Portal(plugin); Plugin.getServer().getPluginManager().registerEvents(this, Plugin); - Plugin.getServer().getScheduler().scheduleSyncRepeatingTask(Plugin, this, 0L, 1200L); StartBook = CraftItemStack.asNewCraftStack(Item.WRITTEN_BOOK); NBTTagCompound bookData = StartBook.getHandle().tag; diff --git a/Plugins/Nautilus.Game.Core/src/nautilus/game/core/engine/TeamGameEngine.java b/Plugins/Nautilus.Game.Core/src/nautilus/game/core/engine/TeamGameEngine.java index 501e32daa..3e1a4a24a 100644 --- a/Plugins/Nautilus.Game.Core/src/nautilus/game/core/engine/TeamGameEngine.java +++ b/Plugins/Nautilus.Game.Core/src/nautilus/game/core/engine/TeamGameEngine.java @@ -188,9 +188,12 @@ public abstract class TeamGameEngine 0) { GameType game = Scheduler.GetGames().get(Scheduler.GetGames().size() - 1); @@ -198,34 +201,21 @@ public abstract class TeamGameEngine= MinQueuePlayersToStart) { - if (game.GetPlayers().size() % 2 != 0) - { - if (BroadcastQueueJoinMessage ) - { - for (Player gameplayer : game.GetBlueTeam().GetPlayers().get(0).GetPlayer().getWorld().getPlayers()) - { - gameplayer.sendMessage(F.main("Play Queue", "Waiting for teams to be even before start timer resumes.")); - } - } - } - else - { - _gameQueueTickValue++; - - if (_gameQueueTickValue > TimeToStart) - { - TeamSize = players/2; - TryToActivateGames(); - } - else if (BroadcastQueueJoinMessage) - { - for (Player gameplayer : game.GetBlueTeam().GetPlayers().get(0).GetPlayer().getWorld().getPlayers()) - { - String minuteMessage = (3 - _gameQueueTickValue) == 1 ? "minute" : "minutes"; - gameplayer.sendMessage(F.main("Play Queue", "Game will start in " + (3 - _gameQueueTickValue) + " " + minuteMessage + "!")); - } - } - } + _gameQueueTickValue++; + + if (_gameQueueTickValue > TimeToStart) + { + TeamSize = players/2; + TryToActivateGames(); + } + else if (BroadcastQueueJoinMessage) + { + for (Player gameplayer : game.GetBlueTeam().GetPlayers().get(0).GetPlayer().getWorld().getPlayers()) + { + String minuteMessage = (3 - _gameQueueTickValue) == 1 ? "minute" : "minutes"; + gameplayer.sendMessage(F.main("Play Queue", "Game will start in " + (3 - _gameQueueTickValue) + " " + minuteMessage + "!")); + } + } } } } diff --git a/Plugins/Nautilus.Game.Core/src/nautilus/game/core/game/Game.java b/Plugins/Nautilus.Game.Core/src/nautilus/game/core/game/Game.java index cdf97dda6..5b82aad83 100644 --- a/Plugins/Nautilus.Game.Core/src/nautilus/game/core/game/Game.java +++ b/Plugins/Nautilus.Game.Core/src/nautilus/game/core/game/Game.java @@ -1,7 +1,5 @@ package nautilus.game.core.game; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -15,6 +13,7 @@ import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; @@ -23,6 +22,8 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.util.Vector; import mineplex.core.energy.Energy; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.classcombat.Class.ClassManager; import mineplex.minecraft.game.classcombat.Class.ClientClass; import mineplex.minecraft.game.classcombat.Skill.ISkill; @@ -31,7 +32,6 @@ import mineplex.minecraft.game.core.condition.Condition.ConditionType; import nautilus.game.core.arena.IArena; import nautilus.game.core.notifier.PlayerNotifier; import nautilus.game.core.player.IGamePlayer; -import nautilus.game.core.util.BroadcastSecondTimer; import nautilus.minecraft.core.utils.GenericRunnable; public abstract class Game implements IGame, Listener, Runnable @@ -48,11 +48,13 @@ public abstract class Game PlayerTaskIdMap; protected int UpdaterTaskId; + protected PlayerNotifier, ArenaType, PlayerType> Notifier; + + private int _countDown; public Game(JavaPlugin plugin, ClassManager classManager, ConditionManager conditionManager, Energy energy) { @@ -301,26 +303,50 @@ public abstract class Game, ArenaType, PlayerType>(Plugin, "Dominate"), this, 30, "Game starting", "Game starting...", new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - try - { - ReallyStartGame(); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - }); - - StartTimer.Start(); + Notifier = new PlayerNotifier, ArenaType, PlayerType>(Plugin, "Dominate"); + _countDown = 30; CountdownRunning = true; } + @EventHandler + public void updateStartTimer(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + return; + + if (!CountdownRunning) + return; + + if (_countDown == 0) + { + ReallyStartGame(); + CountdownRunning = false; + } + else if (_countDown == 1) + { + Notifier.BroadcastMessageToPlayers("Game starting in 1 second.", GetPlayers()); + } + else if (_countDown < 11) + { + Notifier.BroadcastMessageToPlayers("Game starting in " + _countDown + " seconds.", GetPlayers()); + } + else if (_countDown == 15) + { + Notifier.BroadcastMessageToPlayers("Game starting in " + _countDown + " seconds.", GetPlayers()); + } + else if (_countDown == 30) + { + Notifier.BroadcastMessageToPlayers("Game starting in " + _countDown + " seconds.", GetPlayers()); + } + else if (_countDown == 45) + { + Notifier.BroadcastMessageToPlayers("Game starting in " + _countDown + " seconds.", GetPlayers()); + } + + _countDown--; + } + public boolean IsActive() { return CountdownRunning || HasStarted; @@ -357,13 +383,9 @@ public abstract class Game 0 && sortedScores.size() > 0) { _first = sortedScores.get(0); - manager.RewardGems(_first.GetDriver().getName(), 8 * _gp.GetPlayers().size() + buffer); + manager.RewardGems(null, _first.GetDriver().getName(), 8 * _gp.GetPlayers().size() + buffer); } buffer += 2; @@ -70,7 +70,7 @@ public class GPResult if (_gp.GetTrack().GetPositions().size() > 1 && sortedScores.size() > 1) { _second = sortedScores.get(1); - manager.RewardGems(_second.GetDriver().getName(), 5 * _gp.GetPlayers().size() + buffer); + manager.RewardGems(null, _second.GetDriver().getName(), 5 * _gp.GetPlayers().size() + buffer); } buffer += 2; @@ -78,14 +78,14 @@ public class GPResult if (_gp.GetTrack().GetPositions().size() > 2 && sortedScores.size() > 2) { _third = sortedScores.get(2); - manager.RewardGems(_third.GetDriver().getName(), 2 * _gp.GetPlayers().size() + buffer); + manager.RewardGems(null, _third.GetDriver().getName(), 2 * _gp.GetPlayers().size() + buffer); } buffer += 2; for (int i = 3; i < sortedScores.size(); i++) { - manager.RewardGems(sortedScores.get(i).GetDriver().getName(), buffer); + manager.RewardGems(null, sortedScores.get(i).GetDriver().getName(), buffer); } _fireworkLocations = new ArrayList(5);