SteamWar/BauSystem2.0
Archiviert
12
0

Update TraceCommand make TabComplete better for '/trace show'
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-12-25 23:17:32 +01:00
Ursprung 8d63bea4a3
Commit 0d440994cb

Datei anzeigen

@ -35,19 +35,16 @@ import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.shared.ShowMode; import de.steamwar.bausystem.shared.ShowMode;
import de.steamwar.bausystem.utils.ListChatView; import de.steamwar.bausystem.utils.ListChatView;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@Linked(LinkageType.COMMAND) @Linked(LinkageType.COMMAND)
@ -59,39 +56,45 @@ 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<>();
showModeParameterTypeListMap.put(ShowModeParameterType.WATER, Arrays.asList("-water"));
showModeParameterTypeListMap.put(ShowModeParameterType.INTERPOLATE_Y, Arrays.asList("-interpolatey", "-interpolate-y", "-interpolate_y", "-y"));
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"));
Map<String, ShowModeParameterType> showModeParameterTypesMap = new HashMap<>(); Map<String, ShowModeParameterType> showModeParameterTypesMap = new HashMap<>();
showModeParameterTypesMap.put("-water", ShowModeParameterType.WATER); showModeParameterTypeListMap.forEach((k, v) -> v.forEach(s -> showModeParameterTypesMap.put(s, k)));
showModeParameterTypesMap.put("-interpolatey", ShowModeParameterType.INTERPOLATE_Y); return new TypeMapper<ShowModeParameterType>() {
showModeParameterTypesMap.put("-interpolate-y", ShowModeParameterType.INTERPOLATE_Y); @Override
showModeParameterTypesMap.put("-interpolate_y", ShowModeParameterType.INTERPOLATE_Y); public ShowModeParameterType map(CommandSender commandSender, String[] previousArguments, String s) {
showModeParameterTypesMap.put("-y", ShowModeParameterType.INTERPOLATE_Y); return showModeParameterTypesMap.get(s);
}
showModeParameterTypesMap.put("-interpolatex", ShowModeParameterType.INTERPOLATE_XZ); @Override
showModeParameterTypesMap.put("-interpolate-x", ShowModeParameterType.INTERPOLATE_XZ); public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
showModeParameterTypesMap.put("-interpolate_x", ShowModeParameterType.INTERPOLATE_XZ); Set<ShowModeParameterType> showModeParameterTypeSet = new HashSet<>();
showModeParameterTypesMap.put("-x", ShowModeParameterType.INTERPOLATE_XZ); for (String previousArgument : strings) {
showModeParameterTypeSet.add(showModeParameterTypesMap.get(previousArgument));
showModeParameterTypesMap.put("-interpolatez", ShowModeParameterType.INTERPOLATE_XZ); }
showModeParameterTypesMap.put("-interpolate-z", ShowModeParameterType.INTERPOLATE_XZ); showModeParameterTypeSet.remove(null);
showModeParameterTypesMap.put("-interpolate_z", ShowModeParameterType.INTERPOLATE_XZ); List<String> tabCompletes = new ArrayList<>();
showModeParameterTypesMap.put("-z", ShowModeParameterType.INTERPOLATE_XZ); for (ShowModeParameterType showModeParameterType : showModeParameterTypeListMap.keySet()) {
if ((showModeParameterTypeSet.contains(ShowModeParameterType.INTERPOLATE_XZ) || showModeParameterTypeSet.contains(ShowModeParameterType.INTERPOLATE_Y)) && showModeParameterType == ShowModeParameterType.ADVANCED) {
showModeParameterTypesMap.put("-interpolatexz", ShowModeParameterType.INTERPOLATE_XZ); continue;
showModeParameterTypesMap.put("-interpolate-xz", ShowModeParameterType.INTERPOLATE_XZ); }
showModeParameterTypesMap.put("-interpolate_xz", ShowModeParameterType.INTERPOLATE_XZ); if (showModeParameterTypeSet.contains(ShowModeParameterType.ADVANCED) && (showModeParameterType == ShowModeParameterType.INTERPOLATE_XZ || showModeParameterType == ShowModeParameterType.INTERPOLATE_Y)) {
showModeParameterTypesMap.put("-xz", ShowModeParameterType.INTERPOLATE_XZ); continue;
}
showModeParameterTypesMap.put("-advanced", ShowModeParameterType.ADVANCED); if (showModeParameterTypeSet.contains(showModeParameterType)) {
showModeParameterTypesMap.put("-a", ShowModeParameterType.ADVANCED); continue;
showModeParameterTypesMap.put("advanced", ShowModeParameterType.ADVANCED); }
showModeParameterTypesMap.put("a", ShowModeParameterType.ADVANCED); tabCompletes.addAll(showModeParameterTypeListMap.get(showModeParameterType));
}
showModeParameterTypesMap.put("-explode", ShowModeParameterType.EXPLODE); return tabCompletes;
showModeParameterTypesMap.put("-explodeonly", ShowModeParameterType.EXPLODE); }
};
List<String> tabCompletes = new ArrayList<>(showModeParameterTypesMap.keySet());
return SWCommandUtils.createMapper(s -> showModeParameterTypesMap.getOrDefault(s, null), s -> tabCompletes);
} }
@Register(help = true) @Register(help = true)