SteamWar/BauSystem2.0
Archiviert
12
0

Update TraceCommand.showCommand by -ticks as option
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-12-26 00:04:12 +01:00
Ursprung 8256c1fa7a
Commit 2c77e1a0d1
2 geänderte Dateien mit 47 neuen und 35 gelöschten Zeilen

Datei anzeigen

@ -56,13 +56,10 @@ public class TraceCommand extends SWCommand {
@ClassMapper(value = ShowModeParameterType.class, local = true) @ClassMapper(value = ShowModeParameterType.class, local = true)
public TypeMapper<ShowModeParameterType> showModeParameterTypesTypeMapper() { public TypeMapper<ShowModeParameterType> showModeParameterTypesTypeMapper() {
Map<ShowModeParameterType, List<String>> showModeParameterTypeListMap = new HashMap<>(); Map<ShowModeParameterType, List<String>> showModeParameterTypeListMap = new EnumMap<>(ShowModeParameterType.class);
showModeParameterTypeListMap.put(ShowModeParameterType.WATER, Arrays.asList("-water")); for (ShowModeParameterType value : ShowModeParameterType.values()) {
showModeParameterTypeListMap.put(ShowModeParameterType.INTERPOLATE_Y, Arrays.asList("-interpolatey", "-interpolate-y", "-interpolate_y", "-y")); showModeParameterTypeListMap.put(value, value.getTabCompletes());
showModeParameterTypeListMap.put(ShowModeParameterType.INTERPOLATE_XZ, Arrays.asList("-interpolatex", "-interpolate-x", "-interpolate_x", "-x", "-interpolatez", "-interpolate-z", "-interpolate_z", "-z", "-interpolatexz", "-interpolate-xz", "-interpolate_xz", "-xz")); }
showModeParameterTypeListMap.put(ShowModeParameterType.ADVANCED, Arrays.asList("-advanced", "-a"));
showModeParameterTypeListMap.put(ShowModeParameterType.EXPLODE, Arrays.asList("-explode", "-explodeonly"));
showModeParameterTypeListMap.put(ShowModeParameterType.TICKS, Arrays.asList("-ticks", "-t"));
Map<String, ShowModeParameterType> showModeParameterTypesMap = new HashMap<>(); Map<String, ShowModeParameterType> showModeParameterTypesMap = new HashMap<>();
showModeParameterTypeListMap.forEach((k, v) -> v.forEach(s -> showModeParameterTypesMap.put(s, k))); showModeParameterTypeListMap.forEach((k, v) -> v.forEach(s -> showModeParameterTypesMap.put(s, k)));
@ -76,11 +73,10 @@ public class TraceCommand extends SWCommand {
@Override @Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) { public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
Set<ShowModeParameterType> showModeParameterTypeSet = new HashSet<>(); Set<ShowModeParameterType> showModeParameterTypeSet = new HashSet<>();
boolean allowTicks = true;
for (String previousArgument : strings) { for (String previousArgument : strings) {
try { try {
ShowModeType showModeType = ShowModeType.valueOf(previousArgument.toUpperCase()); ShowModeType showModeType = ShowModeType.valueOf(previousArgument.toUpperCase());
allowTicks &= showModeType.allowTicks; showModeParameterTypeSet.addAll(Arrays.asList(showModeType.removedTypes));
} catch (IllegalArgumentException ignored) { } catch (IllegalArgumentException ignored) {
// Ignored // Ignored
} }
@ -88,21 +84,15 @@ public class TraceCommand extends SWCommand {
} }
showModeParameterTypeSet.remove(null); showModeParameterTypeSet.remove(null);
List<String> tabCompletes = new ArrayList<>(); List<String> tabCompletes = new ArrayList<>();
for (ShowModeParameterType showModeParameterType : showModeParameterTypeListMap.keySet()) { for (Map.Entry<ShowModeParameterType, List<String>> entry : showModeParameterTypeListMap.entrySet()) {
if (showModeParameterType == ShowModeParameterType.TICKS && !allowTicks) { if ((showModeParameterTypeSet.contains(ShowModeParameterType.INTERPOLATE_XZ) || showModeParameterTypeSet.contains(ShowModeParameterType.INTERPOLATE_Y)) && entry.getKey() == ShowModeParameterType.ADVANCED) {
continue; continue;
} }
if (showModeParameterTypeSet.contains(entry.getKey())) {
if ((showModeParameterTypeSet.contains(ShowModeParameterType.INTERPOLATE_XZ) || showModeParameterTypeSet.contains(ShowModeParameterType.INTERPOLATE_Y)) && showModeParameterType == ShowModeParameterType.ADVANCED) {
continue; continue;
} }
if (showModeParameterTypeSet.contains(ShowModeParameterType.ADVANCED) && (showModeParameterType == ShowModeParameterType.INTERPOLATE_XZ || showModeParameterType == ShowModeParameterType.INTERPOLATE_Y)) { tabCompletes.addAll(entry.getValue());
continue; showModeParameterTypeSet.addAll(Arrays.asList(entry.getKey().getRemoved().get()));
}
if (showModeParameterTypeSet.contains(showModeParameterType)) {
continue;
}
tabCompletes.addAll(showModeParameterTypeListMap.get(showModeParameterType));
} }
return tabCompletes; return tabCompletes;
} }
@ -324,13 +314,13 @@ public class TraceCommand extends SWCommand {
@AllArgsConstructor @AllArgsConstructor
private enum ShowModeType { private enum ShowModeType {
ENTITY(TraceEntityShowMode::new, true), ENTITY(TraceEntityShowMode::new, new ShowModeParameterType[]{}),
RAW(RawEntityShowMode::new, true), RAW(RawEntityShowMode::new, new ShowModeParameterType[]{}),
PARTICLE(ParticleShowMode::new, false), PARTICLE(ParticleShowMode::new, new ShowModeParameterType[]{ShowModeParameterType.TICKS}),
BLOCK(BlockShowMode::new, false); BLOCK(BlockShowMode::new, new ShowModeParameterType[]{ShowModeParameterType.TICKS});
private BiFunction<Player, ShowModeParameter, ShowMode<TNTPosition>> showModeBiFunction; private BiFunction<Player, ShowModeParameter, ShowMode<TNTPosition>> showModeBiFunction;
private boolean allowTicks; private ShowModeParameterType[] removedTypes;
} }
@Register({"show", "gui"}) @Register({"show", "gui"})

Datei anzeigen

@ -19,27 +19,49 @@
package de.steamwar.bausystem.features.tracer.show; package de.steamwar.bausystem.features.tracer.show;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier;
public enum ShowModeParameterType { public enum ShowModeParameterType {
WATER(showModeParameter -> showModeParameter.setWater(true)), WATER(showModeParameter -> showModeParameter.setWater(true), Arrays.asList("-water")),
INTERPOLATE_Y(showModeParameter -> showModeParameter.setInterpolate_Y(true)), INTERPOLATE_Y(showModeParameter -> showModeParameter.setInterpolate_Y(true), Arrays.asList("-interpolatey", "-interpolate-y", "-interpolate_y", "-y"), "ADVANCED"),
INTERPOLATE_XZ(showModeParameter -> showModeParameter.setInterpolate_XZ(true)), INTERPOLATE_XZ(showModeParameter -> showModeParameter.setInterpolate_XZ(true), Arrays.asList("-interpolatex", "-interpolate-x", "-interpolate_x", "-x", "-interpolatez", "-interpolate-z", "-interpolate_z", "-z", "-interpolatexz", "-interpolate-xz", "-interpolate_xz", "-xz"), "ADVANCED"),
ADVANCED(showModeParameter -> { ADVANCED(showModeParameter -> {
showModeParameter.setInterpolate_Y(true); showModeParameter.setInterpolate_Y(true);
showModeParameter.setInterpolate_XZ(true); showModeParameter.setInterpolate_XZ(true);
}), }, Arrays.asList("-advanced", "-a"), "INTERPOLATE_Y", "INTERPOLATE_XZ"),
EXPLODE(showModeParameter -> showModeParameter.setExplodeOnly(true)), EXPLODE(showModeParameter -> showModeParameter.setExplodeOnly(true), Arrays.asList("-explode", "-explodeonly")),
TICKS(showModeParameter -> showModeParameter.setTicks(true)); TICKS(showModeParameter -> showModeParameter.setTicks(true), Arrays.asList("-ticks", "-t"));
@Getter
private final Consumer<ShowModeParameter> showModeParameterConsumer; private final Consumer<ShowModeParameter> showModeParameterConsumer;
public Consumer<ShowModeParameter> getShowModeParameterConsumer() { @Getter
return showModeParameterConsumer; private List<String> tabCompletes;
}
ShowModeParameterType(Consumer<ShowModeParameter> showModeParameterConsumer) { @Getter
private final Supplier<ShowModeParameterType[]> removed;
private AtomicReference<ShowModeParameterType[]> cached = new AtomicReference<>();
ShowModeParameterType(Consumer<ShowModeParameter> showModeParameterConsumer, List<String> tabCompletes, String... removed) {
this.showModeParameterConsumer = showModeParameterConsumer; this.showModeParameterConsumer = showModeParameterConsumer;
this.tabCompletes = tabCompletes;
this.removed = () -> {
if (cached.get() == null) {
ShowModeParameterType[] showModeParameterTypes = new ShowModeParameterType[removed.length];
for (int i = 0; i < removed.length; i++) {
showModeParameterTypes[i] = ShowModeParameterType.valueOf(removed[i]);
}
cached.set(showModeParameterTypes);
return showModeParameterTypes;
}
return cached.get();
};
} }
} }