Archiviert
1
0

Merge pull request 'Adjust config for new fight system' (#192) from newFightSystem into master

Reviewed-on: SteamWar/BungeeCore#192
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2021-03-31 20:07:00 +02:00
Commit e83d2686cb
11 geänderte Dateien mit 116 neuen und 60 gelöschten Zeilen

Datei anzeigen

@ -19,17 +19,18 @@
package de.steamwar.bungeecore; package de.steamwar.bungeecore;
import de.steamwar.bungeecore.sql.SchematicType;
import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.Configuration;
import java.util.*; import java.util.*;
public class ArenaMode { public class ArenaMode {
private static Map<String, ArenaMode> byChat = new HashMap<>(); private static final Map<String, ArenaMode> byChat = new HashMap<>();
private static Map<String, ArenaMode> byInternal = new HashMap<>(); private static final Map<String, ArenaMode> byInternal = new HashMap<>();
private static Map<String, ArenaMode> byCheckSchemType = new HashMap<>(); private static final Map<SchematicType, ArenaMode> bySchemType = new HashMap<>();
private static List<ArenaMode> allModes = new LinkedList<>(); private static final List<ArenaMode> allModes = new LinkedList<>();
private static Random random = new Random(); private static final Random random = new Random();
static void init(Configuration config){ static void init(Configuration config){
for(String internalName : config.getKeys()){ for(String internalName : config.getKeys()){
@ -63,32 +64,39 @@ public class ArenaMode {
return chatNames; return chatNames;
} }
public static ArenaMode getByCheckSchemType(String checkSchemType){ public static ArenaMode getBySchemType(SchematicType schemType){
return byCheckSchemType.get(checkSchemType); return bySchemType.get(schemType);
} }
public static List<ArenaMode> getAllModes(){ public static List<ArenaMode> getAllModes(){
return allModes; return allModes;
} }
private final String internalName;
private final String displayName; private final String displayName;
private final String folder;
private final List<String> chatNames; private final List<String> chatNames;
private final String serverJar; private final String serverJar;
private final String config;
private final List<String> maps; private final List<String> maps;
private final boolean historic; private final boolean historic;
private final boolean ranked; private final boolean ranked;
private final String schemType; private final String schemType;
private ArenaMode(String internalName, Configuration config){ private ArenaMode(String internalName, Configuration config){
this.internalName = internalName; this.folder = config.getString("folder");
this.displayName = config.getString("displayName");
this.serverJar = config.getString("serverJar"); this.serverJar = config.getString("serverJar");
this.chatNames = config.getStringList("chatNames"); this.config = config.getString("config");
this.maps = config.getStringList("maps"); this.maps = config.getStringList("maps");
this.displayName = config.getString("displayName", internalName);
if(config.contains("chatNames"))
this.chatNames = config.getStringList("chatNames");
else
this.chatNames = Collections.emptyList();
this.historic = config.getBoolean("historic", false); this.historic = config.getBoolean("historic", false);
this.schemType = config.getString("schemType", "").toLowerCase();
this.ranked = config.getBoolean("ranked", false); this.ranked = config.getBoolean("ranked", false);
this.schemType = config.getString("schemType", null);
allModes.add(this); allModes.add(this);
byInternal.put(internalName, this); byInternal.put(internalName, this);
@ -96,12 +104,8 @@ public class ArenaMode {
byChat.put(name.toLowerCase(), this); byChat.put(name.toLowerCase(), this);
} }
if(config.contains("checkSchemType")) if(!this.schemType.equals(""))
byCheckSchemType.put(config.getString("checkSchemType").toLowerCase(), this); bySchemType.put(SchematicType.fromDB(this.schemType), this);
}
public String getInternalName() {
return internalName;
} }
public String getDisplayName() { public String getDisplayName() {
@ -112,6 +116,10 @@ public class ArenaMode {
return serverJar; return serverJar;
} }
public String getConfig(){
return config;
}
public String hasMap(String map){ public String hasMap(String map){
for(String m : maps){ for(String m : maps){
if(m.equalsIgnoreCase(map)) if(m.equalsIgnoreCase(map))
@ -120,6 +128,10 @@ public class ArenaMode {
return null; return null;
} }
public String getFolder() {
return folder;
}
public String getRandomMap(){ public String getRandomMap(){
return maps.get(random.nextInt(maps.size())); return maps.get(random.nextInt(maps.size()));
} }
@ -132,8 +144,8 @@ public class ArenaMode {
return chatNames.get(0); return chatNames.get(0);
} }
public boolean hasChatName(){ public boolean withoutChatName(){
return !chatNames.isEmpty(); return chatNames.isEmpty();
} }
public boolean isHistoric(){ public boolean isHistoric(){

Datei anzeigen

@ -87,7 +87,7 @@ public class SubserverSystem {
* @return * @return
* The new started subserver. * The new started subserver.
*/ */
public static Subserver startArena(ArenaMode modus, String map, int eventFightID, int checkSchemID, 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(firstArenaPort);
@ -108,7 +108,7 @@ public class SubserverSystem {
//Copy world //Copy world
try { try {
new ProcessBuilder("cp", "-r", SERVER_PATH + modus.getInternalName() + "/" + 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 | InterruptedException e) {
throw new SecurityException("Could not copy folder", e); throw new SecurityException("Could not copy folder", e);
} }
@ -120,15 +120,17 @@ public class SubserverSystem {
port, port,
"2G", "2G",
"logPath=" + mapName, "logPath=" + mapName,
"config="+modus.getConfig(),
"fightID=" + eventFightID, "fightID=" + eventFightID,
"ranked=" + ranked, "ranked=" + ranked,
"checkSchemID=" + checkSchemID, "checkSchemID=" + checkSchemID,
"prepareSchemID=" + prepareSchemID,
player1 != null && eventFightID != -1 ? "blueLeader=" + player1.toString() : null, player1 != null && eventFightID != -1 ? "blueLeader=" + player1.toString() : null,
player2 != null ? "redLeader=" + player2.toString() : null); player2 != null ? "redLeader=" + player2.toString() : null);
//Start server //Start server
ProcessBuilder process = new ProcessBuilder(cmd); ProcessBuilder process = new ProcessBuilder(cmd);
process.directory(new File(SERVER_PATH, modus.getInternalName())); process.directory(new File(SERVER_PATH, modus.getFolder()));
String finalMapName = mapName; String finalMapName = mapName;
if(eventFightID == -1) if(eventFightID == -1)
@ -152,24 +154,22 @@ public class SubserverSystem {
}); });
} }
public static Subserver startArena(ArenaMode modus, String map, int eventFightID, int checkSchemID, String serverName, String mapName, UUID player1, UUID player2){
return startArena(modus, map, eventFightID, checkSchemID, serverName, mapName, player1, player2, false);
}
public static Subserver startEventArena(EventFight eventFight, String serverName){ public static Subserver startEventArena(EventFight eventFight, String serverName){
return startArena( return startArena(
eventFight.getSpielmodus(), eventFight.getSpielmodus(),
eventFight.getMap(), eventFight.getMap(),
eventFight.getFightID(), eventFight.getFightID(),
0, 0,
0,
serverName, serverName,
serverName.replace(' ', '_') + eventFight.getStartTime().toLocalDateTime().format(DateTimeFormatter.ISO_TIME), serverName.replace(' ', '_') + eventFight.getStartTime().toLocalDateTime().format(DateTimeFormatter.ISO_TIME),
null, null,
null); null,
false);
} }
public static void startTestServer(ProxiedPlayer p, ArenaMode m, String map, int checkSchemId){ public static void startTestServer(ProxiedPlayer p, ArenaMode m, String map, int checkSchemId, int prepareSchemId){
startArena(m, map, -1, checkSchemId, p.getName() + "s Bau", p.getName(), p.getUniqueId(), null).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){ public static void sendToBauServer(ProxiedPlayer p, UUID owner){

Datei anzeigen

@ -266,24 +266,28 @@ public class BauCommand {
}); });
} }
public static void stopBauserver(ProxiedPlayer p){
for (Subserver subserver : Subserver.getServerList()) {
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(p.getUniqueId())) {
if(subserver.getServer().getPlayers().isEmpty()){
Message.send("BAU_START_ALREADY", p);
return;
}
subserver.stop();
try {
Thread.sleep(200); // Wait until possible testarena-World has been deleted
} catch (InterruptedException e) {
throw new SecurityException("Subserver stop interrupted", e);
}
break;
}
}
}
private static void testarena(ProxiedPlayer p, String[] command){ private static void testarena(ProxiedPlayer p, String[] command){
FightCommand.createArena(p, "/bau testarena ", command, 2, false, (player, mode, map) -> ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { FightCommand.createArena(p, "/bau testarena ", command, 2, false, (player, mode, map) -> ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
for (Subserver subserver : Subserver.getServerList()) { stopBauserver(p);
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(p.getUniqueId())) { SubserverSystem.startTestServer(p, mode, map, 0, 0);
if(subserver.getServer().getPlayers().isEmpty()){
Message.send("BAU_START_ALREADY", p);
return;
}
subserver.stop();
try {
Thread.sleep(200); // Wait until possible testarena-World has been deleted
} catch (InterruptedException e) {
throw new SecurityException("Subserver stop interrupted", e);
}
break;
}
}
SubserverSystem.startTestServer(p, mode, map, 0);
})); }));
} }

Datei anzeigen

@ -75,7 +75,7 @@ public class ChallengeCommand extends BasicCommand {
challenges.remove(target); challenges.remove(target);
challenges.remove(player); challenges.remove(player);
Subserver arena = SubserverSystem.startArena(mode, map, 0, 0, null, null, player.getUniqueId(), target.getUniqueId()); Subserver arena = SubserverSystem.startArena(mode, map, 0, 0, 0, null, null, player.getUniqueId(), target.getUniqueId(), false);
arena.sendPlayer(player); arena.sendPlayer(player);
arena.sendPlayer(target); arena.sendPlayer(target);

Datei anzeigen

@ -223,15 +223,10 @@ public class CheckCommand extends BasicCommand {
this.checkList = checkQuestions.get(schematic.getSchemType()).listIterator(); this.checkList = checkQuestions.get(schematic.getSchemType()).listIterator();
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
for (Subserver subserver : Subserver.getServerList()) { BauCommand.stopBauserver(checker);
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(checker.getUniqueId())) {
subserver.stop();
break;
}
}
ArenaMode mode = ArenaMode.getByCheckSchemType(schematic.getSchemType().toDB()); ArenaMode mode = ArenaMode.getBySchemType(schematic.getSchemType().fightType());
SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getSchemID()); SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getSchemID(), 0);
currentCheckers.put(checker.getUniqueId(), this); currentCheckers.put(checker.getUniqueId(), this);
currentSchems.put(schematic.getSchemID(), this); currentSchems.put(schematic.getSchemID(), this);
for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic.getSchemName(), schematic.getSchemOwner())) for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic.getSchemName(), schematic.getSchemOwner()))

Datei anzeigen

@ -69,7 +69,7 @@ public class FightCommand extends BasicCommand {
TextComponent start = new TextComponent(); TextComponent start = new TextComponent();
TextComponent current = start; TextComponent current = start;
for(ArenaMode mode : ArenaMode.getAllModes()){ for(ArenaMode mode : ArenaMode.getAllModes()){
if(!mode.hasChatName() || mode.isHistoric() != historic) if(mode.withoutChatName() || mode.isHistoric() != historic)
continue; continue;
String command = precommand + mode.getChatName(); String command = precommand + mode.getChatName();
current.setBold(true); current.setBold(true);
@ -164,7 +164,7 @@ public class FightCommand extends BasicCommand {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
createArena(sender, "/fight ", args, 0, false, (player, mode, map) -> { createArena(sender, "/fight ", args, 0, false, (player, mode, map) -> {
Subserver arena = SubserverSystem.startArena(mode, map, 0, 0, null, null, player.getUniqueId(), null); Subserver arena = SubserverSystem.startArena(mode, map, 0, 0, 0, null, null, player.getUniqueId(), null, false);
arena.sendPlayer(player); arena.sendPlayer(player);
Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER" Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER"
, new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), mode.getDisplayName(), player.getName()); , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), mode.getDisplayName(), player.getName());

Datei anzeigen

@ -33,7 +33,7 @@ public class HistoricCommand extends BasicCommand {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
FightCommand.createArena(sender, "/historic ", args, 0, true, (player, mode, map) -> { FightCommand.createArena(sender, "/historic ", args, 0, true, (player, mode, map) -> {
Subserver arena = SubserverSystem.startArena(mode, map, 0, 0, null, null, player.getUniqueId(), null); Subserver arena = SubserverSystem.startArena(mode, map, 0, 0, 0, null, null, player.getUniqueId(), null, false);
arena.sendPlayer(player); arena.sendPlayer(player);
Message.broadcast("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER" Message.broadcast("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER"
, new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), mode.getDisplayName(), player.getName()); , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), mode.getDisplayName(), player.getName());

Datei anzeigen

@ -81,7 +81,7 @@ public class RankedCommand extends BasicCommand {
TextComponent start = new TextComponent(); TextComponent start = new TextComponent();
TextComponent current = start; TextComponent current = start;
for(ArenaMode mode : ArenaMode.getAllModes()){ for(ArenaMode mode : ArenaMode.getAllModes()){
if(!mode.hasChatName() || !mode.isRanked()) if(mode.withoutChatName() || !mode.isRanked())
continue; continue;
String command = precommand + mode.getChatName(); String command = precommand + mode.getChatName();
current.setBold(true); current.setBold(true);
@ -165,7 +165,7 @@ public class RankedCommand extends BasicCommand {
removeFromAll(wp1.player); removeFromAll(wp1.player);
removeFromAll(wp2.player); removeFromAll(wp2.player);
Subserver arena = SubserverSystem.startArena(mode, mode.getRandomMap(), 0, 0, null, null, wp1.player.getUniqueId(), wp2.player.getUniqueId(), true); Subserver arena = SubserverSystem.startArena(mode, mode.getRandomMap(), 0, 0, 0, null, null, wp1.player.getUniqueId(), wp2.player.getUniqueId(), true);
arena.sendPlayer(wp1.player); arena.sendPlayer(wp1.player);
arena.sendPlayer(wp2.player); arena.sendPlayer(wp2.player);

Datei anzeigen

@ -24,6 +24,7 @@ public class PacketIdManager {
//0x0(X) Standalone Packets //0x0(X) Standalone Packets
public static final byte PING_PACKET = 0x01; public static final byte PING_PACKET = 0x01;
public static final byte TABLIST_NAME = 0x02; public static final byte TABLIST_NAME = 0x02;
public static final byte PREPARE_SCHEM = 0x03;
//0x1(X) Bungee Inventory //0x1(X) Bungee Inventory
public static final byte INVENTORY_PACKET = 0x10; public static final byte INVENTORY_PACKET = 0x10;

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.bungeecore.comms;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import de.steamwar.bungeecore.comms.handlers.InventoryCallbackHandler; import de.steamwar.bungeecore.comms.handlers.InventoryCallbackHandler;
import de.steamwar.bungeecore.comms.handlers.PrepareSchemHandler;
import de.steamwar.bungeecore.comms.handlers.TablistNameHandler; import de.steamwar.bungeecore.comms.handlers.TablistNameHandler;
import de.steamwar.bungeecore.listeners.BasicListener; import de.steamwar.bungeecore.listeners.BasicListener;
import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.PluginMessageEvent;
@ -55,5 +56,6 @@ public class SpigotReceiver extends BasicListener {
static { static {
registerHandler(PacketIdManager.INVENTORY_CALLBACK_PACKET, new InventoryCallbackHandler()); registerHandler(PacketIdManager.INVENTORY_CALLBACK_PACKET, new InventoryCallbackHandler());
registerHandler(PacketIdManager.TABLIST_NAME, new TablistNameHandler()); registerHandler(PacketIdManager.TABLIST_NAME, new TablistNameHandler());
registerHandler(PacketIdManager.PREPARE_SCHEM, new PrepareSchemHandler());
} }
} }

Datei anzeigen

@ -0,0 +1,42 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms.handlers;
import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.ArenaMode;
import de.steamwar.bungeecore.SubserverSystem;
import de.steamwar.bungeecore.commands.BauCommand;
import de.steamwar.bungeecore.comms.SpigotHandler;
import de.steamwar.bungeecore.sql.SchematicType;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
public class PrepareSchemHandler implements SpigotHandler {
@Override
public void handle(ByteArrayDataInput byteArrayDataInput) {
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUuid());
int schematicID = byteArrayDataInput.readInt();
ArenaMode mode = ArenaMode.getBySchemType(SchematicType.fromDB(byteArrayDataInput.readUTF()));
BauCommand.stopBauserver(player);
SubserverSystem.startTestServer(player, mode, mode.getRandomMap(), 0, schematicID);
}
}