forked from SteamWar/SteamWar
Unify SchematicType loading
This commit is contained in:
@@ -22,7 +22,4 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":CommonCore:SQL"))
|
||||
|
||||
implementation("org.yaml:snakeyaml:2.2")
|
||||
}
|
||||
@@ -23,4 +23,6 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.sqlite)
|
||||
|
||||
implementation("org.yaml:snakeyaml:2.2")
|
||||
}
|
||||
@@ -20,14 +20,17 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.ImplementationProvider;
|
||||
import de.steamwar.data.GameModeConfig;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.File;
|
||||
|
||||
public interface SQLWrapper {
|
||||
SQLWrapper impl = ImplementationProvider.getImpl("de.steamwar.sql.SQLWrapperImpl");
|
||||
|
||||
void loadSchemTypes(List<SchematicType> tmpTypes, Map<String, SchematicType> tmpFromDB);
|
||||
File getSchemTypesFolder();
|
||||
|
||||
default void processSchematicType(GameModeConfig<String, String, String> gameModeConfig, SchematicType type) {
|
||||
}
|
||||
|
||||
void additionalExceptionMetadata(StringBuilder builder);
|
||||
}
|
||||
|
||||
@@ -19,11 +19,14 @@
|
||||
|
||||
package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.data.GameModeConfig;
|
||||
import de.steamwar.sql.internal.SqlTypeMapper;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
public class SchematicType {
|
||||
@@ -41,7 +44,33 @@ public class SchematicType {
|
||||
tmpFromDB.put(Normal.name().toLowerCase(), Normal);
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
SQLWrapper.impl.loadSchemTypes(tmpTypes, tmpFromDB);
|
||||
File folder = SQLWrapper.impl.getSchemTypesFolder();
|
||||
if (folder.exists()) {
|
||||
for (File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) {
|
||||
GameModeConfig<String, String, String> gameModeConfig = new GameModeConfig<>(configFile, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
|
||||
if (!gameModeConfig.Schematic.loaded) continue;
|
||||
String type = gameModeConfig.Schematic.Type;
|
||||
assert type != null;
|
||||
String shortcut = gameModeConfig.Schematic.Shortcut;
|
||||
if (tmpFromDB.containsKey(type.toLowerCase()))
|
||||
continue;
|
||||
|
||||
SchematicType checktype = null;
|
||||
String material = gameModeConfig.Schematic.Material;
|
||||
|
||||
if (!gameModeConfig.CheckQuestions.isEmpty()) {
|
||||
checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true);
|
||||
tmpTypes.add(checktype);
|
||||
tmpFromDB.put(checktype.toDB(), checktype);
|
||||
}
|
||||
|
||||
SchematicType current = new SchematicType(type, shortcut, gameModeConfig.Server.loaded ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, gameModeConfig.Deadline, gameModeConfig.Schematic.ManualCheck);
|
||||
tmpTypes.add(current);
|
||||
tmpFromDB.put(type.toLowerCase(), current);
|
||||
|
||||
SQLWrapper.impl.processSchematicType(gameModeConfig, current);
|
||||
}
|
||||
}
|
||||
time = System.currentTimeMillis() - time;
|
||||
log.info("Loaded {} Schematic Types in {}ms", tmpTypes.size(), time);
|
||||
|
||||
|
||||
@@ -20,45 +20,17 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.data.GameModeConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SQLWrapperImpl implements SQLWrapper {
|
||||
|
||||
@Override
|
||||
public void loadSchemTypes(List<SchematicType> tmpTypes, Map<String, SchematicType> tmpFromDB) {
|
||||
File folder = new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
||||
if (!folder.exists()) return;
|
||||
for (File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) {
|
||||
GameModeConfig<String, String, String> gameModeConfig = new GameModeConfig<>(configFile, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
|
||||
if (!gameModeConfig.Schematic.loaded) continue;
|
||||
String type = gameModeConfig.Schematic.Type;
|
||||
assert type != null;
|
||||
String shortcut = gameModeConfig.Schematic.Shortcut;
|
||||
if (tmpFromDB.containsKey(type.toLowerCase()))
|
||||
continue;
|
||||
|
||||
SchematicType checktype = null;
|
||||
String material = gameModeConfig.Schematic.Material;
|
||||
|
||||
if (!gameModeConfig.CheckQuestions.isEmpty()) {
|
||||
checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true);
|
||||
tmpTypes.add(checktype);
|
||||
tmpFromDB.put(checktype.toDB(), checktype);
|
||||
}
|
||||
|
||||
SchematicType current = new SchematicType(type, shortcut, gameModeConfig.Server.loaded ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, gameModeConfig.Deadline, gameModeConfig.Schematic.ManualCheck);
|
||||
tmpTypes.add(current);
|
||||
tmpFromDB.put(type.toLowerCase(), current);
|
||||
}
|
||||
public File getSchemTypesFolder() {
|
||||
return new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
||||
}
|
||||
|
||||
private static final String SERVER_VERSION = Bukkit.getServer().getVersion();
|
||||
|
||||
@@ -26,39 +26,21 @@ import de.steamwar.velocitycore.VelocityCore;
|
||||
import de.steamwar.velocitycore.commands.CheckCommand;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SQLWrapperImpl implements SQLWrapper {
|
||||
|
||||
@Override
|
||||
public void loadSchemTypes(List<SchematicType> tmpTypes, Map<String, SchematicType> tmpFromDB) {
|
||||
File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem");
|
||||
if(!folder.exists())
|
||||
return;
|
||||
|
||||
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<>(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToInternalName);
|
||||
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 (!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, gameModeConfig.CheckQuestions);
|
||||
public File getSchemTypesFolder() {
|
||||
return new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem");
|
||||
}
|
||||
|
||||
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(gameModeConfig.Schematic.Type.toLowerCase(), current);
|
||||
if(checktype != null)
|
||||
CheckCommand.addFightType(checktype, current);
|
||||
@Override
|
||||
public void processSchematicType(GameModeConfig<String, String, String> gameModeConfig, SchematicType type) {
|
||||
if (!gameModeConfig.CheckQuestions.isEmpty()) {
|
||||
CheckCommand.setCheckQuestions(type.checkType(), gameModeConfig.CheckQuestions);
|
||||
}
|
||||
if (type.checkType() != null) {
|
||||
CheckCommand.addFightType(type.checkType(), type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,42 +19,12 @@
|
||||
|
||||
package de.steamwar.sql
|
||||
|
||||
import de.steamwar.data.GameModeConfig
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import java.util.stream.Collectors
|
||||
|
||||
fun loadSchematicTypes(tmpTypes: MutableList<SchematicType>?, tmpFromDB: MutableMap<String, SchematicType>?) {
|
||||
val folder = File("/configs/GameModes")
|
||||
if (folder.exists()) {
|
||||
for (configFile in Arrays.stream(folder.listFiles { _, name -> name.endsWith(".yml") && !name.endsWith(".kits.yml") })
|
||||
.sorted().collect(Collectors.toList())) {
|
||||
val gameModeConfig = GameModeConfig(configFile, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear)
|
||||
|
||||
if (!gameModeConfig.Schematic.loaded) continue
|
||||
val type = gameModeConfig.Schematic.Type
|
||||
checkNotNull(type)
|
||||
val shortcut = gameModeConfig.Schematic.Shortcut
|
||||
if (tmpFromDB!!.containsKey(type.lowercase(Locale.getDefault()))) continue
|
||||
|
||||
var checktype: SchematicType? = null
|
||||
val material = gameModeConfig.Schematic.Material
|
||||
|
||||
if (!gameModeConfig.CheckQuestions.isEmpty()) {
|
||||
checktype = SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true)
|
||||
tmpTypes!!.add(checktype)
|
||||
tmpFromDB.put(checktype.toDB(), checktype)
|
||||
}
|
||||
|
||||
val current = SchematicType(type, shortcut, if (gameModeConfig.Server.loaded) SchematicType.Type.FIGHT_TYPE else SchematicType.Type.NORMAL, checktype, material, gameModeConfig.Deadline, gameModeConfig.Schematic.ManualCheck)
|
||||
tmpTypes!!.add(current)
|
||||
tmpFromDB.put(type.lowercase(Locale.getDefault()), current)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SQLWrapperImpl: SQLWrapper {
|
||||
override fun loadSchemTypes(tmpTypes: MutableList<SchematicType>?, tmpFromDB: MutableMap<String, SchematicType>?) = loadSchematicTypes(tmpTypes, tmpFromDB)
|
||||
override fun getSchemTypesFolder(): File? {
|
||||
return File("/configs/GameModes")
|
||||
}
|
||||
|
||||
override fun additionalExceptionMetadata(builder: StringBuilder) {
|
||||
builder.append("\n\nWebsiteApi")
|
||||
|
||||
Reference in New Issue
Block a user