mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
improve commands
This commit is contained in:
@@ -11,58 +11,63 @@ config-version: "${config_version}"
|
||||
# Usage: [COMMAND]
|
||||
reload:
|
||||
enable: true
|
||||
permission: ce.command.reload
|
||||
permission: ce.command.admin.reload
|
||||
usage:
|
||||
- /craftengine reload
|
||||
- /ce reload
|
||||
|
||||
get_item:
|
||||
enable: true
|
||||
permission: ce.command.get_item
|
||||
permission: ce.command.admin.get_item
|
||||
usage:
|
||||
- /craftengine item get
|
||||
- /ce item get
|
||||
|
||||
give_item:
|
||||
enable: true
|
||||
permission: ce.command.give_item
|
||||
permission: ce.command.admin.give_item
|
||||
usage:
|
||||
- /craftengine item give
|
||||
- /ce item give
|
||||
|
||||
item_browser:
|
||||
item_browser_player:
|
||||
enable: true
|
||||
permission: ce.command.item_browser
|
||||
permission: ce.command.player.item_browser
|
||||
usage:
|
||||
- /ce
|
||||
|
||||
item_browser_admin:
|
||||
enable: true
|
||||
permission: ce.command.admin.item_browser
|
||||
usage:
|
||||
- /craftengine item browser
|
||||
- /ce item browser
|
||||
- /ce
|
||||
|
||||
item_recipe_browser_player:
|
||||
search_usage_player:
|
||||
enable: true
|
||||
permission: ce.command.player.item_recipe_browser
|
||||
permission: ce.command.player.search_usage
|
||||
usage:
|
||||
- /findrecipe by-result
|
||||
- /search-usage
|
||||
|
||||
item_usage_browser_player:
|
||||
search_recipe_player:
|
||||
enable: true
|
||||
permission: ce.command.player.item_usage_browser
|
||||
permission: ce.command.player.search_recipe
|
||||
usage:
|
||||
- /findrecipe by-ingredient
|
||||
- /search-recipe
|
||||
|
||||
item_recipe_browser_admin:
|
||||
search_usage_admin:
|
||||
enable: true
|
||||
permission: ce.command.admin.item_recipe_browser
|
||||
permission: ce.command.admin.search_usage
|
||||
usage:
|
||||
- /craftengine recipe by-result
|
||||
- /ce recipe by-result
|
||||
- /craftengine item search-usage
|
||||
- /ce item search-usage
|
||||
|
||||
item_usage_browser_admin:
|
||||
search_recipe_admin:
|
||||
enable: true
|
||||
permission: ce.command.admin.item_usage_browser
|
||||
permission: ce.command.admin.search_recipe
|
||||
usage:
|
||||
- /craftengine recipe by-ingredient
|
||||
- /ce recipe by-ingredient
|
||||
- /craftengine item search-recipe
|
||||
- /ce item search-recipe
|
||||
|
||||
# Debug commands
|
||||
debug_set_block:
|
||||
|
||||
@@ -49,5 +49,7 @@ command.item.get.failure.not_exist: "<red><lang:argument.item.id.invalid:'<arg:0
|
||||
command.item.give.success.single: "<lang:commands.give.success.single:'<arg:0>':'<arg:1>':'<arg:2>'>"
|
||||
command.item.give.success.multiple: "<lang:commands.give.success.multiple:'<arg:0>':'<arg:1>':'<arg:2>'>"
|
||||
command.item.give.failure.not_exist: "<red><lang:argument.item.id.invalid:'<arg:0>'></red>"
|
||||
command.item.recipe.browser.recipe.no_found: "<red>No recipe found for this item</red>"
|
||||
command.item.usage.browser.recipe.no_found: "<red>No usage found for this item</red>"
|
||||
command.search_recipe.not_found: "<red>No recipe found for this item</red>"
|
||||
command.search_usage.not_found: "<red>No usage found for this item</red>"
|
||||
command.search_recipe.no_item: "<red>Please hold an item before running this command</red>"
|
||||
command.search_usage.no_item: "<red>Please hold an item before running this command</red>"
|
||||
@@ -49,3 +49,7 @@ command.item.get.failure.not_exist: "<red><lang:argument.item.id.invalid:'<arg:0
|
||||
command.item.give.success.single: "<lang:commands.give.success.single:'<arg:0>':'<arg:1>':'<arg:2>'>"
|
||||
command.item.give.success.multiple: "<lang:commands.give.success.multiple:'<arg:0>':'<arg:1>':'<arg:2>'>"
|
||||
command.item.give.failure.not_exist: "<red><lang:argument.item.id.invalid:'<arg:0>'></red>"
|
||||
command.search_recipe.not_found: "<red>No se encontró ninguna receta para este objeto</red>"
|
||||
command.search_usage.not_found: "<red>No se encontró ningún uso para este objeto</red>"
|
||||
command.search_recipe.no_item: "<red>Por favor, sostén un objeto antes de ejecutar este comando</red>"
|
||||
command.search_usage.no_item: "<red>Por favor, sostén un objeto antes de ejecutar este comando</red>"
|
||||
@@ -51,3 +51,5 @@ command.item.give.success.multiple: "<lang:commands.give.success.multiple:'<arg:
|
||||
command.item.give.failure.not_exist: "<red><lang:argument.item.id.invalid:'<arg:0>'></red>"
|
||||
command.item.recipe.browser.recipe.no_found: "<red>找不到此物品的配方</red>"
|
||||
command.item.usage.browser.recipe.no_found: "<red>找不到此物品的用法</red>"
|
||||
command.search_recipe.no_item: "<red>请手持物品后再执行此命令</red>"
|
||||
command.search_usage.no_item: "<red>请手持物品后再执行此命令</red>"
|
||||
@@ -49,5 +49,7 @@ command.item.get.failure.not_exist: "<red><lang:argument.item.id.invalid:'<arg:0
|
||||
command.item.give.success.single: "<lang:commands.give.success.single:'<arg:0>':'<arg:1>':'<arg:2>'>"
|
||||
command.item.give.success.multiple: "<lang:commands.give.success.multiple:'<arg:0>':'<arg:1>':'<arg:2>'>"
|
||||
command.item.give.failure.not_exist: "<red><lang:argument.item.id.invalid:'<arg:0>'></red>"
|
||||
command.item.recipe.browser.recipe.no_found: "<red>找不到此物品的配方</red>"
|
||||
command.item.usage.browser.recipe.no_found: "<red>找不到此物品的用法</red>"
|
||||
command.search_recipe.not_found: "<red>找不到此物品的配方</red>"
|
||||
command.search_usage.not_found: "<red>找不到此物品的用途</red>"
|
||||
command.search_recipe.no_item: "<red>執行此命令前請手持物品</red>"
|
||||
command.search_usage.no_item: "<red>執行此命令前請手持物品</red>"
|
||||
@@ -31,11 +31,12 @@ public class BukkitCommandManager extends AbstractCommandManager<CommandSender>
|
||||
new ReloadCommand(this, plugin),
|
||||
new GetItemCommand(this, plugin),
|
||||
new GiveItemCommand(this, plugin),
|
||||
new ItemBrowserCommand(this, plugin),
|
||||
new ItemRecipeBrowserPlayerCommand(this, plugin),
|
||||
new ItemUsageBrowserPlayerCommand(this, plugin),
|
||||
new ItemRecipeBrowserAdminCommand(this, plugin),
|
||||
new ItemUsageBrowserAdminCommand(this, plugin),
|
||||
new ItemBrowserPlayerCommand(this, plugin),
|
||||
new ItemBrowserAdminCommand(this, plugin),
|
||||
new SearchRecipePlayerCommand(this, plugin),
|
||||
new SearchUsagePlayerCommand(this, plugin),
|
||||
new SearchRecipeAdminCommand(this, plugin),
|
||||
new SearchUsageAdminCommand(this, plugin),
|
||||
new TestCommand(this, plugin),
|
||||
new DebugGetBlockStateRegistryIdCommand(this, plugin),
|
||||
new DebugGetBlockInternalIdCommand(this, plugin),
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
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.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bukkit.data.MultiplePlayerSelector;
|
||||
import org.incendo.cloud.bukkit.parser.selector.MultiplePlayerSelectorParser;
|
||||
|
||||
public class ItemBrowserAdminCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
public ItemBrowserAdminCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
|
||||
super(commandManager, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command.Builder<? extends CommandSender> assembleCommand(org.incendo.cloud.CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) {
|
||||
return builder
|
||||
.required("players", MultiplePlayerSelectorParser.multiplePlayerSelectorParser(true))
|
||||
.handler(context -> {
|
||||
MultiplePlayerSelector selector = context.get("players");
|
||||
for (Player player : selector.values()) {
|
||||
BukkitServerPlayer serverPlayer = plugin().adapt(player);
|
||||
plugin().itemBrowserManager().open(serverPlayer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeatureID() {
|
||||
return "item_browser_admin";
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,9 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.Command;
|
||||
|
||||
public class ItemBrowserCommand extends BukkitCommandFeature<CommandSender> {
|
||||
public class ItemBrowserPlayerCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
public ItemBrowserCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
|
||||
public ItemBrowserPlayerCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
|
||||
super(commandManager, plugin);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,6 @@ public class ItemBrowserCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
@Override
|
||||
public String getFeatureID() {
|
||||
return "item_browser";
|
||||
return "item_browser_player";
|
||||
}
|
||||
}
|
||||
@@ -25,9 +25,9 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ItemRecipeBrowserAdminCommand extends BukkitCommandFeature<CommandSender> {
|
||||
public class SearchRecipeAdminCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
public ItemRecipeBrowserAdminCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
|
||||
public SearchRecipeAdminCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
|
||||
super(commandManager, plugin);
|
||||
}
|
||||
|
||||
@@ -44,15 +44,13 @@ public class ItemRecipeBrowserAdminCommand extends BukkitCommandFeature<CommandS
|
||||
.handler(context -> {
|
||||
MultiplePlayerSelector selector = context.get("player");
|
||||
Collection<Player> players = selector.values();
|
||||
NamespacedKey namespacedKey = context.get("id");
|
||||
for (Player player : players) {
|
||||
BukkitServerPlayer serverPlayer = plugin().adapt(player);
|
||||
NamespacedKey namespacedKey = context.get("id");
|
||||
Key itemId = Key.of(namespacedKey.namespace(), namespacedKey.value());
|
||||
List<Recipe<Object>> inRecipes = plugin().recipeManager().getRecipeByResult(itemId);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0, false);
|
||||
} else {
|
||||
handleFeedback(context, MessageConstants.COMMAND_ITEM_RECIPE_BROWSER_RECIPE_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -60,6 +58,6 @@ public class ItemRecipeBrowserAdminCommand extends BukkitCommandFeature<CommandS
|
||||
|
||||
@Override
|
||||
public String getFeatureID() {
|
||||
return "item_recipe_browser_admin";
|
||||
return "search_recipe_admin";
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ 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.entity.player.InteractionHand;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.recipe.Recipe;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
|
||||
@@ -22,9 +24,9 @@ import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ItemRecipeBrowserPlayerCommand extends BukkitCommandFeature<CommandSender> {
|
||||
public class SearchRecipePlayerCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
public ItemRecipeBrowserPlayerCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
|
||||
public SearchRecipePlayerCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
|
||||
super(commandManager, plugin);
|
||||
}
|
||||
|
||||
@@ -32,28 +34,26 @@ public class ItemRecipeBrowserPlayerCommand extends BukkitCommandFeature<Command
|
||||
public Command.Builder<? extends CommandSender> assembleCommand(CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) {
|
||||
return builder
|
||||
.senderType(Player.class)
|
||||
.required("id", NamespacedKeyParser.namespacedKeyComponent().suggestionProvider(new SuggestionProvider<>() {
|
||||
@Override
|
||||
public @NonNull CompletableFuture<? extends @NonNull Iterable<? extends @NonNull Suggestion>> suggestionsFuture(@NonNull CommandContext<Object> 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());
|
||||
Item<?> item = serverPlayer.getItemInHand(InteractionHand.MAIN_HAND);
|
||||
if (item == null) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_SEARCH_RECIPE_NO_ITEM);
|
||||
return;
|
||||
}
|
||||
Key itemId = item.id();
|
||||
List<Recipe<Object>> inRecipes = plugin().recipeManager().getRecipeByResult(itemId);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0, false);
|
||||
} else {
|
||||
handleFeedback(context, MessageConstants.COMMAND_ITEM_RECIPE_BROWSER_RECIPE_NOT_FOUND);
|
||||
handleFeedback(context, MessageConstants.COMMAND_SEARCH_RECIPE_NOT_FOUND);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeatureID() {
|
||||
return "item_recipe_browser_player";
|
||||
return "search_recipe_player";
|
||||
}
|
||||
}
|
||||
@@ -25,9 +25,9 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ItemUsageBrowserAdminCommand extends BukkitCommandFeature<CommandSender> {
|
||||
public class SearchUsageAdminCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
public ItemUsageBrowserAdminCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
|
||||
public SearchUsageAdminCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
|
||||
super(commandManager, plugin);
|
||||
}
|
||||
|
||||
@@ -44,15 +44,13 @@ public class ItemUsageBrowserAdminCommand extends BukkitCommandFeature<CommandSe
|
||||
.handler(context -> {
|
||||
MultiplePlayerSelector selector = context.get("player");
|
||||
Collection<Player> players = selector.values();
|
||||
NamespacedKey namespacedKey = context.get("id");
|
||||
for (Player player : players) {
|
||||
BukkitServerPlayer serverPlayer = plugin().adapt(player);
|
||||
NamespacedKey namespacedKey = context.get("id");
|
||||
Key itemId = Key.of(namespacedKey.namespace(), namespacedKey.value());
|
||||
List<Recipe<Object>> inRecipes = plugin().recipeManager().getRecipeByIngredient(itemId);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0, false);
|
||||
} else {
|
||||
handleFeedback(context, MessageConstants.COMMAND_ITEM_USAGE_BROWSER_RECIPE_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -60,6 +58,6 @@ public class ItemUsageBrowserAdminCommand extends BukkitCommandFeature<CommandSe
|
||||
|
||||
@Override
|
||||
public String getFeatureID() {
|
||||
return "item_usage_browser_admin";
|
||||
return "search_usage_admin";
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ 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.entity.player.InteractionHand;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.recipe.Recipe;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
|
||||
@@ -22,9 +24,9 @@ import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ItemUsageBrowserPlayerCommand extends BukkitCommandFeature<CommandSender> {
|
||||
public class SearchUsagePlayerCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
public ItemUsageBrowserPlayerCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
|
||||
public SearchUsagePlayerCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
|
||||
super(commandManager, plugin);
|
||||
}
|
||||
|
||||
@@ -32,28 +34,26 @@ public class ItemUsageBrowserPlayerCommand extends BukkitCommandFeature<CommandS
|
||||
public Command.Builder<? extends CommandSender> assembleCommand(CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) {
|
||||
return builder
|
||||
.senderType(Player.class)
|
||||
.required("id", NamespacedKeyParser.namespacedKeyComponent().suggestionProvider(new SuggestionProvider<>() {
|
||||
@Override
|
||||
public @NonNull CompletableFuture<? extends @NonNull Iterable<? extends @NonNull Suggestion>> suggestionsFuture(@NonNull CommandContext<Object> 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());
|
||||
Item<?> item = serverPlayer.getItemInHand(InteractionHand.MAIN_HAND);
|
||||
if (item == null) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_SEARCH_USAGE_NO_ITEM);
|
||||
return;
|
||||
}
|
||||
Key itemId = item.id();
|
||||
List<Recipe<Object>> inRecipes = plugin().recipeManager().getRecipeByIngredient(itemId);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
plugin().itemBrowserManager().openRecipePage(serverPlayer, null, inRecipes, 0, 0, false);
|
||||
} else {
|
||||
handleFeedback(context, MessageConstants.COMMAND_ITEM_USAGE_BROWSER_RECIPE_NOT_FOUND);
|
||||
handleFeedback(context, MessageConstants.COMMAND_SEARCH_USAGE_NOT_FOUND);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeatureID() {
|
||||
return "item_usage_browser_player";
|
||||
return "search_usage_player";
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@ 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_RECIPE_BROWSER_RECIPE_NOT_FOUND = Component.translatable().key("command.item.recipe.browser.recipe.no_found");
|
||||
TranslatableComponent.Builder COMMAND_ITEM_USAGE_BROWSER_RECIPE_NOT_FOUND = Component.translatable().key("command.item.usage.browser.recipe.no_found");
|
||||
TranslatableComponent.Builder COMMAND_SEARCH_RECIPE_NOT_FOUND = Component.translatable().key("command.search_recipe.not_found");
|
||||
TranslatableComponent.Builder COMMAND_SEARCH_RECIPE_NO_ITEM = Component.translatable().key("command.search_recipe.no_item");
|
||||
TranslatableComponent.Builder COMMAND_SEARCH_USAGE_NOT_FOUND = Component.translatable().key("command.search_usage.not_found");
|
||||
TranslatableComponent.Builder COMMAND_SEARCH_USAGE_NO_ITEM = Component.translatable().key("command.search_usage.no_item");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user