Add cache for GameModeConfig

This commit is contained in:
2025-10-26 13:34:25 +01:00
parent 79ebdcea85
commit 5ab04d0518
9 changed files with 61 additions and 37 deletions
@@ -19,48 +19,30 @@
package de.steamwar.schematicsystem;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.data.GameModeConfigUtils;
import de.steamwar.linkage.AbstractLinker;
import de.steamwar.linkage.SpigotLinker;
import de.steamwar.message.Message;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.sql.SchematicType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
public class SchematicSystem extends JavaPlugin {
public static final Message MESSAGE = new Message("SchematicSystem", SchematicSystem.class.getClassLoader());
private static SchematicSystem instance;
private static final Map<SchematicType, GameModeConfig<Material, String>> types = new HashMap<>();
public static GameModeConfig<Material, String> getGameModeConfig(SchematicType type){
return types.get(type);
GameModeConfig<Material, String> gameModeConfig = GameModeConfig.getBySchematicType(type);
if (gameModeConfig.CheckQuestions.isEmpty() && gameModeConfig.Schematic.ManualCheck) return null;
return gameModeConfig;
}
@Override
public void onEnable() {
instance = this;
File folder = new File(this.getDataFolder().getParentFile(), "FightSystem");
if(folder.exists()) {
for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) {
GameModeConfig<Material, String> gameModeConfig = new GameModeConfig<>(configFile, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
if (gameModeConfig.CheckQuestions.isEmpty() && gameModeConfig.Schematic.ManualCheck)
continue;
types.put(gameModeConfig.Schematic.Type, gameModeConfig);
if (gameModeConfig.Schematic.Type.checkType() != null) {
types.put(gameModeConfig.Schematic.Type.checkType(), gameModeConfig);
}
}
}
SpigotLinker spigotLinker = new SpigotLinker(this, MESSAGE);
try {
spigotLinker.link();