9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00

fix(replay): run ServerPhotographer player ops on main thread (#499)

* fix(replay): schedule ServerPhotographer player ops on main thread when async ticking
This commit is contained in:
MrlingXD
2025-09-15 08:34:39 +08:00
committed by GitHub
parent b9ebfff44c
commit 69b6fe60ad

View File

@@ -62,7 +62,16 @@ public class ServerPhotographer extends ServerPlayer {
photographer.createState = state;
photographer.recorder.start();
// Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled && !server.isSameThread()) {
server.submit(() -> {
MinecraftServer.getServer().getPlayerList().placeNewPhotographer(photographer.recorder, photographer, world);
});
} else {
MinecraftServer.getServer().getPlayerList().placeNewPhotographer(photographer.recorder, photographer, world);
}
// Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
photographer.level().chunkSource.move(photographer);
photographer.setInvisible(true);
photographers.add(photographer);
@@ -85,12 +94,29 @@ public class ServerPhotographer extends ServerPlayer {
if (this.followPlayer != null) {
if (this.getCamera() == this || this.getCamera().level() != this.level()) {
// Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled) {
this.getBukkitEntity().taskScheduler.schedule(entity -> {
((ServerPhotographer) entity).getBukkitPlayer().teleport(((ServerPhotographer) entity).getCamera().getBukkitEntity().getLocation());
((ServerPhotographer) entity).setCamera(((ServerPhotographer) entity).followPlayer);
}, entity -> {}, 0);
} else {
this.getBukkitPlayer().teleport(this.getCamera().getBukkitEntity().getLocation());
this.setCamera(followPlayer);
}
// Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
}
if (lastPos.distanceToSqr(this.position()) > 1024D) {
// Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled) {
this.getBukkitEntity().taskScheduler.schedule(entity -> {
((ServerPhotographer) entity).getBukkitPlayer().teleport(((ServerPhotographer) entity).getCamera().getBukkitEntity().getLocation());
}, entity -> {}, 0);
} else {
this.getBukkitPlayer().teleport(this.getCamera().getBukkitEntity().getLocation());
}
// Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
}
}
lastPos = this.position();
@@ -130,7 +156,16 @@ public class ServerPhotographer extends ServerPlayer {
super.remove(RemovalReason.KILLED);
photographers.remove(this);
this.recorder.stop();
// Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled) {
this.getServer().submit(() -> {
this.getServer().getPlayerList().removePhotographer(this);
});
} else {
this.getServer().getPlayerList().removePhotographer(this);
}
// Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
LeavesLogger.LOGGER.info("Photographer " + createState.id + " removed");