SteamWar/BungeeCore
Archiviert
13
2

Merge pull request 'Using new config' (#269) from configRefactoring into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #269
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2021-12-02 14:26:12 +01:00
Commit f975c4c867
4 geänderte Dateien mit 67 neuen und 51 gelöschten Zeilen

Datei anzeigen

@ -20,9 +20,15 @@
package de.steamwar.bungeecore;
import de.steamwar.bungeecore.sql.SchematicType;
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 java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
public class ArenaMode {
@ -32,9 +38,19 @@ public class ArenaMode {
private static final List<ArenaMode> allModes = new LinkedList<>();
private static final Random random = new Random();
static void init(Configuration config){
for(String internalName : config.getKeys()){
new ArenaMode(internalName, config.getSection(internalName));
static {
File folder = new File(ProxyServer.getInstance().getPluginsFolder(), "FightSystem");
for(File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) {
Configuration config;
try {
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
} catch (IOException e) {
throw new SecurityException("Could not load SchematicTypes", e);
}
if(config.contains("Server"))
new ArenaMode(configFile.getName().replace(".yml", ""), config);
}
}
@ -84,19 +100,16 @@ public class ArenaMode {
private final String schemType;
private ArenaMode(String internalName, Configuration config){
this.folder = config.getString("folder");
this.serverJar = config.getString("serverJar");
this.config = config.getString("config");
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.schemType = config.getString("schemType", "").toLowerCase();
this.folder = config.getString("Server.Folder");
this.serverJar = config.getString("Server.ServerJar");
this.config = internalName + ".yml";
this.maps = config.getStringList("Server.Maps");
this.displayName = config.getString("GameName", internalName);
this.chatNames = config.getStringList("Server.ChatNames");
this.schemType = config.getString("Schematic.Type", "").toLowerCase();
this.ranked = config.getBoolean("ranked", false);
this.ranked = config.getBoolean("Server.Ranked", false);
this.historic = config.getBoolean("Server.Historic", false);
allModes.add(this);
byInternal.put(internalName, this);

Datei anzeigen

@ -270,8 +270,6 @@ public class BungeeCore extends Plugin {
EVENT_MODE = config.getBoolean("eventmode");
Broadcaster.setBroadCastMsgs(config.getStringList("broadcasts").toArray(new String[1]));
PollSystem.init(config.getString("poll.question"), config.getStringList("poll.answers"));
CheckCommand.loadCheckQuestions(config.getSection("checkquestions"));
CheckCommand.loadRanks(config.getSection("checkranks"));
Persistent.setChatPrefix(CHAT_PREFIX);
Persistent.setLobbyServer(LOBBY_SERVER);
@ -281,7 +279,6 @@ public class BungeeCore extends Plugin {
config.getString("db.password")
);
ArenaMode.init(config.getSection("games"));
if (config.getSection("discord") != null) {
SteamwarDiscordBotConfig.loadConfig(config.getSection("discord"));
}

Datei anzeigen

@ -47,16 +47,9 @@ public class CheckCommand extends BasicCommand {
private static Map<UUID, CheckSession> currentCheckers = new HashMap<>();
private static Map<Integer, CheckSession> currentSchems = new HashMap<>();
public static void loadCheckQuestions(Configuration config){
for(String schemType : config.getKeys()){
checkQuestions.put(SchematicType.fromDB(schemType), config.getStringList(schemType));
}
}
public static void loadRanks(Configuration config){
for(String schemType : config.getKeys()){
ranks.put(SchematicType.fromDB(schemType), config.getStringList(schemType));
}
public static void setCheckQuestions(SchematicType checkType, Configuration config) {
checkQuestions.put(checkType, config.getStringList("CheckQuestions"));
ranks.put(checkType, config.getStringList("Ranks"));
}
public static boolean isChecking(ProxiedPlayer player){

Datei anzeigen

@ -19,7 +19,8 @@
package de.steamwar.bungeecore.sql;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.commands.CheckCommand;
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;
@ -35,18 +36,8 @@ public class SchematicType {
private static final Map<SchematicType, SchematicType> fightType;
private static final List<SchematicType> types;
static{
File file = new File(BungeeCore.get().getDataFolder(), "SchematicTypes.yml");
if(!file.exists())
throw new SecurityException("SchematicType-ConfigFile not found!");
Configuration config;
try {
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
} catch (IOException e) {
throw new SecurityException("Could not load SchematicTypes", e);
}
static {
File folder = new File(ProxyServer.getInstance().getPluginsFolder(), "FightSystem");
List<SchematicType> tmpTypes = new LinkedList<>();
Map<String, SchematicType> tmpFromDB = new HashMap<>();
@ -55,16 +46,38 @@ public class SchematicType {
tmpTypes.add(Normal);
tmpFromDB.put(Normal.name().toLowerCase(), Normal);
for(String type : config.getKeys()){
Configuration section = config.getSection(type);
assert section != null;
String checktype = section.getString("checktype");
SchematicType current = new SchematicType(type, section.getString("kuerzel"), Type.valueOf(section.getString("type")), checktype != null ? tmpFromDB.get(checktype.toLowerCase()) : null);
tmpTypes.add(current);
if(current.checkType != null)
tmpFightType.put(current.checkType, current);
if(folder.exists()) {
for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) {
Configuration config;
try {
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
} catch (IOException e) {
throw new SecurityException("Could not load SchematicTypes", e);
}
if(!config.contains("Schematic"))
continue;
String type = config.getString("Schematic.Type");
assert type != null;
String shortcut = config.getString("Schematic.Shortcut");
if(tmpFromDB.containsKey(type.toLowerCase()))
continue;
SchematicType checktype = null;
if(!config.getStringList("CheckQuestions").isEmpty()) {
checktype = new SchematicType("C" + type, "C" + shortcut, Type.CHECK_TYPE, null);
tmpTypes.add(checktype);
tmpFromDB.put(checktype.toDB(), checktype);
CheckCommand.setCheckQuestions(checktype, config);
}
SchematicType current = new SchematicType(type, shortcut, config.getKeys().contains("Server") ? Type.FIGHT_TYPE : Type.NORMAL, checktype);
if(checktype != null)
tmpFightType.put(checktype, current);
tmpFromDB.put(type.toLowerCase(), current);
}
}
fromDB = Collections.unmodifiableMap(tmpFromDB);
fightType = Collections.unmodifiableMap(tmpFightType);
@ -74,7 +87,7 @@ public class SchematicType {
private final String name;
private final String kuerzel;
private final Type type;
private SchematicType checkType;
private final SchematicType checkType;
private SchematicType(String name, String kuerzel, Type type, SchematicType checkType){
this.name = name;