From fbf118436e7d5530b970f8cc53813432680cfc3b Mon Sep 17 00:00:00 2001 From: carm Date: Sun, 26 Jun 2022 10:34:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(command):=20=E6=8C=87=E4=BB=A4=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=96=B0=E5=A2=9E=E5=9F=BA=E7=A1=80=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/command/pom.xml | 2 +- .../easyplugin/command/CommandHandler.java | 4 ++- .../easyplugin/command/SimpleCompleter.java | 28 ++++++++++++++++--- base/gui/pom.xml | 2 +- base/main/pom.xml | 2 +- base/storage/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 +- 13 files changed, 38 insertions(+), 16 deletions(-) diff --git a/base/command/pom.xml b/base/command/pom.xml index c9e5884..9a40a5f 100644 --- a/base/command/pom.xml +++ b/base/command/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.8 + 1.4.9 ../../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 e7d1891..4cc53e5 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 @@ -38,7 +38,9 @@ public abstract class CommandHandler implements TabExecutor, NamedExecutor { public abstract void noArgs(CommandSender sender); - public abstract void unknownCommand(CommandSender sender, String[] args); + public void unknownCommand(CommandSender sender, String[] args) { + noArgs(sender); + } public abstract void noPermission(CommandSender sender); diff --git a/base/command/src/main/java/cc/carm/lib/easyplugin/command/SimpleCompleter.java b/base/command/src/main/java/cc/carm/lib/easyplugin/command/SimpleCompleter.java index cc418f3..d0cb6f7 100644 --- a/base/command/src/main/java/cc/carm/lib/easyplugin/command/SimpleCompleter.java +++ b/base/command/src/main/java/cc/carm/lib/easyplugin/command/SimpleCompleter.java @@ -1,15 +1,18 @@ package cc.carm.lib.easyplugin.command; +import com.google.common.collect.ImmutableList; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.World; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.HumanEntity; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -17,14 +20,22 @@ import java.util.stream.Stream; public class SimpleCompleter { - public static @NotNull List objects(@NotNull String input, List objects) { + public static @NotNull List none() { + return ImmutableList.of(); + } + + public static @NotNull List objects(@NotNull String input, Collection objects) { return objects(input, objects.size(), objects); } - public static @NotNull List objects(@NotNull String input, int limit, List objects) { + public static @NotNull List objects(@NotNull String input, int limit, Collection objects) { return objects(input, limit, objects.stream()); } + public static @NotNull List objects(@NotNull String input, Stream stream) { + return objects(input, 20, stream); + } + public static @NotNull List objects(@NotNull String input, int limit, Stream stream) { return stream.filter(Objects::nonNull).map(Object::toString) .filter(s -> StringUtil.startsWithIgnoreCase(s, input)) @@ -39,11 +50,11 @@ public class SimpleCompleter { return text(input, limit, Arrays.asList(texts)); } - public static @NotNull List text(@NotNull String input, List texts) { + public static @NotNull List text(@NotNull String input, Collection texts) { return text(input, texts.size(), texts); } - public static @NotNull List text(@NotNull String input, int limit, List texts) { + public static @NotNull List text(@NotNull String input, int limit, Collection texts) { return objects(input, limit, texts); } @@ -87,4 +98,13 @@ public class SimpleCompleter { return objects(input, limit, Arrays.stream(PotionEffectType.values()).map(PotionEffectType::getName)); } + public static @NotNull List enchantments(@NotNull String input) { + return effects(input, 10); + } + + @SuppressWarnings("deprecation") + public static @NotNull List enchantments(@NotNull String input, int limit) { + return objects(input, limit, Arrays.stream(Enchantment.values()).map(Enchantment::getName)); + } + } diff --git a/base/gui/pom.xml b/base/gui/pom.xml index e050da1..a54e28e 100644 --- a/base/gui/pom.xml +++ b/base/gui/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.8 + 1.4.9 ../../pom.xml 4.0.0 diff --git a/base/main/pom.xml b/base/main/pom.xml index 8e7960c..558ef0c 100644 --- a/base/main/pom.xml +++ b/base/main/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.8 + 1.4.9 ../../pom.xml 4.0.0 diff --git a/base/storage/pom.xml b/base/storage/pom.xml index 3f34791..a2bd13f 100644 --- a/base/storage/pom.xml +++ b/base/storage/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.8 + 1.4.9 ../../pom.xml 4.0.0 diff --git a/collection/all/pom.xml b/collection/all/pom.xml index 51e3168..dad97ea 100644 --- a/collection/all/pom.xml +++ b/collection/all/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.8 + 1.4.9 ../../pom.xml 4.0.0 diff --git a/collection/bom/pom.xml b/collection/bom/pom.xml index 13514e6..7c879c4 100644 --- a/collection/bom/pom.xml +++ b/collection/bom/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.8 + 1.4.9 ../../pom.xml 4.0.0 diff --git a/collection/common/pom.xml b/collection/common/pom.xml index 3f59430..686c895 100644 --- a/collection/common/pom.xml +++ b/collection/common/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.8 + 1.4.9 ../../pom.xml 4.0.0 diff --git a/extension/gh-checker/pom.xml b/extension/gh-checker/pom.xml index 4f975b5..835f691 100644 --- a/extension/gh-checker/pom.xml +++ b/extension/gh-checker/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.8 + 1.4.9 ../../pom.xml 4.0.0 diff --git a/extension/papi/pom.xml b/extension/papi/pom.xml index d71fe58..089a0e0 100644 --- a/extension/papi/pom.xml +++ b/extension/papi/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.8 + 1.4.9 ../../pom.xml 4.0.0 diff --git a/extension/vault/pom.xml b/extension/vault/pom.xml index f4b2050..2a8a958 100644 --- a/extension/vault/pom.xml +++ b/extension/vault/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.4.8 + 1.4.9 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index c35de5b..83c0214 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ cc.carm.lib easyplugin-parent pom - 1.4.8 + 1.4.9 base/main