SteamWar/BauSystem2.0
Archiviert
12
0

TestBlockPaste-Without-Water #146

Zusammengeführt
YoyoNow hat 25 Commits von TestBlockPaste-Without-Water nach master 2023-08-19 23:29:20 +02:00 zusammengeführt
4 geänderte Dateien mit 55 neuen und 89 gelöschten Zeilen
Nur Änderungen aus Commit d8b93e976f werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -52,46 +52,30 @@ public class TestblockCommand extends SWCommand {
super("testblock", "tb", "dummy"); 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 @Register
public void schematicTestblockCommand(Player p, RegionExtensionType regionExtensionType, @Mapper("withPublic") SchematicNode node) { public void schematicTestblockCommand(@Validator Player p,@OptionalValue("") @Mapper("withPublic") @AllowNull SchematicNode node,TestblockParameter... testblockParameters) {
schematicTestblockCommand(p, node, regionExtensionType); 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);
zOnlyKroks markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

Hier die Daten durchzureichen ist nicht sinnvoll, da RegionType.TESTBLOCK ja doch schon sagt das es der Testblock ist.

Hier die Daten durchzureichen ist nicht sinnvoll, da RegionType.TESTBLOCK ja doch schon sagt das es der Testblock ist.
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") private void resetRegion(Player p,SchematicNode node, RegionExtensionType regionExtensionType,boolean ignoreAir,boolean onlyColors, boolean removeTNT, boolean removeWater) {
public void schematicTestblockCommand(@Validator Player p, @Mapper("withPublic") SchematicNode node, RegionExtensionType regionExtensionType) {
Region region = regionCheck(p); Region region = regionCheck(p);
if (region == null) return; if (region == null) return;
if(node.isDir()) { if(node != null) {
BauSystem.MESSAGE.send("ONLY_SCHEMS", p); if(node.isDir()) {
return; BauSystem.MESSAGE.send("ONLY_SCHEMS", p);
} return;
}
}
try { try {
region.reset(node, RegionType.TESTBLOCK, regionExtensionType,false); region.reset(node,RegionType.TESTBLOCK, regionExtensionType,ignoreAir,onlyColors,removeTNT,removeWater);
RegionUtils.message(region, "REGION_TB_DONE"); RegionUtils.message(region, "REGION_TB_DONE");
} catch (IOException e) { } catch (IOException e) {
BauSystem.MESSAGE.send("REGION_TB_ERROR", p); BauSystem.MESSAGE.send("REGION_TB_ERROR", p);
@ -99,39 +83,39 @@ public class TestblockCommand extends SWCommand {
} }
} }
@ClassMapper(value = TestblockParamaterType.class, local = true) @ClassMapper(value = TestblockParameterType.class, local = true)
private TypeMapper<TestblockParamaterType> testblockParamaterTypeMapper() { private TypeMapper<TestblockParameterType> testblockParameterTypeMapper() {
Map<TestblockParamaterType, List<String>> testblockParamaterTypeListMap = new EnumMap<>(TestblockParamaterType.class); Map<TestblockParameterType, List<String>> testblockParameterTypeListMap = new EnumMap<>(TestblockParameterType.class);
for (TestblockParamaterType value : TestblockParamaterType.values()) { for (TestblockParameterType value : TestblockParameterType.values()) {
zOnlyKroks markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

Siehe oben

Siehe oben
testblockParamaterTypeListMap.put(value, value.getTabCompletes()); testblockParameterTypeListMap.put(value, value.getTabCompletes());
} }
Map<String, TestblockParamaterType> testblockParameterTypesMap = new HashMap<>(); Map<String, TestblockParameterType> testblockParameterTypesMap = new HashMap<>();
testblockParamaterTypeListMap.forEach((k, v) -> v.forEach(s -> testblockParameterTypesMap.put(s, k))); testblockParameterTypeListMap.forEach((k, v) -> v.forEach(s -> testblockParameterTypesMap.put(s, k)));
return new TypeMapper<TestblockParamaterType>() { return new TypeMapper<TestblockParameterType>() {
@Override @Override
public TestblockParamaterType map(CommandSender commandSender, PreviousArguments previousArguments, String s) { public TestblockParameterType map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
return testblockParameterTypesMap.get(s); return testblockParameterTypesMap.get(s);
} }
@Override @Override
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
Set<TestblockParamaterType> testblockParameterTypeSet = new HashSet<>(); Set<TestblockParameterType> testblockParameterTypeSet = new HashSet<>();
previousArguments.getAll(TestblockParamaterType.class).forEach(showModeType -> { previousArguments.getAll(TestblockParameterType.class).forEach(showModeType -> {
testblockParameterTypeSet.addAll(Arrays.asList(showModeType.removed.get())); testblockParameterTypeSet.addAll(Arrays.asList(showModeType.removed.get()));
}); });
Arrays.stream(previousArguments.userArgs).map(testblockParameterTypesMap::get).forEach(testblockParameterTypeSet::add); Arrays.stream(previousArguments.userArgs).map(testblockParameterTypesMap::get).forEach(testblockParameterTypeSet::add);
testblockParameterTypeSet.remove(null); testblockParameterTypeSet.remove(null);
Set<TestblockParamaterType> removed = testblockParameterTypeSet.stream() Set<TestblockParameterType> removed = testblockParameterTypeSet.stream()
.map(TestblockParamaterType::getRemoved) .map(TestblockParameterType::getRemoved)
.map(Supplier::get) .map(Supplier::get)
.flatMap(Arrays::stream) .flatMap(Arrays::stream)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
List<String> tabCompletes = new ArrayList<>(); 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())) { if (removed.contains(entry.getKey()) || testblockParameterTypeSet.contains(entry.getKey())) {
continue; continue;
} }
@ -144,9 +128,7 @@ public class TestblockCommand extends SWCommand {
@ClassValidator(value = Player.class, local = true) @ClassValidator(value = Player.class, local = true)
public TypeValidator<Player> validator() { public TypeValidator<Player> validator() {
return (commandSender, player, messageSender) -> { return (commandSender, player, messageSender) -> !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "REGION_TB_NO_PERMS");
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "REGION_TB_NO_PERMS");
};
} }
private Region regionCheck(Player player) { private Region regionCheck(Player player) {
@ -179,11 +161,12 @@ public class TestblockCommand extends SWCommand {
}; };
} }
private enum TestblockParamaterType { private enum TestblockParameterType {
NORMAL(TestblockParameter::enableWater, Arrays.asList("-n","-normal"), "EXTENSION"), EXTENSION(TestblockParameter::enableExtension, Arrays.asList("-e", "-extension")),
EXTENSION(TestblockParameter::enableExtension, Arrays.asList("-e", "-extension"), "NORMAL"), TNT(TestblockParameter::enableTNT, Arrays.asList("-t", "-tnt")),
TNT(TestblockParameter::enableTNT, Arrays.asList("-t", "-interpolate-x", "-tnt")), WATER(TestblockParameter::enableWater, Arrays.asList("-w", "-water")),
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 @Getter
private final Consumer<TestblockParameter> testblockParameterConsumer; private final Consumer<TestblockParameter> testblockParameterConsumer;
@ -192,17 +175,17 @@ public class TestblockCommand extends SWCommand {
private List<String> tabCompletes; private List<String> tabCompletes;
@Getter @Getter
private final Supplier<TestblockParamaterType[]> removed; private final Supplier<TestblockParameterType[]> removed;
private AtomicReference<TestblockParamaterType[]> cached = new AtomicReference<>(); 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.testblockParameterConsumer = testblockParameterConsumer;
this.tabCompletes = tabCompletes; this.tabCompletes = tabCompletes;
this.removed = () -> { this.removed = () -> {
if (cached.get() == null) { if (cached.get() == null) {
TestblockParamaterType[] showModeParameterTypes = new TestblockParamaterType[removed.length]; TestblockParameterType[] showModeParameterTypes = new TestblockParameterType[removed.length];
for (int i = 0; i < removed.length; i++) { for (int i = 0; i < removed.length; i++) {
showModeParameterTypes[i] = TestblockParamaterType.valueOf(removed[i]); showModeParameterTypes[i] = TestblockParameterType.valueOf(removed[i]);
} }
cached.set(showModeParameterTypes); cached.set(showModeParameterTypes);
return showModeParameterTypes; return showModeParameterTypes;
@ -212,12 +195,13 @@ public class TestblockCommand extends SWCommand {
} }
} }
@Getter public static class TestblockParameter {
private class TestblockParameter {
private boolean water = false; private boolean water = false;
private boolean tnt = false; private boolean tnt = false;
private boolean extension = false; private boolean extension = false;
private boolean normal = false; private boolean onlyColor = false;
private boolean ignoreAir = false;
public void enableWater() { public void enableWater() {
this.water = true; this.water = true;
@ -231,8 +215,8 @@ public class TestblockCommand extends SWCommand {
this.extension = true; this.extension = true;
} }
public void enableNormal() { public void enableOnlyColor() { this.onlyColor = true; }
this.normal = 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) { public boolean click(ClickType click, Player p) {
if (click == ClickType.LEFT) { if (click == ClickType.LEFT) {
p.closeInventory(); p.closeInventory();
testblockCommand.genericTestblockCommand(p); testblockCommand.schematicTestblockCommand(p,null);
} else { } else {
SchematicSelector selector = new SchematicSelector(p, SchematicSelector.selectSchematic(), node -> { SchematicSelector selector = new SchematicSelector(p, SchematicSelector.selectSchematic(), node -> {
p.closeInventory(); p.closeInventory();

Datei anzeigen

@ -47,4 +47,6 @@ public class PasteOptions {
private final boolean testBlock; private final boolean testBlock;
private final boolean removeTNT; 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) { 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(); initSessions();
undoSessions.push(editSession); undoSessions.push(editSession);
} }
public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean removeTNT) throws IOException { public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors,boolean removeTNT, boolean removeWater) 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 {
if (!hasReset(regionType)) { if (!hasReset(regionType)) {
return; return;
} }
zOnlyKroks markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

Muss diese Änderung eigentlich wirklich sein?

Muss diese Änderung eigentlich wirklich sein?
@ -447,7 +427,7 @@ public class Region {
regionExtensionType = RegionExtensionType.NORMAL; 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; Point pastePoint;
File tempFile = null; File tempFile = null;