forked from SteamWar/SteamWar
Improve YMLWrapper
This commit is contained in:
+2
-3
@@ -23,8 +23,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
|||||||
import de.steamwar.bausystem.region.*;
|
import de.steamwar.bausystem.region.*;
|
||||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||||
import de.steamwar.data.GameModeConfig;
|
import de.steamwar.data.GameModeConfig;
|
||||||
import de.steamwar.data.YMLWrapper;
|
import de.steamwar.data.GameModeConfigUtils;
|
||||||
import de.steamwar.data.YMLWrapperUtils;
|
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -95,7 +94,7 @@ public final class FixedGlobalRegion implements Region {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final GameModeConfig<Material, SchematicType, String> GLOBAL_CONFIG = new GameModeConfig<>(null, YMLWrapperUtils.ToMaterial, YMLWrapper.ToSchematicType, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear);
|
private static final GameModeConfig<Material, SchematicType, String> GLOBAL_CONFIG = new GameModeConfig<>(null, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
|
||||||
|
|
||||||
private FixedGlobalRegion() {
|
private FixedGlobalRegion() {
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -29,8 +29,7 @@ import de.steamwar.bausystem.utils.PasteBuilder;
|
|||||||
import de.steamwar.bausystem.worlddata.WorldData;
|
import de.steamwar.bausystem.worlddata.WorldData;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.data.GameModeConfig;
|
import de.steamwar.data.GameModeConfig;
|
||||||
import de.steamwar.data.YMLWrapper;
|
import de.steamwar.data.GameModeConfigUtils;
|
||||||
import de.steamwar.data.YMLWrapperUtils;
|
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -340,7 +339,7 @@ public class FixedRegion implements Region {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.gameModeConfig = new GameModeConfig<>(found, YMLWrapperUtils.ToMaterial, YMLWrapper.ToSchematicType, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear);
|
this.gameModeConfig = new GameModeConfig<>(found, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
|
||||||
this.regionData = new RegionData.RegionDataImpl(regionData, WorldData::write);
|
this.regionData = new RegionData.RegionDataImpl(regionData, WorldData::write);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,12 @@ import java.util.stream.Collectors;
|
|||||||
@ToString
|
@ToString
|
||||||
public final class GameModeConfig<M, ST, W> {
|
public final class GameModeConfig<M, ST, W> {
|
||||||
|
|
||||||
private static final Random random = new Random();
|
public static final Function<String, String> ToString = Function.identity();
|
||||||
|
public static final Function<String, SchematicType> ToSchematicType = SchematicType::fromDB;
|
||||||
|
public static final Function<File, String> ToStaticWarGear = __ -> "WarGear";
|
||||||
|
public static final Function<File, String> ToInternalName = file -> file.getName().replace(".yml", "");
|
||||||
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||||
|
private static final Random random = new Random();
|
||||||
|
|
||||||
public final boolean loaded;
|
public final boolean loaded;
|
||||||
public final File configFile;
|
public final File configFile;
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package de.steamwar.data;
|
package de.steamwar.data;
|
||||||
|
|
||||||
import de.steamwar.sql.SchematicType;
|
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -32,15 +31,8 @@ import java.util.Objects;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public final class YMLWrapper<M, ST, W> {
|
final class YMLWrapper<M, ST, W> {
|
||||||
|
|
||||||
public static final Function<String, String> ToString = Function.identity();
|
|
||||||
public static final Function<String, SchematicType> ToSchematicType = SchematicType::fromDB;
|
|
||||||
|
|
||||||
public static final Function<File, String> ToStaticWarGear = __ -> "WarGear";
|
|
||||||
public static final Function<File, String> ToInternalName = file -> file.getName().replace(".yml", "");
|
|
||||||
|
|
||||||
private final File file;
|
|
||||||
final Function<String, M> materialMapper;
|
final Function<String, M> materialMapper;
|
||||||
final Function<String, ST> schematicTypeMapper;
|
final Function<String, ST> schematicTypeMapper;
|
||||||
final Function<String, W> winconditionMapper;
|
final Function<String, W> winconditionMapper;
|
||||||
@@ -48,8 +40,7 @@ public final class YMLWrapper<M, ST, W> {
|
|||||||
private final boolean canLoad;
|
private final boolean canLoad;
|
||||||
private final Map<String, Object> document;
|
private final Map<String, Object> document;
|
||||||
|
|
||||||
public YMLWrapper(File file, Function<String, M> materialMapper, Function<String, ST> schematicTypeMapper, Function<String, W> winconditionMapper) {
|
YMLWrapper(File file, Function<String, M> materialMapper, Function<String, ST> schematicTypeMapper, Function<String, W> winconditionMapper) {
|
||||||
this.file = file;
|
|
||||||
this.materialMapper = materialMapper;
|
this.materialMapper = materialMapper;
|
||||||
this.schematicTypeMapper = schematicTypeMapper;
|
this.schematicTypeMapper = schematicTypeMapper;
|
||||||
this.winconditionMapper = winconditionMapper;
|
this.winconditionMapper = winconditionMapper;
|
||||||
@@ -70,7 +61,6 @@ public final class YMLWrapper<M, ST, W> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private YMLWrapper(boolean canLoad, Map<String, Object> document, Function<String, M> materialMapper, Function<String, ST> schematicTypeMapper, Function<String, W> winconditionMapper) {
|
private YMLWrapper(boolean canLoad, Map<String, Object> document, Function<String, M> materialMapper, Function<String, ST> schematicTypeMapper, Function<String, W> winconditionMapper) {
|
||||||
this.file = null;
|
|
||||||
this.materialMapper = materialMapper;
|
this.materialMapper = materialMapper;
|
||||||
this.schematicTypeMapper = schematicTypeMapper;
|
this.schematicTypeMapper = schematicTypeMapper;
|
||||||
this.winconditionMapper = winconditionMapper;
|
this.winconditionMapper = winconditionMapper;
|
||||||
|
|||||||
@@ -20,8 +20,7 @@
|
|||||||
package de.steamwar.fightsystem;
|
package de.steamwar.fightsystem;
|
||||||
|
|
||||||
import de.steamwar.data.GameModeConfig;
|
import de.steamwar.data.GameModeConfig;
|
||||||
import de.steamwar.data.YMLWrapper;
|
import de.steamwar.data.GameModeConfigUtils;
|
||||||
import de.steamwar.data.YMLWrapperUtils;
|
|
||||||
import de.steamwar.fightsystem.utils.Region;
|
import de.steamwar.fightsystem.utils.Region;
|
||||||
import de.steamwar.fightsystem.winconditions.Winconditions;
|
import de.steamwar.fightsystem.winconditions.Winconditions;
|
||||||
import de.steamwar.sql.*;
|
import de.steamwar.sql.*;
|
||||||
@@ -110,7 +109,7 @@ public class Config {
|
|||||||
Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!");
|
Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!");
|
||||||
Bukkit.shutdown();
|
Bukkit.shutdown();
|
||||||
}
|
}
|
||||||
GameModeConfig = new GameModeConfig<>(new File(FightSystem.getPlugin().getDataFolder(), configFile), YMLWrapperUtils.ToMaterial, YMLWrapper.ToSchematicType, Winconditions::valueOf, YMLWrapper.ToStaticWarGear);
|
GameModeConfig = new GameModeConfig<>(new File(FightSystem.getPlugin().getDataFolder(), configFile), GameModeConfigUtils.ToMaterial, de.steamwar.data.GameModeConfig.ToSchematicType, Winconditions::valueOf, de.steamwar.data.GameModeConfig.ToStaticWarGear);
|
||||||
|
|
||||||
File worldConfigFile = new File(world.getWorldFolder(), "config.yml");
|
File worldConfigFile = new File(world.getWorldFolder(), "config.yml");
|
||||||
if(!worldConfigFile.exists()) {
|
if(!worldConfigFile.exists()) {
|
||||||
|
|||||||
+2
-3
@@ -20,8 +20,7 @@
|
|||||||
package de.steamwar.schematicsystem;
|
package de.steamwar.schematicsystem;
|
||||||
|
|
||||||
import de.steamwar.data.GameModeConfig;
|
import de.steamwar.data.GameModeConfig;
|
||||||
import de.steamwar.data.YMLWrapper;
|
import de.steamwar.data.GameModeConfigUtils;
|
||||||
import de.steamwar.data.YMLWrapperUtils;
|
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -39,7 +38,7 @@ public class CheckSchemTypeManager {
|
|||||||
File folder = new File(SchematicSystem.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
File folder = new File(SchematicSystem.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
||||||
if(folder.exists()) {
|
if(folder.exists()) {
|
||||||
for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) {
|
for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) {
|
||||||
GameModeConfig<Material, SchematicType, String> gameModeConfig = new GameModeConfig<>(configFile, YMLWrapperUtils.ToMaterial, YMLWrapper.ToSchematicType, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear);
|
GameModeConfig<Material, SchematicType, String> gameModeConfig = new GameModeConfig<>(configFile, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
|
||||||
if (gameModeConfig.CheckQuestions.isEmpty() && gameModeConfig.Schematic.ManualCheck)
|
if (gameModeConfig.CheckQuestions.isEmpty() && gameModeConfig.Schematic.ManualCheck)
|
||||||
continue;
|
continue;
|
||||||
types.put(gameModeConfig.Schematic.Type, gameModeConfig);
|
types.put(gameModeConfig.Schematic.Type, gameModeConfig);
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ import org.bukkit.Material;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class YMLWrapperUtils {
|
public class GameModeConfigUtils {
|
||||||
|
|
||||||
public static final Function<String, Material> ToMaterial = material -> {
|
public static final Function<String, Material> ToMaterial = material -> {
|
||||||
Material mat = Material.getMaterial(material);
|
Material mat = Material.getMaterial(material);
|
||||||
@@ -21,7 +21,6 @@ package de.steamwar.sql;
|
|||||||
|
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.data.GameModeConfig;
|
import de.steamwar.data.GameModeConfig;
|
||||||
import de.steamwar.data.YMLWrapper;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -39,7 +38,7 @@ public class SQLWrapperImpl implements SQLWrapper {
|
|||||||
File folder = new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
File folder = new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
||||||
if (!folder.exists()) return;
|
if (!folder.exists()) return;
|
||||||
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())) {
|
||||||
GameModeConfig<String, String, String> gameModeConfig = new GameModeConfig<>(configFile, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear);
|
GameModeConfig<String, String, String> gameModeConfig = new GameModeConfig<>(configFile, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
|
||||||
if (!gameModeConfig.Schematic.loaded) continue;
|
if (!gameModeConfig.Schematic.loaded) continue;
|
||||||
String type = gameModeConfig.Schematic.Type;
|
String type = gameModeConfig.Schematic.Type;
|
||||||
assert type != null;
|
assert type != null;
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ package de.steamwar.sql;
|
|||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import de.steamwar.data.GameModeConfig;
|
import de.steamwar.data.GameModeConfig;
|
||||||
import de.steamwar.data.YMLWrapper;
|
|
||||||
import de.steamwar.velocitycore.VelocityCore;
|
import de.steamwar.velocitycore.VelocityCore;
|
||||||
import de.steamwar.velocitycore.commands.CheckCommand;
|
import de.steamwar.velocitycore.commands.CheckCommand;
|
||||||
|
|
||||||
@@ -40,7 +39,7 @@ public class SQLWrapperImpl implements SQLWrapper {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
for(File file : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().toList()) {
|
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, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToInternalName);
|
GameModeConfig<String, String, String> gameModeConfig = new GameModeConfig<>(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToInternalName);
|
||||||
if (!gameModeConfig.Schematic.loaded) continue;
|
if (!gameModeConfig.Schematic.loaded) continue;
|
||||||
if (tmpFromDB.containsKey(gameModeConfig.Schematic.Type.toLowerCase())) continue;
|
if (tmpFromDB.containsKey(gameModeConfig.Schematic.Type.toLowerCase())) continue;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
package de.steamwar.velocitycore;
|
package de.steamwar.velocitycore;
|
||||||
|
|
||||||
import de.steamwar.data.GameModeConfig;
|
import de.steamwar.data.GameModeConfig;
|
||||||
import de.steamwar.data.YMLWrapper;
|
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
@@ -52,7 +51,7 @@ public class ArenaMode {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
for(File file : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().toList()) {
|
for(File file : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().toList()) {
|
||||||
GameModeConfig<String, SchematicType, String> gameModeConfig = new GameModeConfig<>(file, YMLWrapper.ToString, YMLWrapper.ToSchematicType, YMLWrapper.ToString, YMLWrapper.ToInternalName);
|
GameModeConfig<String, SchematicType, String> gameModeConfig = new GameModeConfig<>(file, GameModeConfig.ToString, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToInternalName);
|
||||||
if (!gameModeConfig.Server.loaded) continue;
|
if (!gameModeConfig.Server.loaded) continue;
|
||||||
|
|
||||||
allModes.add(gameModeConfig);
|
allModes.add(gameModeConfig);
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
package de.steamwar.sql
|
package de.steamwar.sql
|
||||||
|
|
||||||
import de.steamwar.data.GameModeConfig
|
import de.steamwar.data.GameModeConfig
|
||||||
import de.steamwar.data.YMLWrapper
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.stream.Collectors
|
import java.util.stream.Collectors
|
||||||
@@ -30,7 +29,7 @@ fun loadSchematicTypes(tmpTypes: MutableList<SchematicType>?, tmpFromDB: Mutable
|
|||||||
if (folder.exists()) {
|
if (folder.exists()) {
|
||||||
for (configFile in Arrays.stream(folder.listFiles { _, name -> name.endsWith(".yml") && !name.endsWith(".kits.yml") })
|
for (configFile in Arrays.stream(folder.listFiles { _, name -> name.endsWith(".yml") && !name.endsWith(".kits.yml") })
|
||||||
.sorted().collect(Collectors.toList())) {
|
.sorted().collect(Collectors.toList())) {
|
||||||
val gameModeConfig = GameModeConfig(configFile, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToString, YMLWrapper.ToStaticWarGear)
|
val gameModeConfig = GameModeConfig(configFile, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear)
|
||||||
|
|
||||||
if (!gameModeConfig.Schematic.loaded) continue
|
if (!gameModeConfig.Schematic.loaded) continue
|
||||||
val type = gameModeConfig.Schematic.Type
|
val type = gameModeConfig.Schematic.Type
|
||||||
|
|||||||
Reference in New Issue
Block a user