forked from SteamWar/SteamWar
Redesign GameModeConfig and SchematicType
This commit is contained in:
@@ -52,6 +52,10 @@ public final class GameModeConfig<M, W> {
|
|||||||
private static final Map<String, GameModeConfig<?, String>> byGameName;
|
private static final Map<String, GameModeConfig<?, String>> byGameName;
|
||||||
private static final Map<SchematicType, GameModeConfig<?, String>> bySchematicType;
|
private static final Map<SchematicType, GameModeConfig<?, String>> bySchematicType;
|
||||||
|
|
||||||
|
public static <M> Collection<GameModeConfig<M, String>> getAll() {
|
||||||
|
return (Collection) byFileName.values();
|
||||||
|
}
|
||||||
|
|
||||||
public static <M> GameModeConfig<M, String> getByFileName(File file) {
|
public static <M> GameModeConfig<M, String> getByFileName(File file) {
|
||||||
return (GameModeConfig<M, String>) byFileName.get(file.getName());
|
return (GameModeConfig<M, String>) byFileName.get(file.getName());
|
||||||
}
|
}
|
||||||
@@ -87,8 +91,24 @@ public final class GameModeConfig<M, W> {
|
|||||||
byFileName = new HashMap<>();
|
byFileName = new HashMap<>();
|
||||||
byGameName = new HashMap<>();
|
byGameName = new HashMap<>();
|
||||||
bySchematicType = new HashMap<>();
|
bySchematicType = new HashMap<>();
|
||||||
SchematicType.values();
|
|
||||||
DEFAULTS = SQLWrapper.impl.loadGameModeConfig(null);
|
DEFAULTS = SQLWrapper.impl.loadGameModeConfig(null);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
byFileName.clear();
|
||||||
|
byGameName.clear();
|
||||||
|
bySchematicType.clear();
|
||||||
|
|
||||||
|
File folder = SQLWrapper.impl.getSchemTypesFolder();
|
||||||
|
if (!folder.exists()) return;
|
||||||
|
if (!folder.isDirectory()) return;
|
||||||
|
|
||||||
|
for (File file : Objects.requireNonNull(folder.listFiles())) {
|
||||||
|
if (!file.getName().endsWith(".yml")) continue;
|
||||||
|
if (file.getName().endsWith(".kits.yml")) continue;
|
||||||
|
SQLWrapper.impl.loadGameModeConfig(file);
|
||||||
|
}
|
||||||
|
|
||||||
byFileName.values().forEach(gameModeConfig -> {
|
byFileName.values().forEach(gameModeConfig -> {
|
||||||
List<SchematicType> subTypes = Collections.unmodifiableList(gameModeConfig.Schematic.SubTypesStrings.stream()
|
List<SchematicType> subTypes = Collections.unmodifiableList(gameModeConfig.Schematic.SubTypesStrings.stream()
|
||||||
@@ -671,9 +691,9 @@ public final class GameModeConfig<M, W> {
|
|||||||
loaded = loader.canLoad();
|
loaded = loader.canLoad();
|
||||||
Size = new SizeConfig(loader.with("Size"));
|
Size = new SizeConfig(loader.with("Size"));
|
||||||
Inset = new InsetConfig(loader.with("Inset"));
|
Inset = new InsetConfig(loader.with("Inset"));
|
||||||
Type = loader.getSchematicType("Type", "Normal");
|
Type = null;
|
||||||
SubTypesStrings = loader.getStringList("SubTypes");
|
SubTypesStrings = loader.getStringList("SubTypes");
|
||||||
SubTypes = loader.getSchematicTypeList("SubTypes");
|
SubTypes = new ArrayList<>();
|
||||||
Shortcut = loader.getString("Shortcut", "");
|
Shortcut = loader.getString("Shortcut", "");
|
||||||
Material = loader.getMaterial("Material", "STONE_BUTTON");
|
Material = loader.getMaterial("Material", "STONE_BUTTON");
|
||||||
ManualCheck = loader.getBoolean("ManualCheck", true);
|
ManualCheck = loader.getBoolean("ManualCheck", true);
|
||||||
|
|||||||
@@ -19,11 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.sql
|
package de.steamwar.sql
|
||||||
|
|
||||||
import java.io.File
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.Locale
|
|
||||||
import java.util.Locale.getDefault
|
|
||||||
import java.util.stream.Collectors
|
|
||||||
|
|
||||||
data class SchematicType(
|
data class SchematicType(
|
||||||
val name: String,
|
val name: String,
|
||||||
@@ -47,58 +43,65 @@ data class SchematicType(
|
|||||||
@JvmField
|
@JvmField
|
||||||
val Normal = SchematicType("Normal", "", Type.NORMAL, null, "STONE_BUTTON", false)
|
val Normal = SchematicType("Normal", "", Type.NORMAL, null, "STONE_BUTTON", false)
|
||||||
|
|
||||||
private val types: List<SchematicType>
|
private val types: MutableList<SchematicType> = mutableListOf()
|
||||||
private val fromDB: Map<String, SchematicType>?
|
private val fromDB: MutableMap<String, SchematicType> = mutableMapOf()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val tmpTypes = mutableListOf<SchematicType>()
|
GameModeConfig.init()
|
||||||
val tmpFromDB = mutableMapOf<String, SchematicType>()
|
init()
|
||||||
|
|
||||||
tmpTypes.add(Normal)
|
|
||||||
tmpFromDB[Normal.toDB()] = Normal
|
|
||||||
|
|
||||||
val folder = SQLWrapper.impl.schemTypesFolder
|
|
||||||
if (folder.exists()) {
|
|
||||||
for (configFile in Arrays.stream<File?>(folder.listFiles { _, name ->
|
|
||||||
name.endsWith(
|
|
||||||
".yml"
|
|
||||||
) && !name.endsWith(".kits.yml")
|
|
||||||
}).sorted().collect(Collectors.toList())) {
|
|
||||||
val gameModeConfig = SQLWrapper.impl.loadGameModeConfig(configFile)
|
|
||||||
if (gameModeConfig.Schematic.Type == null) continue
|
|
||||||
if (tmpFromDB.containsKey(gameModeConfig.Schematic.Type.toDB())) continue
|
|
||||||
val current = gameModeConfig.Schematic.Type
|
|
||||||
if (gameModeConfig.CheckQuestions.isNotEmpty()) {
|
|
||||||
val checkType = current.checkType
|
|
||||||
tmpTypes.add(checkType!!)
|
|
||||||
tmpFromDB[checkType.toDB()] = checkType
|
|
||||||
}
|
|
||||||
tmpTypes.add(current)
|
|
||||||
tmpFromDB[current.toDB()] = current
|
|
||||||
SQLWrapper.impl.processSchematicType(gameModeConfig)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
types = tmpTypes.toList()
|
|
||||||
fromDB = tmpFromDB.toMap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun values() = types
|
fun init() {
|
||||||
|
types.clear()
|
||||||
|
fromDB.clear()
|
||||||
|
|
||||||
|
types.add(Normal)
|
||||||
|
fromDB[Normal.toDB()] = Normal
|
||||||
|
|
||||||
|
for (gameModeConfig in GameModeConfig.getAll<Any>()) {
|
||||||
|
val type = gameModeConfig.Schematic.Type
|
||||||
|
?: continue
|
||||||
|
if (fromDB.containsKey(type.toDB())) continue
|
||||||
|
|
||||||
|
types.add(type)
|
||||||
|
fromDB[type.toDB()] = type
|
||||||
|
if (gameModeConfig.CheckQuestions.isNotEmpty() && type.checkType != null) {
|
||||||
|
types.add(type.checkType)
|
||||||
|
fromDB[type.checkType.toDB()] = type.checkType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun fromDB(value: String) = fromDB?.let { it[value.lowercase()] }
|
fun values() =
|
||||||
|
types
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun fromDB(value: String) =
|
||||||
|
fromDB[value.lowercase()]
|
||||||
}
|
}
|
||||||
|
|
||||||
fun name() = name
|
fun name() =
|
||||||
fun toDB() = name.lowercase()
|
name
|
||||||
|
|
||||||
fun check() = type == Type.CHECK_TYPE
|
fun toDB() =
|
||||||
fun fightType() = type == Type.FIGHT_TYPE
|
name.lowercase()
|
||||||
fun writeable() = type == Type.NORMAL
|
|
||||||
|
|
||||||
fun checkType() = if (manualCheck) checkType else this
|
fun check() =
|
||||||
fun isAssignable() = type == Type.NORMAL || (type == Type.FIGHT_TYPE && checkType != null) || !manualCheck
|
type == Type.CHECK_TYPE
|
||||||
|
|
||||||
|
fun fightType() =
|
||||||
|
type == Type.FIGHT_TYPE
|
||||||
|
|
||||||
|
fun writeable() =
|
||||||
|
type == Type.NORMAL
|
||||||
|
|
||||||
|
fun checkType() =
|
||||||
|
if (manualCheck) checkType else this
|
||||||
|
|
||||||
|
fun isAssignable() =
|
||||||
|
type == Type.NORMAL || (type == Type.FIGHT_TYPE && checkType != null) || !manualCheck
|
||||||
|
|
||||||
enum class Type {
|
enum class Type {
|
||||||
NORMAL,
|
NORMAL,
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ import lombok.Getter;
|
|||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class ArenaMode {
|
public class ArenaMode {
|
||||||
@@ -50,12 +53,12 @@ public class ArenaMode {
|
|||||||
if(!folder.exists())
|
if(!folder.exists())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(File file : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml") && !name.equals("config.yml"))).sorted().toList()) {
|
GameModeConfig.init();
|
||||||
GameModeConfig<String, String> gameModeConfig = new GameModeConfig<>(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToInternalName, false);
|
SchematicType.init();
|
||||||
|
for (GameModeConfig<String, String> gameModeConfig : GameModeConfig.<String>getAll()) {
|
||||||
if (!gameModeConfig.Server.loaded) continue;
|
if (!gameModeConfig.Server.loaded) continue;
|
||||||
|
|
||||||
allModes.add(gameModeConfig);
|
allModes.add(gameModeConfig);
|
||||||
byInternal.put(file.getName().replace(".yml", ""), gameModeConfig);
|
byInternal.put(gameModeConfig.configFile.getName().replace(".yml", ""), gameModeConfig);
|
||||||
for (String name : gameModeConfig.Server.ChatNames) {
|
for (String name : gameModeConfig.Server.ChatNames) {
|
||||||
byChat.put(name.toLowerCase(), gameModeConfig);
|
byChat.put(name.toLowerCase(), gameModeConfig);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user