Mineplex2018-withcommit/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/Mineplexer.java

84 lines
2.3 KiB
Java
Raw Normal View History

package mineplex.bungee;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import mineplex.bungee.lobbyBalancer.LobbyBalancer;
import mineplex.bungee.motd.MotdManager;
import mineplex.bungee.playerCount.PlayerCount;
import net.md_5.bungee.api.plugin.Plugin;
public class Mineplexer extends Plugin
{
@Override
public void onEnable()
{
//_dynamicServers = new GlobalServer(this);
new MotdManager(this);
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();
}
*/
}
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);
}
}