From 20382babbbc6b72ffb1db099e6f2b68cb276eb64 Mon Sep 17 00:00:00 2001 From: XiaoMoMi <972454774@qq.com> Date: Sat, 27 Sep 2025 18:59:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/pack/cache/IdAllocator.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/cache/IdAllocator.java b/core/src/main/java/net/momirealms/craftengine/core/pack/cache/IdAllocator.java index 9e6d44b2f..da851ec1d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/cache/IdAllocator.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/cache/IdAllocator.java @@ -49,19 +49,23 @@ public class IdAllocator { * 处理所有待分配的自动ID请求 */ public void processPendingAllocations() { + for (Map.Entry entry : this.cachedIdMap.entrySet()) { + CompletableFuture future = this.pendingAllocations.get(entry.getKey()); + if (future != null) { + int id = entry.getValue(); + if (!isIdAvailable(id)) { + continue; + } + allocateId(id, future); + } + } + for (Map.Entry> entry : this.pendingAllocations.entrySet()) { String name = entry.getKey(); CompletableFuture future = entry.getValue(); if (future.isDone()) { - continue; // 不应该发生的情况 - } - - // 优先尝试使用缓存的ID - Integer cachedId = this.cachedIdMap.get(name); - if (isIdAvailable(cachedId)) { - allocateId(name, cachedId, future); - continue; + continue; // 已经在前面分配过了 } // 分配新的自动ID @@ -71,7 +75,7 @@ public class IdAllocator { continue; } - allocateId(name, newId, future); + allocateId(newId, future); this.cachedIdMap.put(name, newId); } @@ -83,7 +87,7 @@ public class IdAllocator { && !this.occupiedIdSet.get(id); } - private void allocateId(String name, int id, CompletableFuture future) { + private void allocateId(int id, CompletableFuture future) { this.occupiedIdSet.set(id); future.complete(id); }