From ad55b25cf05fc185365c27ecf678b8bfc55fe3f8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 28 Jul 2023 22:16:55 +0200 Subject: [PATCH] Fix TestblockCommand Signed-off-by: yoyosource --- .../features/region/TestblockCommand.java | 95 ++++++++++--------- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index 00fe8fc8..df29c1df 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -59,26 +59,27 @@ public class TestblockCommand extends SWCommand { } @Register - public void schematicTestblockCommand(@Validator Player p,@OptionalValue("") @Mapper("withPublic") @AllowNull SchematicNode node,TestblockParameter... testblockParameters) { - boolean isExtension = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.extension); - boolean isIgnoreAir = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.ignoreAir); - boolean isOnlyColor = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.onlyColor); - boolean replaceTNT = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.tnt); - boolean replaceWater = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.water); + public void schematicTestblockCommand(@Validator Player p, @OptionalValue("") @Mapper("withPublic") @AllowNull SchematicNode node, TestblockParameterType... testblockParameterTypes) { + Set testblockParameterTypesSet = new HashSet<>(Arrays.asList(testblockParameterTypes)); + boolean isExtension = testblockParameterTypesSet.contains(TestblockParameterType.EXTENSION); + boolean isIgnoreAir = testblockParameterTypesSet.contains(TestblockParameterType.IGNORE_AIR); + boolean isOnlyColor = testblockParameterTypesSet.contains(TestblockParameterType.ONLY_COLOR); + boolean replaceTNT = testblockParameterTypesSet.contains(TestblockParameterType.TNT); + boolean replaceWater = testblockParameterTypesSet.contains(TestblockParameterType.WATER); - resetRegion(p,node,isExtension ? RegionExtensionType.EXTENSION : RegionExtensionType.NORMAL,isIgnoreAir,isOnlyColor,replaceTNT,replaceWater); + resetRegion(p, node, isExtension ? RegionExtensionType.EXTENSION : RegionExtensionType.NORMAL, isIgnoreAir, isOnlyColor, replaceTNT, replaceWater); } - private void resetRegion(Player p,SchematicNode node, RegionExtensionType regionExtensionType,boolean ignoreAir,boolean onlyColors, boolean removeTNT, boolean removeWater) { + private void resetRegion(Player p, SchematicNode node, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors, boolean removeTNT, boolean removeWater) { Region region = regionCheck(p); if (region == null) return; - if(node != null) { - if(node.isDir()) { - BauSystem.MESSAGE.send("ONLY_SCHEMS", p); - return; - } - } + if (node != null) { + if (node.isDir()) { + BauSystem.MESSAGE.send("ONLY_SCHEMS", p); + return; + } + } if (bauServer.getOwner() != p.getUniqueId()) { if (Punishment.isPunished(SteamwarUser.get(p.getUniqueId()), Punishment.PunishmentType.NoSchemSharing, punishment -> BauSystem.MESSAGE.parse("REGION_TB_NO_SCHEMSHARING", p, punishment.getEndTime()))) { @@ -89,7 +90,7 @@ public class TestblockCommand extends SWCommand { } try { - region.reset(node,RegionType.TESTBLOCK, regionExtensionType,ignoreAir,onlyColors,removeTNT,removeWater); + region.reset(node, RegionType.TESTBLOCK, regionExtensionType, ignoreAir, onlyColors, removeTNT, removeWater); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); @@ -98,7 +99,7 @@ public class TestblockCommand extends SWCommand { } @ClassMapper(value = TestblockParameterType.class, local = true) - private TypeMapper testblockParameterTypeMapper() { + public TypeMapper testblockParameterTypeMapper() { Map> testblockParameterTypeListMap = new EnumMap<>(TestblockParameterType.class); for (TestblockParameterType value : TestblockParameterType.values()) { testblockParameterTypeListMap.put(value, value.getTabCompletes()); @@ -117,7 +118,7 @@ public class TestblockCommand extends SWCommand { public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { Set testblockParameterTypeSet = new HashSet<>(); previousArguments.getAll(TestblockParameterType.class).forEach(showModeType -> { - testblockParameterTypeSet.addAll(Arrays.asList(showModeType.removed.get())); + testblockParameterTypeSet.addAll(Arrays.asList(showModeType.getRemoved().get())); }); Arrays.stream(previousArguments.userArgs).map(testblockParameterTypesMap::get).forEach(testblockParameterTypeSet::add); testblockParameterTypeSet.remove(null); @@ -167,7 +168,7 @@ public class TestblockCommand extends SWCommand { @Override public SchematicNode map(CommandSender commandSender, PreviousArguments previousArguments, String s) { SchematicNode node = SchematicNode.getNodeFromPath(SteamwarUser.get(((Player) commandSender).getUniqueId()), s); - if(node == null) { + if (node == null) { node = SchematicNode.getNodeFromPath(SteamwarUser.get(0), s); } return node; @@ -175,12 +176,41 @@ public class TestblockCommand extends SWCommand { }; } - private enum TestblockParameterType { + public static class TestblockParameter { + private boolean water = false; + private boolean tnt = false; + private boolean extension = false; + private boolean onlyColor = false; + + private boolean ignoreAir = false; + + public void enableWater() { + this.water = true; + } + + public void enableTNT() { + this.tnt = true; + } + + public void enableExtension() { + this.extension = true; + } + + public void enableOnlyColor() { + this.onlyColor = true; + } + + public void enableIgnoreAir() { + this.ignoreAir = true; + } + } + + public enum TestblockParameterType { EXTENSION(TestblockParameter::enableExtension, Arrays.asList("-e", "-extension")), TNT(TestblockParameter::enableTNT, Arrays.asList("-t", "-tnt")), WATER(TestblockParameter::enableWater, Arrays.asList("-w", "-water")), IGNORE_AIR(TestblockParameter::enableIgnoreAir, Arrays.asList("-ig", "-ignore_air")), - ONLY_COLOR(TestblockParameter::enableOnlyColor, Arrays.asList("-o","-color","-only_color")); + ONLY_COLOR(TestblockParameter::enableOnlyColor, Arrays.asList("-o", "-color", "-only_color")); @Getter private final Consumer testblockParameterConsumer; @@ -208,29 +238,4 @@ public class TestblockCommand extends SWCommand { }; } } - - public static class TestblockParameter { - private boolean water = false; - private boolean tnt = false; - private boolean extension = false; - private boolean onlyColor = false; - - private boolean ignoreAir = false; - - public void enableWater() { - this.water = true; - } - - public void enableTNT() { - this.tnt = true; - } - - public void enableExtension() { - this.extension = true; - } - - public void enableOnlyColor() { this.onlyColor = true; } - - public void enableIgnoreAir() { this.ignoreAir = true; } - } }