mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-27 10:59:07 +00:00
添加resource指令
This commit is contained in:
@@ -76,6 +76,27 @@ totem_animation:
|
||||
- /craftengine feature totem-animation
|
||||
- /ce feature totem-animation
|
||||
|
||||
enable_resource:
|
||||
enable: true
|
||||
permission: ce.command.admin.resource
|
||||
usage:
|
||||
- /craftengine resource enable
|
||||
- /ce resource enable
|
||||
|
||||
disable_resource:
|
||||
enable: true
|
||||
permission: ce.command.admin.resource
|
||||
usage:
|
||||
- /craftengine resource disable
|
||||
- /ce resource disable
|
||||
|
||||
list_resource:
|
||||
enable: true
|
||||
permission: ce.command.admin.resource
|
||||
usage:
|
||||
- /craftengine resource list
|
||||
- /ce resource list
|
||||
|
||||
# Debug commands
|
||||
debug_set_block:
|
||||
enable: true
|
||||
|
||||
@@ -54,6 +54,11 @@ 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>"
|
||||
command.totem_animation.failure.not_totem: "<red>Item '<arg:0>' is not minecraft:totem_of_undying</red>"
|
||||
command.resource.enable.success: "<white>Enabled resource <arg:0>. Run <click:run_command:/ce reload all><u>/ce reload all</u></click> to apply changes</white>"
|
||||
command.resource.enable.failure.unknown: "<red>Unknown resource <arg:0></red>"
|
||||
command.resource.disable.success: "<white>Disabled resource <arg:0>. Run <click:run_command:/ce reload all><u>/ce reload all</u></click> to apply changes</white>"
|
||||
command.resource.disable.failure.unknown: "<red>Unknown resource <arg:0></red>"
|
||||
command.resource.list: "<white>Enabled resources(<arg:0>): <green><arg:1></green><newline>Disabled resources(<arg:2>): <red><arg:3></red></white>"
|
||||
warning.config.image.duplicated: "<yellow>Issue found in file <arg:0> - Duplicated image '<arg:1>'.</yellow>"
|
||||
warning.config.image.lack_height: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is missing the required 'height' argument.</yellow>"
|
||||
warning.config.image.height_smaller_than_ascent: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' violates the bitmap image rule: 'height' should be no lower than 'ascent'.</yellow>"
|
||||
|
||||
@@ -54,6 +54,11 @@ command.search_usage.not_found: "<red>找不到此物品的用途</red>"
|
||||
command.search_recipe.no_item: "<red>请手持物品后再执行此命令</red>"
|
||||
command.search_usage.no_item: "<red>请手持物品后再执行此命令</red>"
|
||||
command.totem_animation.failure.not_totem: "<red>'<arg:0>' 不是 totem_of_undying 类型</red>"
|
||||
command.resource.enable.success: "<white>已启用 <arg:0>. 执行 <click:run_command:/ce reload all><u>/ce reload all</u></click> 以应用更改</white>"
|
||||
command.resource.enable.failure.unknown: "<red>未知资源 <arg:0></red>"
|
||||
command.resource.disable.success: "<white>已禁用 <arg:0>. 执行 <click:run_command:/ce reload all><u>/ce reload all</u></click> 以应用更改</white>"
|
||||
command.resource.disable.failure.unknown: "<red>未知资源 <arg:0></red>"
|
||||
command.resource.list: "<white>启用的资源(<arg:0>): <green><arg:1></green><newline>禁用的资源(<arg:2>): <red><arg:3></red></white>"
|
||||
warning.config.image.duplicated: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 重复定义</yellow>"
|
||||
warning.config.image.lack_height: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 缺少必要的 'height' 高度参数</yellow>"
|
||||
warning.config.image.height_smaller_than_ascent: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 违反位图规则:'height' 高度值不应小于 'ascent' 基准线高度</yellow>"
|
||||
|
||||
@@ -46,7 +46,10 @@ public class BukkitCommandManager extends AbstractCommandManager<CommandSender>
|
||||
new DebugSetBlockCommand(this, plugin),
|
||||
new DebugSpawnFurnitureCommand(this, plugin),
|
||||
new DebugTargetBlockCommand(this, plugin),
|
||||
new TotemAnimationCommand(this, plugin)
|
||||
new TotemAnimationCommand(this, plugin),
|
||||
new EnableResourceCommand(this, plugin),
|
||||
new DisableResourceCommand(this, plugin),
|
||||
new ListResourceCommand(this, plugin)
|
||||
));
|
||||
final LegacyPaperCommandManager<CommandSender> manager = (LegacyPaperCommandManager<CommandSender>) getCommandManager();
|
||||
manager.settings().set(ManagerSetting.ALLOW_UNSAFE_REGISTRATION, true);
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.command.feature;
|
||||
|
||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
|
||||
import net.momirealms.craftengine.core.plugin.locale.MessageConstants;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class DisableResourceCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
public DisableResourceCommand(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
|
||||
.flag(manager.flagBuilder("silent").withAliases("s"))
|
||||
.required("pack", StringParser.stringComponent(StringParser.StringMode.GREEDY).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().packManager().loadedPacks().stream().filter(Pack::enabled).map(pack -> Suggestion.suggestion(pack.name())).toList());
|
||||
}
|
||||
}))
|
||||
.handler(context -> {
|
||||
String packFolder = context.get("pack");
|
||||
Path path = plugin().dataFolderPath().resolve("resources").resolve(packFolder);
|
||||
if (!Files.exists(path)) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_RESOURCE_DISABLE_FAILURE, Component.text(packFolder));
|
||||
return;
|
||||
}
|
||||
Path packMetaPath = path.resolve("pack.yml");
|
||||
if (!Files.exists(packMetaPath)) {
|
||||
try {
|
||||
Files.createFile(packMetaPath);
|
||||
} catch (IOException e) {
|
||||
plugin().logger().warn("Could not create pack.yml file: " + packMetaPath);
|
||||
return;
|
||||
}
|
||||
}
|
||||
YamlDocument document = plugin().config().loadYamlData(packMetaPath.toFile());
|
||||
document.set("enable", false);
|
||||
try {
|
||||
document.save(packMetaPath.toFile());
|
||||
} catch (IOException e) {
|
||||
plugin().logger().warn("Could not save pack.yml file: " + packMetaPath);
|
||||
return;
|
||||
}
|
||||
handleFeedback(context, MessageConstants.COMMAND_RESOURCE_DISABLE_SUCCESS, Component.text(packFolder));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeatureID() {
|
||||
return "disable_resource";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.command.feature;
|
||||
|
||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
|
||||
import net.momirealms.craftengine.core.plugin.locale.MessageConstants;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class EnableResourceCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
public EnableResourceCommand(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
|
||||
.flag(manager.flagBuilder("silent").withAliases("s"))
|
||||
.required("pack", StringParser.stringComponent(StringParser.StringMode.GREEDY).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().packManager().loadedPacks().stream().filter(pack -> !pack.enabled()).map(pack -> Suggestion.suggestion(pack.name())).toList());
|
||||
}
|
||||
}))
|
||||
.handler(context -> {
|
||||
String packFolder = context.get("pack");
|
||||
Path path = plugin().dataFolderPath().resolve("resources").resolve(packFolder);
|
||||
if (!Files.exists(path)) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_RESOURCE_ENABLE_FAILURE, Component.text(packFolder));
|
||||
return;
|
||||
}
|
||||
Path packMetaPath = path.resolve("pack.yml");
|
||||
if (!Files.exists(packMetaPath)) {
|
||||
try {
|
||||
Files.createFile(packMetaPath);
|
||||
} catch (IOException e) {
|
||||
plugin().logger().warn("Could not create pack.yml file: " + packMetaPath);
|
||||
return;
|
||||
}
|
||||
}
|
||||
YamlDocument document = plugin().config().loadYamlData(packMetaPath.toFile());
|
||||
document.set("enable", true);
|
||||
try {
|
||||
document.save(packMetaPath.toFile());
|
||||
} catch (IOException e) {
|
||||
plugin().logger().warn("Could not save pack.yml file: " + packMetaPath);
|
||||
return;
|
||||
}
|
||||
handleFeedback(context, MessageConstants.COMMAND_RESOURCE_ENABLE_SUCCESS, Component.text(packFolder));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeatureID() {
|
||||
return "enable_resource";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.command.feature;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
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.AdventureHelper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.incendo.cloud.Command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ListResourceCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
public ListResourceCommand(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
|
||||
.handler(context -> {
|
||||
Collection<Pack> packs = plugin().packManager().loadedPacks();
|
||||
List<Pack> enabled = new ArrayList<>();
|
||||
List<Pack> disabled = new ArrayList<>();
|
||||
for (Pack pack : packs) {
|
||||
if (pack.enabled()) {
|
||||
enabled.add(pack);
|
||||
} else {
|
||||
disabled.add(pack);
|
||||
}
|
||||
}
|
||||
handleFeedback(context, MessageConstants.COMMAND_RESOURCE_LIST, Component.text(enabled.size()), Component.empty().children(getChildComponents(enabled)), Component.text(disabled.size()), Component.empty().children(getChildComponents(disabled)));
|
||||
});
|
||||
}
|
||||
|
||||
private List<Component> getChildComponents(List<Pack> disabled) {
|
||||
List<Component> components = new ArrayList<>();
|
||||
for (int i = 0; i < disabled.size(); i++) {
|
||||
Pack pack = disabled.get(i);
|
||||
components.add(getPackComponent(pack));
|
||||
if (i != disabled.size() - 1) {
|
||||
components.add(Component.text(", "));
|
||||
}
|
||||
}
|
||||
if (components.isEmpty()) {
|
||||
return List.of(Component.text("[]"));
|
||||
}
|
||||
return components;
|
||||
}
|
||||
|
||||
private Component getPackComponent(Pack pack) {
|
||||
String description = pack.meta().description();
|
||||
String version = pack.meta().version();
|
||||
String author = pack.meta().author();
|
||||
String text = version == null ? pack.name() : pack.name() + " v" + version;
|
||||
Component base = Component.text("[" + text + "]");
|
||||
if (author != null || description != null) {
|
||||
if (author != null && description != null) {
|
||||
base = base.hoverEvent(HoverEvent.showText(Component.empty().children(List.of(Component.text("by: " + author).color(NamedTextColor.YELLOW), Component.newline(), AdventureHelper.miniMessage().deserialize(description)))));
|
||||
} else if (author != null) {
|
||||
base = base.hoverEvent(HoverEvent.showText(Component.text("by: " + author)));
|
||||
} else {
|
||||
base = base.hoverEvent(HoverEvent.showText(AdventureHelper.miniMessage().deserialize(description)));
|
||||
}
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeatureID() {
|
||||
return "list_resource";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user