2018-01-31 21:24:54 +01:00
|
|
|
import net.knarcraft.serverlauncher.profile.Collection;
|
2018-01-28 19:06:50 +01:00
|
|
|
import net.knarcraft.serverlauncher.profile.Profile;
|
2018-01-29 20:14:17 +01:00
|
|
|
import net.knarcraft.serverlauncher.server.ServerType;
|
2018-01-26 20:26:16 +01:00
|
|
|
import net.knarcraft.serverlauncher.userinterface.GUI;
|
2018-01-30 19:35:42 +01:00
|
|
|
import net.knarcraft.serverlauncher.userinterface.ServerConsoles;
|
2018-01-26 20:26:16 +01:00
|
|
|
|
2018-01-25 17:34:45 +01:00
|
|
|
import javax.naming.ConfigurationException;
|
2018-01-27 23:34:02 +01:00
|
|
|
import java.awt.*;
|
2018-01-31 21:24:54 +01:00
|
|
|
import java.io.IOException;
|
2018-01-30 00:44:03 +01:00
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
2018-01-29 20:14:17 +01:00
|
|
|
//Java 8 required.
|
2018-01-24 12:18:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A software for managing Minecraft servers.
|
2018-01-25 21:17:02 +01:00
|
|
|
*
|
|
|
|
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
|
|
|
* @version 0.0.0.1
|
|
|
|
* @since 0.0.0.1
|
2018-01-24 12:18:06 +01:00
|
|
|
*/
|
2018-01-26 23:15:19 +01:00
|
|
|
|
2018-01-26 20:34:15 +01:00
|
|
|
class Main {
|
2018-01-23 23:39:37 +01:00
|
|
|
public static void main(String[] args) {
|
2018-01-27 23:34:02 +01:00
|
|
|
EventQueue.invokeLater(() -> {
|
|
|
|
try {
|
|
|
|
setup();
|
2018-01-28 19:06:50 +01:00
|
|
|
new GUI();
|
2018-01-31 17:40:28 +01:00
|
|
|
new ServerConsoles();
|
2018-01-28 19:06:50 +01:00
|
|
|
Profile.addProfile("Default");
|
2018-01-30 00:44:03 +01:00
|
|
|
//TODO: replace with profiles loading generating a default profile if empty.
|
|
|
|
|
|
|
|
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
|
|
|
|
exec.scheduleAtFixedRate(() -> {
|
2018-01-31 21:24:54 +01:00
|
|
|
for (Collection collection : GUI.getGUI().currentProfile().getCollections()) {
|
|
|
|
if (collection.getServer().isEnabled() && collection.getServer().getProcess() != null) {
|
|
|
|
try {
|
|
|
|
String readText = collection.getServer().read();
|
|
|
|
if (!readText.equals("")) {
|
|
|
|
collection.getServerConsole().output(readText);
|
2018-02-01 13:16:25 +01:00
|
|
|
updatePlayerList(readText, collection);
|
2018-01-31 21:24:54 +01:00
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 10, 250, TimeUnit.MILLISECONDS);
|
2018-01-27 23:34:02 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
});
|
2018-01-25 21:17:02 +01:00
|
|
|
}
|
|
|
|
|
2018-01-26 20:34:15 +01:00
|
|
|
private static void setup() {
|
2018-01-25 17:34:45 +01:00
|
|
|
try {
|
2018-01-25 21:17:02 +01:00
|
|
|
ServerType.loadServerTypes();
|
2018-01-25 17:34:45 +01:00
|
|
|
} catch (ConfigurationException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(1);
|
|
|
|
}
|
2018-01-23 23:39:37 +01:00
|
|
|
}
|
2018-02-01 13:16:25 +01:00
|
|
|
|
|
|
|
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 (!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 (!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
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds a substring between two substrings in a string.
|
|
|
|
*
|
|
|
|
* @param string The string containing the substrings
|
|
|
|
* @param start The substring before the wanted substring
|
|
|
|
* @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) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return string.substring(startPos, string.indexOf(end, startPos));
|
|
|
|
}
|
2018-01-23 23:39:37 +01:00
|
|
|
}
|