Archiviert
1
0

Merge pull request 'Using new config' (#269) from configRefactoring into master

Reviewed-on: SteamWar/BungeeCore#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; package de.steamwar.bungeecore;
import de.steamwar.bungeecore.sql.SchematicType; 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.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.*;
import java.util.stream.Collectors;
public class ArenaMode { public class ArenaMode {
@ -32,9 +38,19 @@ public class ArenaMode {
private static final List<ArenaMode> allModes = new LinkedList<>(); private static final List<ArenaMode> allModes = new LinkedList<>();
private static final Random random = new Random(); private static final Random random = new Random();
static void init(Configuration config){ static {
for(String internalName : config.getKeys()){ File folder = new File(ProxyServer.getInstance().getPluginsFolder(), "FightSystem");
new ArenaMode(internalName, config.getSection(internalName));
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 final String schemType;
private ArenaMode(String internalName, Configuration config){ private ArenaMode(String internalName, Configuration config){
this.folder = config.getString("folder"); this.folder = config.getString("Server.Folder");
this.serverJar = config.getString("serverJar"); this.serverJar = config.getString("Server.ServerJar");
this.config = config.getString("config"); this.config = internalName + ".yml";
this.maps = config.getStringList("maps"); this.maps = config.getStringList("Server.Maps");
this.displayName = config.getString("displayName", internalName); this.displayName = config.getString("GameName", internalName);
if(config.contains("chatNames")) this.chatNames = config.getStringList("Server.ChatNames");
this.chatNames = config.getStringList("chatNames"); this.schemType = config.getString("Schematic.Type", "").toLowerCase();
else
this.chatNames = Collections.emptyList();
this.historic = config.getBoolean("historic", false);
this.schemType = config.getString("schemType", "").toLowerCase();
this.ranked = config.getBoolean("ranked", false); this.ranked = config.getBoolean("Server.Ranked", false);
this.historic = config.getBoolean("Server.Historic", false);
allModes.add(this); allModes.add(this);
byInternal.put(internalName, this); byInternal.put(internalName, this);

Datei anzeigen

@ -270,8 +270,6 @@ public class BungeeCore extends Plugin {
EVENT_MODE = config.getBoolean("eventmode"); EVENT_MODE = config.getBoolean("eventmode");
Broadcaster.setBroadCastMsgs(config.getStringList("broadcasts").toArray(new String[1])); Broadcaster.setBroadCastMsgs(config.getStringList("broadcasts").toArray(new String[1]));
PollSystem.init(config.getString("poll.question"), config.getStringList("poll.answers")); 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.setChatPrefix(CHAT_PREFIX);
Persistent.setLobbyServer(LOBBY_SERVER); Persistent.setLobbyServer(LOBBY_SERVER);
@ -281,7 +279,6 @@ public class BungeeCore extends Plugin {
config.getString("db.password") config.getString("db.password")
); );
ArenaMode.init(config.getSection("games"));
if (config.getSection("discord") != null) { if (config.getSection("discord") != null) {
SteamwarDiscordBotConfig.loadConfig(config.getSection("discord")); 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<UUID, CheckSession> currentCheckers = new HashMap<>();
private static Map<Integer, CheckSession> currentSchems = new HashMap<>(); private static Map<Integer, CheckSession> currentSchems = new HashMap<>();
public static void loadCheckQuestions(Configuration config){ public static void setCheckQuestions(SchematicType checkType, Configuration config) {
for(String schemType : config.getKeys()){ checkQuestions.put(checkType, config.getStringList("CheckQuestions"));
checkQuestions.put(SchematicType.fromDB(schemType), config.getStringList(schemType)); ranks.put(checkType, config.getStringList("Ranks"));
}
}
public static void loadRanks(Configuration config){
for(String schemType : config.getKeys()){
ranks.put(SchematicType.fromDB(schemType), config.getStringList(schemType));
}
} }
public static boolean isChecking(ProxiedPlayer player){ public static boolean isChecking(ProxiedPlayer player){

Datei anzeigen

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