Add Unified GameModeConfig

This commit is contained in:
2025-10-25 21:45:44 +02:00
parent 0a6977e433
commit 87a4836fa1
103 changed files with 1731 additions and 876 deletions
@@ -24,7 +24,8 @@ 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.schematicsystem.CheckSchemType;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.SchematicType;
import org.bukkit.Material;
import java.util.*;
@@ -118,7 +119,7 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker {
}
@Override
public AutoCheckerResult check(Clipboard clipboard, CheckSchemType type) {
public AutoCheckerResult check(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type) {
return AutoCheckerResult.builder()
.type(type)
.height(clipboard.getDimensions().getBlockY())
@@ -130,7 +131,7 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker {
}
@Override
public AutoCheckerResult sizeCheck(Clipboard clipboard, CheckSchemType type) {
public AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type) {
return AutoCheckerResult.builder()
.type(type)
.height(clipboard.getDimensions().getBlockY())
@@ -31,10 +31,10 @@ 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.schematicsystem.CheckSchemType;
import de.steamwar.data.GameModeConfig;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
import de.steamwar.schematicsystem.autocheck.BlockPos;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
import de.steamwar.sql.SchematicType;
import org.bukkit.Material;
import java.util.*;
@@ -42,7 +42,7 @@ import java.util.stream.Collectors;
public class SchematicCommand15 implements SchematicCommand.ISchematicCommand {
@Override
public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, CheckSchemType type) throws Exception {
public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig<Material, SchematicType, 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())));
@@ -76,9 +76,9 @@ public class SchematicCommand15 implements SchematicCommand.ISchematicCommand {
clipboard.setBlock(vector, block.toBaseBlock(builder.build()));
}
if(type.getMaxDispenserItems() > 0 ) {
if(type.Schematic.MaxDispenserItems > 0 ) {
for (Map.Entry<BlockPos, Integer> entry : result.getBlockScanResult().getDispenserItems().entrySet()) {
if(entry.getValue() <= type.getMaxDispenserItems()) {
if(entry.getValue() <= type.Schematic.MaxDispenserItems) {
continue;
}
@@ -90,7 +90,7 @@ public class SchematicCommand15 implements SchematicCommand.ISchematicCommand {
List<CompoundTag> items = tag.getList("Items", CompoundTag.class);
Collections.reverse(items); // To let the first item be in the Dispenser
List<CompoundTag> list = new ArrayList<>();
int diff = entry.getValue() - type.getMaxDispenserItems();
int diff = entry.getValue() - type.Schematic.MaxDispenserItems;
for (CompoundTag item : items) {
if(item == null) {
continue;
@@ -117,10 +117,9 @@ public class SchematicCommand15 implements SchematicCommand.ISchematicCommand {
}
if(!result.isLimitedBlocksOK()) {
Set<Material> toReplace = type.getLimits().entrySet().stream()
Set<Material> toReplace = type.Schematic.Limited.entrySet().stream()
.filter(setIntegerEntry -> setIntegerEntry.getValue() == 0)
.flatMap(setIntegerEntry -> setIntegerEntry.getKey().stream())
.map(Material::matchMaterial)
.collect(Collectors.toSet());
BlockState replaceType = Objects.requireNonNull(toReplace.contains(Material.END_STONE) ? BlockTypes.IRON_BLOCK : BlockTypes.END_STONE).getDefaultState();
BlockVector3 min = clipboard.getMinimumPoint();
@@ -25,7 +25,8 @@ 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.schematicsystem.CheckSchemType;
import de.steamwar.data.GameModeConfig;
import de.steamwar.sql.SchematicType;
import org.bukkit.Material;
import java.util.*;
@@ -148,7 +149,7 @@ public class AutoChecker8 implements AutoChecker.IAutoChecker {
}
@Override
public AutoCheckerResult check(Clipboard clipboard, CheckSchemType type) {
public AutoCheckerResult check(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type) {
AutoChecker.BlockScanResult blockScanResult = new AutoChecker.BlockScanResult();
scan(blockScanResult, clipboard);
@@ -163,7 +164,7 @@ public class AutoChecker8 implements AutoChecker.IAutoChecker {
}
@Override
public AutoCheckerResult sizeCheck(Clipboard clipboard, CheckSchemType type) {
public AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type) {
return AutoCheckerResult.builder()
.type(type)
.height(clipboard.getDimensions().getBlockY())
@@ -24,14 +24,15 @@ 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.schematicsystem.CheckSchemType;
import de.steamwar.data.GameModeConfig;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
import de.steamwar.sql.SchematicType;
import org.bukkit.Material;
public class SchematicCommand8 implements SchematicCommand.ISchematicCommand {
@Override
public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, CheckSchemType type) throws Exception {
public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig<Material, SchematicType, String> type) throws Exception {
return null;
}
@@ -1,113 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2025 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem;
import de.steamwar.sql.SchematicType;
import lombok.Getter;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.*;
@Getter
public class CheckSchemType {
private static final Map<SchematicType, CheckSchemType> types = new HashMap<>();
private final int width;
private final int height;
private final int depth;
private final int maxDispenserItems;
private final Map<Set<String>, Integer> limits;
private final int maxBlocks;
private final Date deadline;
private final float maxBlastResistance;
private CheckSchemType(ConfigurationSection section) {
String name = section.getString("Schematic.Type");
width = section.getInt("Schematic.Size.x");
height = section.getInt("Schematic.Size.y");
depth = section.getInt("Schematic.Size.z");
maxDispenserItems = section.getInt("Schematic.MaxDispenserItems", 128);
maxBlocks = section.getInt("Schematic.MaxBlocks", 0);
maxBlastResistance = (float) section.getDouble("Schematic.MaxDesignBlastResistance", Double.MAX_VALUE);
limits = new HashMap<>();
for(Map<?, ?> entry : section.getMapList("Schematic.Limited")) {
int amount = (Integer) entry.get("Amount");
Set<String> materials = new HashSet<>((List<String>) entry.get("Materials"));
if(amount == 0) {
materials.forEach(material -> limits.put(Collections.singleton(material), 0));
} else {
limits.put(materials, amount);
}
}
String deadlineString = section.getString("deadline", null);
if (deadlineString != null) {
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
deadline = dateFormat.parse(deadlineString);
} catch (ParseException e) {
throw new SecurityException(e.getMessage(), e);
}
} else {
deadline = null;
}
types.put(SchematicType.fromDB(name.toLowerCase()), this);
types.put(SchematicType.fromDB("c" + name.toLowerCase()), this);
}
static {
File folder = new File(SchematicSystem.getInstance().getDataFolder().getParentFile(), "FightSystem");
if(folder.exists()) {
for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) {
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
if (!config.isList("CheckQuestions") && config.getBoolean("Schematic.ManualCheck", true))
continue;
new CheckSchemType(config);
}
}
}
public static CheckSchemType get(SchematicType type){
return types.get(type);
}
public Map<Set<String>, Integer> getLimits() {
return new HashMap<>(limits);
}
public boolean isAfterDeadline() {
return deadline != null && deadline.before(Date.from(Instant.now()));
}
}
@@ -0,0 +1,56 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2025 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem;
import de.steamwar.data.GameModeConfig;
import de.steamwar.data.YMLWrapperImpl;
import de.steamwar.sql.SchematicType;
import lombok.experimental.UtilityClass;
import org.bukkit.Material;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
@UtilityClass
public class CheckSchemTypeManager {
private static final Map<SchematicType, GameModeConfig<Material, SchematicType, String>> types = new HashMap<>();
static {
File folder = new File(SchematicSystem.getInstance().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<>(YMLWrapperImpl.ofTyped(configFile));
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);
}
}
}
}
public static GameModeConfig<Material, SchematicType, String> get(SchematicType type){
return types.get(type);
}
}
@@ -21,8 +21,9 @@ package de.steamwar.schematicsystem.autocheck;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.VersionDependent;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.data.GameModeConfig;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.sql.SchematicType;
import lombok.Getter;
import lombok.ToString;
import org.bukkit.Material;
@@ -31,19 +32,19 @@ import java.util.*;
public class AutoChecker {
public static AutoCheckerResult check(Clipboard clipboard, CheckSchemType type) {
public static AutoCheckerResult check(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type) {
return impl.check(clipboard, type);
}
public static AutoCheckerResult sizeCheck(Clipboard clipboard, CheckSchemType type) {
public static AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type) {
return impl.sizeCheck(clipboard, type);
}
private static final IAutoChecker impl = VersionDependent.getVersionImpl(SchematicSystem.getInstance());
public interface IAutoChecker {
AutoCheckerResult check(Clipboard clipboard, CheckSchemType type);
AutoCheckerResult sizeCheck(Clipboard clipboard, CheckSchemType type);
AutoCheckerResult check(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type);
AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type);
}
@Getter
@@ -20,8 +20,9 @@
package de.steamwar.schematicsystem.autocheck;
import de.steamwar.core.Core;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.data.GameModeConfig;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.sql.SchematicType;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
@@ -29,13 +30,15 @@ import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@Builder
@Getter
@ToString
public class AutoCheckerResult {
private final CheckSchemType type;
private final GameModeConfig<Material, SchematicType, String> type;
private final int width;
private final int height;
private final int depth;
@@ -61,7 +64,7 @@ public class AutoCheckerResult {
}
public boolean isDispenserItemsOK() {
return blockScanResult.getDispenserItems().values().stream().allMatch(i -> i <= type.getMaxDispenserItems());
return blockScanResult.getDispenserItems().values().stream().allMatch(i -> i <= type.Schematic.MaxDispenserItems);
}
public boolean hasWarnings() {
@@ -73,25 +76,25 @@ public class AutoCheckerResult {
}
public boolean isTooWide() {
return width > type.getWidth();
return width > type.Schematic.Size.x;
}
public boolean isTooHigh() {
return height > type.getHeight();
return height > type.Schematic.Size.y;
}
public boolean isTooDeep() {
return depth > type.getDepth();
return depth > type.Schematic.Size.z;
}
public boolean isBlockCountOk() {
return type.getMaxBlocks() == 0 || blockScanResult.getBlockCounts().entrySet().stream().filter(entry -> entry.getKey() != Material.AIR).map(Map.Entry::getValue).reduce(Integer::sum).map(i -> i <= type.getMaxBlocks()).orElse(false);
return type.Schematic.MaxBlocks == 0 || blockScanResult.getBlockCounts().entrySet().stream().filter(entry -> entry.getKey() != Material.AIR).map(Map.Entry::getValue).reduce(Integer::sum).map(i -> i <= type.Schematic.MaxBlocks).orElse(false);
}
public boolean isLimitedBlocksOK() {
try {
return type.getLimits().entrySet().stream()
.map(setIntegerEntry -> setIntegerEntry.getKey().stream().map(Material::getMaterial).map(blockScanResult.getBlockCounts()::get).map(i -> i == null || i <= setIntegerEntry.getValue()).reduce(Boolean::logicalAnd).orElse(false))
return type.Schematic.Limited.entrySet().stream()
.map(setIntegerEntry -> setIntegerEntry.getKey().stream().map(blockScanResult.getBlockCounts()::get).map(i -> i == null || i <= setIntegerEntry.getValue()).reduce(Boolean::logicalAnd).orElse(false))
.reduce(Boolean::logicalAnd).orElse(true);
} catch (NullPointerException e) {
return false;
@@ -99,21 +102,20 @@ public class AutoCheckerResult {
}
public boolean isDesignBlastResistanceOK() {
return blockScanResult.getDesignBlocks().keySet().stream().map(Material::getBlastResistance).noneMatch(i -> i > type.getMaxBlastResistance());
return blockScanResult.getDesignBlocks().keySet().stream().map(Material::getBlastResistance).noneMatch(i -> i > type.Schematic.MaxDesignBlastResistance);
}
public void sendErrorMessage(Player p, String schemName) {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_HEADER", p, schemName);
if(isTooWide()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_WIDTH", p, width, type.getWidth());
if(isTooHigh()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_HEIGHT", p, height, type.getHeight());
if(isTooDeep()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_LENGTH", p, depth, type.getDepth());
if(type.getMaxBlocks() != 0 && !isBlockCountOk()) {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_BLOCKS", p, blockScanResult.getBlockCounts().values().stream().reduce(Integer::sum).orElse(0), type.getMaxBlocks());
if(isTooWide()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_WIDTH", p, width, type.Schematic.Size.x);
if(isTooHigh()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_HEIGHT", p, height, type.Schematic.Size.y);
if(isTooDeep()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_LENGTH", p, depth, type.Schematic.Size.z);
if(type.Schematic.MaxBlocks != 0 && !isBlockCountOk()) {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_BLOCKS", p, blockScanResult.getBlockCounts().values().stream().reduce(Integer::sum).orElse(0), type.Schematic.MaxBlocks);
}
if(!isLimitedBlocksOK()) {
type.getLimits().forEach((strings, integer) -> {
for (String string : strings) {
Material mat = Material.matchMaterial(string);
type.Schematic.Limited.forEach((materials, integer) -> {
for (Material mat : materials) {
if(mat != null && blockScanResult.getBlockCounts().getOrDefault(mat, 0) > integer) {
if(integer == 0) {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_FORBIDDEN_BLOCK", p, mat.name());
@@ -124,13 +126,13 @@ public class AutoCheckerResult {
}
});
}
blockScanResult.getDispenserItems().entrySet().stream().filter(blockVector3IntegerEntry -> blockVector3IntegerEntry.getValue() > type.getMaxDispenserItems()).forEach(blockVector3IntegerEntry -> {
blockScanResult.getDispenserItems().entrySet().stream().filter(blockVector3IntegerEntry -> blockVector3IntegerEntry.getValue() > type.Schematic.MaxDispenserItems).forEach(blockVector3IntegerEntry -> {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(blockVector3IntegerEntry.getKey()),
blockVector3IntegerEntry.getKey().getBlockX(),
blockVector3IntegerEntry.getKey().getBlockY(),
blockVector3IntegerEntry.getKey().getBlockZ(),
blockVector3IntegerEntry.getValue(),
type.getMaxDispenserItems());
type.Schematic.MaxDispenserItems);
});
blockScanResult.getRecords().forEach(blockVector3 -> {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_RECORD", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(blockVector3), blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ());
@@ -146,7 +148,7 @@ public class AutoCheckerResult {
});
if(Core.getVersion() > 12) {
blockScanResult.getDesignBlocks().forEach((material, poss) -> {
if(material.getBlastResistance() > type.getMaxBlastResistance()) {
if(material.getBlastResistance() > type.Schematic.MaxDesignBlastResistance) {
poss.forEach(pos -> {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_DESIGN_BLOCK", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(pos), material.name(), pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
});
@@ -157,7 +159,7 @@ public class AutoCheckerResult {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_ENTITY", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(blockPos), blockPos.getX(), blockPos.getY(), blockPos.getZ());
});
if(type.isAfterDeadline()) {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_AFTER_DEADLINE", p, type.getDeadline());
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_AFTER_DEADLINE", p, type.Deadline);
}
}
@@ -23,7 +23,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.Core;
import de.steamwar.data.CMDs;
import de.steamwar.inventory.*;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.CheckSchemTypeManager;
import de.steamwar.schematicsystem.SafeSchematicNode;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoChecker;
@@ -245,7 +245,7 @@ public class GUI {
Clipboard finalClipboard = clipboard;
List<SchematicType> types = SchematicType.values().parallelStream()
.filter(SchematicType::isAssignable)
.filter(type -> finalClipboard == null || CheckSchemType.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemType.get(type)).fastOk())
.filter(type -> finalClipboard == null || CheckSchemTypeManager.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemTypeManager.get(type)).fastOk())
.collect(Collectors.toList());
List<SWListInv.SWListEntry<SchematicType>> items = types.stream()
@@ -19,20 +19,25 @@
package de.steamwar.schematicsystem.commands.schematiccommand;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.command.*;
import de.steamwar.command.AbstractSWCommand;
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.linkage.Linked;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
import de.steamwar.sql.*;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandHelp.*;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.*;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.togglePublic;
@SuppressWarnings("unused")
@Linked
@@ -107,9 +112,9 @@ public class SchematicCommand extends SWCommand {
return SchematicMapper.nodeTypeMapper();
}
@ClassMapper(value = CheckSchemType.class, local = true)
public static TypeMapper<CheckSchemType> checkSchemTypeTypeMapper() {
return SchematicMapper.checkSchemTypeTypeMapper();
@ClassMapper(value = GameModeConfig.class, local = true)
public static TypeMapper<GameModeConfig<Material, SchematicType, String>> gameModeConfigTypeMapper() {
return SchematicMapper.gameModeConfigTypeMapper();
}
@Override
@@ -145,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, CheckSchemType type) throws Exception;
Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig<Material, SchematicType, String> type) throws Exception;
void createCopy(EditSession editSession, Clipboard clipboard) throws WorldEditException;
}
}
@@ -20,12 +20,13 @@
package de.steamwar.schematicsystem.commands.schematiccommand;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.data.GameModeConfig;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.network.NetworkSender;
import de.steamwar.network.packets.client.PrepareSchemPacket;
import de.steamwar.providers.BauServerInfo;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.CheckSchemTypeManager;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoChecker;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
@@ -40,6 +41,7 @@ import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.io.IOException;
@@ -311,7 +313,7 @@ public class SchematicCommandUtils {
}
}
public static void check(Player player, Clipboard clipboard, CheckSchemType type, String schemName, boolean gui) {
public static void check(Player player, Clipboard clipboard, GameModeConfig<Material, SchematicType, String> type, String schemName, boolean gui) {
AutoCheckerResult result = AutoChecker.check(clipboard, type);
if(!result.isOk()) {
result.sendErrorMessage(player, schemName);
@@ -454,9 +456,9 @@ public class SchematicCommandUtils {
return;
}
CheckSchemType checkSchemType = CheckSchemType.get(type);
GameModeConfig<Material, SchematicType, String> checkSchemType = CheckSchemTypeManager.get(type);
if (checkSchemType.isAfterDeadline()) {
SchematicSystem.MESSAGE.send("UTIL_TYPE_AFTER_DEADLINE", player, checkSchemType.getDeadline());
SchematicSystem.MESSAGE.send("UTIL_TYPE_AFTER_DEADLINE", player, checkSchemType.Deadline);
return;
}
@@ -20,11 +20,13 @@
package de.steamwar.schematicsystem.commands.schematiccommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.data.GameModeConfig;
import de.steamwar.schematicsystem.CheckSchemTypeManager;
import de.steamwar.sql.NodeMember;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -175,16 +177,16 @@ public class SchematicMapper {
};
}
public static TypeMapper<CheckSchemType> checkSchemTypeTypeMapper() {
return new TypeMapper<CheckSchemType>() {
public static TypeMapper<GameModeConfig<Material, SchematicType, String>> gameModeConfigTypeMapper() {
return new TypeMapper<GameModeConfig<Material, SchematicType, String>>() {
@Override
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return SchematicType.values().stream().filter(type -> CheckSchemType.get(type) != null).map(SchematicType::name).collect(Collectors.toList());
return SchematicType.values().stream().filter(type -> CheckSchemTypeManager.get(type) != null).map(SchematicType::name).collect(Collectors.toList());
}
@Override
public CheckSchemType map(CommandSender commandSender, String[] previousArguments, String s) {
return SchematicType.values().stream().filter(type -> type.name().equalsIgnoreCase(s)).map(CheckSchemType::get).findAny().orElse(null);
public GameModeConfig<Material, SchematicType, String> map(CommandSender commandSender, String[] previousArguments, String s) {
return SchematicType.values().stream().filter(type -> type.name().equalsIgnoreCase(s)).map(CheckSchemTypeManager::get).findAny().orElse(null);
}
};
}
@@ -19,7 +19,6 @@
package de.steamwar.schematicsystem.commands.schematiccommand;
import de.steamwar.command.AbstractSWCommand;
import de.steamwar.command.AbstractValidator;
import de.steamwar.command.TypeValidator;
import de.steamwar.sql.SchematicNode;
@@ -28,21 +28,23 @@ 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.linkage.Linked;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoChecker;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.io.IOException;
import java.util.logging.Level;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.check;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand.impl;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.check;
@AbstractSWCommand.PartOf(SchematicCommand.class)
@Linked
@@ -52,7 +54,7 @@ public class CheckPart extends SWCommand {
}
@Register("check")
public void checkCommand(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, CheckSchemType type) {
public void checkCommand(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, GameModeConfig<Material, SchematicType, String> type) {
try {
check(player, new SchematicData(node).load(), type, node.getName(), false);
} catch (IOException e) {
@@ -61,7 +63,7 @@ public class CheckPart extends SWCommand {
}
@Register(value = {"check", "clipboard"})
public void checkClipboardCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) {
public void checkClipboardCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig<Material, SchematicType, String> type) {
try {
check(player, WorldEdit.getInstance().getSessionManager().findByName(player.getName()).getClipboard().getClipboard(), type, "clipboard", false);
} catch (EmptyClipboardException e) {
@@ -70,7 +72,7 @@ public class CheckPart extends SWCommand {
}
@Register(value = {"check", "selection"})
public void checkSelectionCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) {
public void checkSelectionCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig<Material, SchematicType, 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);
@@ -86,7 +88,7 @@ public class CheckPart extends SWCommand {
}
@Register("fix")
public void fixSchematicCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) {
public void fixSchematicCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") GameModeConfig<Material, SchematicType, String> type) {
if(Core.getVersion() < 15) {
SchematicSystem.MESSAGE.send("COMMAND_FIX_WRONG_VERSION", player);
return;
@@ -23,7 +23,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.command.AbstractSWCommand;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.CheckSchemTypeManager;
import de.steamwar.schematicsystem.SafeSchematicNode;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoChecker;
@@ -63,7 +63,7 @@ public class ModifyPart extends SWCommand {
SchematicType.values().parallelStream()
.filter(SchematicType::isAssignable)
.filter(type -> finalClipboard == null || CheckSchemType.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemType.get(type)).fastOk())
.filter(type -> finalClipboard == null || CheckSchemTypeManager.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemTypeManager.get(type)).fastOk())
.forEach(type -> {
TextComponent component = new TextComponent(type.name() + " ");
component.setColor(ChatColor.GRAY);
@@ -22,8 +22,8 @@ package de.steamwar.schematicsystem.commands.schematiccommand.parts;
import de.steamwar.command.*;
import de.steamwar.linkage.Linked;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import de.steamwar.sql.SteamwarUser;