From 5e903f115dba7e570cb99c2e73fdd8e3b8fb4cbd Mon Sep 17 00:00:00 2001 From: MoBrot <90271578+MoBrot@users.noreply.github.com> Date: Sun, 22 Jan 2023 23:54:13 +0100 Subject: [PATCH 1/3] Buckets in inventories --- .../steamwar/schematicsystem/autocheck/AutoChecker15.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java b/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java index fba059a..4bfd30f 100644 --- a/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java +++ b/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java @@ -140,8 +140,11 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker { if(material == Material.DISPENSER && (itemType.equals(Material.FIRE_CHARGE) || itemType.equals(Material.ARROW))) { counter += item.getByte("Count"); - }else if (!FLOWERS.contains(itemType) && !((material == Material.CHEST || material == Material.BARREL) && itemType.equals(Material.TNT)) - && (material == Material.DISPENSER && !itemType.equals(Material.BUCKET))) { + }else if (!FLOWERS.contains(itemType) && !((material == Material.CHEST || material == Material.BARREL) && itemType.equals(Material.TNT))) { + + if(material == Material.DISPENSER && itemType.equals(Material.BUCKET)) + return; + result.getForbiddenItems().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType); } else if (item.containsKey("tag")) { result.getForbiddenNbt().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType); From bd37391e88ceb3dc1521d8afca60704ad22b15b0 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 4 Feb 2023 19:51:12 +0100 Subject: [PATCH 2/3] Refactor (should be working) --- .../autocheck/AutoChecker15.java | 20 +++++++++---------- .../autocheck/AutoChecker8.java | 15 +++++++++----- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java b/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java index 4bfd30f..ddbf4ef 100644 --- a/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java +++ b/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2022 SteamWar.de-Serverteam + Copyright (C) 2023 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 @@ -26,10 +26,7 @@ import com.sk89q.worldedit.world.block.BaseBlock; import de.steamwar.schematicsystem.CheckSchemType; import org.bukkit.Material; -import java.util.EnumSet; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; public class AutoChecker15 implements AutoChecker.IAutoChecker { private static final Set INVENTORY = EnumSet.of( @@ -110,6 +107,13 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker { return result; } + private static final Map> itemsInInv = new EnumMap<>(Material.class); + + static { + itemsInInv.put(Material.BUCKET, EnumSet.of(Material.DISPENSER)); + itemsInInv.put(Material.TNT, EnumSet.of(Material.CHEST, Material.BARREL)); + } + private void checkInventory(AutoChecker.BlockScanResult result, BaseBlock block, Material material, BlockPos pos) { CompoundTag nbt = block.getNbtData(); if(nbt == null) { @@ -140,11 +144,7 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker { if(material == Material.DISPENSER && (itemType.equals(Material.FIRE_CHARGE) || itemType.equals(Material.ARROW))) { counter += item.getByte("Count"); - }else if (!FLOWERS.contains(itemType) && !((material == Material.CHEST || material == Material.BARREL) && itemType.equals(Material.TNT))) { - - if(material == Material.DISPENSER && itemType.equals(Material.BUCKET)) - return; - + }else if (!FLOWERS.contains(itemType) && !itemsInInv.getOrDefault(itemType, EnumSet.noneOf(Material.class)).contains(material)) { result.getForbiddenItems().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType); } else if (item.containsKey("tag")) { result.getForbiddenNbt().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType); diff --git a/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java b/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java index 0efbb09..784ddc5 100644 --- a/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java +++ b/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2022 SteamWar.de-Serverteam + Copyright (C) 2023 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 @@ -27,9 +27,7 @@ import com.sk89q.worldedit.regions.Region; import de.steamwar.schematicsystem.CheckSchemType; import org.bukkit.Material; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; @SuppressWarnings("deprecation") public class AutoChecker8 implements AutoChecker.IAutoChecker { @@ -90,6 +88,13 @@ public class AutoChecker8 implements AutoChecker.IAutoChecker { } } + private static final Map> itemsInInv = new EnumMap<>(Material.class); + + static { + itemsInInv.put(Material.BUCKET, EnumSet.of(Material.DISPENSER)); + itemsInInv.put(Material.TNT, EnumSet.of(Material.CHEST)); + } + private static void checkInventory(AutoChecker.BlockScanResult result, BaseBlock block, int blockId, BlockPos pos) { CompoundTag nbt = block.getNbtData(); if(nbt == null){ @@ -125,7 +130,7 @@ public class AutoChecker8 implements AutoChecker.IAutoChecker { if(blockId == DISPENSER && (itemType.equals(Material.FIREBALL) || itemType.equals(Material.ARROW))) counter += item.getByte("Count"); - else if(!FLOWERS.contains(itemType) && !(blockId == CHEST && itemType.equals(Material.TNT))) { + else if(!FLOWERS.contains(itemType) && !itemsInInv.getOrDefault(itemType, EnumSet.noneOf(Material.class)).contains(Material.getMaterial(blockId))) { result.getForbiddenItems().computeIfAbsent(pos, blockPos -> new HashSet<>()).add(Material.getMaterial(blockId)); } else if(item.containsKey("tag")) { From 2fce9f927f6b72d8ad81fc46b9860ca8f2a7da8b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 4 Feb 2023 20:10:14 +0100 Subject: [PATCH 3/3] Another --- .../schematicsystem/autocheck/AutoChecker15.java | 14 +++++++++----- .../schematicsystem/autocheck/AutoChecker8.java | 13 +++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java b/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java index ddbf4ef..6728a7f 100644 --- a/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java +++ b/SchematicSystem_15/src/de/steamwar/schematicsystem/autocheck/AutoChecker15.java @@ -107,11 +107,14 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker { return result; } - private static final Map> itemsInInv = new EnumMap<>(Material.class); + private static final Map> itemsInInv = new EnumMap<>(Material.class); static { itemsInInv.put(Material.BUCKET, EnumSet.of(Material.DISPENSER)); itemsInInv.put(Material.TNT, EnumSet.of(Material.CHEST, Material.BARREL)); + itemsInInv.put(Material.FIRE_CHARGE, EnumSet.of(Material.DISPENSER)); + itemsInInv.put(Material.ARROW, EnumSet.of(Material.DISPENSER)); + FLOWERS.forEach(material -> itemsInInv.put(material, INVENTORY)); } private void checkInventory(AutoChecker.BlockScanResult result, BaseBlock block, Material material, BlockPos pos) { @@ -142,11 +145,12 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker { if(itemType == null) //Leere Slots continue; - if(material == Material.DISPENSER && (itemType.equals(Material.FIRE_CHARGE) || itemType.equals(Material.ARROW))) { - counter += item.getByte("Count"); - }else if (!FLOWERS.contains(itemType) && !itemsInInv.getOrDefault(itemType, EnumSet.noneOf(Material.class)).contains(material)) { + if (!itemsInInv.getOrDefault(itemType, EnumSet.noneOf(Material.class)).contains(material)) { result.getForbiddenItems().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType); - } else if (item.containsKey("tag")) { + } else if(material == Material.DISPENSER && (itemType == Material.ARROW || itemType == Material.FIRE_CHARGE)) { + counter += item.getByte("Count"); + } + if (item.containsKey("tag")) { result.getForbiddenNbt().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType); } } diff --git a/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java b/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java index 784ddc5..e983a73 100644 --- a/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java +++ b/SchematicSystem_8/src/de/steamwar/schematicsystem/autocheck/AutoChecker8.java @@ -28,6 +28,7 @@ import de.steamwar.schematicsystem.CheckSchemType; import org.bukkit.Material; import java.util.*; +import java.util.stream.Collectors; @SuppressWarnings("deprecation") public class AutoChecker8 implements AutoChecker.IAutoChecker { @@ -93,6 +94,9 @@ public class AutoChecker8 implements AutoChecker.IAutoChecker { static { itemsInInv.put(Material.BUCKET, EnumSet.of(Material.DISPENSER)); itemsInInv.put(Material.TNT, EnumSet.of(Material.CHEST)); + itemsInInv.put(Material.FIREBALL, EnumSet.of(Material.DISPENSER)); + itemsInInv.put(Material.ARROW, EnumSet.of(Material.DISPENSER)); + FLOWERS.forEach(material -> itemsInInv.put(material, INVENTORY.stream().map(Material::getMaterial).collect(Collectors.toCollection(() -> EnumSet.noneOf(Material.class))))); } private static void checkInventory(AutoChecker.BlockScanResult result, BaseBlock block, int blockId, BlockPos pos) { @@ -128,12 +132,13 @@ public class AutoChecker8 implements AutoChecker.IAutoChecker { if(itemType == null) //Leere Slots continue; - if(blockId == DISPENSER && (itemType.equals(Material.FIREBALL) || itemType.equals(Material.ARROW))) - counter += item.getByte("Count"); - else if(!FLOWERS.contains(itemType) && !itemsInInv.getOrDefault(itemType, EnumSet.noneOf(Material.class)).contains(Material.getMaterial(blockId))) { + + if(!itemsInInv.getOrDefault(itemType, EnumSet.noneOf(Material.class)).contains(Material.getMaterial(blockId))) { result.getForbiddenItems().computeIfAbsent(pos, blockPos -> new HashSet<>()).add(Material.getMaterial(blockId)); + } else if(blockId == DISPENSER && (itemType.equals(Material.FIREBALL) || itemType.equals(Material.ARROW))) { + counter += item.getByte("Count"); } - else if(item.containsKey("tag")) { + if(item.containsKey("tag")) { result.getForbiddenNbt().computeIfAbsent(pos, blockPos -> new HashSet<>()).add(Material.getMaterial(blockId)); } }