9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-30 20:39:10 +00:00

修复team

This commit is contained in:
XiaoMoMi
2025-05-04 15:36:08 +08:00
parent 11642aa1ad
commit 5e28d964be
2 changed files with 18 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.plugin.network;
import com.mojang.datafixers.util.Either;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import it.unimi.dsi.fastutil.ints.IntList;
@@ -331,8 +332,17 @@ public class PacketConsumers {
Tag displayName = buf.readNbt(false);
if (displayName == null) return;
byte friendlyFlags = buf.readByte();
String nameTagVisibility = buf.readUtf(40);
String collisionRule = buf.readUtf(40);
Either<String, Integer> eitherVisibility;
Either<String, Integer> eitherCollisionRule;
if (VersionHelper.isOrAbove1_21_5()) {
eitherVisibility = Either.right(buf.readVarInt());
eitherCollisionRule = Either.right(buf.readVarInt());
} else {
eitherVisibility = Either.left(buf.readUtf(40));
eitherCollisionRule = Either.left(buf.readUtf(40));
}
int color = buf.readVarInt();
Tag prefix = buf.readNbt(false);
if (prefix == null) return;
@@ -368,8 +378,8 @@ public class PacketConsumers {
}
buf.writeByte(friendlyFlags);
buf.writeUtf(nameTagVisibility);
buf.writeUtf(collisionRule);
eitherVisibility.ifLeft(buf::writeUtf).ifRight(buf::writeVarInt);
eitherCollisionRule.ifLeft(buf::writeUtf).ifRight(buf::writeVarInt);
buf.writeVarInt(color);
if (!tokens2.isEmpty()) {

View File

@@ -15,13 +15,14 @@ import java.util.concurrent.TimeUnit;
public class DelayedDefaultRegionFileStorage extends DefaultRegionFileStorage {
private final Cache<ChunkPos, CEChunk> chunkCache;
private boolean isClosed;
public DelayedDefaultRegionFileStorage(Path directory, int time) {
super(directory);
this.chunkCache = Caffeine.newBuilder()
.expireAfterWrite(time, TimeUnit.SECONDS)
.removalListener((ChunkPos key, CEChunk value, RemovalCause cause) -> {
if (key == null || value == null) {
if (key == null || value == null || isClosed) {
return;
}
if (cause == RemovalCause.EXPIRED || cause == RemovalCause.SIZE) {
@@ -60,8 +61,9 @@ public class DelayedDefaultRegionFileStorage extends DefaultRegionFileStorage {
@Override
public synchronized void close() throws IOException {
this.saveCache();
super.close();
this.chunkCache.cleanUp();
this.isClosed = true;
super.close();
}
private void saveCache() {