From 3deaec2613ef0e367d4d0e4f288d60915130dc07 Mon Sep 17 00:00:00 2001 From: YufiriaMazenta <2199098065@qq.com> Date: Fri, 5 Jan 2024 16:50:34 +0800 Subject: [PATCH] =?UTF-8?q?[1.8.6-dev3]craft=20list=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E6=9D=83=E9=99=90=E7=BB=86=E5=8C=96,=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E5=8F=B0=E9=85=8D=E6=96=B9=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E7=9A=84=E9=9D=9E=E7=A9=BA=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../cmd/sub/AbstractSubCommand.java | 4 ++ .../cmd/sub/recipe/RecipeListCommand.java | 50 +++++++------------ .../menu/creator/CraftingRecipeCreator.java | 11 ++++ .../craftorithm/recipe/RecipeManager.java | 4 +- 5 files changed, 36 insertions(+), 35 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index fc81a5f5..f3c698a2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ import java.text.SimpleDateFormat -version = "1.8.6-dev2" +version = "1.8.6-dev3" plugins { `java-library` diff --git a/src/main/java/com/github/yufiriamazenta/craftorithm/cmd/sub/AbstractSubCommand.java b/src/main/java/com/github/yufiriamazenta/craftorithm/cmd/sub/AbstractSubCommand.java index edf55f23..b1042474 100644 --- a/src/main/java/com/github/yufiriamazenta/craftorithm/cmd/sub/AbstractSubCommand.java +++ b/src/main/java/com/github/yufiriamazenta/craftorithm/cmd/sub/AbstractSubCommand.java @@ -21,6 +21,10 @@ protected AbstractSubCommand(String command) { @Override public boolean onCommand(CommandSender sender, List args) { + if (args.isEmpty()) { + sendNotEnoughCmdParamMsg(sender, 1); + return true; + } SubcmdExecutor subCommand = subcommands().get(args.get(0)); if (subCommand == null) { LangUtil.sendLang(sender, Languages.COMMAND_UNDEFINED_SUBCMD); diff --git a/src/main/java/com/github/yufiriamazenta/craftorithm/cmd/sub/recipe/RecipeListCommand.java b/src/main/java/com/github/yufiriamazenta/craftorithm/cmd/sub/recipe/RecipeListCommand.java index ca4fda79..d3c9cabd 100644 --- a/src/main/java/com/github/yufiriamazenta/craftorithm/cmd/sub/recipe/RecipeListCommand.java +++ b/src/main/java/com/github/yufiriamazenta/craftorithm/cmd/sub/recipe/RecipeListCommand.java @@ -10,10 +10,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; +import java.util.*; + +import static crypticlib.command.CommandManager.subcommand; public final class RecipeListCommand extends AbstractSubCommand { @@ -22,42 +21,29 @@ public final class RecipeListCommand extends AbstractSubCommand { private RecipeListCommand() { super("list", "craftorithm.command.list"); + regSub(subcommand(SERVER) + .setPermission("craftorithm.command.list.server") + .setExecutor((sender, args) -> { + new RecipeListMenu((Player) sender, RecipeManager.INSTANCE.serverRecipesCache().keySet()).openMenu(); + return true; + })); + regSub(subcommand(CRAFTORITHM) + .setPermission("craftorithm.command.list.craftorithm") + .setExecutor((sender, arg) -> { + new RecipeGroupListMenu((Player) sender).openMenu(); + return true; + })); } @Override public boolean onCommand(CommandSender sender, List args) { - if (CrypticLib.minecraftVersion() < 11600) { - LangUtil.sendLang(sender, Languages.COMMAND_LIST_UNSUPPORTED_VERSION); - return true; - } if (!checkSenderIsPlayer(sender)) { return true; } - String listType; - if (args.isEmpty()) - listType = CRAFTORITHM; - else - listType = args.get(0).toLowerCase(Locale.ENGLISH); - Player player = (Player) sender; - switch (listType) { - case SERVER: - new RecipeListMenu(player, RecipeManager.INSTANCE.serverRecipesCache().keySet()).openMenu(); - break; - case CRAFTORITHM: - default: - new RecipeGroupListMenu(player).openMenu(); - break; + if (args.isEmpty()) { + args = new ArrayList<>(Collections.singletonList(CRAFTORITHM)); } - return true; + return super.onCommand(sender, args); } - @Override - public List onTabComplete(CommandSender sender, List args) { - if (args.size() <= 1) { - List list = new ArrayList<>(Arrays.asList(CRAFTORITHM, SERVER)); - filterTabList(list, args.get(0)); - return list; - } - return super.onTabComplete(sender, args); - } } diff --git a/src/main/java/com/github/yufiriamazenta/craftorithm/menu/creator/CraftingRecipeCreator.java b/src/main/java/com/github/yufiriamazenta/craftorithm/menu/creator/CraftingRecipeCreator.java index 3fe6a1ed..75ab158a 100644 --- a/src/main/java/com/github/yufiriamazenta/craftorithm/menu/creator/CraftingRecipeCreator.java +++ b/src/main/java/com/github/yufiriamazenta/craftorithm/menu/creator/CraftingRecipeCreator.java @@ -62,6 +62,17 @@ public CraftingRecipeCreator(@NotNull Player player, RecipeType recipeType, @Not String sourceName = ItemUtils.matchItemNameOrCreate(source, true); sourceList.add(sourceName); } + boolean allEmpty = true; + for (String choice : sourceList) { + if (!choice.isEmpty()) { + allEmpty = false; + break; + } + } + if (allEmpty) { + LangUtil.sendLang(event.getWhoClicked(), Languages.COMMAND_CREATE_NULL_SOURCE); + return; + } ConfigWrapper recipeConfig = createRecipeConfig(recipeName); switch (recipeType()) { case SHAPED: diff --git a/src/main/java/com/github/yufiriamazenta/craftorithm/recipe/RecipeManager.java b/src/main/java/com/github/yufiriamazenta/craftorithm/recipe/RecipeManager.java index adfbefb6..1c207080 100644 --- a/src/main/java/com/github/yufiriamazenta/craftorithm/recipe/RecipeManager.java +++ b/src/main/java/com/github/yufiriamazenta/craftorithm/recipe/RecipeManager.java @@ -115,7 +115,7 @@ public void reloadRecipeManager() { loadRecipeGroups(); loadRecipes(); reloadRemovedRecipes(); - reloadServerRecipeCache(); + loadServerRecipeCache(); } private void loadRecipes() { @@ -444,7 +444,7 @@ public void resetRecipes() { recipeUnlockMap.clear(); } - public void reloadServerRecipeCache() { + public void loadServerRecipeCache() { Iterator recipeIterator = Bukkit.recipeIterator(); serverRecipesCache.clear(); while (recipeIterator.hasNext()) {