From 61d42c7cca424732f173e212540eafaacf48a295 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 16 Jun 2024 20:13:04 +0200 Subject: [PATCH] WIP Velocity: ArenaMode Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/ArenaMode.java | 47 +++++++++++++---------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/de/steamwar/bungeecore/ArenaMode.java b/src/de/steamwar/bungeecore/ArenaMode.java index 1608ce60..0dd0ff9e 100644 --- a/src/de/steamwar/bungeecore/ArenaMode.java +++ b/src/de/steamwar/bungeecore/ArenaMode.java @@ -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 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 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 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 get(Map config, String key) { + return (T) config.get(key); + } + private T get(Map config, String key, T def) { + return (T) config.getOrDefault(key, def); + } + public String hasMap(String map){ for(String m : maps){ if(m.equalsIgnoreCase(map))