Archiviert
1
0

Merge pull request 'Allow paper bau + small code cleanup' (#199) from paperBau into master

Reviewed-on: SteamWar/BungeeCore#199
Reviewed-by: Zeanon <thezeanon@gmail.com>
Dieser Commit ist enthalten in:
Lixfel 2021-04-14 21:00:52 +02:00
Commit d85eb5e3e7
2 geänderte Dateien mit 52 neuen und 72 gelöschten Zeilen

Datei anzeigen

@ -28,8 +28,10 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.logging.Level;
public class SubserverSystem { public class SubserverSystem {
private SubserverSystem(){} private SubserverSystem(){}
@ -41,13 +43,13 @@ public class SubserverSystem {
private static final String SERVER_PATH = BACKBONE + "server/"; private static final String SERVER_PATH = BACKBONE + "server/";
private static final String EVENT_PATH = BACKBONE + "event/"; private static final String EVENT_PATH = BACKBONE + "event/";
private static final int firstArenaPort; private static final int FIRST_ARENA_PORT;
static { static {
if(BungeeCore.EVENT_MODE) if(BungeeCore.EVENT_MODE)
firstArenaPort = 6000; FIRST_ARENA_PORT = 6000;
else 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){ 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 //Generate missing parameters
int port = freePort(firstArenaPort); int port = freePort(FIRST_ARENA_PORT);
if(serverName == null){ if(serverName == null){
if(ranked) if(ranked)
serverName = "Ranked" + (port - firstArenaPort); serverName = "Ranked" + (port - FIRST_ARENA_PORT);
else else
serverName = modus.getDisplayName() + (port - firstArenaPort); serverName = modus.getDisplayName() + (port - FIRST_ARENA_PORT);
} }
if(mapName == null) if(mapName == null)
mapName = serverName; mapName = serverName;
@ -109,8 +111,11 @@ public class SubserverSystem {
//Copy world //Copy world
try { try {
new ProcessBuilder("cp", "-r", SERVER_PATH + modus.getFolder() + "/arenas/" + map, worldDir + mapName).start().waitFor(); 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); 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( List<String> cmd = serverStartCommand(
@ -125,8 +130,8 @@ public class SubserverSystem {
"ranked=" + ranked, "ranked=" + ranked,
"checkSchemID=" + checkSchemID, "checkSchemID=" + checkSchemID,
"prepareSchemID=" + prepareSchemID, "prepareSchemID=" + prepareSchemID,
player1 != null && eventFightID != -1 ? "blueLeader=" + player1.toString() : null, player1 != null && eventFightID != -1 ? "blueLeader=" + player1 : null,
player2 != null ? "redLeader=" + player2.toString() : null); player2 != null ? "redLeader=" + player2 : null);
//Start server //Start server
ProcessBuilder process = new ProcessBuilder(cmd); ProcessBuilder process = new ProcessBuilder(cmd);
@ -134,26 +139,26 @@ public class SubserverSystem {
String finalMapName = mapName; String finalMapName = mapName;
if(eventFightID == -1) if(eventFightID == -1)
return new Bauserver(serverName, player1, port, process, () -> { return new Bauserver(serverName, player1, port, process, () -> deleteFolder(ARENA_PATH + finalMapName));
try {
new ProcessBuilder("rm", "-r", ARENA_PATH + finalMapName).start().waitFor();
} catch (IOException | InterruptedException e) {
throw new SecurityException("Could not clean up folder", e);
}
});
else else
return new Subserver(Servertype.ARENA, serverName, port, process, () -> { return new Subserver(Servertype.ARENA, serverName, port, process, () -> {
if(eventFightID > 0) if(eventFightID > 0)
return; return;
deleteFolder(ARENA_PATH + finalMapName);
try {
new ProcessBuilder("rm", "-r", ARENA_PATH + finalMapName).start().waitFor();
} catch (IOException | InterruptedException e) {
throw new SecurityException("Could not clean up folder", e);
}
}); });
} }
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){ public static Subserver startEventArena(EventFight eventFight, String serverName){
return startArena( return startArena(
eventFight.getSpielmodus(), 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); 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)) if(bauRunning(p, owner))
return; return;
SteamwarUser user = SteamwarUser.get(owner); SteamwarUser user = SteamwarUser.get(owner);
copyBauweltIfRequired(p, BungeeCore.BAUWELT_PROTOTYP, BungeeCore.WORLD_FOLDER + owner.toString()); copyBauweltIfRequired(p, prototype, worldFolder + worldName);
int port = freePort(4000); int port = freePort(4000);
List<String> cmd = serverStartCommand( List<String> cmd = serverStartCommand(
"spigot-1.12.2.jar", serverJar,
"/home/minecraft/userworlds", worldDir,
owner.toString(), worldName,
port, port,
"256M", xmx,
"logPath=" + owner.toString()); "logPath=" + worldName);
//Start server //Start server
ProcessBuilder process = new ProcessBuilder(cmd); 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); new Bauserver(user.getUserName() + "s Bau", owner, port, process, () -> {}).sendPlayer(p);
} }
public static void sendToBau15(ProxiedPlayer p, UUID owner){ public static void sendToBauServer(ProxiedPlayer p, UUID owner){
if(bauRunning(p, owner)) sendToBau(p, owner, BungeeCore.BAUWELT_PROTOTYP, BungeeCore.WORLD_FOLDER, "spigot-1.12.2.jar", "/home/minecraft/userworlds", owner.toString(), "256M", "UserBau");
return; }
private static void sendToBau15(ProxiedPlayer p, UUID owner, String serverJar){
SteamwarUser user = SteamwarUser.get(owner); SteamwarUser user = SteamwarUser.get(owner);
copyBauweltIfRequired(p, BungeeCore.BAUWELT15, BungeeCore.USERWORLDS15 + user.getId()); sendToBau(p, owner, BungeeCore.BAUWELT15, BungeeCore.USERWORLDS15, serverJar, "/home/minecraft/userworlds15", String.valueOf(user.getId()), "512M", "Bau15");
int port = freePort(4000); }
List<String> cmd = serverStartCommand( public static void sendToBau15(ProxiedPlayer p, UUID owner){
"spigot-1.15.2.jar", sendToBau15(p, owner, "spigot-1.15.2.jar");
"/home/minecraft/userworlds15", }
String.valueOf(user.getId()),
port,
"512M",
"logPath=" + user.getId());
//Start server public static void sendToBau15paper(ProxiedPlayer p, UUID owner){
ProcessBuilder process = new ProcessBuilder(cmd); sendToBau15(p, owner, "paper-1.15.2.jar");
process.directory(new File(SERVER_PATH, "Bau15"));
new Bauserver(user.getUserName() + "s Bau", owner, port, process, () -> {}).sendPlayer(p);
} }
public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){ public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){
@ -274,11 +273,7 @@ public class SubserverSystem {
File w = new File(targetPath); File w = new File(targetPath);
if (!w.exists() || !w.isDirectory()){ if (!w.exists() || !w.isDirectory()){
try { try {
Process pr; new ProcessBuilder("cp", "-r", sourcePath, targetPath).start().waitFor();
ProcessBuilder pb = new ProcessBuilder(
"cp", "-r", sourcePath, targetPath);
pr = pb.start();
pr.waitFor();
} catch (IOException e) { } catch (IOException e) {
Message.send("SERVER_WORLD_ERROR", p); Message.send("SERVER_WORLD_ERROR", p);
throw new SecurityException("Could not create Bauwelt", e); throw new SecurityException("Could not create Bauwelt", e);
@ -298,7 +293,7 @@ public class SubserverSystem {
port++; port++;
isFree = true; isFree = true;
for(Subserver server : Subserver.getServerList()){ for(Subserver server : Subserver.getServerList()){
if(server.getServer().getAddress().getPort() == port){ if(((InetSocketAddress)server.getServer().getSocketAddress()).getPort() == port){
isFree = false; isFree = false;
break; break;
} }

Datei anzeigen

@ -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.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.event.ChatEvent;
import java.io.File;
public class BauCommand { public class BauCommand {
private BauCommand(){} private BauCommand(){}
@ -70,6 +68,9 @@ public class BauCommand {
case "1.15": case "1.15":
SubserverSystem.sendToBau15(p, p.getUniqueId()); SubserverSystem.sendToBau15(p, p.getUniqueId());
break; break;
case "paper":
SubserverSystem.sendToBau15paper(p, p.getUniqueId());
break;
case "addmember": case "addmember":
addmember(p, command); addmember(p, command);
break; break;
@ -251,8 +252,7 @@ public class BauCommand {
break; break;
} }
} }
File directory = new File(world); SubserverSystem.deleteFolder(world);
del(directory);
}); });
} }
@ -318,19 +318,4 @@ public class BauCommand {
Message.send("BAU_MEMBER_TOGGLE_OFF", p, what); 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();
}
}
} }