diff --git a/src/Main.java b/src/Main.java index 0ebf079..f3d90b7 100644 --- a/src/Main.java +++ b/src/Main.java @@ -62,59 +62,36 @@ class Main { } private static void updatePlayerList(String text, Collection collection) { - try { - if (!collection.getServer().typeName().equals("Bungee")) { //Bungee servers are not to be treated as normal servers. - String joinedPlayer = stringBetween(text, "[Server thread/INFO]: ", " joined the game"); + if (!collection.getServer().typeName().equals("Bungee")) { //Bungee servers are not to be treated as normal servers. + String joinedPlayer = stringBetween(text, "[Server thread/INFO]: ", " joined the game"); + if (!joinedPlayer.equals("")) { + if (!collection.getServer().hasPlayer(joinedPlayer)) { + collection.getServer().addPlayer(joinedPlayer); + } + } else { + joinedPlayer = stringBetween(text, "UUID of player ", " is "); if (!joinedPlayer.equals("")) { if (!collection.getServer().hasPlayer(joinedPlayer)) { collection.getServer().addPlayer(joinedPlayer); } - } else { - joinedPlayer = stringBetween(text, "UUID of player ", " is "); - if (!joinedPlayer.equals("")) { - if (!collection.getServer().hasPlayer(joinedPlayer)) { - collection.getServer().addPlayer(joinedPlayer); - } - } } - if (joinedPlayer.equals("")) { - String leftPlayer = stringBetween(text, "INFO]: ", " lost connection"); + } + if (joinedPlayer.equals("")) { + String leftPlayer = stringBetween(text, "INFO]: ", " lost connection"); + if (!leftPlayer.equals("")) { + if (collection.getServer().hasPlayer(leftPlayer)) { + collection.getServer().removePlayer(leftPlayer); + } + } else { + leftPlayer = stringBetween(text, "[Server thread/INFO]: ", " left the game"); if (!leftPlayer.equals("")) { if (collection.getServer().hasPlayer(leftPlayer)) { collection.getServer().removePlayer(leftPlayer); } - } else { - leftPlayer = stringBetween(text, "[Server thread/INFO]: ", " left the game"); - if (!leftPlayer.equals("")) { - if (collection.getServer().hasPlayer(leftPlayer)) { - collection.getServer().removePlayer(leftPlayer); - } - } } } } - } catch (Exception e) { - e.printStackTrace(); } - /* - If Not ($PlayersArray = "BUNGEE") Then - $NewDataLine = StringSplit($NewData, @CRLF, 1) - For $x = 0 To UBound($NewDataLine) - 1 - $NewPlayer = _StringBetween($NewDataLine[$x], "[Server thread/INFO]: ", " joined the game", 1, True) - If Not IsArray($NewPlayer) Then $NewPlayer = _StringBetween($NewDataLine[$x], "UUID of player ", " is ", 1, True) - $LeftPlayer = _StringBetween($NewDataLine[$x], "INFO]: ", " lost connection", 1, True) - If Not IsArray($LeftPlayer) Then $LeftPlayer = _StringBetween($NewDataLine[$x], "[Server thread/INFO]: ", " left the game", 1, True) - If IsArray($NewPlayer) Then - If _ArraySearch($PlayersArray, StringReplace($NewPlayer[0], " ", "")) = -1 Then - _ArrayAdd($PlayersArray, StringReplace($NewPlayer[0], " ", "")) - EndIf - EndIf - If IsArray($LeftPlayer) Then - _ArrayDelete($PlayersArray, _ArraySearch($PlayersArray, $LeftPlayer[0])) - EndIf - Next - EndIf - */ } /** @@ -125,11 +102,11 @@ class Main { * @param end The substring after the wanted substring * @return The wanted substring. */ - private static String stringBetween(String string, String start, String end) throws StringIndexOutOfBoundsException { - int startPos = string.indexOf(start) + start.length(); - if (string.indexOf(end, startPos) < startPos) { + private static String stringBetween(String string, String start, String end) { + if (!string.contains(start)) { return ""; } + int startPos = string.indexOf(start) + start.length(); return string.substring(startPos, string.indexOf(end, startPos)); } } \ No newline at end of file diff --git a/src/net/knarcraft/serverlauncher/server/Server.java b/src/net/knarcraft/serverlauncher/server/Server.java index 028fbe5..57a57ca 100644 --- a/src/net/knarcraft/serverlauncher/server/Server.java +++ b/src/net/knarcraft/serverlauncher/server/Server.java @@ -349,7 +349,10 @@ public class Server { * @param end The substring after the wanted substring * @return The wanted substring. */ - private String stringBetween(String string, String start, String end) { + private static String stringBetween(String string, String start, String end) { + if (!string.contains(start)) { + return ""; + } int startPos = string.indexOf(start) + start.length(); return string.substring(startPos, string.indexOf(end, startPos)); }