|
@ -18,6 +18,8 @@ import java.util.*; |
|
|
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; |
|
|
|
|
|
|
|
@ -46,7 +48,7 @@ public class StatusProvider implements Provider { |
|
|
this.desc = desc; |
|
|
this.desc = desc; |
|
|
this.message_id = messageId; |
|
|
this.message_id = messageId; |
|
|
this.serverPort = serverPort; |
|
|
this.serverPort = serverPort; |
|
|
this.mcstatus.command(Resources.getPath_to_mcstatus(), Resources.getMc_server() + ":" + serverPort, "json"); |
|
|
|
|
|
|
|
|
this.mcstatus.command(Resources.getPath_to_mcstatus(), Resources.getMc_server() + ":" + serverPort, "query"); |
|
|
|
|
|
|
|
|
File timeStampSave = new File(String.format("%s/%d.txt", Resources.getResourcePath(), serverPort)); |
|
|
File timeStampSave = new File(String.format("%s/%d.txt", Resources.getResourcePath(), serverPort)); |
|
|
timestampLastPlayerOnline = null; |
|
|
timestampLastPlayerOnline = null; |
|
@ -105,7 +107,25 @@ public class StatusProvider implements Provider { |
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
|
|
|
JSONObject obj = new JSONObject(output); |
|
|
|
|
|
|
|
|
if (output.startsWith("The server did not respond to the query protocol.")){ |
|
|
|
|
|
result.put("online", false); |
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
result.put("online", obj.getBoolean("online")); |
|
|
result.put("online", obj.getBoolean("online")); |
|
|
|
|
|
|
|
@ -118,7 +138,7 @@ public class StatusProvider implements Provider { |
|
|
result.put("playerNames", |
|
|
result.put("playerNames", |
|
|
StreamSupport.stream(obj.getJSONArray("players").spliterator(), false) |
|
|
StreamSupport.stream(obj.getJSONArray("players").spliterator(), false) |
|
|
.map(jsonobj -> ((JSONObject) jsonobj).getString("name")).sorted().collect( |
|
|
.map(jsonobj -> ((JSONObject) jsonobj).getString("name")).sorted().collect( |
|
|
Collectors.toList())); |
|
|
|
|
|
|
|
|
Collectors.toList()));*/ |
|
|
|
|
|
|
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|