mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-22 16:39:28 +00:00
添加创建资源命令
This commit is contained in:
@@ -8,16 +8,15 @@ repositories {
|
||||
maven("https://repo.infernalsuite.com/repository/maven-snapshots/") // slime world
|
||||
maven("https://repo.momirealms.net/releases/")
|
||||
maven("https://mvn.lumine.io/repository/maven-public/") // model engine mythic mobs
|
||||
maven("https://nexus.phoenixdevt.fr/repository/maven-public/") // mmoitems
|
||||
maven("https://nexus.phoenixdevt.fr/repository/maven-public/") // mmocore
|
||||
maven("https://repo.viaversion.com") // via
|
||||
maven("https://repo.skriptlang.org/releases/") // skript
|
||||
maven("https://nexus.neetgames.com/repository/maven-releases/") // mcmmo
|
||||
maven("https://repo.dmulloy2.net/repository/public/") // mcmmo required
|
||||
maven("https://repo.auxilor.io/repository/maven-public/") // eco
|
||||
maven("https://repo.hiusers.com/releases") // zaphkiel
|
||||
maven("https://jitpack.io") // sxitem slimefun
|
||||
maven("https://repo.hiusers.com/releases")
|
||||
maven("https://jitpack.io")
|
||||
maven("https://repo.codemc.io/repository/maven-public/") // quickshop
|
||||
maven("https://repo.nexomc.com/releases/") // nexo
|
||||
maven("https://repo.opencollab.dev/main/") // geyser
|
||||
maven("https://repo.gtemc.net/releases/")
|
||||
}
|
||||
@@ -33,8 +32,6 @@ dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:${rootProject.properties["paper_version"]}-R0.1-SNAPSHOT")
|
||||
// Netty
|
||||
compileOnly("io.netty:netty-all:${rootProject.properties["netty_version"]}")
|
||||
// NeigeItems
|
||||
compileOnly("pers.neige.neigeitems:NeigeItems:1.21.42")
|
||||
// Placeholder
|
||||
compileOnly("me.clip:placeholderapi:${rootProject.properties["placeholder_api_version"]}")
|
||||
// SlimeWorld
|
||||
@@ -44,11 +41,6 @@ dependencies {
|
||||
// BetterModel
|
||||
compileOnly("io.github.toxicity188:bettermodel:1.14.0")
|
||||
compileOnly("com.mojang:authlib:${rootProject.properties["authlib_version"]}")
|
||||
// MMOItems
|
||||
compileOnly("net.Indyuce:MMOItems-API:6.10.1-SNAPSHOT")
|
||||
compileOnly("io.lumine:MythicLib-dist:1.7.1-SNAPSHOT")
|
||||
// Nexo
|
||||
compileOnly("com.nexomc:nexo:1.13.0")
|
||||
// LuckPerms
|
||||
compileOnly("net.luckperms:api:5.4")
|
||||
// viaversion
|
||||
@@ -68,10 +60,9 @@ dependencies {
|
||||
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.2.038")
|
||||
// MMOCore
|
||||
compileOnly("net.Indyuce:MMOCore-API:1.13.1-SNAPSHOT")
|
||||
compileOnly("io.lumine:MythicLib-dist:1.7.1-SNAPSHOT")
|
||||
// JobsReborn
|
||||
compileOnly("com.github.Zrips:Jobs:v5.2.2.3")
|
||||
// CustomFishing
|
||||
compileOnly("net.momirealms:custom-fishing:2.3.3")
|
||||
// CustomNameplates
|
||||
compileOnly("net.momirealms:custom-nameplates:3.0.33")
|
||||
// eco
|
||||
@@ -81,16 +72,8 @@ dependencies {
|
||||
compileOnly("com.willfp:libreforge:4.58.1")
|
||||
// AureliumSkills
|
||||
compileOnly("com.github.Archy-X:AureliumSkills:Beta1.3.21")
|
||||
// Zaphkiel
|
||||
compileOnly("ink.ptms:ZaphkielAPI:2.1.0")
|
||||
// WorldGuard
|
||||
compileOnly(files("${rootProject.rootDir}/libs/worldguard-bukkit-7.0.14-dist.jar"))
|
||||
// HeadDatabase
|
||||
compileOnly("com.arcaniax:HeadDatabase-API:1.3.2")
|
||||
// SXItem
|
||||
compileOnly("com.github.Saukiya:SX-Item:4.4.6")
|
||||
// Slimefun
|
||||
compileOnly("io.github.Slimefun:Slimefun4:RC-32")
|
||||
// QuickShop
|
||||
compileOnly("com.ghostchu:quickshop-api:6.2.0.10")
|
||||
// Geyser
|
||||
|
||||
@@ -47,24 +47,23 @@ public class MythicItemDrop extends ItemDrop implements IItemDrop {
|
||||
}
|
||||
int amountInt = MiscUtils.floor(amount + 0.5F);
|
||||
CustomItem<ItemStack> customItem = this.customItem.get();
|
||||
if (customItem != null) {
|
||||
ItemStack itemStack = this.customItem.get().buildItemStack(context, amountInt);
|
||||
return adapt(itemStack).amount(amountInt);
|
||||
} else {
|
||||
if (customItem == null) {
|
||||
throw new IllegalArgumentException("Cannot find CraftEngine item " + this.itemId);
|
||||
} else {
|
||||
ItemStack itemStack = customItem.buildItemStack(context, amountInt);
|
||||
return adapt(itemStack).amount(amountInt);
|
||||
}
|
||||
}
|
||||
|
||||
private static AbstractItemStack adapt(ItemStack itemStack) {
|
||||
if (useReflection) {
|
||||
try {
|
||||
return (AbstractItemStack) constructor$BukkitItemStack.newInstance(itemStack);
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("adapt(ItemStack itemStack) error: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (!useReflection) {
|
||||
return BukkitAdapter.adapt(itemStack);
|
||||
}
|
||||
try {
|
||||
return (AbstractItemStack) constructor$BukkitItemStack.newInstance(itemStack);
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("adapt(ItemStack itemStack) error: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ public class BukkitCommandManager extends AbstractCommandManager<CommandSender>
|
||||
new EnableResourceCommand(this, plugin),
|
||||
new DisableResourceCommand(this, plugin),
|
||||
new ListResourceCommand(this, plugin),
|
||||
new CreateResourceCommand(this, plugin),
|
||||
new UploadPackCommand(this, plugin),
|
||||
new SendResourcePackCommand(this, plugin),
|
||||
new DebugSaveDefaultResourcesCommand(this, plugin),
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
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.ResourceLocation;
|
||||
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.FileUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class CreateResourceCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
public CreateResourceCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
|
||||
super(commandManager, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command.Builder<? extends CommandSender> assembleCommand(CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) {
|
||||
return builder
|
||||
.flag(manager.flagBuilder("silent").withAliases("s"))
|
||||
.required("pack", StringParser.stringComponent(StringParser.StringMode.SINGLE))
|
||||
.optional("namespace", StringParser.stringComponent(StringParser.StringMode.SINGLE))
|
||||
.optional("author", StringParser.stringComponent(StringParser.StringMode.SINGLE))
|
||||
.optional("description", StringParser.stringComponent(StringParser.StringMode.QUOTED))
|
||||
.handler(context -> {
|
||||
String packFolder = context.get("pack");
|
||||
Path packPath = plugin().dataFolderPath().resolve("resources").resolve(packFolder);
|
||||
Path configurationPath = packPath.resolve("configuration");
|
||||
Path resourcepackPath = packPath.resolve("resourcepack");
|
||||
Path packMetaPath = packPath.resolve("pack.yml");
|
||||
if (Files.exists(packPath)) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_RESOURCE_CREATE_EXISTS, Component.text(packFolder));
|
||||
return;
|
||||
}
|
||||
String namespace = context.getOrDefault("namespace", packFolder);
|
||||
if (!ResourceLocation.isValidNamespace(namespace)) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_RESOURCE_CREATE_FAILURE_INVALID_NAMESPACE, Component.text(packFolder), Component.text(namespace));
|
||||
return;
|
||||
}
|
||||
String author = context.getOrDefault("author", "CraftEngine");
|
||||
String description = context.getOrDefault("description", "Auto-created by CraftEngine");
|
||||
try {
|
||||
FileUtils.createDirectoriesSafe(packPath);
|
||||
FileUtils.createDirectoriesSafe(configurationPath);
|
||||
FileUtils.createDirectoriesSafe(resourcepackPath.resolve("assets").resolve(namespace));
|
||||
Files.createFile(packMetaPath);
|
||||
YamlDocument document = plugin().config().loadYamlData(packMetaPath);
|
||||
document.set("author", author);
|
||||
document.set("version", "0.0.1");
|
||||
document.set("description", description);
|
||||
document.set("namespace", namespace);
|
||||
document.set("enable", false);
|
||||
document.save(packMetaPath.toFile());
|
||||
} catch (IOException e) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_RESOURCE_CREATE_FAILURE, Component.text(packFolder), Component.text(e.getMessage()));
|
||||
return;
|
||||
}
|
||||
handleFeedback(context, MessageConstants.COMMAND_RESOURCE_CREATE_SUCCESS, Component.text(packFolder));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeatureID() {
|
||||
return "create_resource";
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,13 @@ list_resource:
|
||||
- /craftengine resource list
|
||||
- /ce resource list
|
||||
|
||||
create_resource:
|
||||
enable: true
|
||||
permission: ce.command.admin.resource
|
||||
usage:
|
||||
- /craftengine resource create
|
||||
- /ce resource create
|
||||
|
||||
set_locale:
|
||||
enable: true
|
||||
permission: ce.command.admin.set_locale
|
||||
|
||||
@@ -85,6 +85,10 @@ 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>"
|
||||
command.resource.create.success: "<white>Created resource <arg:0>.</white>"
|
||||
command.resource.create.failure: "<red>Failed to create resource <arg:0>, Error: <arg:1></red>"
|
||||
command.resource.create.failure.invalid_namespace: "<red>Failed to create resource <arg:0>, The namespace <arg:1> is invalid.</red>"
|
||||
command.resource.create.exists: "<red>Resource <arg:0> already exists.</red>"
|
||||
command.upload.failure.not_supported: "<red>Current hosting method '<arg:0>' doesn't support uploading resource packs.</red>"
|
||||
command.upload.on_progress: "<white>Started uploading progress. Check the console for more information.</white>"
|
||||
command.send_resource_pack.success.single: "<white>Sent resource pack to <arg:0>.</white>"
|
||||
|
||||
@@ -85,6 +85,10 @@ 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>"
|
||||
command.resource.create.success: "<white>已创建资源 <arg:0></white>"
|
||||
command.resource.create.failure: "<red>创建资源 <arg:0> 失败, 错误信息: <arg:1></red>"
|
||||
command.resource.create.failure.invalid_namespace: "<red>创建资源 <arg:0> 失败, 命名空间 <arg:1> 不合法</red>"
|
||||
command.resource.create.exists: "<red>资源 <arg:0> 已存在</red>"
|
||||
command.upload.failure.not_supported: "<red>当前托管模式 '<arg:0>' 不支持上传资源包</red>"
|
||||
command.upload.on_progress: "<white>已开始上传进程. 检查控制台以获取详细信息</white>"
|
||||
command.send_resource_pack.success.single: "<white>发送资源包给 <arg:0></white>"
|
||||
|
||||
@@ -26,6 +26,10 @@ public interface MessageConstants {
|
||||
TranslatableComponent.Builder COMMAND_RESOURCE_DISABLE_SUCCESS = Component.translatable().key("command.resource.disable.success");
|
||||
TranslatableComponent.Builder COMMAND_RESOURCE_DISABLE_FAILURE = Component.translatable().key("command.resource.disable.failure.unknown");
|
||||
TranslatableComponent.Builder COMMAND_RESOURCE_LIST = Component.translatable().key("command.resource.list");
|
||||
TranslatableComponent.Builder COMMAND_RESOURCE_CREATE_SUCCESS = Component.translatable().key("command.resource.create.success");
|
||||
TranslatableComponent.Builder COMMAND_RESOURCE_CREATE_FAILURE = Component.translatable().key("command.resource.create.failure");
|
||||
TranslatableComponent.Builder COMMAND_RESOURCE_CREATE_FAILURE_INVALID_NAMESPACE = Component.translatable().key("command.resource.create.failure.invalid_namespace");
|
||||
TranslatableComponent.Builder COMMAND_RESOURCE_CREATE_EXISTS = Component.translatable().key("command.resource.create.exists");
|
||||
TranslatableComponent.Builder COMMAND_UPLOAD_FAILURE_NOT_SUPPORTED = Component.translatable().key("command.upload.failure.not_supported");
|
||||
TranslatableComponent.Builder COMMAND_UPLOAD_ON_PROGRESS = Component.translatable().key("command.upload.on_progress");
|
||||
TranslatableComponent.Builder COMMAND_SEND_RESOURCE_PACK_SUCCESS_SINGLE = Component.translatable().key("command.send_resource_pack.success.single");
|
||||
|
||||
Reference in New Issue
Block a user