diff --git a/build.gradle b/build.gradle index 8824e57..85bb9d9 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/src/main/scala/io/izzel/taboolib/module/command/base/Argument.java b/src/main/scala/io/izzel/taboolib/module/command/base/Argument.java index dae6c7e..1537bd7 100644 --- a/src/main/scala/io/izzel/taboolib/module/command/base/Argument.java +++ b/src/main/scala/io/izzel/taboolib/module/command/base/Argument.java @@ -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); + } } diff --git a/src/main/scala/io/izzel/taboolib/module/command/base/SubCommand.java b/src/main/scala/io/izzel/taboolib/module/command/base/SubCommand.java index 1d08471..cace75a 100644 --- a/src/main/scala/io/izzel/taboolib/module/command/base/SubCommand.java +++ b/src/main/scala/io/izzel/taboolib/module/command/base/SubCommand.java @@ -14,5 +14,4 @@ import java.lang.annotation.Target; public @interface SubCommand { double priority() default 0; - } diff --git a/src/main/scala/io/izzel/taboolib/module/command/lite/CommandBuilder.java b/src/main/scala/io/izzel/taboolib/module/command/lite/CommandBuilder.java index 7192200..4bb4863 100644 --- a/src/main/scala/io/izzel/taboolib/module/command/lite/CommandBuilder.java +++ b/src/main/scala/io/izzel/taboolib/module/command/lite/CommandBuilder.java @@ -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; + } } diff --git a/src/main/scala/io/izzel/taboolib/module/inject/TInjectLoader.java b/src/main/scala/io/izzel/taboolib/module/inject/TInjectLoader.java index 02020a9..a1bf816 100644 --- a/src/main/scala/io/izzel/taboolib/module/inject/TInjectLoader.java +++ b/src/main/scala/io/izzel/taboolib/module/inject/TInjectLoader.java @@ -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); }