Archiviert
1
0

WIP Velocity: ArenaMode

Signed-off-by: Lixfel <git-5w3l@lixfel.de>
Dieser Commit ist enthalten in:
Lixfel 2024-06-16 20:13:04 +02:00
Ursprung f6f568ee40
Commit 61d42c7cca

Datei anzeigen

@ -21,15 +21,12 @@ package de.steamwar.bungeecore;
import de.steamwar.sql.SchematicType;
import lombok.Getter;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
public class ArenaMode {
@ -51,17 +48,17 @@ public class ArenaMode {
bySchemType.clear();
allModes.clear();
Yaml yaml = new Yaml();
File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem");
for(File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().toList()) {
Configuration config;
Map<String, Object> config;
try {
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
config = yaml.load(new FileInputStream(configFile));
} catch (IOException e) {
throw new SecurityException("Could not load SchematicTypes", e);
}
if(config.contains("Server"))
if(config.containsKey("Server"))
new ArenaMode(configFile.getName().replace(".yml", ""), config);
}
}
@ -118,19 +115,22 @@ public class ArenaMode {
@Getter
private final String schemType;
private ArenaMode(String internalName, Configuration config) {
private ArenaMode(String internalName, Map<String, Object> config) {
this.internalName = internalName;
this.folder = config.getString("Server.Folder");
this.serverJar = config.getString("Server.ServerJar");
this.config = internalName + ".yml";
this.maps = config.getStringList("Server.Maps");
maps.forEach(map -> lowerToRealMapNames.put(map.toLowerCase(), map));
this.displayName = config.getString("GameName", internalName);
this.chatNames = config.getStringList("Server.ChatNames");
this.schemType = config.getString("Schematic.Type", "").toLowerCase();
this.ranked = config.getBoolean("Server.Ranked", false);
this.historic = config.getBoolean("Server.Historic", false);
this.displayName = get(config, "GameName", internalName);
Map<String, Object> server = get(config, "Server");
this.folder = get(server, "Folder");
this.serverJar = get(server, "ServerJar");
this.chatNames = get(server, "ChatNames");
this.maps = get(server, "Maps");
this.ranked = get(server, "Ranked", false);
this.historic = get(server, "Historic", false);
maps.forEach(map -> lowerToRealMapNames.put(map.toLowerCase(), map));
this.schemType = get(get(config, "Schematic"), "Type", "").toLowerCase();
allModes.add(this);
byInternal.put(internalName, this);
@ -138,10 +138,17 @@ public class ArenaMode {
byChat.put(name.toLowerCase(), this);
}
if(!this.schemType.equals(""))
if(!this.schemType.isEmpty())
bySchemType.put(SchematicType.fromDB(this.schemType), this);
}
private <T> T get(Map<String, Object> config, String key) {
return (T) config.get(key);
}
private <T> T get(Map<String, Object> config, String key, T def) {
return (T) config.getOrDefault(key, def);
}
public String hasMap(String map){
for(String m : maps){
if(m.equalsIgnoreCase(map))