From 279afcd0bcc34d8e73257c1c6dc3c502e4b44b42 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Tue, 6 May 2025 03:13:19 +0800 Subject: [PATCH 1/7] =?UTF-8?q?fix(core):=20=E4=BF=AE=E5=A4=8D=E9=9D=9E?= =?UTF-8?q?=E6=B3=95=E5=8F=82=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../worldedit/FastAsyncWorldEditDelegate.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java index 1adf0be83..7c45577ae 100644 --- a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java +++ b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java @@ -23,6 +23,7 @@ import net.momirealms.craftengine.core.world.CEWorld; import net.momirealms.craftengine.core.world.ChunkPos; import net.momirealms.craftengine.core.world.chunk.CEChunk; import org.bukkit.Bukkit; +import org.bukkit.block.data.BlockData; import java.io.IOException; import java.util.HashSet; @@ -139,7 +140,13 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent { private void processBlock(int blockX, int blockY, int blockZ, BaseBlock blockState, BaseBlock oldBlockState) throws IOException { int chunkX = blockX >> 4; int chunkZ = blockZ >> 4; - int newStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(blockState.getAsString())); + BlockData blockData; + try { + blockData = Bukkit.createBlockData(blockState.getAsString()); + } catch (IllegalArgumentException e) { + blockData = Bukkit.createBlockData(blockState.getBlockType().id()); + } + int newStateId = BlockStateUtils.blockDataToId(blockData); // int oldStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(oldBlockState.getAsString())); if (BlockStateUtils.isVanillaBlock(newStateId) /* && BlockStateUtils.isVanillaBlock(oldStateId) */) return; From 179f4eb43db6a77184a41a1dc7a36a5b960ecd3a Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Tue, 6 May 2025 03:19:42 +0800 Subject: [PATCH 2/7] =?UTF-8?q?fix(core):=20=E4=BF=AE=E5=A4=8D=E9=9D=9E?= =?UTF-8?q?=E6=B3=95=E5=8F=82=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../worldedit/FastAsyncWorldEditDelegate.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java index 7c45577ae..887f85aa7 100644 --- a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java +++ b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java @@ -27,8 +27,10 @@ import org.bukkit.block.data.BlockData; import java.io.IOException; import java.util.HashSet; +import java.util.Locale; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import static java.util.Objects.requireNonNull; @@ -140,13 +142,18 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent { private void processBlock(int blockX, int blockY, int blockZ, BaseBlock blockState, BaseBlock oldBlockState) throws IOException { int chunkX = blockX >> 4; int chunkZ = blockZ >> 4; - BlockData blockData; - try { - blockData = Bukkit.createBlockData(blockState.getAsString()); - } catch (IllegalArgumentException e) { - blockData = Bukkit.createBlockData(blockState.getBlockType().id()); + String stringBlockState; + if (blockState.getStates().isEmpty()) { + stringBlockState = blockState.getBlockType().id(); + } else { + String properties = blockState.getStates().entrySet().stream() + .map(entry -> entry.getKey().getName() + + "=" + + entry.getValue().toString().toLowerCase(Locale.ROOT)) + .collect(Collectors.joining(",")); + stringBlockState = blockState.getBlockType().id() + "[" + properties + "]"; } - int newStateId = BlockStateUtils.blockDataToId(blockData); + int newStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(stringBlockState)); // int oldStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(oldBlockState.getAsString())); if (BlockStateUtils.isVanillaBlock(newStateId) /* && BlockStateUtils.isVanillaBlock(oldStateId) */) return; From c61f6c7e1ae17336fd8f7c12cab7d6f677146b17 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Tue, 6 May 2025 03:21:26 +0800 Subject: [PATCH 3/7] =?UTF-8?q?fix(core):=20=E4=BF=AE=E5=A4=8D=E9=9D=9E?= =?UTF-8?q?=E6=B3=95=E5=8F=82=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../worldedit/FastAsyncWorldEditDelegate.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java index 887f85aa7..e78c6aa4e 100644 --- a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java +++ b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java @@ -23,7 +23,6 @@ import net.momirealms.craftengine.core.world.CEWorld; import net.momirealms.craftengine.core.world.ChunkPos; import net.momirealms.craftengine.core.world.chunk.CEChunk; import org.bukkit.Bukkit; -import org.bukkit.block.data.BlockData; import java.io.IOException; import java.util.HashSet; @@ -142,18 +141,7 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent { private void processBlock(int blockX, int blockY, int blockZ, BaseBlock blockState, BaseBlock oldBlockState) throws IOException { int chunkX = blockX >> 4; int chunkZ = blockZ >> 4; - String stringBlockState; - if (blockState.getStates().isEmpty()) { - stringBlockState = blockState.getBlockType().id(); - } else { - String properties = blockState.getStates().entrySet().stream() - .map(entry -> entry.getKey().getName() - + "=" - + entry.getValue().toString().toLowerCase(Locale.ROOT)) - .collect(Collectors.joining(",")); - stringBlockState = blockState.getBlockType().id() + "[" + properties + "]"; - } - int newStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(stringBlockState)); + int newStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(getStringBlockState(blockState))); // int oldStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(oldBlockState.getAsString())); if (BlockStateUtils.isVanillaBlock(newStateId) /* && BlockStateUtils.isVanillaBlock(oldStateId) */) return; @@ -178,4 +166,17 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent { CraftEngine.instance().logger().warn("Error when recording FastAsyncWorldEdit operation chunks", e); } } + + private String getStringBlockState(BaseBlock blockState) { + if (blockState.getStates().isEmpty()) { + return blockState.getBlockType().id(); + } else { + String properties = blockState.getStates().entrySet().stream() + .map(entry -> entry.getKey().getName() + + "=" + + entry.getValue().toString().toLowerCase(Locale.ROOT)) + .collect(Collectors.joining(",")); + return blockState.getBlockType().id() + "[" + properties + "]"; + } + } } From 3c9651a1b33ec8101f43a6d8c9908797bf065532 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Tue, 6 May 2025 04:19:20 +0800 Subject: [PATCH 4/7] =?UTF-8?q?fix(core):=20=E4=BF=AE=E5=A4=8D=E9=9D=9E?= =?UTF-8?q?=E6=B3=95=E5=8F=82=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../worldedit/FastAsyncWorldEditDelegate.java | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java index e78c6aa4e..36ef29ada 100644 --- a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java +++ b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java @@ -1,8 +1,10 @@ package net.momirealms.craftengine.bukkit.compatibility.worldedit; +import com.fastasyncworldedit.bukkit.adapter.FaweAdapter; import com.fastasyncworldedit.core.configuration.Settings; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.event.extent.EditSessionEvent; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.function.mask.Mask; @@ -26,14 +28,13 @@ import org.bukkit.Bukkit; import java.io.IOException; import java.util.HashSet; -import java.util.Locale; import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; import static java.util.Objects.requireNonNull; public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent { + private final FaweAdapter adapter = (FaweAdapter) WorldEditPlugin.getInstance().getBukkitImplAdapter(); private final Set chunksToSave; private final CEWorld ceWorld; @@ -141,10 +142,10 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent { private void processBlock(int blockX, int blockY, int blockZ, BaseBlock blockState, BaseBlock oldBlockState) throws IOException { int chunkX = blockX >> 4; int chunkZ = blockZ >> 4; - int newStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(getStringBlockState(blockState))); -// int oldStateId = BlockStateUtils.blockDataToId(Bukkit.createBlockData(oldBlockState.getAsString())); - if (BlockStateUtils.isVanillaBlock(newStateId) /* && BlockStateUtils.isVanillaBlock(oldStateId) */) - return; + int newStateId = BlockStateUtils.blockDataToId(this.adapter.adapt(blockState)); + int oldStateId = BlockStateUtils.blockDataToId(this.adapter.adapt(oldBlockState)); + CraftEngine.instance().debug(() -> "Processing block at " + blockX + ", " + blockY + ", " + blockZ + ": " + oldStateId + " -> " + newStateId); + if (BlockStateUtils.isVanillaBlock(newStateId) && BlockStateUtils.isVanillaBlock(oldStateId)) return; CEChunk ceChunk = Optional.ofNullable(this.ceWorld.getChunkAtIfLoaded(chunkX, chunkZ)) .orElse(this.ceWorld.worldDataStorage().readChunkAt(this.ceWorld, new ChunkPos(chunkX, chunkZ))); ImmutableBlockState immutableBlockState = BukkitBlockManager.instance().getImmutableBlockState(newStateId); @@ -159,6 +160,7 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent { private void saveAllChunks() { try { for (CEChunk ceChunk : this.chunksToSave) { + CraftEngine.instance().debug(() -> "Saving chunk " + ceChunk.chunkPos()); this.ceWorld.worldDataStorage().writeChunkAt(ceChunk.chunkPos(), ceChunk, true); } this.chunksToSave.clear(); @@ -166,17 +168,4 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent { CraftEngine.instance().logger().warn("Error when recording FastAsyncWorldEdit operation chunks", e); } } - - private String getStringBlockState(BaseBlock blockState) { - if (blockState.getStates().isEmpty()) { - return blockState.getBlockType().id(); - } else { - String properties = blockState.getStates().entrySet().stream() - .map(entry -> entry.getKey().getName() - + "=" - + entry.getValue().toString().toLowerCase(Locale.ROOT)) - .collect(Collectors.joining(",")); - return blockState.getBlockType().id() + "[" + properties + "]"; - } - } } From afa3d033dcddc1b6a3c86df82e975bf976b89819 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Tue, 6 May 2025 15:37:22 +0800 Subject: [PATCH 5/7] =?UTF-8?q?refactor(core):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=8C=85=E7=9A=84=E4=B8=80=E4=BA=9B=E4=B8=9C?= =?UTF-8?q?=E8=A5=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bukkit/loader/src/main/resources/config.yml | 2 + .../src/main/resources/translations/en.yml | 4 +- .../src/main/resources/translations/zh_cn.yml | 4 +- .../plugin/command/feature/ReloadCommand.java | 8 +++- .../plugin/network/PacketConsumers.java | 3 +- .../core/pack/AbstractPackManager.java | 40 ++++++++++++++++++- .../core/pack/host/impl/SelfHost.java | 9 ++++- .../pack/host/impl/SelfHostHttpServer.java | 6 +++ .../core/plugin/network/ProtocolVersion.java | 4 ++ .../core/util/ProtocolVersionUtils.java | 10 ----- gradle.properties | 4 +- 11 files changed, 76 insertions(+), 18 deletions(-) delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/util/ProtocolVersionUtils.java diff --git a/bukkit/loader/src/main/resources/config.yml b/bukkit/loader/src/main/resources/config.yml index da8cf0aa0..c4d0b734f 100644 --- a/bukkit/loader/src/main/resources/config.yml +++ b/bukkit/loader/src/main/resources/config.yml @@ -78,6 +78,8 @@ resource-pack: ip: "localhost" port: 8163 protocol: "http" + # The optional URL must be complete and include a trailing slash / at the end. + #url: "http://localhost:8163/" deny-non-minecraft-request: true one-time-token: true rate-limit: diff --git a/bukkit/loader/src/main/resources/translations/en.yml b/bukkit/loader/src/main/resources/translations/en.yml index 5e545aeb3..77375beb6 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." @@ -292,4 +293,5 @@ warning.config.conflict_matcher.all_of.missing_terms: "Issue found in co 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 ''." -warning.config.function.command.missing_command: "Issue found in file - The config '' is missing the required 'command' argument for 'command' function." \ No newline at end of file +warning.config.function.command.missing_command: "Issue found in file - The config '' is missing the required 'command' argument for 'command' function." +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/command/feature/ReloadCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ReloadCommand.java index 00056ba91..76af5ab13 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ReloadCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ReloadCommand.java @@ -4,6 +4,7 @@ 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.LocalizedException; import net.momirealms.craftengine.core.plugin.locale.MessageConstants; import org.bukkit.command.CommandSender; import org.incendo.cloud.Command; @@ -68,7 +69,9 @@ public class ReloadCommand extends BukkitCommandFeature { long time2 = System.currentTimeMillis(); long packTime = time2 - time1; handleFeedback(context, MessageConstants.COMMAND_RELOAD_PACK_SUCCESS, Component.text(packTime)); - + } catch (LocalizedException e) { + handleFeedback(context, MessageConstants.COMMAND_RELOAD_PACK_FAILURE); + plugin().logger().warn(e.getMessage()); } catch (Exception e) { handleFeedback(context, MessageConstants.COMMAND_RELOAD_PACK_FAILURE); plugin().logger().warn("Failed to generate resource pack", e); @@ -89,6 +92,9 @@ public class ReloadCommand extends BukkitCommandFeature { Component.text(reloadResult.syncTime()), Component.text(packTime) ); + } catch (LocalizedException e) { + handleFeedback(context, MessageConstants.COMMAND_RELOAD_PACK_FAILURE); + plugin().logger().warn(e.getMessage()); } finally { RELOAD_PACK_FLAG = false; } 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 c611b7049..1651cf099 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 @@ -34,6 +34,7 @@ import net.momirealms.craftengine.core.plugin.config.Config; import net.momirealms.craftengine.core.plugin.network.ConnectionState; import net.momirealms.craftengine.core.plugin.network.NetWorkUser; import net.momirealms.craftengine.core.plugin.network.NetworkManager; +import net.momirealms.craftengine.core.plugin.network.ProtocolVersion; import net.momirealms.craftengine.core.util.*; import net.momirealms.craftengine.core.world.BlockHitResult; import net.momirealms.craftengine.core.world.BlockPos; @@ -1348,7 +1349,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 (VersionHelper.isOrAbove1_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..448873dca 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 @@ -44,6 +44,7 @@ import java.util.*; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Predicate; +import java.util.stream.Stream; import static net.momirealms.craftengine.core.util.MiscUtils.castToMap; @@ -73,6 +74,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; @@ -141,6 +143,7 @@ public abstract class AbstractPackManager implements PackManager { @Override public void load() { + initFileSystemProvider(); List> list = Config.instance().settings().getMapList("resource-pack.delivery.hosting"); if (list == null || list.isEmpty()) { this.resourcePackHost = NoneHost.INSTANCE; @@ -484,8 +487,42 @@ public abstract class AbstractPackManager implements PackManager { } } + private static void initFileSystemProvider() { + String osName = System.getProperty("os.name").toLowerCase(); + String providerClass = null; + if (osName.contains("win")) { + providerClass = "sun.nio.fs.WindowsFileSystemProvider"; + } else if (osName.contains("nix") || osName.contains("nux") || osName.contains("aix")) { + providerClass = "sun.nio.fs.LinuxFileSystemProvider"; + } else if (osName.contains("mac")) { + providerClass = "sun.nio.fs.MacOSXFileSystemProvider"; + } + if (providerClass != null) { + try { + System.setProperty("java.nio.file.spi.DefaultFileSystemProvider", providerClass); + } catch (Exception ignored) {} + } + } + + private static void deleteDirectory(Path folder) throws IOException { + if (!Files.exists(folder)) return; + try (Stream walk = Files.walk(folder)) { + walk.sorted(Comparator.reverseOrder()) + .parallel() + .forEach(path -> { + try { + Files.delete(path); + } catch (IOException ignored) {} + }); + } + } + @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 @@ -494,7 +531,7 @@ public abstract class AbstractPackManager implements PackManager { .resolve("resource_pack"); try { - org.apache.commons.io.FileUtils.deleteDirectory(generatedPackPath.toFile()); + deleteDirectory(generatedPackPath); } catch (IOException e) { this.plugin.logger().severe("Error deleting previous resource pack", e); } @@ -547,6 +584,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 de38d7771..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,6 +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.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); @@ -76,7 +83,7 @@ public class SelfHost implements ResourcePackHost { maxRequests = ResourceConfigUtils.getAsInt(rateMap.getOrDefault("max-requests", 5), "max-requests"); resetInterval = ResourceConfigUtils.getAsInt(rateMap.getOrDefault("reset-interval", 20), "reset-interval") * 1000; } - selfHostHttpServer.updateProperties(ip, port, denyNonMinecraftRequest, protocol, maxRequests, resetInterval, oneTimeToken); + selfHostHttpServer.updateProperties(ip, port, url, denyNonMinecraftRequest, protocol, maxRequests, resetInterval, oneTimeToken); return INSTANCE; } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHostHttpServer.java b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHostHttpServer.java index 6ce927583..785a00c6d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHostHttpServer.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/SelfHostHttpServer.java @@ -48,6 +48,7 @@ public class SelfHostHttpServer { private String ip = "localhost"; private int port = -1; private String protocol = "http"; + private String url; private boolean denyNonMinecraft = true; private boolean useToken; @@ -57,12 +58,14 @@ public class SelfHostHttpServer { public void updateProperties(String ip, int port, + String url, boolean denyNonMinecraft, String protocol, int maxRequests, int resetInternal, boolean token) { this.ip = ip; + this.url = url; this.denyNonMinecraft = denyNonMinecraft; this.protocol = protocol; this.rateLimit = maxRequests; @@ -112,6 +115,9 @@ public class SelfHostHttpServer { } public String url() { + if (this.url != null && !this.url.isEmpty()) { + return this.url; + } return this.protocol + "://" + this.ip + ":" + this.port + "/"; } 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 788fe5770..4c60323b6 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=11 +lang_version=12 project_group=net.momirealms latest_supported_version=1.21.5 @@ -40,7 +40,7 @@ geantyref_version=1.3.16 zstd_version=1.5.7-2 commons_io_version=2.18.0 sparrow_nbt_version=0.7.3 -sparrow_util_version=0.39 +sparrow_util_version=0.40 fastutil_version=8.5.15 netty_version=4.1.119.Final joml_version=1.10.8 From 066f42f1f48c62a6bec9d3cbd39c4937f47dd234 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Tue, 6 May 2025 15:41:04 +0800 Subject: [PATCH 6/7] =?UTF-8?q?refactor(core):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=8C=85=E7=9A=84=E4=B8=80=E4=BA=9B=E4=B8=9C?= =?UTF-8?q?=E8=A5=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bukkit/loader/src/main/resources/translations/en.yml | 4 ++-- bukkit/loader/src/main/resources/translations/zh_cn.yml | 4 ++-- .../momirealms/craftengine/core/pack/AbstractPackManager.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bukkit/loader/src/main/resources/translations/en.yml b/bukkit/loader/src/main/resources/translations/en.yml index 77375beb6..1f496412f 100644 --- a/bukkit/loader/src/main/resources/translations/en.yml +++ b/bukkit/loader/src/main/resources/translations/en.yml @@ -64,6 +64,7 @@ command.upload.failure.not_supported: "Current hosting method '' doe command.upload.on_progress: "Started uploading progress. Check the console for more information." command.send_resource_pack.success.single: "Sent resource pack to ." command.send_resource_pack.success.multiple: "Send resource packs to players." +command.resource_pack.generation_in_progress: "Resource pack generation is already in progress. Please wait until it finishes." warning.config.pack.duplicated_files: "Duplicated files Found. Please resolve them through config.yml 'resource-pack.duplicated-files-handler' section." warning.config.type.int: "Issue found in file - Failed to load '': Cannot cast '' to integer type for option ''." warning.config.type.float: "Issue found in file - Failed to load '': Cannot cast '' to float type for option ''." @@ -293,5 +294,4 @@ warning.config.conflict_matcher.all_of.missing_terms: "Issue found in co 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 ''." -warning.config.function.command.missing_command: "Issue found in file - The config '' is missing the required 'command' argument for 'command' function." -warning.resource_pack.generation_in_progress: "Resource pack generation is already in progress. Please wait until it finishes." \ No newline at end of file +warning.config.function.command.missing_command: "Issue found in file - The config '' is missing the required 'command' argument for 'command' function." \ 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 1a1152fc3..09b3238ad 100644 --- a/bukkit/loader/src/main/resources/translations/zh_cn.yml +++ b/bukkit/loader/src/main/resources/translations/zh_cn.yml @@ -64,6 +64,7 @@ command.upload.failure.not_supported: "当前托管模式 '' 不支 command.upload.on_progress: "已开始上传进程. 检查控制台以获取详细信息." command.send_resource_pack.success.single: "发送资源包给 " command.send_resource_pack.success.multiple: "发送资源包给 个玩家" +command.resource_pack.generation_in_progress: "资源包正在生成中, 请等待完成再试" warning.config.pack.duplicated_files: "发现重复文件 请通过 config.yml 的 'resource-pack.duplicated-files-handler' 部分解决" warning.config.type.int: "在文件 发现问题 - 无法加载 '': 无法将 '' 转换为整数类型 (选项 '')" warning.config.type.float: "在文件 发现问题 - 无法加载 '': 无法将 '' 转换为浮点数类型 (选项 '')" @@ -294,5 +295,4 @@ 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' 处发现问题 - 文件冲突处理器的某个解决方案使用了无效类型 ''" -warning.resource_pack.generation_in_progress: "资源包正在生成中, 请等待完成再试" \ No newline at end of file +warning.config.conflict_resolution.invalid_type: "在 config.yml 的 'resource-pack.duplicated-files-handler' 处发现问题 - 文件冲突处理器的某个解决方案使用了无效类型 ''" \ No newline at end of file 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 448873dca..516939c20 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 @@ -520,7 +520,7 @@ public abstract class AbstractPackManager implements PackManager { @Override public void generateResourcePack() { if (this.generateResourcePack) { - throw new LocalizedException("warning.resource_pack.generation_in_progress"); + throw new LocalizedException("command.resource_pack.generation_in_progress"); } this.generateResourcePack = true; this.plugin.logger().info("Generating resource pack..."); From 6fe8f31f7ccc3837c0fbe8b01657bfdb04c26aec Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Tue, 6 May 2025 15:42:59 +0800 Subject: [PATCH 7/7] =?UTF-8?q?refactor(core):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=8C=85=E7=9A=84=E4=B8=80=E4=BA=9B=E4=B8=9C?= =?UTF-8?q?=E8=A5=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bukkit/loader/src/main/resources/translations/en.yml | 1 - bukkit/loader/src/main/resources/translations/zh_cn.yml | 1 - .../bukkit/plugin/command/feature/ReloadCommand.java | 6 ------ .../craftengine/core/pack/AbstractPackManager.java | 6 ------ 4 files changed, 14 deletions(-) diff --git a/bukkit/loader/src/main/resources/translations/en.yml b/bukkit/loader/src/main/resources/translations/en.yml index 1f496412f..96cd97723 100644 --- a/bukkit/loader/src/main/resources/translations/en.yml +++ b/bukkit/loader/src/main/resources/translations/en.yml @@ -64,7 +64,6 @@ command.upload.failure.not_supported: "Current hosting method '' doe command.upload.on_progress: "Started uploading progress. Check the console for more information." command.send_resource_pack.success.single: "Sent resource pack to ." command.send_resource_pack.success.multiple: "Send resource packs to players." -command.resource_pack.generation_in_progress: "Resource pack generation is already in progress. Please wait until it finishes." warning.config.pack.duplicated_files: "Duplicated files Found. Please resolve them through config.yml 'resource-pack.duplicated-files-handler' section." warning.config.type.int: "Issue found in file - Failed to load '': Cannot cast '' to integer type for option ''." warning.config.type.float: "Issue found in file - Failed to load '': Cannot cast '' to float type for option ''." diff --git a/bukkit/loader/src/main/resources/translations/zh_cn.yml b/bukkit/loader/src/main/resources/translations/zh_cn.yml index 09b3238ad..f191e0076 100644 --- a/bukkit/loader/src/main/resources/translations/zh_cn.yml +++ b/bukkit/loader/src/main/resources/translations/zh_cn.yml @@ -64,7 +64,6 @@ command.upload.failure.not_supported: "当前托管模式 '' 不支 command.upload.on_progress: "已开始上传进程. 检查控制台以获取详细信息." command.send_resource_pack.success.single: "发送资源包给 " command.send_resource_pack.success.multiple: "发送资源包给 个玩家" -command.resource_pack.generation_in_progress: "资源包正在生成中, 请等待完成再试" warning.config.pack.duplicated_files: "发现重复文件 请通过 config.yml 的 'resource-pack.duplicated-files-handler' 部分解决" warning.config.type.int: "在文件 发现问题 - 无法加载 '': 无法将 '' 转换为整数类型 (选项 '')" warning.config.type.float: "在文件 发现问题 - 无法加载 '': 无法将 '' 转换为浮点数类型 (选项 '')" diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ReloadCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ReloadCommand.java index 76af5ab13..b1ee0e30d 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ReloadCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ReloadCommand.java @@ -69,9 +69,6 @@ public class ReloadCommand extends BukkitCommandFeature { long time2 = System.currentTimeMillis(); long packTime = time2 - time1; handleFeedback(context, MessageConstants.COMMAND_RELOAD_PACK_SUCCESS, Component.text(packTime)); - } catch (LocalizedException e) { - handleFeedback(context, MessageConstants.COMMAND_RELOAD_PACK_FAILURE); - plugin().logger().warn(e.getMessage()); } catch (Exception e) { handleFeedback(context, MessageConstants.COMMAND_RELOAD_PACK_FAILURE); plugin().logger().warn("Failed to generate resource pack", e); @@ -92,9 +89,6 @@ public class ReloadCommand extends BukkitCommandFeature { Component.text(reloadResult.syncTime()), Component.text(packTime) ); - } catch (LocalizedException e) { - handleFeedback(context, MessageConstants.COMMAND_RELOAD_PACK_FAILURE); - plugin().logger().warn(e.getMessage()); } finally { RELOAD_PACK_FLAG = false; } 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 516939c20..b582cb7d9 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 @@ -74,7 +74,6 @@ 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; @@ -519,10 +518,6 @@ public abstract class AbstractPackManager implements PackManager { @Override public void generateResourcePack() { - if (this.generateResourcePack) { - throw new LocalizedException("command.resource_pack.generation_in_progress"); - } - this.generateResourcePack = true; this.plugin.logger().info("Generating resource pack..."); long start = System.currentTimeMillis(); // get the target location @@ -584,7 +579,6 @@ 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) {