SteamWar/BauSystem2.0
Archiviert
12
0

Implement Testblock Command
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
zOnlyKroks 2023-07-28 21:41:56 +02:00
Ursprung edfc331d03
Commit d8b93e976f
4 geänderte Dateien mit 55 neuen und 89 gelöschten Zeilen

Datei anzeigen

@ -52,46 +52,30 @@ public class TestblockCommand extends SWCommand {
super("testblock", "tb", "dummy");
}
@Register(description = "REGION_TB_HELP_RESET")
public void genericTestblockCommand(Player p) {
genericTestblockCommand(p, RegionExtensionType.NORMAL);
}
@Register(description = "REGION_TB_HELP_RESET_EXTENSION")
public void genericTestblockCommand(@Validator Player p, RegionExtensionType regionExtensionType) {
Region region = regionCheck(p);
if (region == null) return;
try {
region.reset(RegionType.TESTBLOCK, regionExtensionType, regionExtensionType == null);
RegionUtils.message(region, "REGION_TB_DONE");
} catch (IOException e) {
BauSystem.MESSAGE.send("REGION_TB_ERROR", p);
Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e);
}
}
@Register(description = "REGION_TB_HELP_SCHEMATIC")
public void schematicTestblockCommand(Player p, @Mapper("withPublic") SchematicNode node) {
schematicTestblockCommand(p, node, RegionExtensionType.NORMAL);
}
@Register
public void schematicTestblockCommand(Player p, RegionExtensionType regionExtensionType, @Mapper("withPublic") SchematicNode node) {
schematicTestblockCommand(p, node, regionExtensionType);
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);
resetRegion(p,node,isExtension ? RegionExtensionType.EXTENSION : RegionExtensionType.NORMAL,isIgnoreAir,isOnlyColor,replaceTNT,replaceWater);
}
@Register(description = "REGION_TB_HELP_SCHEMATIC_EXTENSION")
public void schematicTestblockCommand(@Validator Player p, @Mapper("withPublic") SchematicNode node, RegionExtensionType regionExtensionType) {
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.isDir()) {
BauSystem.MESSAGE.send("ONLY_SCHEMS", p);
return;
}
if(node != null) {
if(node.isDir()) {
BauSystem.MESSAGE.send("ONLY_SCHEMS", p);
return;
}
}
try {
region.reset(node, RegionType.TESTBLOCK, regionExtensionType,false);
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);
@ -99,39 +83,39 @@ public class TestblockCommand extends SWCommand {
}
}
@ClassMapper(value = TestblockParamaterType.class, local = true)
private TypeMapper<TestblockParamaterType> testblockParamaterTypeMapper() {
Map<TestblockParamaterType, List<String>> testblockParamaterTypeListMap = new EnumMap<>(TestblockParamaterType.class);
for (TestblockParamaterType value : TestblockParamaterType.values()) {
testblockParamaterTypeListMap.put(value, value.getTabCompletes());
@ClassMapper(value = TestblockParameterType.class, local = true)
private TypeMapper<TestblockParameterType> testblockParameterTypeMapper() {
Map<TestblockParameterType, List<String>> testblockParameterTypeListMap = new EnumMap<>(TestblockParameterType.class);
for (TestblockParameterType value : TestblockParameterType.values()) {
testblockParameterTypeListMap.put(value, value.getTabCompletes());
}
Map<String, TestblockParamaterType> testblockParameterTypesMap = new HashMap<>();
testblockParamaterTypeListMap.forEach((k, v) -> v.forEach(s -> testblockParameterTypesMap.put(s, k)));
Map<String, TestblockParameterType> testblockParameterTypesMap = new HashMap<>();
testblockParameterTypeListMap.forEach((k, v) -> v.forEach(s -> testblockParameterTypesMap.put(s, k)));
return new TypeMapper<TestblockParamaterType>() {
return new TypeMapper<TestblockParameterType>() {
@Override
public TestblockParamaterType map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
public TestblockParameterType map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
return testblockParameterTypesMap.get(s);
}
@Override
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
Set<TestblockParamaterType> testblockParameterTypeSet = new HashSet<>();
previousArguments.getAll(TestblockParamaterType.class).forEach(showModeType -> {
Set<TestblockParameterType> testblockParameterTypeSet = new HashSet<>();
previousArguments.getAll(TestblockParameterType.class).forEach(showModeType -> {
testblockParameterTypeSet.addAll(Arrays.asList(showModeType.removed.get()));
});
Arrays.stream(previousArguments.userArgs).map(testblockParameterTypesMap::get).forEach(testblockParameterTypeSet::add);
testblockParameterTypeSet.remove(null);
Set<TestblockParamaterType> removed = testblockParameterTypeSet.stream()
.map(TestblockParamaterType::getRemoved)
Set<TestblockParameterType> removed = testblockParameterTypeSet.stream()
.map(TestblockParameterType::getRemoved)
.map(Supplier::get)
.flatMap(Arrays::stream)
.collect(Collectors.toSet());
List<String> tabCompletes = new ArrayList<>();
for (Map.Entry<TestblockParamaterType, List<String>> entry : testblockParamaterTypeListMap.entrySet()) {
for (Map.Entry<TestblockParameterType, List<String>> entry : testblockParameterTypeListMap.entrySet()) {
if (removed.contains(entry.getKey()) || testblockParameterTypeSet.contains(entry.getKey())) {
continue;
}
@ -144,9 +128,7 @@ public class TestblockCommand extends SWCommand {
@ClassValidator(value = Player.class, local = true)
public TypeValidator<Player> validator() {
return (commandSender, player, messageSender) -> {
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "REGION_TB_NO_PERMS");
};
return (commandSender, player, messageSender) -> !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "REGION_TB_NO_PERMS");
}
private Region regionCheck(Player player) {
@ -179,11 +161,12 @@ public class TestblockCommand extends SWCommand {
};
}
private enum TestblockParamaterType {
NORMAL(TestblockParameter::enableWater, Arrays.asList("-n","-normal"), "EXTENSION"),
EXTENSION(TestblockParameter::enableExtension, Arrays.asList("-e", "-extension"), "NORMAL"),
TNT(TestblockParameter::enableTNT, Arrays.asList("-t", "-interpolate-x", "-tnt")),
WATER(TestblockParameter::enableWater, Arrays.asList("-w", "-water"));
private 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"));
@Getter
private final Consumer<TestblockParameter> testblockParameterConsumer;
@ -192,17 +175,17 @@ public class TestblockCommand extends SWCommand {
private List<String> tabCompletes;
@Getter
private final Supplier<TestblockParamaterType[]> removed;
private AtomicReference<TestblockParamaterType[]> cached = new AtomicReference<>();
private final Supplier<TestblockParameterType[]> removed;
private AtomicReference<TestblockParameterType[]> cached = new AtomicReference<>();
TestblockParamaterType(Consumer<TestblockParameter> testblockParameterConsumer, List<String> tabCompletes, String... removed) {
TestblockParameterType(Consumer<TestblockParameter> testblockParameterConsumer, List<String> tabCompletes, String... removed) {
this.testblockParameterConsumer = testblockParameterConsumer;
this.tabCompletes = tabCompletes;
this.removed = () -> {
if (cached.get() == null) {
TestblockParamaterType[] showModeParameterTypes = new TestblockParamaterType[removed.length];
TestblockParameterType[] showModeParameterTypes = new TestblockParameterType[removed.length];
for (int i = 0; i < removed.length; i++) {
showModeParameterTypes[i] = TestblockParamaterType.valueOf(removed[i]);
showModeParameterTypes[i] = TestblockParameterType.valueOf(removed[i]);
}
cached.set(showModeParameterTypes);
return showModeParameterTypes;
@ -212,12 +195,13 @@ public class TestblockCommand extends SWCommand {
}
}
@Getter
private class TestblockParameter {
public static class TestblockParameter {
private boolean water = false;
private boolean tnt = false;
private boolean extension = false;
private boolean normal = false;
private boolean onlyColor = false;
private boolean ignoreAir = false;
public void enableWater() {
this.water = true;
@ -231,8 +215,8 @@ public class TestblockCommand extends SWCommand {
this.extension = true;
}
public void enableNormal() {
this.normal = true;
}
public void enableOnlyColor() { this.onlyColor = true; }
public void enableIgnoreAir() { this.ignoreAir = true; }
}
}

Datei anzeigen

@ -51,7 +51,7 @@ public class TestblockBauGuiItem extends BauGuiItem {
public boolean click(ClickType click, Player p) {
if (click == ClickType.LEFT) {
p.closeInventory();
testblockCommand.genericTestblockCommand(p);
testblockCommand.schematicTestblockCommand(p,null);
} else {
SchematicSelector selector = new SchematicSelector(p, SchematicSelector.selectSchematic(), node -> {
p.closeInventory();

Datei anzeigen

@ -47,4 +47,6 @@ public class PasteOptions {
private final boolean testBlock;
private final boolean removeTNT;
private final boolean removeWater;
}

Datei anzeigen

@ -413,33 +413,13 @@ public class Region {
}
}
public void reset(RegionType regionType) throws IOException {
reset(null, regionType);
}
public void reset(SchematicNode schematic, RegionType regionType) throws IOException {
reset(schematic, regionType, RegionExtensionType.NORMAL, false);
}
public void reset(RegionType regionType, RegionExtensionType regionExtensionType,boolean removeTNT) throws IOException {
reset(null, regionType, regionExtensionType,removeTNT);
}
public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType,boolean removeTNT) throws IOException {
reset(schematic, regionType, regionExtensionType, false,removeTNT);
}
public void reset(File file) {
EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, false, false, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel, false,false));
EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, false, false, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel, false,false,false));
initSessions();
undoSessions.push(editSession);
}
public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean removeTNT) throws IOException {
reset(schematic, regionType, regionExtensionType, ignoreAir, false,removeTNT);
}
public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors,boolean removeTNT) throws IOException {
public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors,boolean removeTNT, boolean removeWater) throws IOException {
if (!hasReset(regionType)) {
return;
}
@ -447,7 +427,7 @@ public class Region {
regionExtensionType = RegionExtensionType.NORMAL;
}
PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel, regionType == RegionType.TESTBLOCK,removeTNT);
PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel, regionType == RegionType.TESTBLOCK,removeTNT,removeWater);
Point pastePoint;
File tempFile = null;