Compare commits

...

2 Commits

Author SHA1 Message Date
Manuel Frohn
35346acf02 Continue
Some checks failed
SteamWarCI Build failed
2026-04-29 16:53:27 +02:00
Manuel Frohn
ad45ebf02f Started adding system
Some checks failed
SteamWarCI Build failed
2026-04-29 16:44:00 +02:00
5 changed files with 81 additions and 33 deletions

View File

@@ -687,6 +687,9 @@ public final class GameModeConfig<M, W> {
*/
public final Map<Set<M>, Integer> Limited;
/** */
public final List<AllowedItemsConfig<M>> AllowedItems;
private SchematicConfig(YMLWrapper<M, ?> loader) {
loaded = loader.canLoad();
Size = new SizeConfig(loader.with("Size"));
@@ -706,6 +709,7 @@ public final class GameModeConfig<M, W> {
MaxDispenserItems = loader.getInt("MaxDispenserItems", 128);
MaxBlastResistance = loader.getDouble("MaxBlastResistance", Double.MAX_VALUE);
MaxDesignBlastResistance = loader.getDouble("MaxDesignBlastResistance", MaxBlastResistance);
AllowedItems = loader.withEvery("AllowedItems").stream().map(AllowedItemsConfig::new).collect(Collectors.toList());
Map<Set<M>, Integer> Limited = new HashMap<>();
for (Map<?, ?> entry : loader.getMapList("Limited")) {
@@ -790,6 +794,32 @@ public final class GameModeConfig<M, W> {
bottom = loader.getInt("bottom", 0);
}
}
public static final class AllowedItemsConfig<M> {
/**
* The materials of the items that may be included in inventories
*/
public final List<M> AllowedMaterials;
/**
* The materials of inventory blocks that may contain the listed items
*/
public final List<M> AllowedIn;
/**
* The maximum amount of items of the listed items contained per inventory
*/
public final Integer MaxPerInventory;
/**
* The maximum amount of items of the listed items contained in total within all inventories
*/
public final Integer TotalMax;
private AllowedItemsConfig(YMLWrapper<M, ?> loader) {
AllowedMaterials = loader.getMaterialList("AllowedMaterials");
AllowedIn = loader.getMaterialList("AllowedIn");
MaxPerInventory = loader.getInt("MaxPerInventory", Integer.MAX_VALUE);
TotalMax = loader.getInt("TotalMax", Integer.MAX_VALUE);
}
}
}
@ToString

View File

@@ -76,6 +76,20 @@ final class YMLWrapper<M, W> {
return new YMLWrapper<>(false, Collections.emptyMap(), materialMapper, winconditionMapper);
}
public List<YMLWrapper<M, W>> withEvery(String path) {
if (document.containsKey(path)) {
Object value = document.get(path);
if(value instanceof List<?>) {
List<Object> list = (List<Object>) value;
return list.stream().map(o -> new YMLWrapper<>(true, Collections.singletonMap("value", o), materialMapper, winconditionMapper)).collect(Collectors.toList());
}
}
return Collections.emptyList();
}
public <T> T get(String path, T defaultValue, Function<Object, T> mapper) {
Object value = this.document.get(path);
if (value == null) return defaultValue;

View File

@@ -25,6 +25,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import de.steamwar.core.Core;
import de.steamwar.schematicsystem.autocheck.AutoChecker.InventoryScanResult;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.sql.SchematicType;
import org.bukkit.Material;
@@ -50,7 +51,8 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker {
result.getBlockCounts().merge(material, 1, Integer::sum);
if(AutoCheckerItems.impl.getInventoryMaterials().contains(material)) {
checkInventory(result, block, material, new BlockPos(x, y, z));
InventoryScanResult inventoryResult = checkInventory(result, block, material, new BlockPos(x, y, z));
result.getInventoryScans().put(new BlockPos(x, y, z), inventoryResult);
}
if(x == min.getBlockX() || x == max.getBlockX() || y == max.getBlockY() || z == min.getBlockZ() || z == max.getBlockZ()) {
@@ -62,41 +64,24 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker {
return result;
}
private static final Map<Material, Set<Material>> itemsInInv = new EnumMap<>(Material.class);
static {
itemsInInv.put(Material.BUCKET, EnumSet.of(Material.DISPENSER));
itemsInInv.put(Material.TNT, EnumSet.of(
Material.CHEST, Material.BARREL, Material.SHULKER_BOX, Material.BLACK_SHULKER_BOX,
Material.BLUE_SHULKER_BOX, Material.BROWN_SHULKER_BOX, Material.CYAN_SHULKER_BOX,
Material.GRAY_SHULKER_BOX, Material.GREEN_SHULKER_BOX, Material.LIGHT_BLUE_SHULKER_BOX,
Material.LIGHT_GRAY_SHULKER_BOX, Material.LIME_SHULKER_BOX, Material.MAGENTA_SHULKER_BOX,
Material.ORANGE_SHULKER_BOX, Material.PINK_SHULKER_BOX, Material.PURPLE_SHULKER_BOX,
Material.RED_SHULKER_BOX, Material.WHITE_SHULKER_BOX, Material.YELLOW_SHULKER_BOX
));
itemsInInv.put(Material.FIRE_CHARGE, EnumSet.of(Material.DISPENSER));
itemsInInv.put(Material.ARROW, EnumSet.of(Material.DISPENSER));
AutoCheckerItems.impl.getAllowedMaterialsInInventory().forEach(material -> itemsInInv.put(material, AutoCheckerItems.impl.getInventoryMaterials()));
}
private void checkInventory(AutoChecker.BlockScanResult result, BaseBlock block, Material material, BlockPos pos) {
private InventoryScanResult checkInventory(AutoChecker.BlockScanResult result, BaseBlock block, Material material, BlockPos pos) {
CompoundTag nbt = block.getNbtData();
if(nbt == null) {
result.getDefunctNbt().add(pos);
return;
return null;
}
if(material == Material.JUKEBOX && nbt.getValue().containsKey("RecordItem")){
result.getRecords().add(pos);
return;
return null;
}
List<CompoundTag> items = nbt.getList("Items", CompoundTag.class);
if(items.isEmpty())
return; //Leeres Inventar
return null; //Leeres Inventar
int counter = 0;
Map<Material, Integer> inventoryItemCounts = new HashMap<>();
for(CompoundTag item : items){
if(!item.containsKey("id")){
result.getDefunctNbt().add(pos);
@@ -107,16 +92,18 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker {
if(itemType == null) //Leere Slots
continue;
if (!itemsInInv.getOrDefault(itemType, EnumSet.noneOf(Material.class)).contains(material)) {
result.getForbiddenItems().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType);
} else if(material == Material.DISPENSER && (itemType == Material.ARROW || itemType == Material.FIRE_CHARGE)) {
counter += Core.getVersion() >= 21 ? item.getInt("count") : item.getByte("Count");
}
if (item.containsKey("tag")) {
result.getForbiddenNbt().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType);
}
else {
int count = Core.getVersion() >= 21 ? item.getInt("count") : item.getByte("Count");
inventoryItemCounts.merge(itemType, count, Integer::sum);
}
}
result.getDispenserItems().put(pos, counter);
return new InventoryScanResult(material, inventoryItemCounts);
}
@Override

View File

@@ -24,11 +24,13 @@ import de.steamwar.core.VersionDependent;
import de.steamwar.sql.GameModeConfig;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.sql.SchematicType;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import org.bukkit.Material;
import java.util.*;
import java.util.stream.Collectors;
public class AutoChecker {
@@ -47,6 +49,14 @@ public class AutoChecker {
AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, String> type);
}
@AllArgsConstructor
@Getter
@ToString
public static class InventoryScanResult {
private final Material inventoryMaterial;
private final Map<Material, Integer> itemCounts;
}
@Getter
@ToString
public static class BlockScanResult {
@@ -54,8 +64,13 @@ public class AutoChecker {
private final List<BlockPos> defunctNbt = new ArrayList<>();
private final List<BlockPos> records = new ArrayList<>();
private final Map<Material, List<BlockPos>> designBlocks = new EnumMap<>(Material.class);
private final Map<BlockPos, Integer> dispenserItems = new HashMap<>();
private final Map<BlockPos, Set<Material>> forbiddenItems = new HashMap<>();
private final Map<BlockPos, InventoryScanResult> inventoryScans = new HashMap<>();
private final Map<BlockPos, Set<Material>> forbiddenNbt = new HashMap<>();
public Map<Material, Integer> getItemCounts() {
return inventoryScans.values().stream()
.flatMap(i -> i.getItemCounts().entrySet().stream())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, Integer::sum));
}
}
}

View File

@@ -62,10 +62,12 @@ public class AutoCheckerResult {
!type.isAfterDeadline();
}
public boolean isDispenserItemsOK() {
return blockScanResult.getDispenserItems().values().stream().allMatch(i -> i <= type.Schematic.MaxDispenserItems);
public boolean doInventoriesOnlyContainAllowedItems() {
}
public boolean hasWarnings() {
return blockScanResult.getDefunctNbt().isEmpty();
}