Dieser Commit ist enthalten in:
Ursprung
61d42c7cca
Commit
9b0d7bd856
@ -28,6 +28,8 @@ import java.io.FileInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static de.steamwar.bungeecore.util.YamlUtils.*;
|
||||||
|
|
||||||
public class ArenaMode {
|
public class ArenaMode {
|
||||||
|
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
@ -48,12 +50,11 @@ public class ArenaMode {
|
|||||||
bySchemType.clear();
|
bySchemType.clear();
|
||||||
allModes.clear();
|
allModes.clear();
|
||||||
|
|
||||||
Yaml yaml = new Yaml();
|
|
||||||
File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem");
|
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()) {
|
for(File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().toList()) {
|
||||||
Map<String, Object> config;
|
Map<String, Object> config;
|
||||||
try {
|
try {
|
||||||
config = yaml.load(new FileInputStream(configFile));
|
config = loadYaml(configFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SecurityException("Could not load SchematicTypes", e);
|
throw new SecurityException("Could not load SchematicTypes", e);
|
||||||
}
|
}
|
||||||
@ -130,7 +131,7 @@ public class ArenaMode {
|
|||||||
this.historic = get(server, "Historic", false);
|
this.historic = get(server, "Historic", false);
|
||||||
maps.forEach(map -> lowerToRealMapNames.put(map.toLowerCase(), map));
|
maps.forEach(map -> lowerToRealMapNames.put(map.toLowerCase(), map));
|
||||||
|
|
||||||
this.schemType = get(get(config, "Schematic"), "Type", "").toLowerCase();
|
this.schemType = get(config, "Schematic.Type", "").toLowerCase();
|
||||||
|
|
||||||
allModes.add(this);
|
allModes.add(this);
|
||||||
byInternal.put(internalName, this);
|
byInternal.put(internalName, this);
|
||||||
@ -142,13 +143,6 @@ public class ArenaMode {
|
|||||||
bySchemType.put(SchematicType.fromDB(this.schemType), this);
|
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){
|
public String hasMap(String map){
|
||||||
for(String m : maps){
|
for(String m : maps){
|
||||||
if(m.equalsIgnoreCase(map))
|
if(m.equalsIgnoreCase(map))
|
||||||
|
82
src/de/steamwar/bungeecore/util/YamlUtils.java
Normale Datei
82
src/de/steamwar/bungeecore/util/YamlUtils.java
Normale Datei
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 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.util;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class YamlUtils {
|
||||||
|
|
||||||
|
public <T> T get(Map<String, Object> config, String key) {
|
||||||
|
if (key.contains(".")) {
|
||||||
|
return getRecursive(config, key.split("\\."), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (T) config.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T get(Map<String, Object> config, String key, T def) {
|
||||||
|
if (key.contains(".")) {
|
||||||
|
return getRecursive(config, key.split("\\."), def);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (T) config.getOrDefault(key, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T getRecursive(Map<String, Object> config, String[] keys, T def) {
|
||||||
|
if (keys.length == 1) {
|
||||||
|
return get(config, keys[0], def);
|
||||||
|
} else {
|
||||||
|
Object o = get(config, keys[0], null);
|
||||||
|
if (o == null) {
|
||||||
|
if (def == null) {
|
||||||
|
throw new IllegalArgumentException("Key " + keys[0] + " not found");
|
||||||
|
}
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (o instanceof Map) {
|
||||||
|
return getRecursive((Map<String, Object>) o, Arrays.copyOfRange(keys, 1, keys.length), def);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Key " + keys[0] + " is not a map");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> List<T> getList(Map<String, Object> config, String key) {
|
||||||
|
return (List<T>) config.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T loadYaml(File f) throws FileNotFoundException {
|
||||||
|
return loadYaml(f, new Yaml());
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T loadYaml(File f, Yaml yaml) throws FileNotFoundException {
|
||||||
|
return yaml.load(new FileInputStream(f));
|
||||||
|
}
|
||||||
|
}
|
@ -19,27 +19,23 @@
|
|||||||
|
|
||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import de.steamwar.bungeecore.VelocityCore;
|
import de.steamwar.bungeecore.VelocityCore;
|
||||||
import de.steamwar.bungeecore.commands.CheckCommand;
|
import de.steamwar.bungeecore.commands.CheckCommand;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
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.File;
|
||||||
import java.io.IOException;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SQLWrapperImpl implements SQLWrapper {
|
import static de.steamwar.bungeecore.util.YamlUtils.*;
|
||||||
|
|
||||||
|
public class SQLWrapperImpl implements SQLWrapper {
|
||||||
private static final SimpleDateFormat deadlineFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
private static final SimpleDateFormat deadlineFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||||
private static Date parseDeadline(String deadline) {
|
private static Date parseDeadline(String deadline) {
|
||||||
if(deadline == null)
|
if(deadline == null)
|
||||||
@ -54,37 +50,38 @@ public class SQLWrapperImpl implements SQLWrapper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadSchemTypes(List<SchematicType> tmpTypes, Map<String, SchematicType> tmpFromDB) {
|
public void loadSchemTypes(List<SchematicType> tmpTypes, Map<String, SchematicType> tmpFromDB) {
|
||||||
File folder = new File(VelocityCore.get().getDataFolder().getParentFile(), "FightSystem");
|
File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem");
|
||||||
if(folder.exists()) {
|
if(folder.exists()) {
|
||||||
for(File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) {
|
for(File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) {
|
||||||
Configuration config;
|
Map<String, Object> config;
|
||||||
|
Yaml yaml = new Yaml();
|
||||||
try {
|
try {
|
||||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
config = yaml.load(new FileInputStream(configFile));
|
||||||
} catch (IOException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new SecurityException("Could not load SchematicTypes", e);
|
throw new SecurityException("Could not load config.yml", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!config.contains("Schematic"))
|
if(!config.containsKey("Schematic"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
String type = config.getString("Schematic.Type");
|
String type = get(config, "Schematic.Type");
|
||||||
assert type != null;
|
assert type != null;
|
||||||
String shortcut = config.getString("Schematic.Shortcut");
|
String shortcut = get(config,"Schematic.Shortcut");
|
||||||
if(tmpFromDB.containsKey(type.toLowerCase()))
|
if(tmpFromDB.containsKey(type.toLowerCase()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
SchematicType checktype = null;
|
SchematicType checktype = null;
|
||||||
String material = config.getString("Schematic.Material");
|
String material = get(config,"Schematic.Material");
|
||||||
|
|
||||||
if(!config.getStringList("CheckQuestions").isEmpty()) {
|
if(!getList(config,"CheckQuestions").isEmpty()) {
|
||||||
checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true);
|
checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true);
|
||||||
tmpTypes.add(checktype);
|
tmpTypes.add(checktype);
|
||||||
tmpFromDB.put(checktype.toDB(), checktype);
|
tmpFromDB.put(checktype.toDB(), checktype);
|
||||||
CheckCommand.setCheckQuestions(checktype, config);
|
CheckCommand.setCheckQuestions(checktype, get(config, "CheckQuestions"));
|
||||||
}
|
}
|
||||||
boolean manualCheck = config.getBoolean("Schematic.ManualCheck", true);
|
boolean manualCheck = get(config, "Schematic.ManualCheck", true);
|
||||||
|
|
||||||
SchematicType current = new SchematicType(type, shortcut, !config.contains("Server") ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, parseDeadline(config.getString("deadline", null)), manualCheck);
|
SchematicType current = new SchematicType(type, shortcut, !config.containsKey("Server") ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, parseDeadline(get(config,"deadline", null)), manualCheck);
|
||||||
tmpTypes.add(current);
|
tmpTypes.add(current);
|
||||||
tmpFromDB.put(type.toLowerCase(), current);
|
tmpFromDB.put(type.toLowerCase(), current);
|
||||||
if(checktype != null)
|
if(checktype != null)
|
||||||
@ -96,10 +93,10 @@ public class SQLWrapperImpl implements SQLWrapper {
|
|||||||
@Override
|
@Override
|
||||||
public void additionalExceptionMetadata(StringBuilder builder) {
|
public void additionalExceptionMetadata(StringBuilder builder) {
|
||||||
builder.append("\nServers: ");
|
builder.append("\nServers: ");
|
||||||
for(Map.Entry<String, ServerInfo> server : ProxyServer.getInstance().getServers().entrySet()) {
|
for(RegisteredServer server : VelocityCore.getProxy().getAllServers()) {
|
||||||
builder.append(server.getKey()).append("(");
|
builder.append(server.getServerInfo().getName()).append("(");
|
||||||
for(ProxiedPlayer player : server.getValue().getPlayers()) {
|
for(Player player : server.getPlayersConnected()) {
|
||||||
builder.append(player.getName()).append(" ");
|
builder.append(player.getUsername()).append(" ");
|
||||||
}
|
}
|
||||||
builder.append(") ");
|
builder.append(") ");
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren