Add SWCommand multilingual
Dieser Commit ist enthalten in:
Ursprung
4d1b73dafc
Commit
8706146317
@ -26,10 +26,10 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.*;
|
||||||
import java.lang.reflect.Parameter;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.IntPredicate;
|
import java.util.function.IntPredicate;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -43,6 +43,8 @@ public abstract class SWCommand {
|
|||||||
private final List<SubCommand> commandHelpList = new ArrayList<>();
|
private final List<SubCommand> commandHelpList = new ArrayList<>();
|
||||||
private final Map<String, TypeMapper<?>> localTypeMapper = new HashMap<>();
|
private final Map<String, TypeMapper<?>> localTypeMapper = new HashMap<>();
|
||||||
|
|
||||||
|
private BiFunction<String, CommandSender, String> message = (s, commandSender) -> s;
|
||||||
|
|
||||||
protected SWCommand(String command) {
|
protected SWCommand(String command) {
|
||||||
this(command, new String[0]);
|
this(command, new String[0]);
|
||||||
}
|
}
|
||||||
@ -71,6 +73,8 @@ public abstract class SWCommand {
|
|||||||
unregister();
|
unregister();
|
||||||
register();
|
register();
|
||||||
|
|
||||||
|
messageSystem();
|
||||||
|
|
||||||
List<Method> methods = methods();
|
List<Method> methods = methods();
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
addMapper(Mapper.class, method, i -> i == 0, false, TypeMapper.class, (anno, typeMapper) -> {
|
addMapper(Mapper.class, method, i -> i == 0, false, TypeMapper.class, (anno, typeMapper) -> {
|
||||||
@ -141,6 +145,26 @@ public abstract class SWCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void messageSystem() {
|
||||||
|
try {
|
||||||
|
Field field = getClass().getDeclaredField("MESSAGE");
|
||||||
|
if (!field.getType().getTypeName().equals("de.steamwar.message.Message")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Object o = Modifier.isStatic(field.getModifiers()) ? field.get(null) : field.get(this);
|
||||||
|
Method method = o.getClass().getMethod("parse");
|
||||||
|
message = (s, commandSender) -> {
|
||||||
|
try {
|
||||||
|
return (String) method.invoke(o, s, commandSender);
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException e) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private <T extends Annotation> void add(Class<T> annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class<?> returnType, BiConsumer<T, Parameter[]> consumer) {
|
private <T extends Annotation> void add(Class<T> annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class<?> returnType, BiConsumer<T, Parameter[]> consumer) {
|
||||||
T[] anno = SWCommandUtils.getAnnotation(method, annotation);
|
T[] anno = SWCommandUtils.getAnnotation(method, annotation);
|
||||||
if (anno == null || anno.length == 0) return;
|
if (anno == null || anno.length == 0) return;
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren