Added in dynamic servermanager updating.
Added updating of bungeeServers/servers list. Combined all bungee plugins to Mineplexer Fixed arcade bug on player quit. Fixed ServersUI page errors.
This commit is contained in:
parent
0d98868a1f
commit
d6bd962768
@ -251,5 +251,19 @@
|
|||||||
<copy file="../bin/craftbukkit.jar" todir="../Libraries/"/>
|
<copy file="../bin/craftbukkit.jar" todir="../Libraries/"/>
|
||||||
<delete dir="../bin/craftbukkit_temp" />
|
<delete dir="../bin/craftbukkit_temp" />
|
||||||
</target>
|
</target>
|
||||||
|
<target name ="Mineplexer" description="Mineplexer">
|
||||||
|
<jar jarfile="../bin/Mineplexer.jar">
|
||||||
|
<fileset dir="../Mineplex.Bungee.Mineplexer/bin">
|
||||||
|
<include name="**/*.class"/>
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<fileset dir="../Mineplex.Bungee.Mineplexer">
|
||||||
|
<include name="*.yml"/>
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<zipfileset src="../Libraries/commons-codec-1.6.jar" />
|
||||||
|
<zipfileset src="../Libraries/commons-io-2.4.jar" />
|
||||||
|
</jar>
|
||||||
|
<copy file="../bin/Mineplexer.jar" todir="../../Testing/Proxy/plugins"/>
|
||||||
|
</target>
|
||||||
</project>
|
</project>
|
@ -1,4 +0,0 @@
|
|||||||
name: DynamicServer
|
|
||||||
main: mineplex.bungee.dynamicServer.DynamicServer
|
|
||||||
version: 1
|
|
||||||
author: defek7
|
|
@ -1,24 +0,0 @@
|
|||||||
package mineplex.bungee.dynamicServer;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
|
||||||
|
|
||||||
public class ReloadServerListCommand extends Command
|
|
||||||
{
|
|
||||||
private DynamicServer _plugin;
|
|
||||||
|
|
||||||
public ReloadServerListCommand(DynamicServer plugin)
|
|
||||||
{
|
|
||||||
super( "reloaddynamicserver", "bungeecord.command.reloadserverlist" );
|
|
||||||
|
|
||||||
_plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String[] arg1)
|
|
||||||
{
|
|
||||||
_plugin.LoadServers();
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "DynamicServer>" + ChatColor.GRAY + " Reloaded server list.");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="src" path="src"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre7"/>
|
|
||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/BungeeCord.jar"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
|
||||||
</classpath>
|
|
@ -1,11 +0,0 @@
|
|||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
|
||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
|
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.source=1.7
|
|
@ -1,5 +0,0 @@
|
|||||||
name: LobbyBalancer
|
|
||||||
main: mineplex.bungee.lobbyBalancer.LobbyBalancer
|
|
||||||
version: 1
|
|
||||||
author: defek7
|
|
||||||
depends: [DynamicServer]
|
|
@ -1,24 +0,0 @@
|
|||||||
package mineplex.bungee.lobbyBalancer;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
|
||||||
|
|
||||||
public class ReloadLobbyServerListCommand extends Command
|
|
||||||
{
|
|
||||||
private LobbyBalancer _plugin;
|
|
||||||
|
|
||||||
public ReloadLobbyServerListCommand(LobbyBalancer plugin)
|
|
||||||
{
|
|
||||||
super( "reloadlobbybalancer", "bungeecord.command.reloadserverlist" );
|
|
||||||
|
|
||||||
_plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String[] arg1)
|
|
||||||
{
|
|
||||||
_plugin.loadLobbyServers();
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "LobbyBalancer>" + ChatColor.GRAY + " Reloaded lobby server list.");
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,5 +3,7 @@
|
|||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre7"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre7"/>
|
||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/BungeeCord.jar"/>
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/BungeeCord.jar"/>
|
||||||
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
|
||||||
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-io-2.4.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
|
||||||
|
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="Mineplexer,"/>
|
||||||
|
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS" value="Mineplexer,"/>
|
||||||
|
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="Mineplexer,"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
|
||||||
|
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
|
||||||
|
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
|
||||||
|
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${BUILD_FILES}\common.xml"/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/Mineplex.Bungee.Mineplexer}"/>
|
||||||
|
</launchConfiguration>
|
4
Plugins/Mineplex.Bungee.Mineplexer/plugin.yml
Normal file
4
Plugins/Mineplex.Bungee.Mineplexer/plugin.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
name: Mineplexer
|
||||||
|
main: mineplex.bungee.Mineplexer
|
||||||
|
version: 1
|
||||||
|
author: defek7
|
@ -0,0 +1,33 @@
|
|||||||
|
package mineplex.bungee;
|
||||||
|
|
||||||
|
import mineplex.bungee.bungeeSigns.BungeeSigns;
|
||||||
|
import mineplex.bungee.dynamicServer.DynamicServer;
|
||||||
|
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 LobbyBalancer _lobbyBalancer;
|
||||||
|
private PlayerCount _playerCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
new BungeeSigns(this);
|
||||||
|
new Updater(this);
|
||||||
|
|
||||||
|
_dynamicServers = new DynamicServer(this);
|
||||||
|
_lobbyBalancer = new LobbyBalancer(this);
|
||||||
|
_playerCount = new PlayerCount(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReloadServerLists()
|
||||||
|
{
|
||||||
|
_dynamicServers.LoadServers();
|
||||||
|
_lobbyBalancer.loadLobbyServers();
|
||||||
|
_playerCount.LoadBungeeServers();
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mineplex.bungee.BungeeSigns;
|
package mineplex.bungee.bungeeSigns;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
@ -21,13 +21,16 @@ import net.md_5.bungee.api.plugin.Plugin;
|
|||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
|
import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
|
||||||
|
|
||||||
public class BungeeSigns extends Plugin implements Listener
|
public class BungeeSigns implements Listener
|
||||||
{
|
{
|
||||||
@Override
|
private Plugin _plugin;
|
||||||
public void onEnable()
|
|
||||||
|
public BungeeSigns(Plugin plugin)
|
||||||
{
|
{
|
||||||
getProxy().getPluginManager().registerListener(this, this);
|
_plugin = plugin;
|
||||||
getProxy().registerChannel("BungeeSigns");
|
|
||||||
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
|
_plugin.getProxy().registerChannel("BungeeSigns");
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -40,7 +43,7 @@ public class BungeeSigns extends Plugin implements Listener
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
in = new DataInputStream(new ByteArrayInputStream(event.getData()));
|
in = new DataInputStream(new ByteArrayInputStream(event.getData()));
|
||||||
final ServerInfo serverInfo = getProxy().getServerInfo(in.readUTF());
|
final ServerInfo serverInfo = _plugin.getProxy().getServerInfo(in.readUTF());
|
||||||
|
|
||||||
in.close();
|
in.close();
|
||||||
|
|
@ -10,15 +10,17 @@ import java.net.InetSocketAddress;
|
|||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
public class DynamicServer extends Plugin implements Listener
|
public class DynamicServer implements Listener
|
||||||
{
|
{
|
||||||
@Override
|
private Plugin _plugin;
|
||||||
public void onEnable()
|
|
||||||
|
public DynamicServer(Plugin plugin)
|
||||||
{
|
{
|
||||||
|
_plugin = plugin;
|
||||||
|
|
||||||
LoadServers();
|
LoadServers();
|
||||||
|
|
||||||
getProxy().getPluginManager().registerListener(this, this);
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
getProxy().getPluginManager().registerCommand(this, new ReloadServerListCommand(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadServers()
|
public void LoadServers()
|
||||||
@ -44,7 +46,7 @@ public class DynamicServer extends Plugin implements Listener
|
|||||||
Integer port = Integer.parseInt(line.split(",")[1].split(":")[1]);
|
Integer port = Integer.parseInt(line.split(",")[1].split(":")[1]);
|
||||||
InetSocketAddress socketAddress = new InetSocketAddress(address, port);
|
InetSocketAddress socketAddress = new InetSocketAddress(address, port);
|
||||||
|
|
||||||
getProxy().getServers().put(name, getProxy().constructServerInfo(name, socketAddress, "DynamicServer", false));
|
_plugin.getProxy().getServers().put(name, _plugin.getProxy().constructServerInfo(name, socketAddress, "DynamicServer", false));
|
||||||
line = br.readLine();
|
line = br.readLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,19 +18,23 @@ import net.md_5.bungee.api.plugin.Listener;
|
|||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
public class LobbyBalancer extends Plugin implements Listener, Runnable
|
public class LobbyBalancer implements Listener, Runnable
|
||||||
{
|
{
|
||||||
|
private Plugin _plugin;
|
||||||
private HashMap<String, Integer> _lobbyServers = new HashMap<String, Integer>();
|
private HashMap<String, Integer> _lobbyServers = new HashMap<String, Integer>();
|
||||||
|
|
||||||
@Override
|
private String _bestServer = "Lobby";
|
||||||
public void onEnable()
|
|
||||||
|
private static Object _serverLock = new Object();
|
||||||
|
|
||||||
|
public LobbyBalancer(Plugin plugin)
|
||||||
{
|
{
|
||||||
|
_plugin = plugin;
|
||||||
|
|
||||||
loadLobbyServers();
|
loadLobbyServers();
|
||||||
|
|
||||||
getProxy().getPluginManager().registerListener(this, this);
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
getProxy().getScheduler().schedule(this, this, 1L, 1L, TimeUnit.SECONDS);
|
_plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.SECONDS);
|
||||||
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new ReloadLobbyServerListCommand(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -39,54 +43,59 @@ public class LobbyBalancer extends Plugin implements Listener, Runnable
|
|||||||
if (!event.getTarget().getName().equalsIgnoreCase("Lobby"))
|
if (!event.getTarget().getName().equalsIgnoreCase("Lobby"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String bestServer = null;
|
event.setTarget(_plugin.getProxy().getServerInfo(_bestServer));
|
||||||
Entry<String, Integer> leastPlayerServer = null;
|
|
||||||
|
|
||||||
for (Entry<String, Integer> entry : _lobbyServers.entrySet())
|
|
||||||
{
|
|
||||||
if (entry.getValue() == 999)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (bestServer == null)
|
|
||||||
{
|
|
||||||
bestServer = entry.getKey();
|
|
||||||
leastPlayerServer = entry;
|
|
||||||
}
|
|
||||||
else if (entry.getValue() > _lobbyServers.get(bestServer) && entry.getValue() < 80)
|
|
||||||
bestServer = entry.getKey();
|
|
||||||
|
|
||||||
if (entry.getValue() < leastPlayerServer.getValue())
|
|
||||||
{
|
|
||||||
leastPlayerServer = entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_lobbyServers.get(bestServer) > 80)
|
|
||||||
{
|
|
||||||
bestServer = leastPlayerServer.getKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setTarget(getProxy().getServerInfo(bestServer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
for (String name : _lobbyServers.keySet())
|
synchronized (_serverLock)
|
||||||
{
|
{
|
||||||
try
|
for (String name : _lobbyServers.keySet())
|
||||||
{
|
{
|
||||||
UpdateServerCount(name);
|
try
|
||||||
}
|
{
|
||||||
catch (IOException e)
|
UpdateServerCount(name);
|
||||||
{
|
}
|
||||||
e.printStackTrace();
|
catch (IOException e)
|
||||||
}
|
{
|
||||||
}
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String bestServer = null;
|
||||||
|
Entry<String, Integer> leastPlayerServer = null;
|
||||||
|
|
||||||
|
for (Entry<String, Integer> entry : _lobbyServers.entrySet())
|
||||||
|
{
|
||||||
|
if (entry.getValue() == 999)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (bestServer == null)
|
||||||
|
{
|
||||||
|
bestServer = entry.getKey();
|
||||||
|
leastPlayerServer = entry;
|
||||||
|
}
|
||||||
|
else if (entry.getValue() > _lobbyServers.get(bestServer) && entry.getValue() < 80)
|
||||||
|
bestServer = entry.getKey();
|
||||||
|
|
||||||
|
if (entry.getValue() < leastPlayerServer.getValue())
|
||||||
|
{
|
||||||
|
leastPlayerServer = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_lobbyServers.get(bestServer) > 80)
|
||||||
|
{
|
||||||
|
bestServer = leastPlayerServer.getKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
_bestServer = bestServer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void UpdateServerCount(String name) throws IOException
|
protected void UpdateServerCount(String name) throws IOException
|
||||||
{
|
{
|
||||||
InetSocketAddress address = getProxy().getServerInfo(name).getAddress();
|
InetSocketAddress address = _plugin.getProxy().getServerInfo(name).getAddress();
|
||||||
|
|
||||||
Socket socket = null;
|
Socket socket = null;
|
||||||
DataInputStream dataInputStream = null;
|
DataInputStream dataInputStream = null;
|
||||||
@ -125,24 +134,36 @@ public class LobbyBalancer extends Plugin implements Listener, Runnable
|
|||||||
{
|
{
|
||||||
var27 = var6.substring(1).split("\u0000");
|
var27 = var6.substring(1).split("\u0000");
|
||||||
|
|
||||||
if (var27[3].contains("Restarting"))
|
synchronized (_serverLock)
|
||||||
_lobbyServers.put(name, 999);
|
{
|
||||||
else
|
if (var27[3].contains("Restarting"))
|
||||||
_lobbyServers.put(name, Integer.parseInt(var27[4]));
|
_lobbyServers.put(name, 999);
|
||||||
|
else
|
||||||
|
_lobbyServers.put(name, Integer.parseInt(var27[4]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SocketTimeoutException e)
|
catch (SocketTimeoutException e)
|
||||||
{
|
{
|
||||||
_lobbyServers.put(name, 999);
|
synchronized (_serverLock)
|
||||||
|
{
|
||||||
|
_lobbyServers.put(name, 999);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (ConnectException e)
|
catch (ConnectException e)
|
||||||
{
|
{
|
||||||
_lobbyServers.put(name, 999);
|
synchronized (_serverLock)
|
||||||
|
{
|
||||||
|
_lobbyServers.put(name, 999);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
System.out.println("[LobbyBalancer IOException] Error pinging " + address.getHostString() + ":" + address.getPort());
|
System.out.println("[LobbyBalancer IOException] Error pinging " + address.getHostString() + ":" + address.getPort());
|
||||||
_lobbyServers.put(name, 999);
|
synchronized (_serverLock)
|
||||||
|
{
|
||||||
|
_lobbyServers.put(name, 999);
|
||||||
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@ -225,14 +246,17 @@ public class LobbyBalancer extends Plugin implements Listener, Runnable
|
|||||||
|
|
||||||
public void loadLobbyServers()
|
public void loadLobbyServers()
|
||||||
{
|
{
|
||||||
_lobbyServers.clear();
|
synchronized (_serverLock)
|
||||||
|
{
|
||||||
|
_lobbyServers.clear();
|
||||||
|
|
||||||
for (String key : getProxy().getServers().keySet())
|
for (String key : _plugin.getProxy().getServers().keySet())
|
||||||
{
|
{
|
||||||
if (key.toUpperCase().contains("LOBBY"))
|
if (key.toUpperCase().contains("LOBBY"))
|
||||||
{
|
{
|
||||||
_lobbyServers.put(key, 0);
|
_lobbyServers.put(key, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mineplex.bungee.PlayerCount;
|
package mineplex.bungee.playerCount;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
@ -22,8 +22,10 @@ import net.md_5.bungee.api.plugin.Listener;
|
|||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
public class PlayerCount extends Plugin implements Listener, Runnable
|
public class PlayerCount implements Listener, Runnable
|
||||||
{
|
{
|
||||||
|
private Plugin _plugin;
|
||||||
|
|
||||||
private HashMap<String, InetSocketAddress> _otherBungeeInstances;
|
private HashMap<String, InetSocketAddress> _otherBungeeInstances;
|
||||||
private int _totalPlayers;
|
private int _totalPlayers;
|
||||||
private int _totalMaxPlayers;
|
private int _totalMaxPlayers;
|
||||||
@ -31,38 +33,41 @@ public class PlayerCount extends Plugin implements Listener, Runnable
|
|||||||
private int _tempPlayers;
|
private int _tempPlayers;
|
||||||
private int _tempMaxPlayers;
|
private int _tempMaxPlayers;
|
||||||
|
|
||||||
@Override
|
private static Object _serverLock = new Object();
|
||||||
public void onEnable()
|
|
||||||
|
public PlayerCount(Plugin plugin)
|
||||||
{
|
{
|
||||||
|
_plugin = plugin;
|
||||||
_otherBungeeInstances = new HashMap<String, InetSocketAddress>();
|
_otherBungeeInstances = new HashMap<String, InetSocketAddress>();
|
||||||
|
|
||||||
LoadBungeeServers();
|
LoadBungeeServers();
|
||||||
|
|
||||||
getProxy().getScheduler().schedule(this, this, 1L, 1L, TimeUnit.SECONDS);
|
_plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.SECONDS);
|
||||||
getProxy().getPluginManager().registerListener(this, this);
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new ReloadPlayerCountListCommand(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
_tempPlayers = getProxy().getOnlineCount();
|
_tempPlayers = _plugin.getProxy().getOnlineCount();
|
||||||
_tempMaxPlayers = 0;
|
_tempMaxPlayers = 0;
|
||||||
|
|
||||||
for(ListenerInfo li : getProxy().getConfigurationAdapter().getListeners())
|
for(ListenerInfo li : _plugin.getProxy().getConfigurationAdapter().getListeners())
|
||||||
{
|
{
|
||||||
_tempMaxPlayers += li.getMaxPlayers();
|
_tempMaxPlayers += li.getMaxPlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (InetSocketAddress address : _otherBungeeInstances.values())
|
synchronized (_serverLock)
|
||||||
{
|
{
|
||||||
try
|
for (InetSocketAddress address : _otherBungeeInstances.values())
|
||||||
{
|
{
|
||||||
UpdateServerCount(address);
|
try
|
||||||
} catch (IOException e)
|
{
|
||||||
{
|
UpdateServerCount(address);
|
||||||
e.printStackTrace();
|
} catch (IOException e)
|
||||||
}
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_totalPlayers = _tempPlayers;
|
_totalPlayers = _tempPlayers;
|
||||||
@ -96,17 +101,18 @@ public class PlayerCount extends Plugin implements Listener, Runnable
|
|||||||
dataOutputStream = new DataOutputStream(socket.getOutputStream());
|
dataOutputStream = new DataOutputStream(socket.getOutputStream());
|
||||||
|
|
||||||
dataOutputStream.writeByte(254);
|
dataOutputStream.writeByte(254);
|
||||||
|
|
||||||
dataOutputStream.writeByte(1);
|
dataOutputStream.writeByte(1);
|
||||||
dataOutputStream.writeByte(254);
|
dataOutputStream.writeByte(254);
|
||||||
writeString("MC|PingHost", dataOutputStream);
|
writeString("MC|PingHost", dataOutputStream);
|
||||||
dataOutputStream.writeShort(3 + 2 * address.getAddress().getHostName().length() + 4);
|
dataOutputStream.writeShort(3 + 2 * address.getAddress().getHostName().length() + 4);
|
||||||
dataOutputStream.writeByte(73);
|
dataOutputStream.writeByte(74);
|
||||||
writeString(address.getAddress().getHostName(), dataOutputStream);
|
writeString(address.getAddress().getHostName(), dataOutputStream);
|
||||||
dataOutputStream.writeInt(address.getPort());
|
dataOutputStream.writeInt(address.getPort());
|
||||||
|
|
||||||
if (dataInputStream.read() != 255)
|
if (dataInputStream.read() != 255)
|
||||||
{
|
{
|
||||||
System.out.println("not 255");
|
System.out.println("Bad message");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +138,7 @@ public class PlayerCount extends Plugin implements Listener, Runnable
|
|||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
System.out.println("[BungeeSigns] Error pinging " + address.getHostString() + ":" + address.getPort());
|
System.out.println("[PlayerCount] Error pinging " + address.getHostName() + ":" + address.getPort());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@ -215,6 +221,11 @@ public class PlayerCount extends Plugin implements Listener, Runnable
|
|||||||
|
|
||||||
public void LoadBungeeServers()
|
public void LoadBungeeServers()
|
||||||
{
|
{
|
||||||
|
synchronized (_serverLock)
|
||||||
|
{
|
||||||
|
_otherBungeeInstances.clear();
|
||||||
|
}
|
||||||
|
|
||||||
FileInputStream fstream = null;
|
FileInputStream fstream = null;
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
|
|
||||||
@ -234,7 +245,25 @@ public class PlayerCount extends Plugin implements Listener, Runnable
|
|||||||
String address = line.split(":")[0];
|
String address = line.split(":")[0];
|
||||||
Integer port = Integer.parseInt(line.split(":")[1]);
|
Integer port = Integer.parseInt(line.split(":")[1]);
|
||||||
InetSocketAddress socketAddress = new InetSocketAddress(address, port);
|
InetSocketAddress socketAddress = new InetSocketAddress(address, port);
|
||||||
_otherBungeeInstances.put(socketAddress.getAddress().getHostAddress(), socketAddress);
|
|
||||||
|
boolean addAddress = true;
|
||||||
|
|
||||||
|
for (ListenerInfo listenerInfo : _plugin.getProxy().getConfigurationAdapter().getListeners())
|
||||||
|
{
|
||||||
|
if (address.equalsIgnoreCase(listenerInfo.getHost().getAddress().getHostAddress()))
|
||||||
|
{
|
||||||
|
addAddress = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addAddress)
|
||||||
|
{
|
||||||
|
synchronized (_serverLock)
|
||||||
|
{
|
||||||
|
_otherBungeeInstances.put(socketAddress.getAddress().getHostAddress(), socketAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
line = br.readLine();
|
line = br.readLine();
|
||||||
}
|
}
|
@ -0,0 +1,188 @@
|
|||||||
|
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<String, String> _jarMd5Map = new HashMap<String, String>();
|
||||||
|
private File _updateDirectory;
|
||||||
|
|
||||||
|
private boolean _needUpdate = false;
|
||||||
|
|
||||||
|
public Updater(Mineplexer plugin)
|
||||||
|
{
|
||||||
|
_plugin = plugin;
|
||||||
|
_jarMd5Map = new HashMap<String, String>();
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
_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.");
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="src" path="src"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre7"/>
|
|
||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/BungeeCord.jar"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
|
||||||
</classpath>
|
|
@ -1,11 +0,0 @@
|
|||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
|
||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
|
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.source=1.7
|
|
@ -1,4 +0,0 @@
|
|||||||
name: PlayerCount
|
|
||||||
main: mineplex.bungee.PlayerCount.PlayerCount
|
|
||||||
version: 1
|
|
||||||
author: defek7
|
|
@ -1,24 +0,0 @@
|
|||||||
package mineplex.bungee.PlayerCount;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
|
||||||
|
|
||||||
public class ReloadPlayerCountListCommand extends Command
|
|
||||||
{
|
|
||||||
private PlayerCount _plugin;
|
|
||||||
|
|
||||||
public ReloadPlayerCountListCommand(PlayerCount plugin)
|
|
||||||
{
|
|
||||||
super( "reloadplayercount", "bungeecord.command.reloadserverlist" );
|
|
||||||
|
|
||||||
_plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String[] arg1)
|
|
||||||
{
|
|
||||||
_plugin.LoadBungeeServers();
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "PlayerCount>" + ChatColor.GRAY + " Reloaded player count server list.");
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,5 +10,6 @@
|
|||||||
<classpathentry combineaccessrules="false" kind="src" path="/Nautilus.Core"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/Nautilus.Core"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Minecraft.Game.Core"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Minecraft.Game.Core"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Minecraft.Game.ClassCombat"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Minecraft.Game.ClassCombat"/>
|
||||||
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -11,8 +11,8 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -47,7 +47,7 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
|
|||||||
private Portal _portal;
|
private Portal _portal;
|
||||||
private PartyManager _partyManager;
|
private PartyManager _partyManager;
|
||||||
|
|
||||||
private NautHashMap<String, List<ServerInfo>> _serverNpcMap = new NautHashMap<String, List<ServerInfo>>();
|
private NautHashMap<String, HashSet<ServerInfo>> _serverNpcMap = new NautHashMap<String, HashSet<ServerInfo>>();
|
||||||
private NautHashMap<String, ServerNpcShop> _serverNpcShopMap = new NautHashMap<String, ServerNpcShop>();
|
private NautHashMap<String, ServerNpcShop> _serverNpcShopMap = new NautHashMap<String, ServerNpcShop>();
|
||||||
private NautHashMap<String, ServerInfo> _serverInfoMap = new NautHashMap<String, ServerInfo>();
|
private NautHashMap<String, ServerInfo> _serverInfoMap = new NautHashMap<String, ServerInfo>();
|
||||||
private NautHashMap<String, Long> _serverUpdate = new NautHashMap<String, Long>();
|
private NautHashMap<String, Long> _serverUpdate = new NautHashMap<String, Long>();
|
||||||
@ -69,6 +69,8 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
|
|||||||
plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, "BungeeSigns", this);
|
plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, "BungeeSigns", this);
|
||||||
|
|
||||||
LoadServers();
|
LoadServers();
|
||||||
|
|
||||||
|
new ServerManagerUpdater(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddCommands()
|
public void AddCommands()
|
||||||
@ -81,14 +83,16 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
|
|||||||
ServerInfo serverInfo = new ServerInfo();
|
ServerInfo serverInfo = new ServerInfo();
|
||||||
serverInfo.Name = serverName;
|
serverInfo.Name = serverName;
|
||||||
|
|
||||||
_serverNpcMap.get(serverNpcName).add(serverInfo);
|
if (_serverInfoMap.containsKey(serverName))
|
||||||
|
|
||||||
if (!_serverInfoMap.containsKey(serverName))
|
|
||||||
{
|
{
|
||||||
_serverInfoMap.put(serverName, serverInfo);
|
_serverInfoMap.remove(serverName);
|
||||||
_serverUpdate.put(serverName, System.currentTimeMillis());
|
_serverUpdate.remove(serverName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_serverNpcMap.get(serverNpcName).add(serverInfo);
|
||||||
|
_serverInfoMap.put(serverName, serverInfo);
|
||||||
|
_serverUpdate.put(serverName, System.currentTimeMillis());
|
||||||
|
|
||||||
SaveServers();
|
SaveServers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,13 +108,13 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
|
|||||||
|
|
||||||
public void AddServerNpc(String serverNpcName)
|
public void AddServerNpc(String serverNpcName)
|
||||||
{
|
{
|
||||||
_serverNpcMap.put(serverNpcName, new ArrayList<ServerInfo>());
|
_serverNpcMap.put(serverNpcName, new HashSet<ServerInfo>());
|
||||||
_serverNpcShopMap.put(serverNpcName, new ServerNpcShop(this, _clientManager, _donationManager, serverNpcName));
|
_serverNpcShopMap.put(serverNpcName, new ServerNpcShop(this, _clientManager, _donationManager, serverNpcName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveServerNpc(String serverNpcName)
|
public void RemoveServerNpc(String serverNpcName)
|
||||||
{
|
{
|
||||||
List<ServerInfo> mappedServers = _serverNpcMap.remove(serverNpcName);
|
Set<ServerInfo> mappedServers = _serverNpcMap.remove(serverNpcName);
|
||||||
_serverNpcShopMap.remove(serverNpcName);
|
_serverNpcShopMap.remove(serverNpcName);
|
||||||
|
|
||||||
if (mappedServers != null)
|
if (mappedServers != null)
|
||||||
@ -140,7 +144,7 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ServerInfo> GetServerList(String serverNpcName)
|
public Collection<ServerInfo> GetServerList(String serverNpcName)
|
||||||
{
|
{
|
||||||
return _serverNpcMap.get(serverNpcName);
|
return _serverNpcMap.get(serverNpcName);
|
||||||
}
|
}
|
||||||
@ -434,11 +438,21 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
|
|||||||
|
|
||||||
public void LoadServers()
|
public void LoadServers()
|
||||||
{
|
{
|
||||||
|
_serverInfoMap.clear();
|
||||||
|
_serverUpdate.clear();
|
||||||
|
|
||||||
|
for (String npcName : _serverNpcMap.keySet())
|
||||||
|
{
|
||||||
|
_serverNpcMap.get(npcName).clear();
|
||||||
|
}
|
||||||
|
|
||||||
_loading = true;
|
_loading = true;
|
||||||
|
|
||||||
FileInputStream fstream = null;
|
FileInputStream fstream = null;
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
|
|
||||||
|
HashSet<String> npcNames = new HashSet<String>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File npcFile = new File("ServerManager.dat");
|
File npcFile = new File("ServerManager.dat");
|
||||||
@ -461,6 +475,7 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
AddServer(serverNpcName, server);
|
AddServer(serverNpcName, server);
|
||||||
|
npcNames.add(serverNpcName);
|
||||||
|
|
||||||
line = br.readLine();
|
line = br.readLine();
|
||||||
}
|
}
|
||||||
@ -498,6 +513,15 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
|
|||||||
|
|
||||||
_loading = false;
|
_loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (String npcName : npcNames)
|
||||||
|
{
|
||||||
|
if (!_serverNpcShopMap.containsKey(npcName))
|
||||||
|
_serverNpcShopMap.remove(npcName);
|
||||||
|
|
||||||
|
if (!_serverNpcMap.containsKey(npcName))
|
||||||
|
_serverNpcMap.remove(npcName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetRequiredSlots(Player player, String serverType)
|
public int GetRequiredSlots(Player player, String serverType)
|
||||||
|
@ -0,0 +1,177 @@
|
|||||||
|
package mineplex.hub.server;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import mineplex.core.common.util.NautHashMap;
|
||||||
|
import mineplex.core.updater.UpdateType;
|
||||||
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
|
|
||||||
|
public class ServerManagerUpdater implements Listener
|
||||||
|
{
|
||||||
|
private ServerManager _plugin;
|
||||||
|
private NautHashMap<String, String> _jarMd5Map = new NautHashMap<String, String>();
|
||||||
|
private File _updateDirectory;
|
||||||
|
|
||||||
|
private boolean _needUpdate = false;
|
||||||
|
|
||||||
|
public ServerManagerUpdater(ServerManager plugin)
|
||||||
|
{
|
||||||
|
_plugin = plugin;
|
||||||
|
|
||||||
|
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 + "lobby");
|
||||||
|
|
||||||
|
_updateDirectory.mkdirs();
|
||||||
|
|
||||||
|
plugin.GetPluginManager().registerEvents(this, plugin.GetPlugin());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getCurrentMd5s()
|
||||||
|
{
|
||||||
|
File serverManagerDat = new File("ServerManager.dat");
|
||||||
|
|
||||||
|
FileInputStream fis = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fis = new FileInputStream(serverManagerDat);
|
||||||
|
_jarMd5Map.put(serverManagerDat.getName(), DigestUtils.md5Hex(fis));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.out.println("ServerManagerUpdater: Error parsing ServerManager dat md5's");
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (fis != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fis.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void checkForNewFiles(UpdateEvent event)
|
||||||
|
{
|
||||||
|
if (event.getType() != UpdateType.FAST)
|
||||||
|
return;
|
||||||
|
|
||||||
|
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("ServerManagerUpdater: 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 + "lobby");
|
||||||
|
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("ServerManagerUpdater: Error updating dats");
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentMd5s();
|
||||||
|
_plugin.LoadServers();
|
||||||
|
System.out.println("ServerManagerUpdater: Updated with new dat file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -22,7 +22,7 @@ public class ServerSorter implements Comparator<ServerInfo>
|
|||||||
if ((a.MOTD.contains("Recruiting") || a.MOTD.contains("Waiting") || a.MOTD.contains("Starting") || a.MOTD.contains("Cup")) && !b.MOTD.contains("Recruiting") && !b.MOTD.contains("Waiting") && !b.MOTD.contains("Starting") && !b.MOTD.contains("Cup"))
|
if ((a.MOTD.contains("Recruiting") || a.MOTD.contains("Waiting") || a.MOTD.contains("Starting") || a.MOTD.contains("Cup")) && !b.MOTD.contains("Recruiting") && !b.MOTD.contains("Waiting") && !b.MOTD.contains("Starting") && !b.MOTD.contains("Cup"))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((b.MOTD.contains("Recruiting") || b.MOTD.contains("Waiting") || a.MOTD.contains("Starting") || b.MOTD.contains("Cup")) && !a.MOTD.contains("Recruiting") && !a.MOTD.contains("Waiting") && !a.MOTD.contains("Starting") && !a.MOTD.contains("Cup"))
|
if ((b.MOTD.contains("Recruiting") || b.MOTD.contains("Waiting") || b.MOTD.contains("Starting") || b.MOTD.contains("Cup")) && !a.MOTD.contains("Recruiting") && !a.MOTD.contains("Waiting") && !a.MOTD.contains("Starting") && !a.MOTD.contains("Cup"))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (a.MaxPlayers - a.CurrentPlayers < _requiredSlots && b.MaxPlayers - b.CurrentPlayers >= _requiredSlots)
|
if (a.MaxPlayers - a.CurrentPlayers < _requiredSlots && b.MaxPlayers - b.CurrentPlayers >= _requiredSlots)
|
||||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
import mineplex.core.common.Rank;
|
import mineplex.core.common.Rank;
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
|
import mineplex.core.common.util.F;
|
||||||
import mineplex.core.donation.DonationManager;
|
import mineplex.core.donation.DonationManager;
|
||||||
import mineplex.core.shop.item.ShopItem;
|
import mineplex.core.shop.item.ShopItem;
|
||||||
import mineplex.core.shop.page.ShopPageBase;
|
import mineplex.core.shop.page.ShopPageBase;
|
||||||
@ -34,7 +35,7 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop>
|
|||||||
@Override
|
@Override
|
||||||
protected void BuildPage()
|
protected void BuildPage()
|
||||||
{
|
{
|
||||||
List<ServerInfo> serverList = Plugin.GetServerList(_serverNpcKey);
|
List<ServerInfo> serverList = new ArrayList<ServerInfo>(Plugin.GetServerList(_serverNpcKey));
|
||||||
|
|
||||||
int slots = 1;
|
int slots = 1;
|
||||||
|
|
||||||
@ -43,7 +44,19 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop>
|
|||||||
slots = Plugin.GetRequiredSlots(Player, serverList.get(0).ServerType);
|
slots = Plugin.GetRequiredSlots(Player, serverList.get(0).ServerType);
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(serverList, new ServerSorter(slots));
|
try
|
||||||
|
{
|
||||||
|
Collections.sort(serverList, new ServerSorter(slots));
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
|
||||||
|
for (ServerInfo serverInfo : serverList)
|
||||||
|
{
|
||||||
|
System.out.println(F.main("ServerNpcPage", ChatColor.YELLOW + serverInfo.Name + ": " + serverInfo.MOTD + " " + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int slot = 9;
|
int slot = 9;
|
||||||
int greenCount = 0;
|
int greenCount = 0;
|
||||||
@ -151,6 +164,7 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop>
|
|||||||
{
|
{
|
||||||
ButtonMap.clear();
|
ButtonMap.clear();
|
||||||
BuildPage();
|
BuildPage();
|
||||||
|
System.out.println("Updated " + Player.getName() + "'s page.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectServer(Player player, ServerInfo serverInfo)
|
public void SelectServer(Player player, ServerInfo serverInfo)
|
||||||
|
@ -587,7 +587,8 @@ public class GameFlagManager implements Listener
|
|||||||
|
|
||||||
GameTeam team = game.GetTeam(event.getPlayer());
|
GameTeam team = game.GetTeam(event.getPlayer());
|
||||||
|
|
||||||
team.SetPlayerState(event.getPlayer(), PlayerState.OUT);
|
if (team != null)
|
||||||
|
team.SetPlayerState(event.getPlayer(), PlayerState.OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user