Add CommandFramework (needs Message System for completion)? #1

Zusammengeführt
Lixfel hat 9 Commits von CommandFramework nach master 2022-05-01 22:42:55 +02:00 zusammengeführt
3 geänderte Dateien mit 12 neuen und 13 gelöschten Zeilen
Nur Änderungen aus Commit db254ed13b werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -1,6 +1,6 @@
package de.steamwar.command;
import java.util.List;
import java.util.Collection;
public interface AbstractTypeMapper<K, T> {
/**
@ -8,5 +8,5 @@ public interface AbstractTypeMapper<K, T> {
*/
T map(K sender, String[] previousArguments, String s);
List<String> tabCompletes(K sender, String[] previousArguments, String s);
Collection<String> tabCompletes(K sender, String[] previousArguments, String s);
}

Datei anzeigen

@ -5,6 +5,7 @@ import lombok.Setter;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
class CommandPart<T> {
@ -138,7 +139,7 @@ class CommandPart<T> {
return;
}
}
List<String> strings = typeMapper.tabCompletes(sender, Arrays.copyOf(args, args.length - 1), args[args.length - 1]);
Collection<String> strings = typeMapper.tabCompletes(sender, Arrays.copyOf(args, args.length - 1), args[args.length - 1]);
if (strings != null) {
current.addAll(strings);
}
@ -157,7 +158,7 @@ class CommandPart<T> {
return;
}
List<String> strings = typeMapper.tabCompletes(sender, Arrays.copyOf(args, startIndex), args[startIndex]);
Collection<String> strings = typeMapper.tabCompletes(sender, Arrays.copyOf(args, startIndex), args[startIndex]);
if (strings != null) {
current.addAll(strings);
}

Datei anzeigen

@ -9,7 +9,6 @@ import java.lang.reflect.Parameter;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
@UtilityClass
public class SWCommandUtils {
@ -198,20 +197,19 @@ public class SWCommandUtils {
}
public static AbstractTypeMapper<?, Enum<?>> createEnumMapper(Class<Enum<?>> enumClass) {
Enum<?>[] enums = enumClass.getEnumConstants();
List<String> strings = Arrays.stream(enums).map(Enum::name).map(String::toLowerCase).collect(Collectors.toList());
Map<String, Enum<?>> enumMap = new HashMap<>();
for (Enum<?> e : enumClass.getEnumConstants()) {
enumMap.put(e.name(), e);
}
return new AbstractTypeMapper<Object, Enum<?>>() {
@Override
public Enum<?> map(Object commandSender, String[] previousArguments, String s) {
for (Enum<?> e : enums) {
if (e.name().equalsIgnoreCase(s)) return e;
}
return null;
return enumMap.get(s);
}
@Override
public List<String> tabCompletes(Object commandSender, String[] previousArguments, String s) {
return strings;
public Collection<String> tabCompletes(Object commandSender, String[] previousArguments, String s) {
return enumMap.keySet();
}
};
}