diff --git a/bukkit/compatibility/build.gradle.kts b/bukkit/compatibility/build.gradle.kts index e0f9a3b33..11efc6a11 100644 --- a/bukkit/compatibility/build.gradle.kts +++ b/bukkit/compatibility/build.gradle.kts @@ -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 diff --git a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicItemDrop.java b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicItemDrop.java index 73c3040e0..3c15b879b 100644 --- a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicItemDrop.java +++ b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/mythicmobs/MythicItemDrop.java @@ -47,24 +47,23 @@ public class MythicItemDrop extends ItemDrop implements IItemDrop { } int amountInt = MiscUtils.floor(amount + 0.5F); CustomItem 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; + } } } 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 3ea7fa6a2..0444f9b18 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 @@ -65,6 +65,7 @@ public class BukkitCommandManager extends AbstractCommandManager 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), diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/CreateResourceCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/CreateResourceCommand.java new file mode 100644 index 000000000..b688f5b5f --- /dev/null +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/CreateResourceCommand.java @@ -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 { + + public CreateResourceCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { + super(commandManager, plugin); + } + + @Override + public Command.Builder assembleCommand(CommandManager manager, Command.Builder 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"; + } +} diff --git a/common-files/src/main/resources/commands.yml b/common-files/src/main/resources/commands.yml index 26ec2fe89..39db99285 100644 --- a/common-files/src/main/resources/commands.yml +++ b/common-files/src/main/resources/commands.yml @@ -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 diff --git a/common-files/src/main/resources/translations/en.yml b/common-files/src/main/resources/translations/en.yml index a524baa1a..3d2c7f2e4 100644 --- a/common-files/src/main/resources/translations/en.yml +++ b/common-files/src/main/resources/translations/en.yml @@ -85,6 +85,10 @@ command.resource.enable.failure.unknown: "Unknown resource " command.resource.disable.success: "Disabled resource . Run /ce reload all to apply changes" command.resource.disable.failure.unknown: "Unknown resource " command.resource.list: "Enabled resources(): Disabled resources(): " +command.resource.create.success: "Created resource ." +command.resource.create.failure: "Failed to create resource , Error: " +command.resource.create.failure.invalid_namespace: "Failed to create resource , The namespace is invalid." +command.resource.create.exists: "Resource already exists." command.upload.failure.not_supported: "Current hosting method '' doesn't support uploading resource packs." command.upload.on_progress: "Started uploading progress. Check the console for more information." command.send_resource_pack.success.single: "Sent resource pack to ." diff --git a/common-files/src/main/resources/translations/zh_cn.yml b/common-files/src/main/resources/translations/zh_cn.yml index f1f7138c8..114fc2b64 100644 --- a/common-files/src/main/resources/translations/zh_cn.yml +++ b/common-files/src/main/resources/translations/zh_cn.yml @@ -85,6 +85,10 @@ command.resource.enable.failure.unknown: "未知资源 " command.resource.disable.success: "已禁用 . 执行 /ce reload all 以应用更改" command.resource.disable.failure.unknown: "未知资源 " command.resource.list: "启用的资源(): 禁用的资源(): " +command.resource.create.success: "已创建资源 " +command.resource.create.failure: "创建资源 失败, 错误信息: " +command.resource.create.failure.invalid_namespace: "创建资源 失败, 命名空间 不合法" +command.resource.create.exists: "资源 已存在" command.upload.failure.not_supported: "当前托管模式 '' 不支持上传资源包" command.upload.on_progress: "已开始上传进程. 检查控制台以获取详细信息" command.send_resource_pack.success.single: "发送资源包给 " 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 fafd81f68..195989c08 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 @@ -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");