Added DynamicServer for bungee.

Added reload commands for balancer, dynamicserver, playercount.
Added depends for lboby on dynamic server.
This commit is contained in:
Jonathan Williams 2013-09-05 02:11:47 -07:00
parent 9121d429c2
commit 22ee1522c1
9 changed files with 166 additions and 4 deletions

View File

@ -0,0 +1,7 @@
<?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>

View File

@ -0,0 +1,11 @@
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

View File

@ -0,0 +1,4 @@
name: DynamicServer
main: mineplex.bungee.dynamicServer.DynamicServer
version: 1
author: defek7

View File

@ -0,0 +1,87 @@
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 extends Plugin implements Listener
{
@Override
public void onEnable()
{
LoadServers();
getProxy().getPluginManager().registerListener(this, this);
getProxy().getPluginManager().registerCommand(this, new ReloadServerListCommand(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);
getProxy().getServers().put(name, 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();
}
}
}
}
}

View File

@ -0,0 +1,24 @@
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.");
}
}

View File

@ -2,3 +2,4 @@ name: LobbyBalancer
main: mineplex.bungee.lobbyBalancer.LobbyBalancer
version: 1
author: defek7
depends: [DynamicServer]

View File

@ -29,6 +29,8 @@ public class LobbyBalancer extends Plugin implements Listener, Runnable
getProxy().getPluginManager().registerListener(this, this);
getProxy().getScheduler().schedule(this, this, 1L, 1L, TimeUnit.SECONDS);
getProxy().getPluginManager().registerCommand(this, new ReloadLobbyServerListCommand(this));
}
@EventHandler
@ -220,9 +222,11 @@ public class LobbyBalancer extends Plugin implements Listener, Runnable
return var3.toString();
}
}
private void loadLobbyServers()
{
public void loadLobbyServers()
{
_lobbyServers.clear();
for (String key : getProxy().getServers().keySet())
{
if (key.toUpperCase().contains("LOBBY"))
@ -230,5 +234,5 @@ public class LobbyBalancer extends Plugin implements Listener, Runnable
_lobbyServers.put(key, 0);
}
}
}
}
}

View File

@ -0,0 +1,24 @@
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.");
}
}

Binary file not shown.