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