Improve GameModeConfig

This commit is contained in:
2025-10-26 12:34:16 +01:00
parent 3e918d031d
commit c6dbece550
36 changed files with 212 additions and 202 deletions
@@ -22,7 +22,7 @@ package de.steamwar.bausystem.region;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.bausystem.utils.FlatteningWrapper;
import de.steamwar.bausystem.utils.PasteBuilder;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.sql.SchematicType;
import lombok.NonNull;
import org.bukkit.Location;
@@ -67,7 +67,7 @@ public interface Region {
Area getTestblockArea();
@NonNull
GameModeConfig<Material, SchematicType, String> getGameModeConfig();
GameModeConfig<Material, String> getGameModeConfig();
@NonNull
RegionHistory getHistory();
@@ -22,9 +22,8 @@ package de.steamwar.bausystem.region.fixed;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.bausystem.region.*;
import de.steamwar.bausystem.utils.PasteBuilder;
import de.steamwar.data.GameModeConfig;
import de.steamwar.data.GameModeConfigUtils;
import de.steamwar.sql.SchematicType;
import de.steamwar.sql.GameModeConfig;
import lombok.NonNull;
import lombok.Setter;
import org.bukkit.Location;
@@ -94,7 +93,7 @@ public final class FixedGlobalRegion implements Region {
}
};
private static final GameModeConfig<Material, SchematicType, String> GLOBAL_CONFIG = new GameModeConfig<>(null, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
private static final GameModeConfig<Material, String> GLOBAL_CONFIG = new GameModeConfig<>(null, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
private FixedGlobalRegion() {
}
@@ -28,8 +28,8 @@ import de.steamwar.bausystem.utils.FlatteningWrapper;
import de.steamwar.bausystem.utils.PasteBuilder;
import de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.core.Core;
import de.steamwar.data.GameModeConfig;
import de.steamwar.data.GameModeConfigUtils;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.sql.SchematicType;
import lombok.NonNull;
import org.bukkit.Bukkit;
@@ -60,7 +60,7 @@ public class FixedRegion implements Region {
private final Area testblock;
private final int floorLevel;
private final int waterLevel;
private final GameModeConfig<Material, SchematicType, String> gameModeConfig;
private final GameModeConfig<Material, String> gameModeConfig;
private final RegionData regionData;
private final RegionHistory regionHistory = new RegionHistory.Impl(20);
@@ -339,7 +339,7 @@ public class FixedRegion implements Region {
break;
}
}
this.gameModeConfig = new GameModeConfig<>(found, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
this.gameModeConfig = new GameModeConfig<>(found, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
this.regionData = new RegionData.RegionDataImpl(regionData, WorldData::write);
}
@@ -17,12 +17,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.data;
package de.steamwar.sql;
import de.steamwar.sql.SchematicType;
import lombok.ToString;
import java.io.File;
import java.lang.reflect.Field;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
@@ -32,10 +32,9 @@ import java.util.function.Function;
import java.util.stream.Collectors;
@ToString
public final class GameModeConfig<M, ST, W> {
public final class GameModeConfig<M, 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", "");
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm");
@@ -44,10 +43,11 @@ public final class GameModeConfig<M, ST, W> {
public final boolean loaded;
public final File configFile;
public final Server Server;
public final ServerConfig Server;
/**
* Submission deadline for schematics in 'dd.MM.yyyy HH:mm' format
*
* @implSpec {@code null} by default
*/
public final Date Deadline;
@@ -58,9 +58,9 @@ public final class GameModeConfig<M, ST, W> {
* @implSpec Disables check schem type if missing
*/
public final List<String> CheckQuestions;
public final Times Times;
public final Arena Arena;
public final Schematic<M, ST> Schematic;
public final TimesConfig Times;
public final ArenaConfig Arena;
public final SchematicConfig<M> Schematic;
/**
* The name of the game mode presented to the players
@@ -83,28 +83,39 @@ public final class GameModeConfig<M, ST, W> {
* @implSpec {@code +} by default
*/
public final String TeamChatPrefix;
public final Blue Blue;
public final Red Red;
public final BlueConfig Blue;
public final RedConfig Red;
/**
* The list of active win conditions
*/
public final List<W> WinConditions;
public final WinConditionParams<M> WinConditionParams;
public final Kits<M> Kits;
public final WinConditionParamsConfig<M> WinConditionParams;
public final KitsConfig<M> Kits;
/**
* A list of integers containing the waiting time of this enter stage in the fight
*/
public final List<Integer> EnterStages;
public final Techhider<M> Techhider;
public final TechhiderConfig<M> Techhider;
public GameModeConfig(File file, Function<String, M> materialMapper, Function<String, ST> schematicTypeMapper, Function<String, W> winconditionMapper, Function<File, String> defaultGameName) {
YMLWrapper<M, ST, W> loader = new YMLWrapper<>(file, materialMapper, schematicTypeMapper, winconditionMapper);
private static final Field Schematic_TypeField;
static {
try {
Schematic_TypeField = SchematicConfig.class.getDeclaredField("Type");
Schematic_TypeField.setAccessible(true);
} catch (NoSuchFieldException e) {
throw new SecurityException(e.getMessage(), e);
}
}
public GameModeConfig(File file, Function<String, M> materialMapper, Function<String, W> winconditionMapper, Function<File, String> defaultGameName) {
YMLWrapper<M, W> loader = new YMLWrapper<>(file, materialMapper, winconditionMapper);
configFile = file;
loaded = loader.canLoad();
Server = new Server(loader.with("Server"));
Server = new ServerConfig(loader.with("Server"));
String deadlineString = loader.getString("Deadline", null);
if (deadlineString != null) {
@@ -120,25 +131,44 @@ public final class GameModeConfig<M, ST, W> {
}
CheckQuestions = loader.getStringList("CheckQuestions");
Times = new Times(loader.with("Times"));
Times = new TimesConfig(loader.with("Times"));
// Arena would be here to be in config order but needs Schematic.Size and EnterStages loaded afterwards
Schematic = new Schematic<>(loader.with("Schematic"));
Schematic = new SchematicConfig<>(loader.with("Schematic"));
GameName = loader.getString("GameName", defaultGameName.apply(file));
ActiveMonths = loader.getIntList("ActiveMonths");
TeamChatPrefix = loader.getString("TeamChatPrefix", "+");
Blue = new Blue(loader.with("Blue"));
Red = new Red(loader.with("Red"));
Blue = new BlueConfig(loader.with("Blue"));
Red = new RedConfig(loader.with("Red"));
WinConditions = Collections.unmodifiableList(loader.getStringList("WinConditions").stream().map(loader.winconditionMapper).collect(Collectors.toList()));
WinConditionParams = new WinConditionParams<>(loader.with("WinConditionParams"));
Kits = new Kits<>(loader.with("Kits"));
WinConditionParams = new WinConditionParamsConfig<>(loader.with("WinConditionParams"));
Kits = new KitsConfig<>(loader.with("Kits"));
EnterStages = loader.getIntList("EnterStages");
Techhider = new Techhider<>(loader.with("Techhider"));
Techhider = new TechhiderConfig<>(loader.with("Techhider"));
Arena = new Arena(loader.with("Arena"), Schematic.Size, EnterStages);
Arena = new ArenaConfig(loader.with("Arena"), Schematic.Size, EnterStages);
if (Schematic.Type != null) return;
if (!Schematic.loaded) return;
String Schematic_Type = loader.with("Schematic").getString("Type", "Normal");
if (Schematic_Type.equals("Normal")) return;
String Schematic_Shortcut = Schematic.Shortcut;
SchematicType checktype = null;
String material = loader.with("Schematic").getString("Material", "STONE_BUTTON");
if (!CheckQuestions.isEmpty()) {
checktype = new SchematicType("C" + Schematic_Type, "C" + Schematic_Shortcut, SchematicType.Type.CHECK_TYPE, null, material, true);
}
SchematicType current = new SchematicType(Schematic_Type, Schematic_Shortcut, Server.loaded ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, Deadline, Schematic.ManualCheck);
try {
Schematic_TypeField.set(Schematic, current);
} catch (IllegalAccessException e) {
throw new SecurityException(e.getMessage(), e);
}
}
@ToString
public static final class Server {
public static final class ServerConfig {
public final boolean loaded;
@@ -183,7 +213,7 @@ public final class GameModeConfig<M, ST, W> {
*/
public final boolean Ranked;
private Server(YMLWrapper loader) {
private ServerConfig(YMLWrapper loader) {
loaded = loader.canLoad();
Folder = loader.getString("Folder", null);
ServerJar = loader.getString("ServerJar", null);
@@ -196,7 +226,7 @@ public final class GameModeConfig<M, ST, W> {
}
@ToString
public static final class Times {
public static final class TimesConfig {
public final boolean loaded;
/**
@@ -234,7 +264,7 @@ public final class GameModeConfig<M, ST, W> {
*/
public final int SpectatorDuration;
private Times(YMLWrapper loader) {
private TimesConfig(YMLWrapper loader) {
loaded = loader.canLoad();
NoPlayersOnlineDuration = loader.getInt("NoPlayersOnlineDuration", 300);
PreSchemPasteDuration = loader.getInt("PreSchemPasteDuration", 120);
@@ -245,7 +275,7 @@ public final class GameModeConfig<M, ST, W> {
}
@ToString
public static final class Arena {
public static final class ArenaConfig {
public final boolean loaded;
@@ -259,12 +289,12 @@ public final class GameModeConfig<M, ST, W> {
/**
* The outer border of the arena, measured in blocks around the schematic areas
*/
public final Schem2Border Schem2Border;
public final Schem2BorderConfig Schem2Border;
/**
* The offset the teams spawn relative to the center of their area
*/
public final SpawnOffset SpawnOffset;
public final SpawnOffsetConfig SpawnOffset;
/**
* The size of the team areas are expanded around the schematics
@@ -308,11 +338,11 @@ public final class GameModeConfig<M, ST, W> {
*/
public final boolean NoFloor;
private Arena(YMLWrapper loader, Schematic.Size Size, List<Integer> EnterStages) {
private ArenaConfig(YMLWrapper loader, SchematicConfig.SizeConfig Size, List<Integer> EnterStages) {
loaded = loader.canLoad();
WaterDepth = loader.getInt("WaterDepth", 0);
Schem2Border = new Schem2Border(loader.with("Schem2Border"));
SpawnOffset = new SpawnOffset(loader.with("SpawnOffset"), Size);
Schem2Border = new Schem2BorderConfig(loader.with("Schem2Border"));
SpawnOffset = new SpawnOffsetConfig(loader.with("SpawnOffset"), Size);
BorderFromSchematic = loader.getInt("BorderFromSchematic", 21);
GroundWalkable = loader.getBoolean("GroundWalkable", true);
DisableSnowMelt = loader.getBoolean("DisableSnowMelt", false);
@@ -322,7 +352,7 @@ public final class GameModeConfig<M, ST, W> {
}
@ToString
public static final class Schem2Border {
public static final class Schem2BorderConfig {
public final boolean loaded;
@@ -336,7 +366,7 @@ public final class GameModeConfig<M, ST, W> {
*/
public final int z;
private Schem2Border(YMLWrapper loader) {
private Schem2BorderConfig(YMLWrapper loader) {
loaded = loader.canLoad();
x = loader.getInt("x", 24);
z = loader.getInt("z", 24);
@@ -344,7 +374,7 @@ public final class GameModeConfig<M, ST, W> {
}
@ToString
public static final class SpawnOffset {
public static final class SpawnOffsetConfig {
public final boolean loaded;
@@ -363,7 +393,7 @@ public final class GameModeConfig<M, ST, W> {
*/
public final double z;
private SpawnOffset(YMLWrapper loader, Schematic.Size Size) {
private SpawnOffsetConfig(YMLWrapper loader, SchematicConfig.SizeConfig Size) {
loaded = loader.canLoad();
x = loader.getDouble("x", 0);
y = loader.getDouble("y", Size.y);
@@ -373,31 +403,31 @@ public final class GameModeConfig<M, ST, W> {
}
@ToString
public static final class Schematic<M, ST> {
public static final class SchematicConfig<M> {
public final boolean loaded;
/**
* The size of the schematics
*/
public final Size Size;
public final SizeConfig Size;
/**
* Used for GameModes with a technic area
*/
public final Inset Inset;
public final InsetConfig Inset;
/**
* The schematic type that can be chosen in this arena
*
* @implSpec {@code Normal} by default
*/
public final ST Type;
public final SchematicType Type;
/**
* The schematic types that are also allowed to be chosen in this arena
*/
public final List<ST> SubTypes;
public final List<SchematicType> SubTypes;
/**
* Shortcut of the schematic type
@@ -496,10 +526,10 @@ public final class GameModeConfig<M, ST, W> {
*/
public final Map<Set<M>, Integer> Limited;
private Schematic(YMLWrapper<M, ST, ?> loader) {
private SchematicConfig(YMLWrapper<M, ?> loader) {
loaded = loader.canLoad();
Size = new Size(loader.with("Size"));
Inset = new Inset(loader.with("Inset"));
Size = new SizeConfig(loader.with("Size"));
Inset = new InsetConfig(loader.with("Inset"));
Type = loader.getSchematicType("Type", "Normal");
SubTypes = loader.getSchematicTypeList("SubTypes");
Shortcut = loader.getString("Shortcut", "");
@@ -532,7 +562,7 @@ public final class GameModeConfig<M, ST, W> {
}
@ToString
public static final class Size {
public static final class SizeConfig {
public final boolean loaded;
@@ -551,7 +581,7 @@ public final class GameModeConfig<M, ST, W> {
*/
public final int z;
private Size(YMLWrapper loader) {
private SizeConfig(YMLWrapper loader) {
loaded = loader.canLoad();
x = loader.getInt("x", 0);
y = loader.getInt("y", 0);
@@ -560,7 +590,7 @@ public final class GameModeConfig<M, ST, W> {
}
@ToString
public static final class Inset {
public static final class InsetConfig {
public final boolean loaded;
@@ -584,7 +614,7 @@ public final class GameModeConfig<M, ST, W> {
*/
public final int bottom;
private Inset(YMLWrapper loader) {
private InsetConfig(YMLWrapper loader) {
loaded = loader.canLoad();
x = loader.getInt("x", 0);
z = loader.getInt("z", 0);
@@ -595,7 +625,7 @@ public final class GameModeConfig<M, ST, W> {
}
@ToString
public static final class Blue {
public static final class BlueConfig {
public final boolean loaded;
@@ -609,7 +639,7 @@ public final class GameModeConfig<M, ST, W> {
*/
public final String Prefix;
private Blue(YMLWrapper loader) {
private BlueConfig(YMLWrapper loader) {
loaded = loader.canLoad();
Name = loader.getString("Name", "Blau");
Prefix = loader.getString("Prefix", "§3");
@@ -617,7 +647,7 @@ public final class GameModeConfig<M, ST, W> {
}
@ToString
public static final class Red {
public static final class RedConfig {
public final boolean loaded;
@@ -631,7 +661,7 @@ public final class GameModeConfig<M, ST, W> {
*/
public final String Prefix;
private Red(YMLWrapper loader) {
private RedConfig(YMLWrapper loader) {
loaded = loader.canLoad();
Name = loader.getString("Name", "Rot");
Prefix = loader.getString("Prefix", "§c");
@@ -639,7 +669,7 @@ public final class GameModeConfig<M, ST, W> {
}
@ToString
public static final class WinConditionParams<M> {
public static final class WinConditionParamsConfig<M> {
public final boolean loaded;
@@ -683,7 +713,7 @@ public final class GameModeConfig<M, ST, W> {
*/
public final int TechKoTime;
private WinConditionParams(YMLWrapper<M, ?, ?> loader) {
private WinConditionParamsConfig(YMLWrapper<M, ?> loader) {
loaded = loader.canLoad();
TimeoutTime = loader.getInt("TimeoutTime", 1200);
PercentWin = loader.getDouble("PercentWin", 7.0);
@@ -695,7 +725,7 @@ public final class GameModeConfig<M, ST, W> {
}
@ToString
public static final class Kits<M> {
public static final class KitsConfig<M> {
public final boolean loaded;
@@ -732,7 +762,7 @@ public final class GameModeConfig<M, ST, W> {
*/
public final List<M> ForbiddenItems;
private Kits(YMLWrapper<M, ?, ?> loader) {
private KitsConfig(YMLWrapper<M, ?> loader) {
loaded = loader.canLoad();
File = loader.getString("File", "kits.yml");
MemberDefault = loader.getString("MemberDefault", "default");
@@ -743,7 +773,7 @@ public final class GameModeConfig<M, ST, W> {
}
@ToString
public static final class Techhider<M> {
public static final class TechhiderConfig<M> {
public final boolean loaded;
@@ -771,7 +801,7 @@ public final class GameModeConfig<M, ST, W> {
*/
public final Set<String> HiddenBlockEntities;
private Techhider(YMLWrapper<M, ?, ?> loader) {
private TechhiderConfig(YMLWrapper<M, ?> loader) {
loaded = loader.canLoad();
Active = loader.getBoolean("Active", false);
ObfuscateWith = loader.getMaterial("ObfuscateWith", "end_stone");
@@ -816,12 +846,7 @@ public final class GameModeConfig<M, ST, W> {
public String getSchemTypeOrInternalName() {
if (Schematic.loaded) {
ST type = Schematic.Type;
if (type instanceof SchematicType) {
return ((SchematicType) type).toDB();
} else if (type instanceof String) {
return (String) type;
}
return Schematic.Type.toDB();
}
return configFile.getName().replace(".yml", "");
}
@@ -20,7 +20,6 @@
package de.steamwar.sql;
import de.steamwar.ImplementationProvider;
import de.steamwar.data.GameModeConfig;
import java.io.File;
@@ -29,7 +28,7 @@ public interface SQLWrapper {
File getSchemTypesFolder();
default void processSchematicType(GameModeConfig<String, String, String> gameModeConfig, SchematicType type) {
default void processSchematicType(GameModeConfig<String, String> gameModeConfig) {
}
void additionalExceptionMetadata(StringBuilder builder);
@@ -19,7 +19,6 @@
package de.steamwar.sql;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.internal.SqlTypeMapper;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -47,28 +46,18 @@ 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, String> gameModeConfig = new GameModeConfig<>(configFile, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
if (!gameModeConfig.Schematic.loaded) continue;
String type = gameModeConfig.Schematic.Type;
assert type != null;
String shortcut = gameModeConfig.Schematic.Shortcut;
if (tmpFromDB.containsKey(type.toLowerCase()))
continue;
SchematicType checktype = null;
String material = gameModeConfig.Schematic.Material;
GameModeConfig<String, String> gameModeConfig = new GameModeConfig<>(configFile, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
if (gameModeConfig.Schematic.Type == null) continue;
if (tmpFromDB.containsKey(gameModeConfig.Schematic.Type.toDB())) continue;
SchematicType current = gameModeConfig.Schematic.Type;
if (!gameModeConfig.CheckQuestions.isEmpty()) {
checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true);
tmpTypes.add(checktype);
tmpFromDB.put(checktype.toDB(), checktype);
SchematicType checkType = current.checkType;
tmpTypes.add(checkType);
tmpFromDB.put(checkType.toDB(), checkType);
}
SchematicType current = new SchematicType(type, shortcut, gameModeConfig.Server.loaded ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, gameModeConfig.Deadline, gameModeConfig.Schematic.ManualCheck);
tmpTypes.add(current);
tmpFromDB.put(type.toLowerCase(), current);
SQLWrapper.impl.processSchematicType(gameModeConfig, current);
tmpFromDB.put(current.toDB(), current);
SQLWrapper.impl.processSchematicType(gameModeConfig);
}
}
time = System.currentTimeMillis() - time;
@@ -143,6 +132,7 @@ public class SchematicType {
}
public static SchematicType fromDB(String input) {
if (fromDB == null) return null;
return fromDB.get(input.toLowerCase());
}
@@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.data;
package de.steamwar.sql;
import org.yaml.snakeyaml.Yaml;
@@ -31,18 +31,16 @@ import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
final class YMLWrapper<M, ST, W> {
final class YMLWrapper<M, W> {
final Function<String, M> materialMapper;
final Function<String, ST> schematicTypeMapper;
final Function<String, W> winconditionMapper;
private final boolean canLoad;
private final Map<String, Object> document;
YMLWrapper(File file, Function<String, M> materialMapper, Function<String, ST> schematicTypeMapper, Function<String, W> winconditionMapper) {
YMLWrapper(File file, Function<String, M> materialMapper, Function<String, W> winconditionMapper) {
this.materialMapper = materialMapper;
this.schematicTypeMapper = schematicTypeMapper;
this.winconditionMapper = winconditionMapper;
Yaml yaml = new Yaml();
@@ -60,9 +58,8 @@ final class YMLWrapper<M, ST, W> {
this.canLoad = canLoad;
}
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, W> winconditionMapper) {
this.materialMapper = materialMapper;
this.schematicTypeMapper = schematicTypeMapper;
this.winconditionMapper = winconditionMapper;
this.canLoad = canLoad;
this.document = document;
@@ -72,24 +69,26 @@ final class YMLWrapper<M, ST, W> {
return canLoad;
}
public YMLWrapper<M, ST, W> with(String path) {
public YMLWrapper<M, W> with(String path) {
if (document.containsKey(path)) {
Object value = document.get(path);
if (value instanceof Map) {
return new YMLWrapper<>(true, (Map) value, materialMapper, schematicTypeMapper, winconditionMapper);
return new YMLWrapper<>(true, (Map) value, materialMapper, winconditionMapper);
}
}
return new YMLWrapper<>(false, Collections.emptyMap(), materialMapper, schematicTypeMapper, winconditionMapper);
return new YMLWrapper<>(false, Collections.emptyMap(), materialMapper, winconditionMapper);
}
public <T> T get(String path, T defaultValue, Function<Object, T> mapper) {
Object value = this.document.get(path);
if (value == null) return defaultValue;
try {
return mapper.apply(value);
T mapped = mapper.apply(value);
if (mapped != null) return mapped;
} catch (ClassCastException e) {
return defaultValue;
// Ignore exception
}
return defaultValue;
}
public String getString(String path, String defaultValue) {
@@ -108,9 +107,9 @@ final class YMLWrapper<M, ST, W> {
return get(path, defaultValue, Boolean.class::cast);
}
public ST getSchematicType(String path, String defaultValue) {
public SchematicType getSchematicType(String path, String defaultValue) {
String schematicType = getString(path, defaultValue);
return schematicTypeMapper.apply(schematicType);
return SchematicType.fromDB(schematicType);
}
public M getMaterial(String path, String defaultValue) {
@@ -135,12 +134,12 @@ final class YMLWrapper<M, ST, W> {
return get(path, o -> (List<Integer>) o);
}
public List<ST> getSchematicTypeList(String path) {
public List<SchematicType> getSchematicTypeList(String path) {
List<String> list = getStringList(path);
if (list.isEmpty()) {
return Collections.emptyList();
} else {
return Collections.unmodifiableList(list.stream().map(schematicTypeMapper).collect(Collectors.toList()));
return Collections.unmodifiableList(list.stream().map(SchematicType::fromDB).collect(Collectors.toList()));
}
}
@@ -19,7 +19,7 @@
package de.steamwar.fightsystem;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.data.GameModeConfigUtils;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.fightsystem.winconditions.Winconditions;
@@ -45,7 +45,7 @@ public class Config {
public static final World world = Bukkit.getWorlds().get(0);
public static final GameModeConfig<Material, SchematicType, Winconditions> GameModeConfig;
public static final GameModeConfig<Material, Winconditions> GameModeConfig;
//arena parameter
public static final Region BluePasteRegion;
@@ -109,7 +109,7 @@ public class Config {
Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!");
Bukkit.shutdown();
}
GameModeConfig = new GameModeConfig<>(new File(FightSystem.getPlugin().getDataFolder(), configFile), GameModeConfigUtils.ToMaterial, de.steamwar.data.GameModeConfig.ToSchematicType, Winconditions::valueOf, de.steamwar.data.GameModeConfig.ToStaticWarGear);
GameModeConfig = new GameModeConfig<>(new File(FightSystem.getPlugin().getDataFolder(), configFile), GameModeConfigUtils.ToMaterial, Winconditions::valueOf, de.steamwar.sql.GameModeConfig.ToStaticWarGear);
File worldConfigFile = new File(world.getWorldFolder(), "config.yml");
if(!worldConfigFile.exists()) {
@@ -24,7 +24,7 @@ import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.sql.SchematicType;
import org.bukkit.Material;
@@ -119,7 +119,7 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker {
}
@Override
public AutoCheckerResult check(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type) {
public AutoCheckerResult check(Clipboard clipboard, GameModeConfig<Material, String> type) {
return AutoCheckerResult.builder()
.type(type)
.height(clipboard.getDimensions().getBlockY())
@@ -131,7 +131,7 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker {
}
@Override
public AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type) {
public AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, String> type) {
return AutoCheckerResult.builder()
.type(type)
.height(clipboard.getDimensions().getBlockY())
@@ -31,7 +31,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
import de.steamwar.schematicsystem.autocheck.BlockPos;
import de.steamwar.sql.SchematicType;
@@ -42,7 +42,7 @@ import java.util.stream.Collectors;
public class SchematicCommand15 implements SchematicCommand.ISchematicCommand {
@Override
public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig<Material, SchematicType, String> type) throws Exception {
public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig<Material, String> type) throws Exception {
for (BlockPos blockPos : result.getBlockScanResult().getRecords()) {
BlockVector3 vector = BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ());
clipboard.setBlock(vector, clipboard.getFullBlock(vector).toBaseBlock(new CompoundTag(Collections.emptyMap())));
@@ -25,7 +25,7 @@ import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.regions.Region;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.sql.SchematicType;
import org.bukkit.Material;
@@ -149,7 +149,7 @@ public class AutoChecker8 implements AutoChecker.IAutoChecker {
}
@Override
public AutoCheckerResult check(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type) {
public AutoCheckerResult check(Clipboard clipboard, GameModeConfig<Material, String> type) {
AutoChecker.BlockScanResult blockScanResult = new AutoChecker.BlockScanResult();
scan(blockScanResult, clipboard);
@@ -164,7 +164,7 @@ public class AutoChecker8 implements AutoChecker.IAutoChecker {
}
@Override
public AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type) {
public AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, String> type) {
return AutoCheckerResult.builder()
.type(type)
.height(clipboard.getDimensions().getBlockY())
@@ -24,7 +24,7 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
import de.steamwar.sql.SchematicType;
import org.bukkit.Material;
@@ -32,7 +32,7 @@ import org.bukkit.Material;
public class SchematicCommand8 implements SchematicCommand.ISchematicCommand {
@Override
public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig<Material, SchematicType, String> type) throws Exception {
public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig<Material, String> type) throws Exception {
return null;
}
@@ -19,7 +19,7 @@
package de.steamwar.schematicsystem;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.data.GameModeConfigUtils;
import de.steamwar.linkage.AbstractLinker;
import de.steamwar.linkage.SpigotLinker;
@@ -38,9 +38,9 @@ public class SchematicSystem extends JavaPlugin {
private static SchematicSystem instance;
private static final Map<SchematicType, GameModeConfig<Material, SchematicType, String>> types = new HashMap<>();
private static final Map<SchematicType, GameModeConfig<Material, String>> types = new HashMap<>();
public static GameModeConfig<Material, SchematicType, String> getGameModeConfig(SchematicType type){
public static GameModeConfig<Material, String> getGameModeConfig(SchematicType type){
return types.get(type);
}
@@ -51,7 +51,7 @@ public class SchematicSystem extends JavaPlugin {
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, SchematicType, String> gameModeConfig = new GameModeConfig<>(configFile, GameModeConfigUtils.ToMaterial, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear);
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);
@@ -21,7 +21,7 @@ package de.steamwar.schematicsystem.autocheck;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.VersionDependent;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.sql.SchematicType;
import lombok.Getter;
@@ -32,19 +32,19 @@ import java.util.*;
public class AutoChecker {
public static AutoCheckerResult check(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type) {
public static AutoCheckerResult check(Clipboard clipboard, GameModeConfig<Material, String> type) {
return impl.check(clipboard, type);
}
public static AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type) {
public static AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, String> type) {
return impl.sizeCheck(clipboard, type);
}
private static final IAutoChecker impl = VersionDependent.getVersionImpl(SchematicSystem.getInstance());
public interface IAutoChecker {
AutoCheckerResult check(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type);
AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type);
AutoCheckerResult check(Clipboard clipboard, GameModeConfig<Material, String> type);
AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, String> type);
}
@Getter
@@ -20,7 +20,7 @@
package de.steamwar.schematicsystem.autocheck;
import de.steamwar.core.Core;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.sql.SchematicType;
import lombok.Builder;
@@ -38,7 +38,7 @@ import java.util.Map;
@Getter
@ToString
public class AutoCheckerResult {
private final GameModeConfig<Material, SchematicType, String> type;
private final GameModeConfig<Material, String> type;
private final int width;
private final int height;
private final int depth;
@@ -27,7 +27,7 @@ import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import de.steamwar.core.VersionDependent;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.Linked;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
@@ -113,7 +113,7 @@ public class SchematicCommand extends SWCommand {
}
@ClassMapper(value = GameModeConfig.class, local = true)
public static TypeMapper<GameModeConfig<Material, SchematicType, String>> gameModeConfigTypeMapper() {
public static TypeMapper<GameModeConfig<Material, String>> gameModeConfigTypeMapper() {
return SchematicMapper.gameModeConfigTypeMapper();
}
@@ -150,7 +150,7 @@ public class SchematicCommand extends SWCommand {
public static final ISchematicCommand impl = VersionDependent.getVersionImpl(SchematicSystem.getInstance());
public interface ISchematicCommand {
Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig<Material, SchematicType, String> type) throws Exception;
Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig<Material, String> type) throws Exception;
void createCopy(EditSession editSession, Clipboard clipboard) throws WorldEditException;
}
}
@@ -20,7 +20,7 @@
package de.steamwar.schematicsystem.commands.schematiccommand;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.network.NetworkSender;
@@ -312,7 +312,7 @@ public class SchematicCommandUtils {
}
}
public static void check(Player player, Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type, String schemName, boolean gui) {
public static void check(Player player, Clipboard clipboard, GameModeConfig<Material, String> type, String schemName, boolean gui) {
AutoCheckerResult result = AutoChecker.check(clipboard, type);
if(!result.isOk()) {
result.sendErrorMessage(player, schemName);
@@ -455,7 +455,7 @@ public class SchematicCommandUtils {
return;
}
GameModeConfig<Material, SchematicType, String> checkSchemType = SchematicSystem.getGameModeConfig(type);
GameModeConfig<Material, String> checkSchemType = SchematicSystem.getGameModeConfig(type);
if (checkSchemType.isAfterDeadline()) {
SchematicSystem.MESSAGE.send("UTIL_TYPE_AFTER_DEADLINE", player, checkSchemType.Deadline);
return;
@@ -20,7 +20,7 @@
package de.steamwar.schematicsystem.commands.schematiccommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.sql.NodeMember;
import de.steamwar.sql.SchematicNode;
@@ -177,15 +177,15 @@ public class SchematicMapper {
};
}
public static TypeMapper<GameModeConfig<Material, SchematicType, String>> gameModeConfigTypeMapper() {
return new TypeMapper<GameModeConfig<Material, SchematicType, String>>() {
public static TypeMapper<GameModeConfig<Material, String>> gameModeConfigTypeMapper() {
return new TypeMapper<GameModeConfig<Material, String>>() {
@Override
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return SchematicType.values().stream().filter(type -> SchematicSystem.getGameModeConfig(type) != null).map(SchematicType::name).collect(Collectors.toList());
}
@Override
public GameModeConfig<Material, SchematicType, String> map(CommandSender commandSender, String[] previousArguments, String s) {
public GameModeConfig<Material, String> map(CommandSender commandSender, String[] previousArguments, String s) {
return SchematicType.values().stream().filter(type -> type.name().equalsIgnoreCase(s)).map(SchematicSystem::getGameModeConfig).findAny().orElse(null);
}
};
@@ -28,7 +28,7 @@ import com.sk89q.worldedit.session.ClipboardHolder;
import de.steamwar.command.AbstractSWCommand;
import de.steamwar.command.SWCommand;
import de.steamwar.core.Core;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.Linked;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoChecker;
@@ -54,7 +54,7 @@ public class CheckPart extends SWCommand {
}
@Register("check")
public void checkCommand(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, GameModeConfig<Material, SchematicType, String> type) {
public void checkCommand(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, GameModeConfig<Material, String> type) {
try {
check(player, new SchematicData(node).load(), type, node.getName(), false);
} catch (IOException e) {
@@ -63,7 +63,7 @@ public class CheckPart extends SWCommand {
}
@Register(value = {"check", "clipboard"})
public void checkClipboardCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig<Material, SchematicType, String> type) {
public void checkClipboardCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig<Material, String> type) {
try {
check(player, WorldEdit.getInstance().getSessionManager().findByName(player.getName()).getClipboard().getClipboard(), type, "clipboard", false);
} catch (EmptyClipboardException e) {
@@ -72,7 +72,7 @@ public class CheckPart extends SWCommand {
}
@Register(value = {"check", "selection"})
public void checkSelectionCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig<Material, SchematicType, String> type) {
public void checkSelectionCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig<Material, String> type) {
try {
Clipboard clipboard = new BlockArrayClipboard(WorldEdit.getInstance().getSessionManager().findByName(player.getName()).getSelection(new BukkitWorld(player.getWorld())));
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(player.getWorld()), -1);
@@ -88,7 +88,7 @@ public class CheckPart extends SWCommand {
}
@Register("fix")
public void fixSchematicCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig<Material, SchematicType, String> type) {
public void fixSchematicCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig<Material, String> type) {
if(Core.getVersion() < 15) {
SchematicSystem.MESSAGE.send("COMMAND_FIX_WRONG_VERSION", player);
return;
@@ -21,7 +21,6 @@ package de.steamwar.sql;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import de.steamwar.data.GameModeConfig;
import de.steamwar.velocitycore.VelocityCore;
import de.steamwar.velocitycore.commands.CheckCommand;
@@ -35,7 +34,8 @@ public class SQLWrapperImpl implements SQLWrapper {
}
@Override
public void processSchematicType(GameModeConfig<String, String, String> gameModeConfig, SchematicType type) {
public void processSchematicType(GameModeConfig<String, String> gameModeConfig) {
SchematicType type = gameModeConfig.Schematic.Type;
if (type.checkType() != null) {
CheckCommand.setCheckQuestions(type.checkType(), gameModeConfig.CheckQuestions);
CheckCommand.addFightType(type.checkType(), type);
@@ -19,7 +19,7 @@
package de.steamwar.velocitycore;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.sql.SchematicType;
import lombok.Getter;
import lombok.experimental.UtilityClass;
@@ -30,11 +30,11 @@ import java.util.*;
@UtilityClass
public class ArenaMode {
private static final Map<String, GameModeConfig<String, SchematicType, String>> byChat = new HashMap<>();
private static final Map<String, GameModeConfig<String, SchematicType, String>> byInternal = new HashMap<>();
private static final Map<SchematicType, GameModeConfig<String, SchematicType, String>> bySchemType = new HashMap<>();
private static final Map<String, GameModeConfig<String, String>> byChat = new HashMap<>();
private static final Map<String, GameModeConfig<String, String>> byInternal = new HashMap<>();
private static final Map<SchematicType, GameModeConfig<String, String>> bySchemType = new HashMap<>();
@Getter
private static final List<GameModeConfig<String, SchematicType, String>> allModes = new LinkedList<>();
private static final List<GameModeConfig<String, String>> allModes = new LinkedList<>();
static {
init();
@@ -51,7 +51,7 @@ public class ArenaMode {
return;
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, GameModeConfig.ToString, GameModeConfig.ToSchematicType, GameModeConfig.ToString, GameModeConfig.ToInternalName);
GameModeConfig<String, String> gameModeConfig = new GameModeConfig<>(file, GameModeConfig.ToString, GameModeConfig.ToString, GameModeConfig.ToInternalName);
if (!gameModeConfig.Server.loaded) continue;
allModes.add(gameModeConfig);
@@ -65,24 +65,24 @@ public class ArenaMode {
}
}
public static GameModeConfig<String, SchematicType, String> getByChat(String name){
public static GameModeConfig<String, String> getByChat(String name){
return byChat.get(name.toLowerCase());
}
public static GameModeConfig<String, SchematicType, String> getByInternal(String name){
public static GameModeConfig<String, String> getByInternal(String name){
return byInternal.get(name);
}
public static List<String> getAllChatNames(boolean historic) {
List<String> chatNames = new LinkedList<>();
for(GameModeConfig<String, SchematicType, String> mode : byInternal.values()){
for(GameModeConfig<String, String> mode : byInternal.values()){
if(mode.isActive() && historic == mode.Server.Historic)
chatNames.addAll(mode.Server.ChatNames);
}
return chatNames;
}
public static GameModeConfig<String, SchematicType, String> getBySchemType(SchematicType schemType){
public static GameModeConfig<String, String> getBySchemType(SchematicType schemType){
return bySchemType.get(schemType);
}
}
@@ -22,7 +22,7 @@ package de.steamwar.velocitycore;
import com.velocitypowered.api.proxy.Player;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.velocity.platform.VelocityViaConfig;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.messages.Chatter;
import de.steamwar.persistent.Arenaserver;
import de.steamwar.persistent.Bauserver;
@@ -80,7 +80,7 @@ public class ServerStarter {
private final Set<Player> playersToSend = new HashSet<>();
private final Map<String, String> arguments = new HashMap<>();
public ServerStarter arena(GameModeConfig<String, SchematicType, String> mode, String map) {
public ServerStarter arena(GameModeConfig<String, String> mode, String map) {
portrange = ARENA_PORTS;
serverNameProvider = port -> mode.GameName + (port - portrange.start);
version = ServerVersion.from(mode);
@@ -116,7 +116,7 @@ public class ServerStarter {
return this;
}
public ServerStarter test(GameModeConfig<String, SchematicType, String> mode, String map, Player owner) {
public ServerStarter test(GameModeConfig<String, String> mode, String map, Player owner) {
arena(mode, map);
buildWithTemp(owner);
portrange = BAU_PORTS;
@@ -20,7 +20,7 @@
package de.steamwar.velocitycore;
import com.velocitypowered.api.network.ProtocolVersion;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.sql.SchematicType;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -115,7 +115,7 @@ public enum ServerVersion {
private static final Pattern terminatingNumber = Pattern.compile("(\\d+)$");
public static ServerVersion from(GameModeConfig<String, SchematicType, String> type) {
public static ServerVersion from(GameModeConfig<String, String> type) {
Matcher matcher = terminatingNumber.matcher(type.Server.Folder);
matcher.find();
return ServerVersion.valueOf((type.Server.Spigot ? "SPIGOT_" : "PAPER_") + matcher.group(1));
@@ -23,7 +23,7 @@ import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.EventMode;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
@@ -240,7 +240,7 @@ public class BauCommand extends SWCommand {
@Register("test")
@Register("testarena")
public void testarena(PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig<String, SchematicType, String> arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
public void testarena(PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig<String, String> arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
FightCommand.createArena(sender, "/bau testarena ", false, arenaMode, map, false, (chatter, mode, m) ->
new ServerStarter().test(mode, m, sender.getPlayer()).start()
);
@@ -19,7 +19,7 @@
package de.steamwar.velocitycore.commands;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.Linked;
import de.steamwar.sql.SchematicType;
import de.steamwar.velocitycore.ArenaMode;
@@ -87,7 +87,7 @@ public class BuilderCloudCommand extends SWCommand {
}
@Register(value = "deploy", description = "BUILDERCLOUD_DEPLOY_USAGE")
public void deploy(Chatter sender, @Mapper("nonHistoricArenaMode") GameModeConfig<String, SchematicType, String> arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) {
public void deploy(Chatter sender, @Mapper("nonHistoricArenaMode") GameModeConfig<String, String> arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) {
if(!mapFile(version, map).exists()) {
sender.system("BUILDERCLOUD_UNKNOWN_MAP");
return;
@@ -22,7 +22,7 @@ package de.steamwar.velocitycore.commands;
import com.velocitypowered.api.proxy.Player;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.EventMode;
import de.steamwar.linkage.Linked;
import de.steamwar.messages.Chatter;
@@ -31,7 +31,6 @@ import de.steamwar.messages.PlayerChatter;
import de.steamwar.persistent.Subserver;
import de.steamwar.sql.IgnoreSystem;
import de.steamwar.sql.SchematicType;
import de.steamwar.velocitycore.ArenaMode;
import de.steamwar.velocitycore.ServerStarter;
import net.kyori.adventure.text.event.ClickEvent;
@@ -48,7 +47,7 @@ public class ChallengeCommand extends SWCommand {
}
@Register(description = "CHALLENGE_USAGE")
public void challenge(@Validator("arenaPlayer") PlayerChatter sender, @Validator("target") Player target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig<String, SchematicType, String> arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
public void challenge(@Validator("arenaPlayer") PlayerChatter sender, @Validator("target") Player target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig<String, String> arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
FightCommand.createArena(sender, "/challenge " + target.getUsername() + " ", false, arenaMode, map, false, (chatter, mode, m) -> {
Player p = sender.getPlayer();
if(challenges.containsKey(target) && challenges.get(target).contains(p)){
@@ -21,7 +21,7 @@ package de.steamwar.velocitycore.commands;
import com.velocitypowered.api.proxy.Player;
import de.steamwar.command.SWCommand;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.Linked;
import de.steamwar.messages.Chatter;
import de.steamwar.messages.Message;
@@ -221,7 +221,7 @@ public class CheckCommand extends SWCommand {
this.startTime = Timestamp.from(Instant.now());
this.checkList = checkQuestions.get(schematic.getSchemtype()).listIterator();
GameModeConfig<String, SchematicType, String> mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype()));
GameModeConfig<String, String> mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype()));
new ServerStarter().test(mode, mode.getRandomMap(), checker.getPlayer()).check(schematic.getId()).callback(subserver -> {
currentCheckers.put(checker.user().getUUID(), this);
currentSchems.put(schematic.getId(), this);
@@ -21,7 +21,7 @@ package de.steamwar.velocitycore.commands;
import com.velocitypowered.api.proxy.Player;
import de.steamwar.command.SWCommand;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.EventMode;
import de.steamwar.linkage.Linked;
import de.steamwar.messages.Chatter;
@@ -50,7 +50,7 @@ public class FightCommand extends SWCommand {
private static void getModes(Chatter sender, String precommand, boolean historic){
Component start = Component.empty();
for(GameModeConfig<String, SchematicType, String> mode : ArenaMode.getAllModes()){
for(GameModeConfig<String, String> mode : ArenaMode.getAllModes()){
if (!mode.isActive() || mode.Server.Historic != historic)
continue;
@@ -66,7 +66,7 @@ public class FightCommand extends SWCommand {
sender.sendMessage(start);
}
static void createArena(PlayerChatter sender, String precommand, boolean allowMerging, GameModeConfig<String, SchematicType, String> arenaMode, String map, boolean historic, FightCallback callback) {
static void createArena(PlayerChatter sender, String precommand, boolean allowMerging, GameModeConfig<String, String> arenaMode, String map, boolean historic, FightCallback callback) {
if (arenaMode == null) {
getModes(sender, precommand, historic);
return;
@@ -82,7 +82,7 @@ public class FightCommand extends SWCommand {
}
}
private static void suggestMerging(PlayerChatter sender, GameModeConfig<String, SchematicType, String> mode, String map, FightCallback declineMerge) {
private static void suggestMerging(PlayerChatter sender, GameModeConfig<String, String> mode, String map, FightCallback declineMerge) {
Arenaserver mergable = null;
synchronized (Subserver.getServerList()) {
for (Subserver subserver : Subserver.getServerList()) {
@@ -120,7 +120,7 @@ public class FightCommand extends SWCommand {
}
@Register
public void fight(@Validator("arenaPlayer") PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig<String, SchematicType, String> arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
public void fight(@Validator("arenaPlayer") PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull GameModeConfig<String, String> arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
createArena(sender, "/fight ", true, arenaMode, map, false,
(p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p.getPlayer()).callback(
arena -> Chatter.broadcast().system("FIGHT_BROADCAST", new Message("FIGHT_BROADCAST_HOVER", p.getPlayer().getUsername()), ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.GameName, p.getPlayer().getUsername())
@@ -129,6 +129,6 @@ public class FightCommand extends SWCommand {
}
public interface FightCallback {
void run(PlayerChatter player, GameModeConfig<String, SchematicType, String> mode, String map);
void run(PlayerChatter player, GameModeConfig<String, String> mode, String map);
}
}
@@ -20,14 +20,13 @@
package de.steamwar.velocitycore.commands;
import de.steamwar.command.SWCommand;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.EventMode;
import de.steamwar.linkage.Linked;
import de.steamwar.messages.Chatter;
import de.steamwar.messages.Message;
import de.steamwar.messages.PlayerChatter;
import de.steamwar.sql.SchematicType;
import de.steamwar.velocitycore.ArenaMode;
import de.steamwar.velocitycore.ServerStarter;
import net.kyori.adventure.text.event.ClickEvent;
@@ -39,7 +38,7 @@ public class HistoricCommand extends SWCommand {
}
@Register
public void historic(@Validator("arenaPlayer") PlayerChatter player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull GameModeConfig<String, SchematicType, String> arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
public void historic(@Validator("arenaPlayer") PlayerChatter player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull GameModeConfig<String, String> arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p.getPlayer()).callback(
arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", new Message("HISTORIC_BROADCAST_HOVER", p), ClickEvent.runCommand("/arena " + arena.getServer().getName()), mode.GameName, p.getPlayer())
).start());
@@ -20,7 +20,7 @@
package de.steamwar.velocitycore.commands;
import de.steamwar.command.SWCommand;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.Linked;
import de.steamwar.messages.Chatter;
import de.steamwar.messages.Message;
@@ -48,7 +48,7 @@ public class RankCommand extends SWCommand {
if (!sender.user().equals(user))
sender.prefixless("RANK_PLAYER_FOUND", user);
for(GameModeConfig<String, SchematicType, String> mode : ArenaMode.getAllModes()) {
for(GameModeConfig<String, String> mode : ArenaMode.getAllModes()) {
if (!mode.Server.Ranked)
continue;
@@ -20,7 +20,7 @@
package de.steamwar.velocitycore.commands;
import de.steamwar.command.SWCommand;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.EventMode;
import de.steamwar.linkage.Linked;
import de.steamwar.messages.Message;
@@ -69,7 +69,7 @@ public class ReplayCommand extends SWCommand {
if (PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer))
return;
GameModeConfig<String, SchematicType, String> mode = ArenaMode.getBySchemType(fight.getSchemType());
GameModeConfig<String, String> mode = ArenaMode.getBySchemType(fight.getSchemType());
ServerStarter starter = new ServerStarter().replay(fight.getFightID()).blueLeader(sender.getPlayer());
String map = mode.getRandomMap();
@@ -23,7 +23,7 @@ import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.messages.Chatter;
import de.steamwar.messages.PlayerChatter;
import de.steamwar.sql.Punishment;
@@ -47,11 +47,11 @@ public class TypeMappers {
return (sender, player, messageSender) -> !PunishmentCommand.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer);
}
private static TypeMapper<GameModeConfig<String, SchematicType, String>> arenaModeTypeMapper(boolean historic) {
private static TypeMapper<GameModeConfig<String, String>> arenaModeTypeMapper(boolean historic) {
return new TypeMapper<>() {
@Override
public GameModeConfig<String, SchematicType, String> map(Chatter sender, PreviousArguments previousArguments, String s) {
GameModeConfig<String, SchematicType, String> arenaMode = ArenaMode.getByChat(s);
public GameModeConfig<String, String> map(Chatter sender, PreviousArguments previousArguments, String s) {
GameModeConfig<String, String> arenaMode = ArenaMode.getByChat(s);
if (arenaMode == null) return null;
if (arenaMode.Server.Historic != historic) return null;
if (!arenaMode.isActive()) return null;
@@ -76,7 +76,7 @@ public class TypeMappers {
@Override
public Collection<String> tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) {
if (previousArguments.userArgs.length == 0) return null;
GameModeConfig<String, SchematicType, String> arenaMode = ArenaMode.getByChat(previousArguments.userArgs[previousArguments.userArgs.length - 1]);
GameModeConfig<String, String> arenaMode = ArenaMode.getByChat(previousArguments.userArgs[previousArguments.userArgs.length - 1]);
if (arenaMode == null) return null;
return arenaMode.Server.Maps;
}
@@ -29,7 +29,7 @@ import com.velocitypowered.api.proxy.ConsoleCommandSource;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.server.ServerInfo;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.Linked;
import de.steamwar.messages.Chatter;
import de.steamwar.messages.ChatterGroup;
@@ -20,7 +20,7 @@
package de.steamwar.velocitycore.network.handlers;
import com.velocitypowered.api.proxy.Player;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.Linked;
import de.steamwar.messages.Chatter;
import de.steamwar.network.packets.PacketHandler;
@@ -56,7 +56,7 @@ public class EloPlayerHandler extends PacketHandler {
@Handler
public void handle(FightEndsPacket fightEndsPacket) {
SchematicType schematicType = SchematicType.fromDB(fightEndsPacket.getGameMode());
GameModeConfig<String, SchematicType, String> arenaMode;
GameModeConfig<String, String> arenaMode;
if (schematicType == null) {
arenaMode = ArenaMode.getByInternal(fightEndsPacket.getGameMode());
} else {
@@ -19,7 +19,7 @@
package de.steamwar.velocitycore.network.handlers;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.Linked;
import de.steamwar.network.packets.PacketHandler;
import de.steamwar.network.packets.common.FightEndsPacket;
@@ -46,7 +46,7 @@ public class EloSchemHandler extends PacketHandler {
public void handle(FightEndsPacket fightEndsPacket) {
SchematicType type = SchematicType.fromDB(fightEndsPacket.getGameMode());
if (type == null) return;
GameModeConfig<String, SchematicType, String> arenaMode = ArenaMode.getBySchemType(type);
GameModeConfig<String, String> arenaMode = ArenaMode.getBySchemType(type);
if (!arenaMode.Server.Ranked) return;
if (publicVsPrivate(fightEndsPacket))
@@ -20,7 +20,7 @@
package de.steamwar.velocitycore.network.handlers;
import com.velocitypowered.api.proxy.Player;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.linkage.Linked;
import de.steamwar.network.packets.PacketHandler;
import de.steamwar.network.packets.client.PrepareSchemPacket;
@@ -37,7 +37,7 @@ public class PrepareSchemHandler extends PacketHandler {
public void handle(PrepareSchemPacket packet) {
Player player = VelocityCore.getProxy().getPlayer(SteamwarUser.get(packet.getPlayer()).getUUID()).orElse(null);
int schematicID = packet.getSchem();
GameModeConfig<String, SchematicType, String> mode = ArenaMode.getBySchemType(SchematicType.fromDB(packet.getSchemType()));
GameModeConfig<String, String> mode = ArenaMode.getBySchemType(SchematicType.fromDB(packet.getSchemType()));
new ServerStarter().test(mode, mode.getRandomMap(), player).prepare(schematicID).start();
}