From 20d032682805eab6951dfda1368cf5d0f5cb1080 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Sun, 16 Mar 2025 18:53:37 +0800 Subject: [PATCH 01/10] =?UTF-8?q?feat(core):=20=E6=B7=BB=E5=8A=A0=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E7=89=A9=E5=93=81=E9=85=8D=E6=96=B9=E5=92=8C=E7=94=A8?= =?UTF-8?q?=E6=B3=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bukkit-loader/src/main/resources/commands.yml | 14 +++++ .../src/main/resources/translations/en.yml | 3 +- .../src/main/resources/translations/es.yml | 1 + .../src/main/resources/translations/zh_cn.yml | 1 + .../src/main/resources/translations/zh_tw.yml | 1 + .../plugin/command/BukkitCommandManager.java | 2 + .../feature/ItemRecipeBrowserCommand.java | 58 ++++++++++++++++++ .../feature/ItemUsageBrowserCommand.java | 59 +++++++++++++++++++ .../plugin/user/BukkitServerPlayer.java | 5 ++ .../core/entity/player/Player.java | 2 + .../gui/category/ItemBrowserManager.java | 6 ++ .../gui/category/ItemBrowserManagerImpl.java | 34 +++++++++-- .../core/plugin/locale/MessageConstants.java | 1 + gradle.properties | 4 +- 14 files changed, 182 insertions(+), 9 deletions(-) create mode 100644 bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserCommand.java create mode 100644 bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemUsageBrowserCommand.java diff --git a/bukkit-loader/src/main/resources/commands.yml b/bukkit-loader/src/main/resources/commands.yml index 02e9b64c1..fb536fccc 100644 --- a/bukkit-loader/src/main/resources/commands.yml +++ b/bukkit-loader/src/main/resources/commands.yml @@ -38,6 +38,20 @@ item_browser: - /ce item browser - /ce +item_recipe_browser: + enable: true + permission: ce.command.item_recipe_browser + usage: + - /craftengine item recipe + - /ce item recipe + +item_usage_browser: + enable: true + permission: ce.command.item_usage_browser + usage: + - /craftengine item usage + - /ce item usage + # Debug commands debug_set_block: enable: true diff --git a/bukkit-loader/src/main/resources/translations/en.yml b/bukkit-loader/src/main/resources/translations/en.yml index a0e77f1fa..ba6ea921f 100644 --- a/bukkit-loader/src/main/resources/translations/en.yml +++ b/bukkit-loader/src/main/resources/translations/en.yml @@ -48,4 +48,5 @@ command.item.get.success: "Got " command.item.get.failure.not_exist: "'>" command.item.give.success.single: "':'':''>" command.item.give.success.multiple: "':'':''>" -command.item.give.failure.not_exist: "'>" \ No newline at end of file +command.item.give.failure.not_exist: "'>" +command.item.usage.browser.recipe.no_found: "No usage found for this item" \ No newline at end of file diff --git a/bukkit-loader/src/main/resources/translations/es.yml b/bukkit-loader/src/main/resources/translations/es.yml index 4517db462..7c4d9cbe3 100644 --- a/bukkit-loader/src/main/resources/translations/es.yml +++ b/bukkit-loader/src/main/resources/translations/es.yml @@ -49,3 +49,4 @@ command.item.get.failure.not_exist: "':'':''>" command.item.give.success.multiple: "':'':''>" command.item.give.failure.not_exist: "'>" +command.item.usage.browser.recipe.no_found: "No usage found for this item" \ No newline at end of file diff --git a/bukkit-loader/src/main/resources/translations/zh_cn.yml b/bukkit-loader/src/main/resources/translations/zh_cn.yml index 1375301c7..5af0fef1b 100644 --- a/bukkit-loader/src/main/resources/translations/zh_cn.yml +++ b/bukkit-loader/src/main/resources/translations/zh_cn.yml @@ -49,3 +49,4 @@ command.item.get.failure.not_exist: "':'':''>" command.item.give.success.multiple: "':'':''>" command.item.give.failure.not_exist: "'>" +command.item.usage.browser.recipe.no_found: "找不到此物品的用法" \ No newline at end of file diff --git a/bukkit-loader/src/main/resources/translations/zh_tw.yml b/bukkit-loader/src/main/resources/translations/zh_tw.yml index d38e5b80c..26f5aec3b 100644 --- a/bukkit-loader/src/main/resources/translations/zh_tw.yml +++ b/bukkit-loader/src/main/resources/translations/zh_tw.yml @@ -49,3 +49,4 @@ command.item.get.failure.not_exist: "':'':''>" command.item.give.success.multiple: "':'':''>" command.item.give.failure.not_exist: "'>" +command.item.usage.browser.recipe.no_found: "找不到此物品的用法" \ No newline at end of file diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java index 9553c3c45..54d5523cd 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java @@ -32,6 +32,8 @@ public class BukkitCommandManager extends AbstractCommandManager new GetItemCommand(this, plugin), new GiveItemCommand(this, plugin), new ItemBrowserCommand(this, plugin), + new ItemRecipeBrowserCommand(this, plugin), + new ItemUsageBrowserCommand(this, plugin), new TestCommand(this, plugin), new DebugGetBlockStateRegistryIdCommand(this, plugin), new DebugGetBlockInternalIdCommand(this, plugin), diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserCommand.java new file mode 100644 index 000000000..3389898fe --- /dev/null +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserCommand.java @@ -0,0 +1,58 @@ +package net.momirealms.craftengine.bukkit.plugin.command.feature; + +import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature; +import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer; +import net.momirealms.craftengine.core.item.recipe.Recipe; +import net.momirealms.craftengine.core.plugin.CraftEngine; +import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; +import net.momirealms.craftengine.core.util.Key; +import org.bukkit.NamespacedKey; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.incendo.cloud.Command; +import org.incendo.cloud.CommandManager; +import org.incendo.cloud.bukkit.parser.NamespacedKeyParser; +import org.incendo.cloud.context.CommandContext; +import org.incendo.cloud.context.CommandInput; +import org.incendo.cloud.suggestion.Suggestion; +import org.incendo.cloud.suggestion.SuggestionProvider; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class ItemRecipeBrowserCommand extends BukkitCommandFeature { + + public ItemRecipeBrowserCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { + super(commandManager, plugin); + } + + @Override + public Command.Builder assembleCommand(CommandManager manager, Command.Builder builder) { + return builder + .senderType(Player.class) + .required("id", NamespacedKeyParser.namespacedKeyComponent().suggestionProvider(new SuggestionProvider<>() { + @Override + public @NonNull CompletableFuture> suggestionsFuture(@NonNull CommandContext context, @NonNull CommandInput input) { + return CompletableFuture.completedFuture(plugin().itemManager().cachedSuggestions()); + } + })) + .handler(context -> { + Player player = context.sender(); + BukkitServerPlayer serverPlayer = plugin().adapt(player); + NamespacedKey namespacedKey = context.get("id"); + Key itemId = Key.of(namespacedKey.namespace(), namespacedKey.value()); + List> inRecipes = plugin().recipeManager().getRecipeByResult(itemId); + if (!inRecipes.isEmpty()) { + plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0); + } else { + plugin().itemBrowserManager().openNoRecipePage(serverPlayer, itemId, null, 0); + } + }); + } + + @Override + public String getFeatureID() { + return "item_recipe_browser"; + } +} diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemUsageBrowserCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemUsageBrowserCommand.java new file mode 100644 index 000000000..d479f18c9 --- /dev/null +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemUsageBrowserCommand.java @@ -0,0 +1,59 @@ +package net.momirealms.craftengine.bukkit.plugin.command.feature; + +import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature; +import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer; +import net.momirealms.craftengine.core.item.recipe.Recipe; +import net.momirealms.craftengine.core.plugin.CraftEngine; +import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; +import net.momirealms.craftengine.core.plugin.locale.MessageConstants; +import net.momirealms.craftengine.core.util.Key; +import org.bukkit.NamespacedKey; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.incendo.cloud.Command; +import org.incendo.cloud.CommandManager; +import org.incendo.cloud.bukkit.parser.NamespacedKeyParser; +import org.incendo.cloud.context.CommandContext; +import org.incendo.cloud.context.CommandInput; +import org.incendo.cloud.suggestion.Suggestion; +import org.incendo.cloud.suggestion.SuggestionProvider; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class ItemUsageBrowserCommand extends BukkitCommandFeature { + + public ItemUsageBrowserCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { + super(commandManager, plugin); + } + + @Override + public Command.Builder assembleCommand(CommandManager manager, Command.Builder builder) { + return builder + .senderType(Player.class) + .required("id", NamespacedKeyParser.namespacedKeyComponent().suggestionProvider(new SuggestionProvider<>() { + @Override + public @NonNull CompletableFuture> suggestionsFuture(@NonNull CommandContext context, @NonNull CommandInput input) { + return CompletableFuture.completedFuture(plugin().itemManager().cachedSuggestions()); + } + })) + .handler(context -> { + Player player = context.sender(); + BukkitServerPlayer serverPlayer = plugin().adapt(player); + NamespacedKey namespacedKey = context.get("id"); + Key itemId = Key.of(namespacedKey.namespace(), namespacedKey.value()); + List> inRecipes = plugin().recipeManager().getRecipeByIngredient(itemId); + if (!inRecipes.isEmpty()) { + plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0); + } else { + handleFeedback(context, MessageConstants.COMMAND_ITEM_USAGE_BROWSER_RECIPE_NO_FOUND); + } + }); + } + + @Override + public String getFeatureID() { + return "item_usage_browser"; + } +} diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java index 89cd4b05d..d6cc5e3bf 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java @@ -196,6 +196,11 @@ public class BukkitServerPlayer extends Player { PlayerUtils.giveItem(platformPlayer(), (ItemStack) item.getItem(), item.count()); } + @Override + public void closeInventory() { + platformPlayer().closeInventory(); + } + @Override public void sendPacket(Object packet, boolean immediately) { this.plugin.networkManager().sendPacket(this, packet, immediately); diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java b/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java index 3f236352e..67cf0d33f 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java @@ -66,4 +66,6 @@ public abstract class Player extends Entity implements NetWorkUser { public abstract void playSound(Key sound, float volume, float pitch); public abstract void giveItem(Item item); + + public abstract void closeInventory(); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManager.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManager.java index fa7667d4d..9630e5f03 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManager.java @@ -2,10 +2,12 @@ package net.momirealms.craftengine.core.plugin.gui.category; import dev.dejvokep.boostedyaml.block.implementation.Section; import net.momirealms.craftengine.core.entity.player.Player; +import net.momirealms.craftengine.core.item.recipe.Recipe; import net.momirealms.craftengine.core.pack.LoadingSequence; import net.momirealms.craftengine.core.plugin.Reloadable; import net.momirealms.craftengine.core.plugin.config.ConfigManager; import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser; +import net.momirealms.craftengine.core.plugin.gui.Gui; import net.momirealms.craftengine.core.util.Key; import java.util.List; @@ -33,6 +35,10 @@ public interface ItemBrowserManager extends Reloadable, ConfigSectionParser { void open(Player player); + void openRecipePage(Player player, Gui parentGui, List> recipes, int index, int depth); + + void openNoRecipePage(Player player, Key result, Gui parentGui, int depth); + TreeSet categories(); Optional byId(Key key); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java index 5cbbbd786..379706da0 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java @@ -7,8 +7,8 @@ import net.momirealms.craftengine.core.item.ItemKeys; import net.momirealms.craftengine.core.item.recipe.*; import net.momirealms.craftengine.core.pack.Pack; import net.momirealms.craftengine.core.plugin.CraftEngine; -import net.momirealms.craftengine.core.plugin.gui.Ingredient; import net.momirealms.craftengine.core.plugin.gui.*; +import net.momirealms.craftengine.core.plugin.gui.Ingredient; import net.momirealms.craftengine.core.registry.Holder; import net.momirealms.craftengine.core.util.AdventureHelper; import net.momirealms.craftengine.core.util.Key; @@ -175,7 +175,11 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { ((element, click) -> { click.cancel(); player.playSound(Constants.SOUND_RETURN_PAGE, 0.25f, 1); - parentGui.open(player); + if (parentGui != null) { + parentGui.open(player); + } else { + player.closeInventory(); + } })) ) .addIngredient('>', GuiElement.paged((element) -> { @@ -270,6 +274,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { .open(player); } + @Override public void openNoRecipePage(Player player, Key result, Gui parentGui, int depth) { GuiLayout layout = new GuiLayout( " ", @@ -309,7 +314,11 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { ((element, click) -> { click.cancel(); player.playSound(Constants.SOUND_RETURN_PAGE, 0.25f, 1); - parentGui.open(player); + if (parentGui != null) { + parentGui.open(player); + } else { + player.closeInventory(); + } })) ); @@ -326,6 +335,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { .open(player); } + @Override public void openRecipePage(Player player, Gui parentGui, List> recipes, int index, int depth) { if (index >= recipes.size()) return; if (depth > MAX_RECIPE_DEPTH) return; @@ -431,7 +441,11 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { ((element, click) -> { click.cancel(); player.playSound(Constants.SOUND_RETURN_PAGE, 0.25f, 1); - parentGui.open(player); + if (parentGui != null) { + parentGui.open(player); + } else { + player.closeInventory(); + } })) ) .addIngredient('>', GuiElement.constant(this.plugin.itemManager() @@ -566,7 +580,11 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { ((element, click) -> { click.cancel(); player.playSound(Constants.SOUND_RETURN_PAGE, 0.25f, 1); - parentGui.open(player); + if (parentGui != null) { + parentGui.open(player); + } else { + player.closeInventory(); + } })) ) .addIngredient('>', GuiElement.constant(this.plugin.itemManager() @@ -675,7 +693,11 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { ((element, click) -> { click.cancel(); player.playSound(Constants.SOUND_RETURN_PAGE, 0.25f, 1); - parentGui.open(player); + if (parentGui != null) { + parentGui.open(player); + } else { + player.closeInventory(); + } })) ) .addIngredient('>', GuiElement.constant(this.plugin.itemManager() diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/MessageConstants.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/MessageConstants.java index 3d322fab1..d06a27150 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/MessageConstants.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/MessageConstants.java @@ -16,4 +16,5 @@ public interface MessageConstants { TranslatableComponent.Builder COMMAND_ITEM_GIVE_SUCCESS_SINGLE = Component.translatable().key("command.item.give.success.single"); TranslatableComponent.Builder COMMAND_ITEM_GIVE_SUCCESS_MULTIPLE = Component.translatable().key("command.item.give.success.multiple"); TranslatableComponent.Builder COMMAND_ITEM_GIVE_FAILURE_NOT_EXIST = Component.translatable().key("command.item.give.failure.not_exist"); + TranslatableComponent.Builder COMMAND_ITEM_USAGE_BROWSER_RECIPE_NO_FOUND = Component.translatable().key("command.item.usage.browser.recipe.no_found"); } diff --git a/gradle.properties b/gradle.properties index 269c7bc63..e25398ede 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,8 @@ # Project settings # Rule: [major update].[feature update].[bug fix] project_version=0.0.33 -config_version=13 -lang_version=2 +config_version=14 +lang_version=3 project_group=net.momirealms latest_minecraft_version=1.21.4 From 7f77bf16ff3e442f423c4904b15636c3162f8171 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Sun, 16 Mar 2025 18:58:54 +0800 Subject: [PATCH 02/10] =?UTF-8?q?feat(core):=20=E6=B7=BB=E5=8A=A0=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E7=89=A9=E5=93=81=E9=85=8D=E6=96=B9=E5=92=8C=E7=94=A8?= =?UTF-8?q?=E6=B3=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bukkit-loader/src/main/resources/translations/en.yml | 1 + bukkit-loader/src/main/resources/translations/es.yml | 1 + bukkit-loader/src/main/resources/translations/zh_cn.yml | 1 + bukkit-loader/src/main/resources/translations/zh_tw.yml | 1 + .../plugin/command/feature/ItemRecipeBrowserCommand.java | 3 ++- .../craftengine/core/plugin/locale/MessageConstants.java | 1 + 6 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bukkit-loader/src/main/resources/translations/en.yml b/bukkit-loader/src/main/resources/translations/en.yml index ba6ea921f..6961f5aed 100644 --- a/bukkit-loader/src/main/resources/translations/en.yml +++ b/bukkit-loader/src/main/resources/translations/en.yml @@ -49,4 +49,5 @@ command.item.get.failure.not_exist: "':'':''>" command.item.give.success.multiple: "':'':''>" command.item.give.failure.not_exist: "'>" +command.item.recipe.browser.recipe.no_found: "No recipe found for this item" command.item.usage.browser.recipe.no_found: "No usage found for this item" \ No newline at end of file diff --git a/bukkit-loader/src/main/resources/translations/es.yml b/bukkit-loader/src/main/resources/translations/es.yml index 7c4d9cbe3..9897a5ae1 100644 --- a/bukkit-loader/src/main/resources/translations/es.yml +++ b/bukkit-loader/src/main/resources/translations/es.yml @@ -49,4 +49,5 @@ command.item.get.failure.not_exist: "':'':''>" command.item.give.success.multiple: "':'':''>" command.item.give.failure.not_exist: "'>" +command.item.recipe.browser.recipe.no_found: "No recipe found for this item" command.item.usage.browser.recipe.no_found: "No usage found for this item" \ No newline at end of file diff --git a/bukkit-loader/src/main/resources/translations/zh_cn.yml b/bukkit-loader/src/main/resources/translations/zh_cn.yml index 5af0fef1b..020a922e3 100644 --- a/bukkit-loader/src/main/resources/translations/zh_cn.yml +++ b/bukkit-loader/src/main/resources/translations/zh_cn.yml @@ -49,4 +49,5 @@ command.item.get.failure.not_exist: "':'':''>" command.item.give.success.multiple: "':'':''>" command.item.give.failure.not_exist: "'>" +command.item.recipe.browser.recipe.no_found: "找不到此物品的配方" command.item.usage.browser.recipe.no_found: "找不到此物品的用法" \ No newline at end of file diff --git a/bukkit-loader/src/main/resources/translations/zh_tw.yml b/bukkit-loader/src/main/resources/translations/zh_tw.yml index 26f5aec3b..ac1506a69 100644 --- a/bukkit-loader/src/main/resources/translations/zh_tw.yml +++ b/bukkit-loader/src/main/resources/translations/zh_tw.yml @@ -49,4 +49,5 @@ command.item.get.failure.not_exist: "':'':''>" command.item.give.success.multiple: "':'':''>" command.item.give.failure.not_exist: "'>" +command.item.recipe.browser.recipe.no_found: "找不到此物品的配方" command.item.usage.browser.recipe.no_found: "找不到此物品的用法" \ No newline at end of file diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserCommand.java index 3389898fe..d0dbd2a38 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserCommand.java @@ -5,6 +5,7 @@ import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer; import net.momirealms.craftengine.core.item.recipe.Recipe; import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; +import net.momirealms.craftengine.core.plugin.locale.MessageConstants; import net.momirealms.craftengine.core.util.Key; import org.bukkit.NamespacedKey; import org.bukkit.command.CommandSender; @@ -46,7 +47,7 @@ public class ItemRecipeBrowserCommand extends BukkitCommandFeature Date: Sun, 16 Mar 2025 19:01:02 +0800 Subject: [PATCH 03/10] =?UTF-8?q?feat(core):=20=E6=B7=BB=E5=8A=A0=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E7=89=A9=E5=93=81=E9=85=8D=E6=96=B9=E5=92=8C=E7=94=A8?= =?UTF-8?q?=E6=B3=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bukkit-loader/src/main/resources/commands.yml | 8 ++++---- bukkit-loader/src/main/resources/translations/es.yml | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/bukkit-loader/src/main/resources/commands.yml b/bukkit-loader/src/main/resources/commands.yml index fb536fccc..9b8d9648d 100644 --- a/bukkit-loader/src/main/resources/commands.yml +++ b/bukkit-loader/src/main/resources/commands.yml @@ -42,15 +42,15 @@ item_recipe_browser: enable: true permission: ce.command.item_recipe_browser usage: - - /craftengine item recipe - - /ce item recipe + - /craftengine recipe by-result + - /ce recipe by-result item_usage_browser: enable: true permission: ce.command.item_usage_browser usage: - - /craftengine item usage - - /ce item usage + - /craftengine recipe by-ingredient + - /ce recipe by-ingredient # Debug commands debug_set_block: diff --git a/bukkit-loader/src/main/resources/translations/es.yml b/bukkit-loader/src/main/resources/translations/es.yml index 9897a5ae1..272c2b804 100644 --- a/bukkit-loader/src/main/resources/translations/es.yml +++ b/bukkit-loader/src/main/resources/translations/es.yml @@ -48,6 +48,4 @@ command.item.get.success: "Obtener " command.item.get.failure.not_exist: "'>" command.item.give.success.single: "':'':''>" command.item.give.success.multiple: "':'':''>" -command.item.give.failure.not_exist: "'>" -command.item.recipe.browser.recipe.no_found: "No recipe found for this item" -command.item.usage.browser.recipe.no_found: "No usage found for this item" \ No newline at end of file +command.item.give.failure.not_exist: "'>" \ No newline at end of file From 2053ce5fb761bdc70d9d14ebd2dee2fa6404d561 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Sun, 16 Mar 2025 19:08:02 +0800 Subject: [PATCH 04/10] =?UTF-8?q?feat(core):=20=E6=B7=BB=E5=8A=A0=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E7=89=A9=E5=93=81=E9=85=8D=E6=96=B9=E5=92=8C=E7=94=A8?= =?UTF-8?q?=E6=B3=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/command/feature/ItemRecipeBrowserCommand.java | 4 ++++ .../momirealms/craftengine/core/plugin/command/FlagKeys.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserCommand.java index d0dbd2a38..eca22e414 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserCommand.java @@ -5,6 +5,7 @@ import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer; import net.momirealms.craftengine.core.item.recipe.Recipe; import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; +import net.momirealms.craftengine.core.plugin.command.FlagKeys; import net.momirealms.craftengine.core.plugin.locale.MessageConstants; import net.momirealms.craftengine.core.util.Key; import org.bukkit.NamespacedKey; @@ -32,6 +33,7 @@ public class ItemRecipeBrowserCommand extends BukkitCommandFeature assembleCommand(CommandManager manager, Command.Builder builder) { return builder .senderType(Player.class) + .flag(FlagKeys.BROWSE_FLAG) .required("id", NamespacedKeyParser.namespacedKeyComponent().suggestionProvider(new SuggestionProvider<>() { @Override public @NonNull CompletableFuture> suggestionsFuture(@NonNull CommandContext context, @NonNull CommandInput input) { @@ -46,6 +48,8 @@ public class ItemRecipeBrowserCommand extends BukkitCommandFeature> inRecipes = plugin().recipeManager().getRecipeByResult(itemId); if (!inRecipes.isEmpty()) { plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0); + } else if (context.flags().hasFlag(FlagKeys.BROWSE)) { + plugin().itemBrowserManager().openNoRecipePage(serverPlayer, itemId, null, 0); } else { handleFeedback(context, MessageConstants.COMMAND_ITEM_RECIPE_BROWSER_RECIPE_NO_FOUND); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/command/FlagKeys.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/command/FlagKeys.java index 5cde8bd5c..6f55a828a 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/command/FlagKeys.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/command/FlagKeys.java @@ -7,4 +7,6 @@ public final class FlagKeys { public static final CommandFlag SILENT_FLAG = CommandFlag.builder("silent").withAliases("s").build(); public static final String TO_INVENTORY = "to-inventory"; public static final CommandFlag TO_INVENTORY_FLAG = CommandFlag.builder("to-inventory").build(); + public static final String BROWSE = "browse"; + public static final CommandFlag BROWSE_FLAG = CommandFlag.builder("browse").withAliases("b").build(); } From 9716bdb7ff83ace2961be06e73a54fa7a1143ce2 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Sun, 16 Mar 2025 19:25:05 +0800 Subject: [PATCH 05/10] =?UTF-8?q?feat(core):=20=E5=AE=9E=E7=8E=B0=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bukkit-loader/src/main/resources/commands.yml | 16 ++++- .../plugin/command/BukkitCommandManager.java | 2 + .../SelectorItemRecipeBrowserCommand.java | 69 +++++++++++++++++++ .../SelectorItemUsageBrowserCommand.java | 65 +++++++++++++++++ 4 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SelectorItemRecipeBrowserCommand.java create mode 100644 bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SelectorItemUsageBrowserCommand.java diff --git a/bukkit-loader/src/main/resources/commands.yml b/bukkit-loader/src/main/resources/commands.yml index 9b8d9648d..9756178c1 100644 --- a/bukkit-loader/src/main/resources/commands.yml +++ b/bukkit-loader/src/main/resources/commands.yml @@ -42,12 +42,24 @@ item_recipe_browser: enable: true permission: ce.command.item_recipe_browser usage: - - /craftengine recipe by-result - - /ce recipe by-result + - /findrecipe by-result item_usage_browser: enable: true permission: ce.command.item_usage_browser + usage: + - /findrecipe by-ingredient + +selector_item_recipe_browser: + enable: true + permission: ce.command.selector_item_recipe_browser + usage: + - /craftengine recipe by-result + - /ce recipe by-result + +selector_item_usage_browser: + enable: true + permission: ce.command.selector_item_usage_browser usage: - /craftengine recipe by-ingredient - /ce recipe by-ingredient diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java index 54d5523cd..f986ceee0 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java @@ -34,6 +34,8 @@ public class BukkitCommandManager extends AbstractCommandManager new ItemBrowserCommand(this, plugin), new ItemRecipeBrowserCommand(this, plugin), new ItemUsageBrowserCommand(this, plugin), + new SelectorItemRecipeBrowserCommand(this, plugin), + new SelectorItemUsageBrowserCommand(this, plugin), new TestCommand(this, plugin), new DebugGetBlockStateRegistryIdCommand(this, plugin), new DebugGetBlockInternalIdCommand(this, plugin), diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SelectorItemRecipeBrowserCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SelectorItemRecipeBrowserCommand.java new file mode 100644 index 000000000..0a9786ddc --- /dev/null +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SelectorItemRecipeBrowserCommand.java @@ -0,0 +1,69 @@ +package net.momirealms.craftengine.bukkit.plugin.command.feature; + +import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature; +import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer; +import net.momirealms.craftengine.core.item.recipe.Recipe; +import net.momirealms.craftengine.core.plugin.CraftEngine; +import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; +import net.momirealms.craftengine.core.plugin.command.FlagKeys; +import net.momirealms.craftengine.core.plugin.locale.MessageConstants; +import net.momirealms.craftengine.core.util.Key; +import org.bukkit.NamespacedKey; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.incendo.cloud.Command; +import org.incendo.cloud.CommandManager; +import org.incendo.cloud.bukkit.data.MultiplePlayerSelector; +import org.incendo.cloud.bukkit.parser.NamespacedKeyParser; +import org.incendo.cloud.bukkit.parser.selector.MultiplePlayerSelectorParser; +import org.incendo.cloud.context.CommandContext; +import org.incendo.cloud.context.CommandInput; +import org.incendo.cloud.suggestion.Suggestion; +import org.incendo.cloud.suggestion.SuggestionProvider; + +import java.util.Collection; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class SelectorItemRecipeBrowserCommand extends BukkitCommandFeature { + + public SelectorItemRecipeBrowserCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { + super(commandManager, plugin); + } + + @Override + public Command.Builder assembleCommand(CommandManager manager, Command.Builder builder) { + return builder + .flag(FlagKeys.BROWSE_FLAG) + .required("player", MultiplePlayerSelectorParser.multiplePlayerSelectorParser(true)) + .required("id", NamespacedKeyParser.namespacedKeyComponent().suggestionProvider(new SuggestionProvider<>() { + @Override + public @NonNull CompletableFuture> suggestionsFuture(@NonNull CommandContext context, @NonNull CommandInput input) { + return CompletableFuture.completedFuture(plugin().itemManager().cachedSuggestions()); + } + })) + .handler(context -> { + MultiplePlayerSelector selector = context.get("player"); + Collection players = selector.values(); + for (Player player : players) { + BukkitServerPlayer serverPlayer = plugin().adapt(player); + NamespacedKey namespacedKey = context.get("id"); + Key itemId = Key.of(namespacedKey.namespace(), namespacedKey.value()); + List> inRecipes = plugin().recipeManager().getRecipeByResult(itemId); + if (!inRecipes.isEmpty()) { + plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0); + } else if (context.flags().hasFlag(FlagKeys.BROWSE)) { + plugin().itemBrowserManager().openNoRecipePage(serverPlayer, itemId, null, 0); + } else { + handleFeedback(context, MessageConstants.COMMAND_ITEM_RECIPE_BROWSER_RECIPE_NO_FOUND); + } + } + }); + } + + @Override + public String getFeatureID() { + return "selector_item_recipe_browser"; + } +} diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SelectorItemUsageBrowserCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SelectorItemUsageBrowserCommand.java new file mode 100644 index 000000000..a12a232fe --- /dev/null +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SelectorItemUsageBrowserCommand.java @@ -0,0 +1,65 @@ +package net.momirealms.craftengine.bukkit.plugin.command.feature; + +import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature; +import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer; +import net.momirealms.craftengine.core.item.recipe.Recipe; +import net.momirealms.craftengine.core.plugin.CraftEngine; +import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; +import net.momirealms.craftengine.core.plugin.locale.MessageConstants; +import net.momirealms.craftengine.core.util.Key; +import org.bukkit.NamespacedKey; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.incendo.cloud.Command; +import org.incendo.cloud.CommandManager; +import org.incendo.cloud.bukkit.data.MultiplePlayerSelector; +import org.incendo.cloud.bukkit.parser.NamespacedKeyParser; +import org.incendo.cloud.bukkit.parser.selector.MultiplePlayerSelectorParser; +import org.incendo.cloud.context.CommandContext; +import org.incendo.cloud.context.CommandInput; +import org.incendo.cloud.suggestion.Suggestion; +import org.incendo.cloud.suggestion.SuggestionProvider; + +import java.util.Collection; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class SelectorItemUsageBrowserCommand extends BukkitCommandFeature { + + public SelectorItemUsageBrowserCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { + super(commandManager, plugin); + } + + @Override + public Command.Builder assembleCommand(CommandManager manager, Command.Builder builder) { + return builder + .required("player", MultiplePlayerSelectorParser.multiplePlayerSelectorParser(true)) + .required("id", NamespacedKeyParser.namespacedKeyComponent().suggestionProvider(new SuggestionProvider<>() { + @Override + public @NonNull CompletableFuture> suggestionsFuture(@NonNull CommandContext context, @NonNull CommandInput input) { + return CompletableFuture.completedFuture(plugin().itemManager().cachedSuggestions()); + } + })) + .handler(context -> { + MultiplePlayerSelector selector = context.get("player"); + Collection players = selector.values(); + for (Player player : players) { + BukkitServerPlayer serverPlayer = plugin().adapt(player); + NamespacedKey namespacedKey = context.get("id"); + Key itemId = Key.of(namespacedKey.namespace(), namespacedKey.value()); + List> inRecipes = plugin().recipeManager().getRecipeByIngredient(itemId); + if (!inRecipes.isEmpty()) { + plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0); + } else { + handleFeedback(context, MessageConstants.COMMAND_ITEM_USAGE_BROWSER_RECIPE_NO_FOUND); + } + } + }); + } + + @Override + public String getFeatureID() { + return "selector_item_usage_browser"; + } +} From c08e808a30d0ce27520a76fc567fe4449713be72 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Sun, 16 Mar 2025 19:35:21 +0800 Subject: [PATCH 06/10] =?UTF-8?q?refactor(bukkit):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bukkit-loader/src/main/resources/commands.yml | 16 ++++++++-------- .../plugin/command/BukkitCommandManager.java | 8 ++++---- ...d.java => ItemRecipeBrowserAdminCommand.java} | 6 +++--- ....java => ItemRecipeBrowserPlayerCommand.java} | 6 +++--- ...nd.java => ItemUsageBrowserAdminCommand.java} | 6 +++--- ...d.java => ItemUsageBrowserPlayerCommand.java} | 6 +++--- 6 files changed, 24 insertions(+), 24 deletions(-) rename bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/{SelectorItemRecipeBrowserCommand.java => ItemRecipeBrowserAdminCommand.java} (92%) rename bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/{ItemRecipeBrowserCommand.java => ItemRecipeBrowserPlayerCommand.java} (92%) rename bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/{SelectorItemUsageBrowserCommand.java => ItemUsageBrowserAdminCommand.java} (92%) rename bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/{ItemUsageBrowserCommand.java => ItemUsageBrowserPlayerCommand.java} (91%) diff --git a/bukkit-loader/src/main/resources/commands.yml b/bukkit-loader/src/main/resources/commands.yml index 9756178c1..afa113781 100644 --- a/bukkit-loader/src/main/resources/commands.yml +++ b/bukkit-loader/src/main/resources/commands.yml @@ -38,28 +38,28 @@ item_browser: - /ce item browser - /ce -item_recipe_browser: +item_recipe_browser_player: enable: true - permission: ce.command.item_recipe_browser + permission: ce.command.player.item_recipe_browser usage: - /findrecipe by-result -item_usage_browser: +item_usage_browser_player: enable: true - permission: ce.command.item_usage_browser + permission: ce.command.player.item_usage_browser usage: - /findrecipe by-ingredient -selector_item_recipe_browser: +item_recipe_browser_admin: enable: true - permission: ce.command.selector_item_recipe_browser + permission: ce.command.admin.item_recipe_browser usage: - /craftengine recipe by-result - /ce recipe by-result -selector_item_usage_browser: +item_usage_browser_admin: enable: true - permission: ce.command.selector_item_usage_browser + permission: ce.command.admin.item_usage_browser usage: - /craftengine recipe by-ingredient - /ce recipe by-ingredient diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java index f986ceee0..9b7a4c66b 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java @@ -32,10 +32,10 @@ public class BukkitCommandManager extends AbstractCommandManager new GetItemCommand(this, plugin), new GiveItemCommand(this, plugin), new ItemBrowserCommand(this, plugin), - new ItemRecipeBrowserCommand(this, plugin), - new ItemUsageBrowserCommand(this, plugin), - new SelectorItemRecipeBrowserCommand(this, plugin), - new SelectorItemUsageBrowserCommand(this, plugin), + new ItemRecipeBrowserPlayerCommand(this, plugin), + new ItemUsageBrowserPlayerCommand(this, plugin), + new ItemRecipeBrowserAdminCommand(this, plugin), + new ItemUsageBrowserAdminCommand(this, plugin), new TestCommand(this, plugin), new DebugGetBlockStateRegistryIdCommand(this, plugin), new DebugGetBlockInternalIdCommand(this, plugin), diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SelectorItemRecipeBrowserCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserAdminCommand.java similarity index 92% rename from bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SelectorItemRecipeBrowserCommand.java rename to bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserAdminCommand.java index 0a9786ddc..3899a67b0 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SelectorItemRecipeBrowserCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserAdminCommand.java @@ -26,9 +26,9 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.CompletableFuture; -public class SelectorItemRecipeBrowserCommand extends BukkitCommandFeature { +public class ItemRecipeBrowserAdminCommand extends BukkitCommandFeature { - public SelectorItemRecipeBrowserCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { + public ItemRecipeBrowserAdminCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { super(commandManager, plugin); } @@ -64,6 +64,6 @@ public class SelectorItemRecipeBrowserCommand extends BukkitCommandFeature { +public class ItemRecipeBrowserPlayerCommand extends BukkitCommandFeature { - public ItemRecipeBrowserCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { + public ItemRecipeBrowserPlayerCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { super(commandManager, plugin); } @@ -58,6 +58,6 @@ public class ItemRecipeBrowserCommand extends BukkitCommandFeature { +public class ItemUsageBrowserAdminCommand extends BukkitCommandFeature { - public SelectorItemUsageBrowserCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { + public ItemUsageBrowserAdminCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { super(commandManager, plugin); } @@ -60,6 +60,6 @@ public class SelectorItemUsageBrowserCommand extends BukkitCommandFeature { +public class ItemUsageBrowserPlayerCommand extends BukkitCommandFeature { - public ItemUsageBrowserCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { + public ItemUsageBrowserPlayerCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { super(commandManager, plugin); } @@ -54,6 +54,6 @@ public class ItemUsageBrowserCommand extends BukkitCommandFeature @Override public String getFeatureID() { - return "item_usage_browser"; + return "item_usage_browser_player"; } } From 3ea792555a8a3d81fee68878d57795daa4ad5450 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Sun, 16 Mar 2025 20:14:31 +0800 Subject: [PATCH 07/10] =?UTF-8?q?refactor(item-browser):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ItemRecipeBrowserAdminCommand.java | 5 +- .../ItemRecipeBrowserPlayerCommand.java | 5 +- .../feature/ItemUsageBrowserAdminCommand.java | 2 +- .../ItemUsageBrowserPlayerCommand.java | 2 +- .../core/plugin/command/FlagKeys.java | 2 - .../gui/category/ItemBrowserManager.java | 2 +- .../gui/category/ItemBrowserManagerImpl.java | 66 +++++++++---------- 7 files changed, 38 insertions(+), 46 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserAdminCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserAdminCommand.java index 3899a67b0..e59b923aa 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserAdminCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserAdminCommand.java @@ -35,7 +35,6 @@ public class ItemRecipeBrowserAdminCommand extends BukkitCommandFeature assembleCommand(CommandManager manager, Command.Builder builder) { return builder - .flag(FlagKeys.BROWSE_FLAG) .required("player", MultiplePlayerSelectorParser.multiplePlayerSelectorParser(true)) .required("id", NamespacedKeyParser.namespacedKeyComponent().suggestionProvider(new SuggestionProvider<>() { @Override @@ -52,9 +51,7 @@ public class ItemRecipeBrowserAdminCommand extends BukkitCommandFeature> inRecipes = plugin().recipeManager().getRecipeByResult(itemId); if (!inRecipes.isEmpty()) { - plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0); - } else if (context.flags().hasFlag(FlagKeys.BROWSE)) { - plugin().itemBrowserManager().openNoRecipePage(serverPlayer, itemId, null, 0); + plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0, false); } else { handleFeedback(context, MessageConstants.COMMAND_ITEM_RECIPE_BROWSER_RECIPE_NO_FOUND); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserPlayerCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserPlayerCommand.java index f65f90f5b..85f69db08 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserPlayerCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserPlayerCommand.java @@ -33,7 +33,6 @@ public class ItemRecipeBrowserPlayerCommand extends BukkitCommandFeature assembleCommand(CommandManager manager, Command.Builder builder) { return builder .senderType(Player.class) - .flag(FlagKeys.BROWSE_FLAG) .required("id", NamespacedKeyParser.namespacedKeyComponent().suggestionProvider(new SuggestionProvider<>() { @Override public @NonNull CompletableFuture> suggestionsFuture(@NonNull CommandContext context, @NonNull CommandInput input) { @@ -47,9 +46,7 @@ public class ItemRecipeBrowserPlayerCommand extends BukkitCommandFeature> inRecipes = plugin().recipeManager().getRecipeByResult(itemId); if (!inRecipes.isEmpty()) { - plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0); - } else if (context.flags().hasFlag(FlagKeys.BROWSE)) { - plugin().itemBrowserManager().openNoRecipePage(serverPlayer, itemId, null, 0); + plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0, false); } else { handleFeedback(context, MessageConstants.COMMAND_ITEM_RECIPE_BROWSER_RECIPE_NO_FOUND); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemUsageBrowserAdminCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemUsageBrowserAdminCommand.java index b3c0cb244..ba80a1756 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemUsageBrowserAdminCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemUsageBrowserAdminCommand.java @@ -50,7 +50,7 @@ public class ItemUsageBrowserAdminCommand extends BukkitCommandFeature> inRecipes = plugin().recipeManager().getRecipeByIngredient(itemId); if (!inRecipes.isEmpty()) { - plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0); + plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0, false); } else { handleFeedback(context, MessageConstants.COMMAND_ITEM_USAGE_BROWSER_RECIPE_NO_FOUND); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemUsageBrowserPlayerCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemUsageBrowserPlayerCommand.java index d552b51a1..abe4dbfae 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemUsageBrowserPlayerCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemUsageBrowserPlayerCommand.java @@ -45,7 +45,7 @@ public class ItemUsageBrowserPlayerCommand extends BukkitCommandFeature> inRecipes = plugin().recipeManager().getRecipeByIngredient(itemId); if (!inRecipes.isEmpty()) { - plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0); + plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0, false); } else { handleFeedback(context, MessageConstants.COMMAND_ITEM_USAGE_BROWSER_RECIPE_NO_FOUND); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/command/FlagKeys.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/command/FlagKeys.java index 6f55a828a..5cde8bd5c 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/command/FlagKeys.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/command/FlagKeys.java @@ -7,6 +7,4 @@ public final class FlagKeys { public static final CommandFlag SILENT_FLAG = CommandFlag.builder("silent").withAliases("s").build(); public static final String TO_INVENTORY = "to-inventory"; public static final CommandFlag TO_INVENTORY_FLAG = CommandFlag.builder("to-inventory").build(); - public static final String BROWSE = "browse"; - public static final CommandFlag BROWSE_FLAG = CommandFlag.builder("browse").withAliases("b").build(); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManager.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManager.java index 9630e5f03..1a7dd0f63 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManager.java @@ -35,7 +35,7 @@ public interface ItemBrowserManager extends Reloadable, ConfigSectionParser { void open(Player player); - void openRecipePage(Player player, Gui parentGui, List> recipes, int index, int depth); + void openRecipePage(Player player, Gui parentGui, List> recipes, int index, int depth, boolean canOpenNoRecipePage); void openNoRecipePage(Player player, Key result, Gui parentGui, int depth); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java index 379706da0..e1b1392b2 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java @@ -141,7 +141,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { return new ItemWithAction(item, (element, click) -> { click.cancel(); player.playSound(Constants.SOUND_CLICK_BUTTON); - openCategoryPage(click.clicker(), it.id(), element.gui()); + openCategoryPage(click.clicker(), it.id(), element.gui(), true); }); }).filter(Objects::nonNull).toList(); @@ -159,7 +159,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { .open(player); } - public void openCategoryPage(Player player, Key categoryId, Gui parentGui) { + public void openCategoryPage(Player player, Key categoryId, Gui parentGui, boolean canOpenNoRecipePage) { GuiLayout layout = new GuiLayout( "AAAAAAAAA", "AAAAAAAAA", @@ -227,7 +227,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { return new ItemWithAction(item, (element, click) -> { click.cancel(); player.playSound(Constants.SOUND_CLICK_BUTTON); - openCategoryPage(click.clicker(), subCategory.id(), element.gui()); + openCategoryPage(click.clicker(), subCategory.id(), element.gui(), canOpenNoRecipePage); }); } else { Key itemId = Key.of(it); @@ -245,7 +245,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { List> inRecipes = this.plugin.recipeManager().getRecipeByResult(itemId); player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } else { openNoRecipePage(player, itemId, e.gui(), 0); } @@ -253,7 +253,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { List> inRecipes = this.plugin.recipeManager().getRecipeByIngredient(itemId); player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } } }); @@ -294,7 +294,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { List> inRecipes = this.plugin.recipeManager().getRecipeByIngredient(result); player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, depth + 1); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, depth + 1, true); } } })) @@ -336,26 +336,26 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { } @Override - public void openRecipePage(Player player, Gui parentGui, List> recipes, int index, int depth) { + public void openRecipePage(Player player, Gui parentGui, List> recipes, int index, int depth, boolean canOpenNoRecipePage) { if (index >= recipes.size()) return; if (depth > MAX_RECIPE_DEPTH) return; Recipe recipe = recipes.get(index); Key recipeType = recipe.type(); if (recipeType == RecipeTypes.SHAPELESS || recipeType == RecipeTypes.SHAPED) { - openCraftingRecipePage(player, (CustomCraftingTableRecipe) recipe, parentGui, recipes, index, depth); + openCraftingRecipePage(player, (CustomCraftingTableRecipe) recipe, parentGui, recipes, index, depth, canOpenNoRecipePage); return; } if (recipeType == RecipeTypes.BLASTING || recipeType == RecipeTypes.CAMPFIRE_COOKING || recipeType == RecipeTypes.SMOKING || recipeType == RecipeTypes.SMELTING) { - openCookingRecipePage(player, (CustomCookingRecipe) recipe, parentGui, recipes, index, depth); + openCookingRecipePage(player, (CustomCookingRecipe) recipe, parentGui, recipes, index, depth, canOpenNoRecipePage); return; } if (recipeType == RecipeTypes.STONE_CUTTING) { - openStoneCuttingRecipePage(player, (CustomStoneCuttingRecipe) recipe, parentGui, recipes, index, depth); + openStoneCuttingRecipePage(player, (CustomStoneCuttingRecipe) recipe, parentGui, recipes, index, depth, canOpenNoRecipePage); return; } } - public void openStoneCuttingRecipePage(Player player, CustomStoneCuttingRecipe recipe, Gui parentGui, List> recipes, int index, int depth) { + public void openStoneCuttingRecipePage(Player player, CustomStoneCuttingRecipe recipe, Gui parentGui, List> recipes, int index, int depth, boolean canOpenNoRecipePage) { Key previous = index > 0 ? Constants.RECIPE_PREVIOUS_PAGE_AVAILABLE : Constants.RECIPE_PREVIOUS_PAGE_BLOCK; Key next = index + 1 < recipes.size() ? Constants.RECIPE_NEXT_PAGE_AVAILABLE : Constants.RECIPE_NEXT_PAGE_BLOCK; Key result = recipe.result().item().id(); @@ -386,7 +386,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } else { openNoRecipePage(player, result, e.gui(), 0); } @@ -395,7 +395,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } } })) @@ -422,7 +422,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } else { openNoRecipePage(player, e.item().id(), e.gui(), 0); } @@ -431,7 +431,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } } })) @@ -458,7 +458,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { c.cancel(); if (index + 1 < recipes.size()) { player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1); - openRecipePage(player, parentGui, recipes, index + 1, depth); + openRecipePage(player, parentGui, recipes, index + 1, depth, canOpenNoRecipePage); } })) .addIngredient('<', GuiElement.constant(this.plugin.itemManager() @@ -471,7 +471,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { c.cancel(); if (index > 0) { player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1); - openRecipePage(player, parentGui, recipes, index - 1, depth); + openRecipePage(player, parentGui, recipes, index - 1, depth, canOpenNoRecipePage); } })); @@ -488,7 +488,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { .open(player); } - public void openCookingRecipePage(Player player, CustomCookingRecipe recipe, Gui parentGui, List> recipes, int index, int depth) { + public void openCookingRecipePage(Player player, CustomCookingRecipe recipe, Gui parentGui, List> recipes, int index, int depth, boolean canOpenNoRecipePage) { Key previous = index > 0 ? Constants.RECIPE_PREVIOUS_PAGE_AVAILABLE : Constants.RECIPE_PREVIOUS_PAGE_BLOCK; Key next = index + 1 < recipes.size() ? Constants.RECIPE_NEXT_PAGE_AVAILABLE : Constants.RECIPE_NEXT_PAGE_BLOCK; Key result = recipe.result().item().id(); @@ -519,7 +519,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } else { openNoRecipePage(player, result, e.gui(), 0); } @@ -528,7 +528,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } } })) @@ -561,7 +561,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } else { openNoRecipePage(player, e.item().id(), e.gui(), 0); } @@ -570,7 +570,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } } })) @@ -597,7 +597,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { c.cancel(); if (index + 1 < recipes.size()) { player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1); - openRecipePage(player, parentGui, recipes, index + 1, depth); + openRecipePage(player, parentGui, recipes, index + 1, depth, canOpenNoRecipePage); } })) .addIngredient('<', GuiElement.constant(this.plugin.itemManager() @@ -610,7 +610,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { c.cancel(); if (index > 0) { player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1); - openRecipePage(player, parentGui, recipes, index - 1, depth); + openRecipePage(player, parentGui, recipes, index - 1, depth, canOpenNoRecipePage); } })); @@ -638,7 +638,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { .open(player); } - public void openCraftingRecipePage(Player player, CustomCraftingTableRecipe recipe, Gui parentGui, List> recipes, int index, int depth) { + public void openCraftingRecipePage(Player player, CustomCraftingTableRecipe recipe, Gui parentGui, List> recipes, int index, int depth, boolean canOpenNoRecipePage) { Key previous = index > 0 ? Constants.RECIPE_PREVIOUS_PAGE_AVAILABLE : Constants.RECIPE_PREVIOUS_PAGE_BLOCK; Key next = index + 1 < recipes.size() ? Constants.RECIPE_NEXT_PAGE_AVAILABLE : Constants.RECIPE_NEXT_PAGE_BLOCK; Key result = recipe.result().item().id(); @@ -664,7 +664,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } else { openNoRecipePage(player, result, e.gui(), 0); } @@ -673,7 +673,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } } })) @@ -710,7 +710,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { c.cancel(); if (index + 1 < recipes.size()) { player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1); - openRecipePage(player, parentGui, recipes, index + 1, depth); + openRecipePage(player, parentGui, recipes, index + 1, depth, canOpenNoRecipePage); } })) .addIngredient('<', GuiElement.constant(this.plugin.itemManager() @@ -723,7 +723,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { c.cancel(); if (index > 0) { player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1); - openRecipePage(player, parentGui, recipes, index - 1, depth); + openRecipePage(player, parentGui, recipes, index - 1, depth, canOpenNoRecipePage); } })); @@ -756,7 +756,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } else { openNoRecipePage(player, e.item().id(), e.gui(), 0); } @@ -765,7 +765,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } } })); @@ -799,7 +799,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } else { openNoRecipePage(player, e.item().id(), e.gui(), 0); } @@ -808,7 +808,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { if (inRecipes == recipes) return; player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { - openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0); + openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); } } })); From c59a4d9205d93ff5c657a301426f52d7a4da6d01 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Sun, 16 Mar 2025 20:17:11 +0800 Subject: [PATCH 08/10] =?UTF-8?q?refactor(item-browser):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/category/ItemBrowserManagerImpl.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java index e1b1392b2..77eb7fdbb 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java @@ -246,7 +246,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); - } else { + } else if (canOpenNoRecipePage) { openNoRecipePage(player, itemId, e.gui(), 0); } } else if (RIGHT_CLICK.contains(c.type())) { @@ -387,7 +387,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); - } else { + } else if (canOpenNoRecipePage) { openNoRecipePage(player, result, e.gui(), 0); } } else if (RIGHT_CLICK.contains(c.type())) { @@ -423,7 +423,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); - } else { + } else if (canOpenNoRecipePage) { openNoRecipePage(player, e.item().id(), e.gui(), 0); } } else if (RIGHT_CLICK.contains(c.type())) { @@ -520,7 +520,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); - } else { + } else if (canOpenNoRecipePage) { openNoRecipePage(player, result, e.gui(), 0); } } else if (RIGHT_CLICK.contains(c.type())) { @@ -562,7 +562,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); - } else { + } else if (canOpenNoRecipePage) { openNoRecipePage(player, e.item().id(), e.gui(), 0); } } else if (RIGHT_CLICK.contains(c.type())) { @@ -665,7 +665,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); - } else { + } else if (canOpenNoRecipePage) { openNoRecipePage(player, result, e.gui(), 0); } } else if (RIGHT_CLICK.contains(c.type())) { @@ -757,7 +757,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); - } else { + } else if (canOpenNoRecipePage) { openNoRecipePage(player, e.item().id(), e.gui(), 0); } } else if (RIGHT_CLICK.contains(c.type())) { @@ -800,7 +800,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { player.playSound(Constants.SOUND_CLICK_BUTTON); if (!inRecipes.isEmpty()) { openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0, canOpenNoRecipePage); - } else { + } else if (canOpenNoRecipePage) { openNoRecipePage(player, e.item().id(), e.gui(), 0); } } else if (RIGHT_CLICK.contains(c.type())) { From 2dd27522628e72e45ff63834425248887756a995 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Sun, 16 Mar 2025 21:09:32 +0800 Subject: [PATCH 09/10] =?UTF-8?q?feat(gui):=20=E6=B7=BB=E5=8A=A0=E9=80=80?= =?UTF-8?q?=E5=87=BA=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bukkit-loader/src/main/resources/config.yml | 2 ++ .../resources/internal/configuration/gui.yml | 9 +++++++- .../resources/internal/configuration/i18n.yml | 2 ++ .../textures/item/custom/gui/exit.png | Bin 0 -> 267 bytes .../core/pack/AbstractPackManager.java | 1 + .../gui/category/ItemBrowserManager.java | 4 ++++ .../gui/category/ItemBrowserManagerImpl.java | 20 +++++++++--------- gradle.properties | 2 +- 8 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 bukkit-loader/src/main/resources/resources/internal/resourcepack/assets/minecraft/textures/item/custom/gui/exit.png diff --git a/bukkit-loader/src/main/resources/config.yml b/bukkit-loader/src/main/resources/config.yml index 1f47e72c3..7c3c61845 100644 --- a/bukkit-loader/src/main/resources/config.yml +++ b/bukkit-loader/src/main/resources/config.yml @@ -162,6 +162,7 @@ gui: available: "internal:previous_page_0" not-available: "internal:previous_page_1" return: "internal:return" + exit: "internal:exit" recipe: get-item-icon: internal:get_item cooking-information-icon: internal:cooking_info @@ -173,6 +174,7 @@ gui: available: "internal:previous_recipe_0" not-available: "internal:previous_recipe_1" return: "internal:return" + exit: "internal:exit" none: title: "" blasting: diff --git a/bukkit-loader/src/main/resources/resources/internal/configuration/gui.yml b/bukkit-loader/src/main/resources/resources/internal/configuration/gui.yml index 2101ee69c..c8245f2b1 100644 --- a/bukkit-loader/src/main/resources/resources/internal/configuration/gui.yml +++ b/bukkit-loader/src/main/resources/resources/internal/configuration/gui.yml @@ -158,4 +158,11 @@ items: name: "<#FF8C00>" lore: - "" - - "" \ No newline at end of file + - "" + internal:exit: + template: "internal:2d_icon" + arguments: + model_data: 1007 + texture: exit + name: "<#DAA520>" + lore: null \ No newline at end of file diff --git a/bukkit-loader/src/main/resources/resources/internal/configuration/i18n.yml b/bukkit-loader/src/main/resources/resources/internal/configuration/i18n.yml index 9fb579d89..5f4af8c2d 100644 --- a/bukkit-loader/src/main/resources/resources/internal/configuration/i18n.yml +++ b/bukkit-loader/src/main/resources/resources/internal/configuration/i18n.yml @@ -3,6 +3,7 @@ i18n: internal.next_page: "Next Page" internal.previous_page: "Previous Page" internal.return: "Return to Parent Page" + internal.exit: "Exit" internal.next_recipe: "Next Recipe" internal.previous_recipe: "Previous Recipe" internal.get_item: "Get Item" @@ -15,6 +16,7 @@ i18n: internal.next_page: "下一页" internal.previous_page: "上一页" internal.return: "返回上一级" + internal.exit: "退出" internal.next_recipe: "下一个配方" internal.previous_recipe: "上一个配方" internal.get_item: "获取物品" diff --git a/bukkit-loader/src/main/resources/resources/internal/resourcepack/assets/minecraft/textures/item/custom/gui/exit.png b/bukkit-loader/src/main/resources/resources/internal/resourcepack/assets/minecraft/textures/item/custom/gui/exit.png new file mode 100644 index 0000000000000000000000000000000000000000..25c6f603d93cdb7821adaa7a672ac03ae516b7e2 GIT binary patch literal 267 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|j(WN{hFJ6_ zKM67ZdES9BAu%B#VaGn3_J=3G-dD+-axo?KLeCr~!v{bv&s=Z6$tez%J(`DD4IZSf z@|f~0clrCnH+^1An#VYa2Z$wR6?7&`G^}Bip1pu^=hfo{x4LxNFEi)|yRP9XUfrL_ zt1QMN$mYSZ*gYF)%HgN8^Eq}qgvYX+dlyqArCK%dX@OM3nwzIXCLTN;BA73A@B@>N z;imeDypH_rJj?~EYB7%rm=ioFOEk!c>G1IIs61y*IpC35#>T+8%IbTQ9_uQghZsCv L{an^LB{Ts5B>rQl literal 0 HcmV?d00001 diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java b/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java index 486660122..359bd76bd 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java @@ -258,6 +258,7 @@ public abstract class AbstractPackManager implements PackManager { plugin.saveResource("resources/internal/resourcepack/assets/minecraft/textures/item/custom/gui/previous_page_0.png"); plugin.saveResource("resources/internal/resourcepack/assets/minecraft/textures/item/custom/gui/previous_page_1.png"); plugin.saveResource("resources/internal/resourcepack/assets/minecraft/textures/item/custom/gui/return.png"); + plugin.saveResource("resources/internal/resourcepack/assets/minecraft/textures/item/custom/gui/exit.png"); plugin.saveResource("resources/internal/resourcepack/assets/minecraft/textures/item/custom/gui/cooking_info.png"); plugin.saveResource("resources/internal/resourcepack/assets/minecraft/textures/item/custom/gui/cooking_info.png.mcmeta"); // default pack diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManager.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManager.java index 1a7dd0f63..222136c53 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManager.java @@ -52,6 +52,7 @@ public interface ItemBrowserManager extends Reloadable, ConfigSectionParser { public static String CATEGORY_TITLE; public static Key CATEGORY_BACK; + public static Key CATEGORY_EXIT; public static Key CATEGORY_NEXT_PAGE_AVAILABLE; public static Key CATEGORY_NEXT_PAGE_BLOCK; public static Key CATEGORY_PREVIOUS_PAGE_AVAILABLE; @@ -65,6 +66,7 @@ public interface ItemBrowserManager extends Reloadable, ConfigSectionParser { public static String RECIPE_CRAFTING_TITLE; public static String RECIPE_STONECUTTING_TITLE; public static Key RECIPE_BACK; + public static Key RECIPE_EXIT; public static Key RECIPE_NEXT_PAGE_AVAILABLE; public static Key RECIPE_NEXT_PAGE_BLOCK; public static Key RECIPE_PREVIOUS_PAGE_AVAILABLE; @@ -88,6 +90,7 @@ public interface ItemBrowserManager extends Reloadable, ConfigSectionParser { CATEGORY_TITLE = getOrThrow(section, "category.title"); CATEGORY_BACK = Key.of(getOrThrow(section, "category.page-navigation.return")); + CATEGORY_EXIT = Key.of(getOrThrow(section, "category.page-navigation.exit")); CATEGORY_NEXT_PAGE_AVAILABLE = Key.of(getOrThrow(section, "category.page-navigation.next.available")); CATEGORY_NEXT_PAGE_BLOCK = Key.of(getOrThrow(section, "category.page-navigation.next.not-available")); CATEGORY_PREVIOUS_PAGE_AVAILABLE = Key.of(getOrThrow(section, "category.page-navigation.previous.available")); @@ -101,6 +104,7 @@ public interface ItemBrowserManager extends Reloadable, ConfigSectionParser { RECIPE_CRAFTING_TITLE = getOrThrow(section, "recipe.crafting.title"); RECIPE_STONECUTTING_TITLE = getOrThrow(section, "recipe.stonecutting.title"); RECIPE_BACK = Key.of(getOrThrow(section, "recipe.page-navigation.return")); + RECIPE_EXIT = Key.of(getOrThrow(section, "recipe.page-navigation.exit")); RECIPE_NEXT_PAGE_AVAILABLE = Key.of(getOrThrow(section, "recipe.page-navigation.next.available")); RECIPE_NEXT_PAGE_BLOCK = Key.of(getOrThrow(section, "recipe.page-navigation.next.not-available")); RECIPE_PREVIOUS_PAGE_AVAILABLE = Key.of(getOrThrow(section, "recipe.page-navigation.previous.available")); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java index 77eb7fdbb..47a0bf905 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java @@ -169,9 +169,9 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { " < = > " ) .addIngredient('A', Ingredient.paged()) - .addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(Constants.CATEGORY_BACK) + .addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(parentGui != null ? Constants.CATEGORY_BACK : Constants.CATEGORY_EXIT) .map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.EMPTY))) - .orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + Constants.CATEGORY_BACK)), + .orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + (parentGui != null ? Constants.CATEGORY_BACK : Constants.CATEGORY_EXIT))), ((element, click) -> { click.cancel(); player.playSound(Constants.SOUND_RETURN_PAGE, 0.25f, 1); @@ -308,9 +308,9 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { player.giveItem(item.count(item.maxStackSize())); } }) : GuiElement.EMPTY) - .addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(Constants.RECIPE_BACK) + .addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT) .map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.EMPTY))) - .orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + Constants.RECIPE_BACK)), + .orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + (parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT))), ((element, click) -> { click.cancel(); player.playSound(Constants.SOUND_RETURN_PAGE, 0.25f, 1); @@ -435,9 +435,9 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { } } })) - .addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(Constants.RECIPE_BACK) + .addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT) .map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.EMPTY))) - .orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + Constants.RECIPE_BACK)), + .orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + (parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT))), ((element, click) -> { click.cancel(); player.playSound(Constants.SOUND_RETURN_PAGE, 0.25f, 1); @@ -574,9 +574,9 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { } } })) - .addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(Constants.RECIPE_BACK) + .addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT) .map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.EMPTY))) - .orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + Constants.RECIPE_BACK)), + .orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + (parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT))), ((element, click) -> { click.cancel(); player.playSound(Constants.SOUND_RETURN_PAGE, 0.25f, 1); @@ -687,9 +687,9 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager { player.giveItem(item.count(item.maxStackSize())); } }) : GuiElement.EMPTY) - .addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(Constants.RECIPE_BACK) + .addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT) .map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.EMPTY))) - .orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + Constants.RECIPE_BACK)), + .orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + (parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT))), ((element, click) -> { click.cancel(); player.playSound(Constants.SOUND_RETURN_PAGE, 0.25f, 1); diff --git a/gradle.properties b/gradle.properties index e25398ede..fbc8cbd28 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=0.0.33 +project_version=0.0.34 config_version=14 lang_version=3 project_group=net.momirealms From 91c14bf31a7dbf0e6b442dde75f0c276e800b02c Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Sun, 16 Mar 2025 21:18:15 +0800 Subject: [PATCH 10/10] =?UTF-8?q?refactor(i18n):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/command/feature/ItemRecipeBrowserAdminCommand.java | 3 +-- .../command/feature/ItemRecipeBrowserPlayerCommand.java | 3 +-- .../plugin/command/feature/ItemUsageBrowserAdminCommand.java | 2 +- .../plugin/command/feature/ItemUsageBrowserPlayerCommand.java | 2 +- .../craftengine/core/plugin/locale/MessageConstants.java | 4 ++-- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserAdminCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserAdminCommand.java index e59b923aa..d02a22805 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserAdminCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ItemRecipeBrowserAdminCommand.java @@ -5,7 +5,6 @@ import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer; import net.momirealms.craftengine.core.item.recipe.Recipe; import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; -import net.momirealms.craftengine.core.plugin.command.FlagKeys; import net.momirealms.craftengine.core.plugin.locale.MessageConstants; import net.momirealms.craftengine.core.util.Key; import org.bukkit.NamespacedKey; @@ -53,7 +52,7 @@ public class ItemRecipeBrowserAdminCommand extends BukkitCommandFeature