Make lecterns more reliable on chunk load in Spigot

This commit is contained in:
Camotoy 2021-02-26 00:54:05 -05:00
parent 6be71fc045
commit 13c924f841
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F

View file

@ -182,7 +182,7 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager {
@Override
public NbtMap getLecternDataAt(GeyserSession session, int x, int y, int z, boolean isChunkLoad) {
// Run as a task to prevent async issues
Bukkit.getScheduler().runTask(this.plugin, () -> {
Runnable lecternInfoGet = () -> {
Player bukkitPlayer;
if ((bukkitPlayer = Bukkit.getPlayer(session.getPlayerEntity().getUsername())) == null) {
return;
@ -220,7 +220,13 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager {
lecternTag.putCompound("book", bookTag.build());
NbtMap blockEntityTag = lecternTag.build();
BlockEntityUtils.updateBlockEntity(session, blockEntityTag, Vector3i.from(x, y, z));
});
};
if (isChunkLoad) {
// Delay to ensure the chunk is sent first, and then the lectern data
Bukkit.getScheduler().runTaskLater(this.plugin, lecternInfoGet, 5);
} else {
Bukkit.getScheduler().runTask(this.plugin, lecternInfoGet);
}
return LecternInventoryTranslator.getBaseLecternTag(x, y, z, 0).build(); // Will be updated later
}