geforkt von SteamWar/BungeeCore
Allow paper bau + small code cleanup
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
3a23ab5f36
Commit
3676051e40
@ -28,8 +28,10 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class SubserverSystem {
|
||||
private SubserverSystem(){}
|
||||
@ -41,13 +43,13 @@ public class SubserverSystem {
|
||||
private static final String SERVER_PATH = BACKBONE + "server/";
|
||||
private static final String EVENT_PATH = BACKBONE + "event/";
|
||||
|
||||
private static final int firstArenaPort;
|
||||
private static final int FIRST_ARENA_PORT;
|
||||
|
||||
static {
|
||||
if(BungeeCore.EVENT_MODE)
|
||||
firstArenaPort = 6000;
|
||||
FIRST_ARENA_PORT = 6000;
|
||||
else
|
||||
firstArenaPort = 2500;
|
||||
FIRST_ARENA_PORT = 2500;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,13 +91,13 @@ public class SubserverSystem {
|
||||
*/
|
||||
public static Subserver startArena(ArenaMode modus, String map, int eventFightID, int checkSchemID, int prepareSchemID, String serverName, String mapName, UUID player1, UUID player2, boolean ranked){
|
||||
//Generate missing parameters
|
||||
int port = freePort(firstArenaPort);
|
||||
int port = freePort(FIRST_ARENA_PORT);
|
||||
|
||||
if(serverName == null){
|
||||
if(ranked)
|
||||
serverName = "Ranked" + (port - firstArenaPort);
|
||||
serverName = "Ranked" + (port - FIRST_ARENA_PORT);
|
||||
else
|
||||
serverName = modus.getDisplayName() + (port - firstArenaPort);
|
||||
serverName = modus.getDisplayName() + (port - FIRST_ARENA_PORT);
|
||||
}
|
||||
if(mapName == null)
|
||||
mapName = serverName;
|
||||
@ -109,8 +111,11 @@ public class SubserverSystem {
|
||||
//Copy world
|
||||
try {
|
||||
new ProcessBuilder("cp", "-r", SERVER_PATH + modus.getFolder() + "/arenas/" + map, worldDir + mapName).start().waitFor();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException("Could not copy folder", e);
|
||||
} catch (InterruptedException e) {
|
||||
ProxyServer.getInstance().getLogger().log(Level.SEVERE, "Interrupted while copying folder", e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
List<String> cmd = serverStartCommand(
|
||||
@ -125,8 +130,8 @@ public class SubserverSystem {
|
||||
"ranked=" + ranked,
|
||||
"checkSchemID=" + checkSchemID,
|
||||
"prepareSchemID=" + prepareSchemID,
|
||||
player1 != null && eventFightID != -1 ? "blueLeader=" + player1.toString() : null,
|
||||
player2 != null ? "redLeader=" + player2.toString() : null);
|
||||
player1 != null && eventFightID != -1 ? "blueLeader=" + player1 : null,
|
||||
player2 != null ? "redLeader=" + player2 : null);
|
||||
|
||||
//Start server
|
||||
ProcessBuilder process = new ProcessBuilder(cmd);
|
||||
@ -134,26 +139,26 @@ public class SubserverSystem {
|
||||
|
||||
String finalMapName = mapName;
|
||||
if(eventFightID == -1)
|
||||
return new Bauserver(serverName, player1, port, process, () -> {
|
||||
try {
|
||||
new ProcessBuilder("rm", "-r", ARENA_PATH + finalMapName).start().waitFor();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new SecurityException("Could not clean up folder", e);
|
||||
}
|
||||
});
|
||||
return new Bauserver(serverName, player1, port, process, () -> deleteFolder(ARENA_PATH + finalMapName));
|
||||
else
|
||||
return new Subserver(Servertype.ARENA, serverName, port, process, () -> {
|
||||
if(eventFightID > 0)
|
||||
return;
|
||||
|
||||
try {
|
||||
new ProcessBuilder("rm", "-r", ARENA_PATH + finalMapName).start().waitFor();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new SecurityException("Could not clean up folder", e);
|
||||
}
|
||||
deleteFolder(ARENA_PATH + finalMapName);
|
||||
});
|
||||
}
|
||||
|
||||
public static void deleteFolder(String worldName){
|
||||
try {
|
||||
new ProcessBuilder("rm", "-r", worldName).start().waitFor();
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException("Could not clean up folder", e);
|
||||
} catch (InterruptedException e) {
|
||||
ProxyServer.getInstance().getLogger().log(Level.SEVERE, "Interrupted while deleting folder", e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public static Subserver startEventArena(EventFight eventFight, String serverName){
|
||||
return startArena(
|
||||
eventFight.getSpielmodus(),
|
||||
@ -172,50 +177,44 @@ public class SubserverSystem {
|
||||
startArena(m, map, -1, checkSchemId, prepareSchemId, p.getName() + "s Bau", p.getName(), p.getUniqueId(), null, false).sendPlayer(p);
|
||||
}
|
||||
|
||||
public static void sendToBauServer(ProxiedPlayer p, UUID owner){
|
||||
private static void sendToBau(ProxiedPlayer p, UUID owner, String prototype, String worldFolder, String serverJar, String worldDir, String worldName, String xmx, String serverName){
|
||||
if(bauRunning(p, owner))
|
||||
return;
|
||||
|
||||
SteamwarUser user = SteamwarUser.get(owner);
|
||||
copyBauweltIfRequired(p, BungeeCore.BAUWELT_PROTOTYP, BungeeCore.WORLD_FOLDER + owner.toString());
|
||||
copyBauweltIfRequired(p, prototype, worldFolder + worldName);
|
||||
int port = freePort(4000);
|
||||
|
||||
List<String> cmd = serverStartCommand(
|
||||
"spigot-1.12.2.jar",
|
||||
"/home/minecraft/userworlds",
|
||||
owner.toString(),
|
||||
serverJar,
|
||||
worldDir,
|
||||
worldName,
|
||||
port,
|
||||
"256M",
|
||||
"logPath=" + owner.toString());
|
||||
xmx,
|
||||
"logPath=" + worldName);
|
||||
|
||||
//Start server
|
||||
ProcessBuilder process = new ProcessBuilder(cmd);
|
||||
process.directory(new File(SERVER_PATH, "UserBau"));
|
||||
process.directory(new File(SERVER_PATH, serverName));
|
||||
|
||||
new Bauserver(user.getUserName() + "s Bau", owner, port, process, () -> {}).sendPlayer(p);
|
||||
}
|
||||
|
||||
public static void sendToBau15(ProxiedPlayer p, UUID owner){
|
||||
if(bauRunning(p, owner))
|
||||
return;
|
||||
public static void sendToBauServer(ProxiedPlayer p, UUID owner){
|
||||
sendToBau(p, owner, BungeeCore.BAUWELT_PROTOTYP, BungeeCore.WORLD_FOLDER, "spigot-1.12.2.jar", "/home/minecraft/userworlds", owner.toString(), "256M", "UserBau");
|
||||
}
|
||||
|
||||
private static void sendToBau15(ProxiedPlayer p, UUID owner, String serverJar){
|
||||
SteamwarUser user = SteamwarUser.get(owner);
|
||||
copyBauweltIfRequired(p, BungeeCore.BAUWELT15, BungeeCore.USERWORLDS15 + user.getId());
|
||||
int port = freePort(4000);
|
||||
sendToBau(p, owner, BungeeCore.BAUWELT15, BungeeCore.USERWORLDS15, serverJar, "/home/minecraft/userworlds15", String.valueOf(user.getId()), "512M", "Bau15");
|
||||
}
|
||||
|
||||
List<String> cmd = serverStartCommand(
|
||||
"spigot-1.15.2.jar",
|
||||
"/home/minecraft/userworlds15",
|
||||
String.valueOf(user.getId()),
|
||||
port,
|
||||
"512M",
|
||||
"logPath=" + user.getId());
|
||||
public static void sendToBau15(ProxiedPlayer p, UUID owner){
|
||||
sendToBau15(p, owner, "spigot-1.15.2.jar");
|
||||
}
|
||||
|
||||
//Start server
|
||||
ProcessBuilder process = new ProcessBuilder(cmd);
|
||||
process.directory(new File(SERVER_PATH, "Bau15"));
|
||||
|
||||
new Bauserver(user.getUserName() + "s Bau", owner, port, process, () -> {}).sendPlayer(p);
|
||||
public static void sendToBau15paper(ProxiedPlayer p, UUID owner){
|
||||
sendToBau15(p, owner, "paper-1.15.2.jar");
|
||||
}
|
||||
|
||||
public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){
|
||||
@ -274,11 +273,7 @@ public class SubserverSystem {
|
||||
File w = new File(targetPath);
|
||||
if (!w.exists() || !w.isDirectory()){
|
||||
try {
|
||||
Process pr;
|
||||
ProcessBuilder pb = new ProcessBuilder(
|
||||
"cp", "-r", sourcePath, targetPath);
|
||||
pr = pb.start();
|
||||
pr.waitFor();
|
||||
new ProcessBuilder("cp", "-r", sourcePath, targetPath).start().waitFor();
|
||||
} catch (IOException e) {
|
||||
Message.send("SERVER_WORLD_ERROR", p);
|
||||
throw new SecurityException("Could not create Bauwelt", e);
|
||||
@ -298,7 +293,7 @@ public class SubserverSystem {
|
||||
port++;
|
||||
isFree = true;
|
||||
for(Subserver server : Subserver.getServerList()){
|
||||
if(server.getServer().getAddress().getPort() == port){
|
||||
if(((InetSocketAddress)server.getServer().getSocketAddress()).getPort() == port){
|
||||
isFree = false;
|
||||
break;
|
||||
}
|
||||
|
@ -28,8 +28,6 @@ import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class BauCommand {
|
||||
|
||||
private BauCommand(){}
|
||||
@ -70,6 +68,9 @@ public class BauCommand {
|
||||
case "1.15":
|
||||
SubserverSystem.sendToBau15(p, p.getUniqueId());
|
||||
break;
|
||||
case "paper":
|
||||
SubserverSystem.sendToBau15paper(p, p.getUniqueId());
|
||||
break;
|
||||
case "addmember":
|
||||
addmember(p, command);
|
||||
break;
|
||||
@ -251,8 +252,7 @@ public class BauCommand {
|
||||
break;
|
||||
}
|
||||
}
|
||||
File directory = new File(world);
|
||||
del(directory);
|
||||
SubserverSystem.deleteFolder(world);
|
||||
});
|
||||
}
|
||||
|
||||
@ -318,19 +318,4 @@ public class BauCommand {
|
||||
Message.send("BAU_MEMBER_TOGGLE_OFF", p, what);
|
||||
}
|
||||
}
|
||||
|
||||
private static void del(File dir){
|
||||
if (dir.isDirectory()){
|
||||
String[] entries = dir.list();
|
||||
assert entries != null;
|
||||
for (String entry : entries) {
|
||||
File aktFile = new File(dir.getPath(), entry);
|
||||
del(aktFile);
|
||||
}
|
||||
dir.delete();
|
||||
}
|
||||
else{
|
||||
dir.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren