ich bin dabei ein "JoinSigns"-Plugin für BungeeCord zu Programmieren, welches in einer Config eingestellte Server anpingt und unter anderem das MOTD ausliest.
Auf den einzelnen Servern wird das MOTD mit dem ServerListPingEvent geändert.
Vorweg: Google hat mir gesagt, das der Fehler an meiner Ping-Klasse liege.
Hier die Ping-Klasse:
Code:
public class Ping
{
public static String motd;
public static int playercount;
public static int maxplayers;
public static boolean online;
public static void ping(String address, int port)
{
try
{
InetSocketAddress isa = new InetSocketAddress(address, port);
Socket socket = new Socket();
OutputStream outputStream;
DataOutputStream dataOutputStream;
InputStream inputStream;
InputStreamReader inputStreamReader;
socket.setSoTimeout(4000);
socket.connect(isa, 4000);
outputStream = socket.getOutputStream();
dataOutputStream = new DataOutputStream(outputStream);
inputStream = socket.getInputStream();
inputStreamReader = new InputStreamReader(inputStream,Charset.forName("UTF-16BE"));
dataOutputStream.write(new byte[]{(byte) 0xFE,(byte) 0x01});
int packetId = inputStream.read();
if(packetId == -1)
{
dataOutputStream.close();
outputStream.close();
inputStreamReader.close();
inputStream.close();
socket.close();
throw new IOException("Premature end of stream.");
}
if(packetId != 0xFF)
{
dataOutputStream.close();
outputStream.close();
inputStreamReader.close();
inputStream.close();
socket.close();
throw new IOException("Invalid packet ID (" + packetId + ").");
}
int length = inputStreamReader.read();
if(length == -1)
{
dataOutputStream.close();
outputStream.close();
inputStreamReader.close();
inputStream.close();
socket.close();
throw new IOException("Premature end of stream.");
}
if(length == 0)
{
dataOutputStream.close();
outputStream.close();
inputStreamReader.close();
inputStream.close();
socket.close();
throw new IOException("Invalid string length.");
}
char[] chars = new char[length];
if(inputStreamReader.read(chars,0,length) != length)
{
dataOutputStream.close();
outputStream.close();
inputStreamReader.close();
inputStream.close();
socket.close();
throw new IOException("Premature end of stream.");
}
String string = new String(chars);
if(string.startsWith("§"))
{
String[] data = string.split("\0");
motd = data[3];
playercount = Integer.parseInt(data[4]);
maxplayers = Integer.parseInt(data[5]);
}
else{
String[] data = string.split("§");
motd = data[0];
playercount = Integer.parseInt(data[1]);
maxplayers = Integer.parseInt(data[2]);
}
online = true;
dataOutputStream.close();
outputStream.close();
inputStreamReader.close();
inputStream.close();
socket.close();
}
catch (SocketException exception)
{
online = false;
}
catch (IOException exception)
{
online = false;
}
}
}
Mit freundlichen Grüßen,
LuisKillergurke







