forked from SteamWar/SteamWar
Add Unified GameModeConfig
This commit is contained in:
@@ -21,52 +21,46 @@ package de.steamwar.sql;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import de.steamwar.velocitycore.GameModeConfig;
|
||||
import de.steamwar.data.GameModeConfig;
|
||||
import de.steamwar.data.YMLWrapperImpl;
|
||||
import de.steamwar.velocitycore.VelocityCore;
|
||||
import de.steamwar.velocitycore.commands.CheckCommand;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SQLWrapperImpl implements SQLWrapper {
|
||||
private static final SimpleDateFormat deadlineFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||
private static Date parseDeadline(String deadline) {
|
||||
if(deadline == null)
|
||||
return null;
|
||||
|
||||
try {
|
||||
return deadlineFormat.parse(deadline);
|
||||
} catch (ParseException e) {
|
||||
throw new SecurityException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadSchemTypes(List<SchematicType> tmpTypes, Map<String, SchematicType> tmpFromDB) {
|
||||
GameModeConfig.loadAll(GameModeConfig.class, (file, config) -> {
|
||||
if(config.getSchematic() == null || tmpFromDB.containsKey(config.getSchemType().toLowerCase()))
|
||||
return;
|
||||
File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem");
|
||||
if(!folder.exists())
|
||||
return;
|
||||
|
||||
String shortcut = config.getSchematic().getShortcut();
|
||||
String material = config.getSchematic().getMaterial();
|
||||
for(File file : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().toList()) {
|
||||
GameModeConfig<String, String, String> gameModeConfig = new GameModeConfig<>(YMLWrapperImpl.ofRaw(file));
|
||||
if (!gameModeConfig.Schematic.loaded) continue;
|
||||
if (tmpFromDB.containsKey(gameModeConfig.Schematic.Type.toLowerCase())) continue;
|
||||
|
||||
String shortcut = gameModeConfig.Schematic.Shortcut;
|
||||
String material = gameModeConfig.Schematic.Material;
|
||||
|
||||
SchematicType checktype = null;
|
||||
if(!config.getCheckQuestions().isEmpty()) {
|
||||
checktype = new SchematicType("C" + config.getSchemType(), "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true);
|
||||
if (!gameModeConfig.CheckQuestions.isEmpty()) {
|
||||
checktype = new SchematicType("C" + gameModeConfig.Schematic.Type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true);
|
||||
tmpTypes.add(checktype);
|
||||
tmpFromDB.put(checktype.toDB(), checktype);
|
||||
CheckCommand.setCheckQuestions(checktype, config.getCheckQuestions());
|
||||
CheckCommand.setCheckQuestions(checktype, gameModeConfig.CheckQuestions);
|
||||
}
|
||||
|
||||
SchematicType current = new SchematicType(config.getSchemType(), shortcut, config.getServer() != null ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, parseDeadline(config.getDeadline()), config.getSchematic().isManualCheck());
|
||||
SchematicType current = new SchematicType(gameModeConfig.Schematic.Type, shortcut, gameModeConfig.Server.loaded ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, gameModeConfig.Deadline, gameModeConfig.Schematic.ManualCheck);
|
||||
tmpTypes.add(current);
|
||||
tmpFromDB.put(config.getSchemType().toLowerCase(), current);
|
||||
tmpFromDB.put(gameModeConfig.Schematic.Type.toLowerCase(), current);
|
||||
if(checktype != null)
|
||||
CheckCommand.addFightType(checktype, current);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user