From 99e2d5cd36b48efbc1f3a66b7cb84cca1f0d64ef Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Mon, 5 May 2025 09:02:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(core):=20=E4=B8=80=E4=BA=9B=E5=AF=B9?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=8C=85=E6=89=98=E7=AE=A1=E5=92=8C=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E5=8C=85=E7=94=9F=E6=88=90=E7=9A=84=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bukkit/loader/src/main/resources/translations/en.yml | 4 +++- .../loader/src/main/resources/translations/zh_cn.yml | 4 +++- .../bukkit/plugin/network/PacketConsumers.java | 2 +- .../craftengine/core/pack/AbstractPackManager.java | 6 ++++++ .../craftengine/core/pack/host/impl/SelfHost.java | 8 +++++++- .../core/plugin/network/ProtocolVersion.java | 4 ++++ .../craftengine/core/util/ProtocolVersionUtils.java | 10 ---------- gradle.properties | 2 +- 8 files changed, 25 insertions(+), 15 deletions(-) delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/util/ProtocolVersionUtils.java diff --git a/bukkit/loader/src/main/resources/translations/en.yml b/bukkit/loader/src/main/resources/translations/en.yml index 6011167dd..eae6aee64 100644 --- a/bukkit/loader/src/main/resources/translations/en.yml +++ b/bukkit/loader/src/main/resources/translations/en.yml @@ -272,6 +272,7 @@ warning.config.host.s3.missing_secret: "Issue found in config.yml at 're warning.config.host.s3.missing_upload_path: "Issue found in config.yml at 'resource-pack.delivery.hosting' - Missing required 'upload-path' argument for s3 host." warning.config.host.self.missing_ip: "Issue found in config.yml at 'resource-pack.delivery.hosting' - Missing required 'ip' argument for self host." warning.config.host.self.invalid_port: "Issue found in config.yml at 'resource-pack.delivery.hosting' - Invalid port '' for self host." +warning.config.host.self.invalid_url: "Issue found in config.yml at 'resource-pack.delivery.hosting' - Invalid url '' for self host." warning.config.host.gitlab.missing_url: "Issue found in config.yml at 'resource-pack.delivery.hosting' - Missing required 'gitlab-url' argument for gitlab host." warning.config.host.gitlab.missing_token: "Issue found in config.yml at 'resource-pack.delivery.hosting' - Missing required 'access-token' argument for gitlab host." warning.config.host.gitlab.missing_project: "Issue found in config.yml at 'resource-pack.delivery.hosting' - Missing required 'project-id' argument for gitlab host." @@ -291,4 +292,5 @@ warning.config.conflict_matcher.inverted.missing_term: "Issue found in c warning.config.conflict_matcher.all_of.missing_terms: "Issue found in config.yml at 'resource-pack.duplicated-files-handler' - Missing required 'terms' argument for 'all_of' matcher." warning.config.conflict_matcher.any_of.missing_terms: "Issue found in config.yml at 'resource-pack.duplicated-files-handler' - Missing required 'terms' argument for 'any_of' matcher." warning.config.conflict_resolution.missing_type: "Issue found in config.yml at 'resource-pack.duplicated-files-handler' - Missing required 'type' argument for one of the resolutions." -warning.config.conflict_resolution.invalid_type: "Issue found in config.yml at 'resource-pack.duplicated-files-handler' - One of the resolutions is using the invalid type ''." \ No newline at end of file +warning.config.conflict_resolution.invalid_type: "Issue found in config.yml at 'resource-pack.duplicated-files-handler' - One of the resolutions is using the invalid type ''." +warning.resource_pack.generation_in_progress: "Resource pack generation is already in progress. Please wait until it finishes." \ 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 d2dd13dd8..1a1152fc3 100644 --- a/bukkit/loader/src/main/resources/translations/zh_cn.yml +++ b/bukkit/loader/src/main/resources/translations/zh_cn.yml @@ -274,6 +274,7 @@ warning.config.host.s3.missing_secret: "在 config.yml 的 'resource-pac warning.config.host.s3.missing_upload_path: "在 config.yml 的 'resource-pack.delivery.hosting' 处发现问题 - S3 托管缺少必需的 'upload-path' 参数" warning.config.host.self.missing_ip: "在 config.yml 的 'resource-pack.delivery.hosting' 处发现问题 - 自托管托管缺少必需的 'ip' 参数" warning.config.host.self.invalid_port: "在 config.yml 的 'resource-pack.delivery.hosting' 处发现问题 - 自托管托管的端口 '' 无效" +warning.config.host.self.invalid_url: "在 config.yml 的 'resource-pack.delivery.hosting' 处发现问题 - 自托管托管的 URL '' 无效" warning.config.host.gitlab.missing_url: "在 config.yml 的 'resource-pack.delivery.hosting' 处发现问题 - GitLab 托管缺少必需的 'gitlab-url' 参数" warning.config.host.gitlab.missing_token: "在 config.yml 的 'resource-pack.delivery.hosting' 处发现问题 - GitLab 托管缺少必需的 'access-token' 参数" warning.config.host.gitlab.missing_project: "在 config.yml 的 'resource-pack.delivery.hosting' 处发现问题 - GitLab 托管缺少必需的 'project-id' 参数" @@ -293,4 +294,5 @@ warning.config.conflict_matcher.inverted.missing_term: "在 config.yml warning.config.conflict_matcher.all_of.missing_terms: "在 config.yml 的 'resource-pack.duplicated-files-handler' 处发现问题 - 全匹配器缺少必需的 'terms' 参数" warning.config.conflict_matcher.any_of.missing_terms: "在 config.yml 的 'resource-pack.duplicated-files-handler' 处发现问题 - 任一匹配器缺少必需的 'terms' 参数" warning.config.conflict_resolution.missing_type: "在 config.yml 的 'resource-pack.duplicated-files-handler' 处发现问题 - 文件冲突处理器的某个解决方案缺少必需的 'type' 参数" -warning.config.conflict_resolution.invalid_type: "在 config.yml 的 'resource-pack.duplicated-files-handler' 处发现问题 - 文件冲突处理器的某个解决方案使用了无效类型 ''" \ No newline at end of file +warning.config.conflict_resolution.invalid_type: "在 config.yml 的 'resource-pack.duplicated-files-handler' 处发现问题 - 文件冲突处理器的某个解决方案使用了无效类型 ''" +warning.resource_pack.generation_in_progress: "资源包正在生成中, 请等待完成再试" \ No newline at end of file diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java index 08578f7dc..9858ea30a 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java @@ -1354,7 +1354,7 @@ public class PacketConsumers { // When the hotbar is full, the latest creative mode inventory can only be accessed when the player opens the inventory screen. Currently, it is not worth further handling this issue. public static final TriConsumer SET_CREATIVE_SLOT = (user, event, packet) -> { try { - if (ProtocolVersionUtils.isVersionNewerThan(user.protocolVersion(), ProtocolVersion.V1_21_4)) return; + if (user.protocolVersion().isVersionNewerThan(ProtocolVersion.V1_21_4)) return; if (!user.isOnline()) return; BukkitServerPlayer player = (BukkitServerPlayer) user; if (VersionHelper.isFolia()) { 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 ff722cd59..43529efe4 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 @@ -73,6 +73,7 @@ public abstract class AbstractPackManager implements PackManager { private final TreeMap> cachedConfigs = new TreeMap<>(); protected BiConsumer zipGenerator; protected ResourcePackHost resourcePackHost; + private boolean generateResourcePack = false; public AbstractPackManager(CraftEngine plugin, BiConsumer eventDispatcher) { this.plugin = plugin; @@ -486,6 +487,10 @@ public abstract class AbstractPackManager implements PackManager { @Override public void generateResourcePack() { + if (this.generateResourcePack) { + throw new LocalizedException("warning.resource_pack.generation_in_progress"); + } + this.generateResourcePack = true; this.plugin.logger().info("Generating resource pack..."); long start = System.currentTimeMillis(); // get the target location @@ -547,6 +552,7 @@ public abstract class AbstractPackManager implements PackManager { long end = System.currentTimeMillis(); this.plugin.logger().info("Finished generating resource pack in " + (end - start) + "ms"); this.eventDispatcher.accept(generatedPackPath, zipFile); + this.generateResourcePack = false; } private void generateParticle(Path generatedPackPath) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHost.java b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHost.java index 4a8fa9a9b..acfdd0800 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHost.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHost.java @@ -66,7 +66,13 @@ public class SelfHost implements ResourcePackHost { if (port <= 0 || port > 65535) { throw new LocalizedException("warning.config.host.self.invalid_port", String.valueOf(port)); } - String url = arguments.get("url").toString(); + String url = arguments.getOrDefault("url", "").toString(); + if (!url.isEmpty()) { + if (!url.startsWith("http://") && !url.startsWith("https://")) { + throw new LocalizedException("warning.config.host.self.invalid_url", url); + } + if (!url.endsWith("/")) url += "/"; + } boolean oneTimeToken = (boolean) arguments.getOrDefault("one-time-token", true); String protocol = arguments.getOrDefault("protocol", "http").toString(); boolean denyNonMinecraftRequest = (boolean) arguments.getOrDefault("deny-non-minecraft-request", true); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/network/ProtocolVersion.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/network/ProtocolVersion.java index c692c6da6..f9e3c4b05 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/network/ProtocolVersion.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/network/ProtocolVersion.java @@ -32,6 +32,10 @@ public enum ProtocolVersion { return name; } + public boolean isVersionNewerThan(ProtocolVersion targetVersion) { + return this.getId() >= targetVersion.getId(); + } + public static ProtocolVersion getByName(String name) { for (ProtocolVersion version : values()) { if (version.getName().equals(name)) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/ProtocolVersionUtils.java b/core/src/main/java/net/momirealms/craftengine/core/util/ProtocolVersionUtils.java deleted file mode 100644 index 8372e1117..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/util/ProtocolVersionUtils.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.momirealms.craftengine.core.util; - -import net.momirealms.craftengine.core.plugin.network.ProtocolVersion; - -public class ProtocolVersionUtils { - - public static boolean isVersionNewerThan(ProtocolVersion version, ProtocolVersion targetVersion) { - return version.getId() >= targetVersion.getId(); - } -} diff --git a/gradle.properties b/gradle.properties index 833e03059..962420ca7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G # Rule: [major update].[feature update].[bug fix] project_version=0.0.53-beta.3 config_version=31 -lang_version=10 +lang_version=11 project_group=net.momirealms latest_supported_version=1.21.5