forked from SteamWar/SteamWar
Make SchematicType static init type safe
This commit is contained in:
@@ -23,12 +23,14 @@ import de.steamwar.ImplementationProvider;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface SQLWrapper {
|
||||
SQLWrapper impl = ImplementationProvider.getImpl("de.steamwar.sql.SQLWrapperImpl");
|
||||
public interface SQLWrapper<M> {
|
||||
SQLWrapper<?> impl = ImplementationProvider.getImpl("de.steamwar.sql.SQLWrapperImpl");
|
||||
|
||||
File getSchemTypesFolder();
|
||||
|
||||
default void processSchematicType(GameModeConfig<String, String> gameModeConfig) {
|
||||
GameModeConfig<M, String> loadGameModeConfig(File file);
|
||||
|
||||
default void processSchematicType(GameModeConfig<?, String> gameModeConfig) {
|
||||
}
|
||||
|
||||
void additionalExceptionMetadata(StringBuilder builder);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class SchematicType {
|
||||
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> gameModeConfig = new GameModeConfig<>(configFile, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
|
||||
GameModeConfig<?, String> gameModeConfig = SQLWrapper.impl.loadGameModeConfig(configFile);
|
||||
if (gameModeConfig.Schematic.Type == null) continue;
|
||||
if (tmpFromDB.containsKey(gameModeConfig.Schematic.Type.toDB())) continue;
|
||||
SchematicType current = gameModeConfig.Schematic.Type;
|
||||
|
||||
@@ -20,19 +20,26 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.data.GameModeConfigUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SQLWrapperImpl implements SQLWrapper {
|
||||
public class SQLWrapperImpl implements SQLWrapper<Material> {
|
||||
|
||||
@Override
|
||||
public File getSchemTypesFolder() {
|
||||
return new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameModeConfig<Material, String> loadGameModeConfig(File file) {
|
||||
return new GameModeConfig<>(file, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
|
||||
}
|
||||
|
||||
private static final String SERVER_VERSION = Bukkit.getServer().getVersion();
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,7 +26,7 @@ import de.steamwar.velocitycore.commands.CheckCommand;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SQLWrapperImpl implements SQLWrapper {
|
||||
public class SQLWrapperImpl implements SQLWrapper<String> {
|
||||
|
||||
@Override
|
||||
public File getSchemTypesFolder() {
|
||||
@@ -34,7 +34,12 @@ public class SQLWrapperImpl implements SQLWrapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processSchematicType(GameModeConfig<String, String> gameModeConfig) {
|
||||
public GameModeConfig<String, String> loadGameModeConfig(File file) {
|
||||
return new GameModeConfig<>(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToInternalName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processSchematicType(GameModeConfig<?, String> gameModeConfig) {
|
||||
SchematicType type = gameModeConfig.Schematic.Type;
|
||||
if (type.checkType() != null) {
|
||||
CheckCommand.setCheckQuestions(type.checkType(), gameModeConfig.CheckQuestions);
|
||||
|
||||
@@ -21,11 +21,15 @@ package de.steamwar.sql
|
||||
|
||||
import java.io.File
|
||||
|
||||
class SQLWrapperImpl: SQLWrapper {
|
||||
override fun getSchemTypesFolder(): File? {
|
||||
class SQLWrapperImpl: SQLWrapper<String> {
|
||||
override fun getSchemTypesFolder(): File {
|
||||
return File("/configs/GameModes")
|
||||
}
|
||||
|
||||
override fun loadGameModeConfig(file: File): GameModeConfig<String, String> {
|
||||
return GameModeConfig(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear)
|
||||
}
|
||||
|
||||
override fun additionalExceptionMetadata(builder: StringBuilder) {
|
||||
builder.append("\n\nWebsiteApi")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user