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:
@@ -62,7 +62,16 @@ public class ServerPhotographer extends ServerPlayer {
|
||||
photographer.createState = state;
|
||||
|
||||
photographer.recorder.start();
|
||||
MinecraftServer.getServer().getPlayerList().placeNewPhotographer(photographer.recorder, photographer, world);
|
||||
// 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,11 +94,28 @@ public class ServerPhotographer extends ServerPlayer {
|
||||
|
||||
if (this.followPlayer != null) {
|
||||
if (this.getCamera() == this || this.getCamera().level() != this.level()) {
|
||||
this.getBukkitPlayer().teleport(this.getCamera().getBukkitEntity().getLocation());
|
||||
this.setCamera(followPlayer);
|
||||
// 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) {
|
||||
this.getBukkitPlayer().teleport(this.getCamera().getBukkitEntity().getLocation());
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +156,16 @@ public class ServerPhotographer extends ServerPlayer {
|
||||
super.remove(RemovalReason.KILLED);
|
||||
photographers.remove(this);
|
||||
this.recorder.stop();
|
||||
this.getServer().getPlayerList().removePhotographer(this);
|
||||
|
||||
// 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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user