SteamWar/BauSystem2.0
Archiviert
12
0

Fix TestblockCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-07-28 22:16:55 +02:00
Ursprung 8a01394092
Commit ad55b25cf0

Datei anzeigen

@ -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<TestblockParameterType> 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<TestblockParameterType> testblockParameterTypeMapper() {
public TypeMapper<TestblockParameterType> testblockParameterTypeMapper() {
Map<TestblockParameterType, List<String>> 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<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
Set<TestblockParameterType> 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<TestblockParameter> 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; }
}
}