+ update commandbuilder

+ update argument
This commit is contained in:
坏黑 2019-09-11 17:01:39 +08:00
parent f6f42cd570
commit b0623575ab
5 changed files with 22 additions and 2 deletions

View File

@ -5,7 +5,7 @@ plugins {
id 'com.github.johnrengelman.shadow' version '4.0.4'
}
group = 'me.skymc'
version = '5.05'
version = '5.06'
sourceCompatibility = 1.8
targetCompatibility = 1.8

View File

@ -2,6 +2,7 @@ package io.izzel.taboolib.module.command.base;
import io.izzel.taboolib.module.locale.TLocale;
import java.util.Arrays;
import java.util.Objects;
/**
@ -70,4 +71,8 @@ public class Argument {
public int hashCode() {
return Objects.hash(getName(), isRequired(), tab);
}
public static Argument[] of(String expression) {
return Arrays.stream(expression.split("[,;]")).map(s -> s.endsWith("?") ? new Argument(s.substring(0, s.length() - 1), false) : new Argument(s)).toArray(Argument[]::new);
}
}

View File

@ -14,5 +14,4 @@ import java.lang.annotation.Target;
public @interface SubCommand {
double priority() default 0;
}

View File

@ -1,12 +1,15 @@
package io.izzel.taboolib.module.command.lite;
import com.google.common.base.Preconditions;
import io.izzel.taboolib.TabooLib;
import io.izzel.taboolib.module.command.TCommandHandler;
import io.izzel.taboolib.util.ArrayUtil;
import io.izzel.taboolib.util.Ref;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* @Author sky
@ -29,6 +32,7 @@ public class CommandBuilder {
private CompleterCommand completerCommand = EMPTY_COMPLETER_COMMAND;
private boolean forceRegister;
private boolean build;
private boolean simpleMode;
CommandBuilder(String command, Plugin plugin) {
this.command = command;
@ -39,6 +43,11 @@ public class CommandBuilder {
this.build = false;
}
public static CommandBuilder create() {
Class<?> callerClass = Ref.getCallerClass(3).orElse(null);
return new CommandBuilder(UUID.randomUUID().toString(), null).plugin(callerClass == null ? TabooLib.getPlugin() : Ref.getCallerPlugin(callerClass));
}
public static CommandBuilder create(String command, Plugin plugin) {
return new CommandBuilder(command.toLowerCase(), plugin);
}
@ -174,4 +183,8 @@ public class CommandBuilder {
public boolean isBuild() {
return build;
}
public boolean isSimpleMode() {
return simpleMode;
}
}

View File

@ -83,6 +83,9 @@ public class TInjectLoader implements TabooLibLoader.Loader {
try {
CommandBuilder builder = (CommandBuilder) field.get(instance);
if (!builder.isBuild()) {
if (builder.isSimpleMode()) {
builder.command(field.getName());
}
if (builder.getPlugin() == null) {
builder.plugin(plugin);
}