mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-23 17:09:29 +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.createState = state;
|
||||||
|
|
||||||
photographer.recorder.start();
|
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);
|
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.level().chunkSource.move(photographer);
|
||||||
photographer.setInvisible(true);
|
photographer.setInvisible(true);
|
||||||
photographers.add(photographer);
|
photographers.add(photographer);
|
||||||
@@ -85,12 +94,29 @@ public class ServerPhotographer extends ServerPlayer {
|
|||||||
|
|
||||||
if (this.followPlayer != null) {
|
if (this.followPlayer != null) {
|
||||||
if (this.getCamera() == this || this.getCamera().level() != this.level()) {
|
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.getBukkitPlayer().teleport(this.getCamera().getBukkitEntity().getLocation());
|
||||||
this.setCamera(followPlayer);
|
this.setCamera(followPlayer);
|
||||||
}
|
}
|
||||||
|
// Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
|
||||||
|
}
|
||||||
if (lastPos.distanceToSqr(this.position()) > 1024D) {
|
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());
|
this.getBukkitPlayer().teleport(this.getCamera().getBukkitEntity().getLocation());
|
||||||
}
|
}
|
||||||
|
// Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPos = this.position();
|
lastPos = this.position();
|
||||||
@@ -130,7 +156,16 @@ public class ServerPhotographer extends ServerPlayer {
|
|||||||
super.remove(RemovalReason.KILLED);
|
super.remove(RemovalReason.KILLED);
|
||||||
photographers.remove(this);
|
photographers.remove(this);
|
||||||
this.recorder.stop();
|
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);
|
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");
|
LeavesLogger.LOGGER.info("Photographer " + createState.id + " removed");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user