From 088cc62855ceef475337b14acdf06a5558348b5a Mon Sep 17 00:00:00 2001 From: carm Date: Sat, 11 Feb 2023 21:11:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(cmd):=20=E4=BF=AE=E5=A4=8DCommandHandler?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/command/pom.xml | 2 +- .../easyplugin/command/CommandHandler.java | 50 +++++++++++-------- base/conf/pom.xml | 2 +- base/database/pom.xml | 2 +- base/gui/pom.xml | 2 +- base/listener/pom.xml | 2 +- base/main/pom.xml | 2 +- base/storage/pom.xml | 2 +- base/utils/pom.xml | 2 +- collection/all/pom.xml | 2 +- collection/bom/pom.xml | 2 +- collection/common/pom.xml | 2 +- extension/gh-checker/pom.xml | 2 +- extension/papi/pom.xml | 2 +- extension/vault/pom.xml | 2 +- pom.xml | 2 +- 16 files changed, 43 insertions(+), 37 deletions(-) diff --git a/base/command/pom.xml b/base/command/pom.xml index 6af601c..2627d27 100644 --- a/base/command/pom.xml +++ b/base/command/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/base/command/src/main/java/cc/carm/lib/easyplugin/command/CommandHandler.java b/base/command/src/main/java/cc/carm/lib/easyplugin/command/CommandHandler.java index 8e4dd92..c4cc94b 100644 --- a/base/command/src/main/java/cc/carm/lib/easyplugin/command/CommandHandler.java +++ b/base/command/src/main/java/cc/carm/lib/easyplugin/command/CommandHandler.java @@ -74,36 +74,42 @@ public abstract class CommandHandler implements TabExecutor, NamedExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + if (!this.hasPermission(sender)) { + noPermission(sender); + return true; + } + if (args.length == 0) { this.noArgs(sender); - } else { - String input = args[0].toLowerCase(); + return true; + } - CommandHandler handler = getHandler(input); - if (handler != null) { - if (!handler.hasPermission(sender)) { - this.noPermission(sender); - } else { - handler.onCommand(sender, command, label, this.shortenArgs(args)); - } - } + String input = args[0].toLowerCase(); - SubCommand sub = getSubCommand(input); - if (sub == null) { - this.unknownCommand(sender, args); - } else if (!sub.hasPermission(sender)) { + CommandHandler handler = getHandler(input); + if (handler != null) { + if (!handler.hasPermission(sender)) { this.noPermission(sender); } else { - try { - sub.execute(this.plugin, sender, this.shortenArgs(args)); - } catch (ArrayIndexOutOfBoundsException ex) { - this.unknownCommand(sender, args); - } catch (Exception ex) { - this.onException(sender, sub, ex); - } + handler.onCommand(sender, command, label, this.shortenArgs(args)); } - + return true; } + + SubCommand sub = getSubCommand(input); + if (sub == null) { + this.unknownCommand(sender, args); + } else if (!sub.hasPermission(sender)) { + this.noPermission(sender); + } else { + try { + sub.execute(this.plugin, sender, this.shortenArgs(args)); + } catch (Exception ex) { + this.onException(sender, sub, ex); + ex.printStackTrace(); + } + } + return true; } diff --git a/base/conf/pom.xml b/base/conf/pom.xml index 7b42e40..2aff869 100644 --- a/base/conf/pom.xml +++ b/base/conf/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/base/database/pom.xml b/base/database/pom.xml index da19828..1f34b0a 100644 --- a/base/database/pom.xml +++ b/base/database/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/base/gui/pom.xml b/base/gui/pom.xml index f5798ae..3f54529 100644 --- a/base/gui/pom.xml +++ b/base/gui/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/base/listener/pom.xml b/base/listener/pom.xml index c5961b0..95b23b1 100644 --- a/base/listener/pom.xml +++ b/base/listener/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/base/main/pom.xml b/base/main/pom.xml index f3eae59..afd44f5 100644 --- a/base/main/pom.xml +++ b/base/main/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/base/storage/pom.xml b/base/storage/pom.xml index 4669e12..eb91941 100644 --- a/base/storage/pom.xml +++ b/base/storage/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/base/utils/pom.xml b/base/utils/pom.xml index 3706650..e127164 100644 --- a/base/utils/pom.xml +++ b/base/utils/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/collection/all/pom.xml b/collection/all/pom.xml index b36a071..67b020b 100644 --- a/collection/all/pom.xml +++ b/collection/all/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/collection/bom/pom.xml b/collection/bom/pom.xml index 5eb15d4..30e901f 100644 --- a/collection/bom/pom.xml +++ b/collection/bom/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/collection/common/pom.xml b/collection/common/pom.xml index bc2b935..03df911 100644 --- a/collection/common/pom.xml +++ b/collection/common/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/extension/gh-checker/pom.xml b/extension/gh-checker/pom.xml index d022bdb..80ceb98 100644 --- a/extension/gh-checker/pom.xml +++ b/extension/gh-checker/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/extension/papi/pom.xml b/extension/papi/pom.xml index 8a07476..5d41741 100644 --- a/extension/papi/pom.xml +++ b/extension/papi/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/extension/vault/pom.xml b/extension/vault/pom.xml index 359f3fe..b16cc43 100644 --- a/extension/vault/pom.xml +++ b/extension/vault/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.18 + 1.4.19 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 6bd2a28..6fc297a 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ cc.carm.lib easyplugin-parent pom - 1.4.18 + 1.4.19 base/utils