|
@ -5,21 +5,22 @@ import net.dv8tion.jda.api.EmbedBuilder; |
|
|
import net.dv8tion.jda.api.entities.Guild; |
|
|
import net.dv8tion.jda.api.entities.Guild; |
|
|
import net.dv8tion.jda.api.entities.TextChannel; |
|
|
import net.dv8tion.jda.api.entities.TextChannel; |
|
|
import org.apache.commons.io.FileUtils; |
|
|
import org.apache.commons.io.FileUtils; |
|
|
import org.json.JSONArray; |
|
|
|
|
|
import org.json.JSONObject; |
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
|
|
import java.net.Socket; |
|
|
|
|
|
import java.net.UnknownHostException; |
|
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.io.InputStreamReader; |
|
|
import java.nio.file.Files; |
|
|
import java.nio.file.Files; |
|
|
import java.time.LocalDateTime; |
|
|
import java.time.LocalDateTime; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Locale; |
|
|
|
|
|
import java.util.Map; |
|
|
import java.util.concurrent.Executors; |
|
|
import java.util.concurrent.Executors; |
|
|
import java.util.concurrent.ScheduledExecutorService; |
|
|
import java.util.concurrent.ScheduledExecutorService; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.regex.Matcher; |
|
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.StreamSupport; |
|
|
import java.util.stream.StreamSupport; |
|
|
|
|
|
|
|
@ -74,31 +75,35 @@ public class StatusProvider implements Provider { |
|
|
try { |
|
|
try { |
|
|
Map<String, Object> serverInfo = getPlayersOnline(); |
|
|
Map<String, Object> serverInfo = getPlayersOnline(); |
|
|
if ((boolean) serverInfo.get("online")) { |
|
|
if ((boolean) serverInfo.get("online")) { |
|
|
int newPlayersOnline = (int) serverInfo.get("playerCount"); |
|
|
|
|
|
if (newPlayersOnline == lastPlayersOnline) return; |
|
|
|
|
|
else { |
|
|
|
|
|
if (timestampLastPlayerOnline == null && newPlayersOnline == 0 && lastPlayersOnline != -1) { |
|
|
|
|
|
timestampLastPlayerOnline = LocalDateTime.now(); |
|
|
|
|
|
} else if (timestampLastPlayerOnline != null && newPlayersOnline > 0) { |
|
|
|
|
|
timestampLastPlayerOnline = null; |
|
|
|
|
|
|
|
|
if ((boolean) serverInfo.get("Server starting")) { |
|
|
|
|
|
eb.addField("Server still Starting", "True", false); |
|
|
|
|
|
} else { |
|
|
|
|
|
int newPlayersOnline = (int) serverInfo.get("playerCount"); |
|
|
|
|
|
if (newPlayersOnline == lastPlayersOnline) return; |
|
|
|
|
|
else { |
|
|
|
|
|
if (timestampLastPlayerOnline == null && newPlayersOnline == 0 && lastPlayersOnline != -1) { |
|
|
|
|
|
timestampLastPlayerOnline = LocalDateTime.now(); |
|
|
|
|
|
} else if (timestampLastPlayerOnline != null && newPlayersOnline > 0) { |
|
|
|
|
|
timestampLastPlayerOnline = null; |
|
|
|
|
|
} |
|
|
|
|
|
lastPlayersOnline = newPlayersOnline; |
|
|
|
|
|
} |
|
|
|
|
|
eb.addField("Version", (String) serverInfo.get("version"), true); |
|
|
|
|
|
eb.addField("MOTD", (String) serverInfo.get("motd"), true); |
|
|
|
|
|
eb.addField("Spieler online", lastPlayersOnline + " / " + serverInfo.get("playerMax"), false); |
|
|
|
|
|
if (timestampLastPlayerOnline != null) { |
|
|
|
|
|
eb.addField("Zuletzt gesehen", TIME_FORMATTER.format(timestampLastPlayerOnline), false); |
|
|
|
|
|
} |
|
|
|
|
|
if (lastPlayersOnline > 0) { |
|
|
|
|
|
eb.addField("Spieler:", String.join(", ", (List<String>) serverInfo.get("playerNames")), false); |
|
|
} |
|
|
} |
|
|
lastPlayersOnline = newPlayersOnline; |
|
|
|
|
|
} |
|
|
|
|
|
eb.addField("Version", (String) serverInfo.get("version"), true); |
|
|
|
|
|
eb.addField("MOTD", (String) serverInfo.get("motd"), true); |
|
|
|
|
|
eb.addField("Spieler online", lastPlayersOnline + " / " + serverInfo.get("playerMax"), false); |
|
|
|
|
|
if (timestampLastPlayerOnline != null) { |
|
|
|
|
|
eb.addField("Zuletzt gesehen", TIME_FORMATTER.format(timestampLastPlayerOnline), false); |
|
|
|
|
|
} |
|
|
|
|
|
if (lastPlayersOnline > 0) { |
|
|
|
|
|
eb.addField("Spieler:", String.join(", ", (List<String>) serverInfo.get("playerNames")), false); |
|
|
|
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
eb.addField("Offline", "", false); |
|
|
eb.addField("Offline", "", false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
statusChannel.editMessageById(this.message_id, eb.build()).queue(); |
|
|
statusChannel.editMessageById(this.message_id, eb.build()).queue(); |
|
|
} catch (IOException e){ |
|
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
Logger.logError(e.toString()); |
|
|
Logger.logError(e.toString()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -112,7 +117,7 @@ public class StatusProvider implements Provider { |
|
|
} catch (InterruptedException e) { |
|
|
} catch (InterruptedException e) { |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|
} |
|
|
} |
|
|
if (process.exitValue() != 0){ |
|
|
|
|
|
|
|
|
if (process.exitValue() != 0) { |
|
|
Logger.logError("MCStatus on port " + serverPort + " exited with errorcode " + process.exitValue()); |
|
|
Logger.logError("MCStatus on port " + serverPort + " exited with errorcode " + process.exitValue()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -121,24 +126,10 @@ public class StatusProvider implements Provider { |
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
|
|
|
if (output.startsWith("The server did not respond to the query protocol.")){ |
|
|
|
|
|
|
|
|
if (output.startsWith("The server did not respond to the query protocol.")) { |
|
|
result.put("online", false); |
|
|
result.put("online", false); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
/* |
|
|
|
|
|
String part = output.split("players")[1].replace(",", "").replace("'", ""); |
|
|
|
|
|
String[] players = part.substring(part.indexOf("[")+1, part.indexOf("]")).split(" "); |
|
|
|
|
|
|
|
|
|
|
|
String playerAmount = part.split(" ")[1]; |
|
|
|
|
|
int playersOnline = Integer.parseInt(playerAmount.split("/")[0]); |
|
|
|
|
|
int playersMax = Integer.parseInt(playerAmount.split("/")[1]); |
|
|
|
|
|
|
|
|
|
|
|
result.put("online", true); |
|
|
|
|
|
result.put("playerCount", playersOnline); |
|
|
|
|
|
result.put("playerMax", playersMax); |
|
|
|
|
|
result.put("playerNames", Arrays.asList(players)); |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
JSONObject obj = new JSONObject(output); |
|
|
JSONObject obj = new JSONObject(output); |
|
|
|
|
|
|
|
|
result.put("online", obj.getBoolean("online")); |
|
|
result.put("online", obj.getBoolean("online")); |
|
@ -146,6 +137,13 @@ public class StatusProvider implements Provider { |
|
|
if (!obj.getBoolean("online")) { |
|
|
if (!obj.getBoolean("online")) { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
for (String key : new String[]{"player_count", "player_max", "players", "motd", "version"}) { |
|
|
|
|
|
if (!obj.has(key)) { |
|
|
|
|
|
result.put("Server starting", true); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
result.put("Server starting", false); |
|
|
|
|
|
|
|
|
result.put("playerCount", obj.getInt("player_count")); |
|
|
result.put("playerCount", obj.getInt("player_count")); |
|
|
result.put("playerMax", obj.getInt("player_max")); |
|
|
result.put("playerMax", obj.getInt("player_max")); |
|
|