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

为区块读写添加缓存

This commit is contained in:
XiaoMoMi
2025-04-24 22:44:04 +08:00
parent 54cd0576a9
commit d9ab391a85
33 changed files with 185 additions and 311 deletions

View File

@@ -453,7 +453,11 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
}
targetLocation.setYaw(player.getLocation().getYaw());
targetLocation.setPitch(player.getLocation().getPitch());
player.teleport(targetLocation);
if (VersionHelper.isFolia()) {
player.teleportAsync(targetLocation);
} else {
player.teleport(targetLocation);
}
}
protected boolean isSeatCarrierType(Entity entity) {

View File

@@ -17,11 +17,9 @@ import net.momirealms.craftengine.core.world.SectionPos;
import net.momirealms.craftengine.core.world.WorldManager;
import net.momirealms.craftengine.core.world.chunk.CEChunk;
import net.momirealms.craftengine.core.world.chunk.CESection;
import net.momirealms.craftengine.core.world.chunk.serialization.ChunkSerializer;
import net.momirealms.craftengine.core.world.chunk.storage.DefaultStorageAdaptor;
import net.momirealms.craftengine.core.world.chunk.storage.StorageAdaptor;
import net.momirealms.craftengine.core.world.chunk.storage.WorldDataStorage;
import net.momirealms.sparrow.nbt.CompoundTag;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
@@ -29,10 +27,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.event.world.*;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -148,6 +143,11 @@ public class BukkitWorldManager implements WorldManager, Listener {
for (Chunk chunk : world.getLoadedChunks()) {
handleChunkUnload(ceWorld, chunk);
}
try {
ceWorld.worldDataStorage().close();
} catch (IOException e) {
this.plugin.logger().warn("Error unloading world: " + world.getName(), e);
}
}
this.worlds.clear();
}
@@ -198,6 +198,11 @@ public class BukkitWorldManager implements WorldManager, Listener {
unloadWorld(new BukkitWorld(event.getWorld()));
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onWorldSave(WorldSaveEvent event) {
// TODO Timely saving?
}
@Override
public void unloadWorld(net.momirealms.craftengine.core.world.World world) {
CEWorld ceWorld;
@@ -270,10 +275,9 @@ public class BukkitWorldManager implements WorldManager, Listener {
CEChunk ceChunk = world.getChunkAtIfLoaded(chunk.getX(), chunk.getZ());
if (ceChunk != null) {
try {
world.worldDataStorage().writeChunkTagAt(pos, ChunkSerializer.serialize(ceChunk));
world.worldDataStorage().writeChunkAt(pos, ceChunk);
} catch (IOException e) {
plugin.logger().warn("Failed to write chunk tag at " + chunk.getX() + " " + chunk.getZ(), e);
return;
this.plugin.logger().warn("Failed to write chunk tag at " + chunk.getX() + " " + chunk.getZ(), e);
} finally {
if (Config.restoreVanillaBlocks()) {
CESection[] ceSections = ceChunk.sections();
@@ -308,12 +312,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
if (ceWorld.isChunkLoaded(pos.longKey)) return;
CEChunk ceChunk;
try {
CompoundTag chunkNbt = ceWorld.worldDataStorage().readChunkTagAt(pos);
if (chunkNbt != null) {
ceChunk = ChunkSerializer.deserialize(ceWorld, pos, chunkNbt);
} else {
ceChunk = new CEChunk(ceWorld, pos);
}
ceChunk = ceWorld.worldDataStorage().readChunkAt(ceWorld, pos);
try {
CESection[] ceSections = ceChunk.sections();
Object worldServer = FastNMS.INSTANCE.field$CraftChunk$worldServer(chunk);