Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 35346acf02 | |||
| ad45ebf02f |
@@ -687,6 +687,9 @@ public final class GameModeConfig<M, W> {
|
|||||||
*/
|
*/
|
||||||
public final Map<Set<M>, Integer> Limited;
|
public final Map<Set<M>, Integer> Limited;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
public final List<AllowedItemsConfig<M>> AllowedItems;
|
||||||
|
|
||||||
private SchematicConfig(YMLWrapper<M, ?> loader) {
|
private SchematicConfig(YMLWrapper<M, ?> loader) {
|
||||||
loaded = loader.canLoad();
|
loaded = loader.canLoad();
|
||||||
Size = new SizeConfig(loader.with("Size"));
|
Size = new SizeConfig(loader.with("Size"));
|
||||||
@@ -706,6 +709,7 @@ public final class GameModeConfig<M, W> {
|
|||||||
MaxDispenserItems = loader.getInt("MaxDispenserItems", 128);
|
MaxDispenserItems = loader.getInt("MaxDispenserItems", 128);
|
||||||
MaxBlastResistance = loader.getDouble("MaxBlastResistance", Double.MAX_VALUE);
|
MaxBlastResistance = loader.getDouble("MaxBlastResistance", Double.MAX_VALUE);
|
||||||
MaxDesignBlastResistance = loader.getDouble("MaxDesignBlastResistance", MaxBlastResistance);
|
MaxDesignBlastResistance = loader.getDouble("MaxDesignBlastResistance", MaxBlastResistance);
|
||||||
|
AllowedItems = loader.withEvery("AllowedItems").stream().map(AllowedItemsConfig::new).collect(Collectors.toList());
|
||||||
|
|
||||||
Map<Set<M>, Integer> Limited = new HashMap<>();
|
Map<Set<M>, Integer> Limited = new HashMap<>();
|
||||||
for (Map<?, ?> entry : loader.getMapList("Limited")) {
|
for (Map<?, ?> entry : loader.getMapList("Limited")) {
|
||||||
@@ -790,6 +794,32 @@ public final class GameModeConfig<M, W> {
|
|||||||
bottom = loader.getInt("bottom", 0);
|
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
|
@ToString
|
||||||
|
|||||||
@@ -76,6 +76,20 @@ final class YMLWrapper<M, W> {
|
|||||||
return new YMLWrapper<>(false, Collections.emptyMap(), materialMapper, winconditionMapper);
|
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) {
|
public <T> T get(String path, T defaultValue, Function<Object, T> mapper) {
|
||||||
Object value = this.document.get(path);
|
Object value = this.document.get(path);
|
||||||
if (value == null) return defaultValue;
|
if (value == null) return defaultValue;
|
||||||
|
|||||||
+16
-29
@@ -25,6 +25,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
|||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.schematicsystem.autocheck.AutoChecker.InventoryScanResult;
|
||||||
import de.steamwar.sql.GameModeConfig;
|
import de.steamwar.sql.GameModeConfig;
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -50,7 +51,8 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker {
|
|||||||
result.getBlockCounts().merge(material, 1, Integer::sum);
|
result.getBlockCounts().merge(material, 1, Integer::sum);
|
||||||
|
|
||||||
if(AutoCheckerItems.impl.getInventoryMaterials().contains(material)) {
|
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()) {
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<Material, Set<Material>> itemsInInv = new EnumMap<>(Material.class);
|
private InventoryScanResult checkInventory(AutoChecker.BlockScanResult result, BaseBlock block, Material material, BlockPos pos) {
|
||||||
|
|
||||||
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) {
|
|
||||||
CompoundTag nbt = block.getNbtData();
|
CompoundTag nbt = block.getNbtData();
|
||||||
if(nbt == null) {
|
if(nbt == null) {
|
||||||
result.getDefunctNbt().add(pos);
|
result.getDefunctNbt().add(pos);
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(material == Material.JUKEBOX && nbt.getValue().containsKey("RecordItem")){
|
if(material == Material.JUKEBOX && nbt.getValue().containsKey("RecordItem")){
|
||||||
result.getRecords().add(pos);
|
result.getRecords().add(pos);
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CompoundTag> items = nbt.getList("Items", CompoundTag.class);
|
List<CompoundTag> items = nbt.getList("Items", CompoundTag.class);
|
||||||
if(items.isEmpty())
|
if(items.isEmpty())
|
||||||
return; //Leeres Inventar
|
return null; //Leeres Inventar
|
||||||
|
|
||||||
int counter = 0;
|
Map<Material, Integer> inventoryItemCounts = new HashMap<>();
|
||||||
for(CompoundTag item : items){
|
for(CompoundTag item : items){
|
||||||
if(!item.containsKey("id")){
|
if(!item.containsKey("id")){
|
||||||
result.getDefunctNbt().add(pos);
|
result.getDefunctNbt().add(pos);
|
||||||
@@ -107,16 +92,18 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker {
|
|||||||
if(itemType == null) //Leere Slots
|
if(itemType == null) //Leere Slots
|
||||||
continue;
|
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")) {
|
if (item.containsKey("tag")) {
|
||||||
result.getForbiddenNbt().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType);
|
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
|
@Override
|
||||||
|
|||||||
+17
-2
@@ -24,11 +24,13 @@ import de.steamwar.core.VersionDependent;
|
|||||||
import de.steamwar.sql.GameModeConfig;
|
import de.steamwar.sql.GameModeConfig;
|
||||||
import de.steamwar.schematicsystem.SchematicSystem;
|
import de.steamwar.schematicsystem.SchematicSystem;
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class AutoChecker {
|
public class AutoChecker {
|
||||||
|
|
||||||
@@ -47,6 +49,14 @@ public class AutoChecker {
|
|||||||
AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, String> type);
|
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
|
@Getter
|
||||||
@ToString
|
@ToString
|
||||||
public static class BlockScanResult {
|
public static class BlockScanResult {
|
||||||
@@ -54,8 +64,13 @@ public class AutoChecker {
|
|||||||
private final List<BlockPos> defunctNbt = new ArrayList<>();
|
private final List<BlockPos> defunctNbt = new ArrayList<>();
|
||||||
private final List<BlockPos> records = new ArrayList<>();
|
private final List<BlockPos> records = new ArrayList<>();
|
||||||
private final Map<Material, List<BlockPos>> designBlocks = new EnumMap<>(Material.class);
|
private final Map<Material, List<BlockPos>> designBlocks = new EnumMap<>(Material.class);
|
||||||
private final Map<BlockPos, Integer> dispenserItems = new HashMap<>();
|
private final Map<BlockPos, InventoryScanResult> inventoryScans = new HashMap<>();
|
||||||
private final Map<BlockPos, Set<Material>> forbiddenItems = new HashMap<>();
|
|
||||||
private final Map<BlockPos, Set<Material>> forbiddenNbt = 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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -62,10 +62,12 @@ public class AutoCheckerResult {
|
|||||||
!type.isAfterDeadline();
|
!type.isAfterDeadline();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDispenserItemsOK() {
|
|
||||||
return blockScanResult.getDispenserItems().values().stream().allMatch(i -> i <= type.Schematic.MaxDispenserItems);
|
public boolean doInventoriesOnlyContainAllowedItems() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public boolean hasWarnings() {
|
public boolean hasWarnings() {
|
||||||
return blockScanResult.getDefunctNbt().isEmpty();
|
return blockScanResult.getDefunctNbt().isEmpty();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user