add chunk tickets and don't force sync sending chunk packets

This commit is contained in:
dordsor21 2021-01-01 18:04:30 +00:00
parent 39b0da2b99
commit 580cb4a91e
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
8 changed files with 181 additions and 149 deletions

View File

@ -9,6 +9,7 @@ import com.boydti.fawe.object.collection.BitArray;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.ReflectionUtils;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
@ -154,25 +155,33 @@ public final class BukkitAdapter_1_15_2 extends NMSAdapter {
}
public static Chunk ensureLoaded(World nmsWorld, int chunkX, int chunkZ) {
Chunk nmsChunk = nmsWorld.getChunkIfLoaded(chunkX, chunkZ);
final Chunk nmsChunk = nmsWorld.getChunkProvider().getChunkAt(chunkX, chunkZ, false);
if (nmsChunk != null) {
TaskManager.IMP.task(() -> nmsChunk.bukkitChunk.addPluginChunkTicket(WorldEditPlugin.getInstance()));
return nmsChunk;
}
if (Fawe.isMainThread()) {
return nmsWorld.getChunkAt(chunkX, chunkZ);
final Chunk nmsChunkMain = nmsWorld.getChunkAt(chunkX, chunkZ);
TaskManager.IMP.task(() -> nmsChunkMain.bukkitChunk.addPluginChunkTicket(WorldEditPlugin.getInstance()));
return nmsChunkMain;
}
if (PaperLib.isPaper()) {
CraftWorld craftWorld = nmsWorld.getWorld();
CompletableFuture<org.bukkit.Chunk> future = craftWorld.getChunkAtAsync(chunkX, chunkZ, true);
try {
CraftChunk chunk = (CraftChunk) future.get();
final CraftChunk chunk = (CraftChunk) future.get();
TaskManager.IMP.task(() -> chunk.addPluginChunkTicket(WorldEditPlugin.getInstance()));
return chunk.getHandle();
} catch (Throwable e) {
e.printStackTrace();
}
}
// TODO optimize
return TaskManager.IMP.sync(() -> nmsWorld.getChunkAt(chunkX, chunkZ));
return TaskManager.IMP.sync(() -> {
Chunk chunk = nmsWorld.getChunkAt(chunkX, chunkZ);
chunk.bukkitChunk.addPluginChunkTicket(WorldEditPlugin.getInstance());
return chunk;
});
}
public static PlayerChunk getPlayerChunk(WorldServer nmsWorld, final int cx, final int cz) {
@ -190,7 +199,6 @@ public final class BukkitAdapter_1_15_2 extends NMSAdapter {
return;
}
if (playerChunk.hasBeenLoaded()) {
TaskManager.IMP.sync(() -> {
try {
int dirtyBits = fieldDirtyBits.getInt(playerChunk);
if (dirtyBits == 0) {
@ -216,11 +224,7 @@ public final class BukkitAdapter_1_15_2 extends NMSAdapter {
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
});
return;
}
return;
}
/*

View File

@ -607,6 +607,7 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks {
task.run();
}
}
nmsChunk.bukkitChunk.removePluginChunkTicket(WorldEditPlugin.getInstance());
if (callback == null) {
if (finalizer != null) {
finalizer.run();

View File

@ -9,6 +9,7 @@ import com.boydti.fawe.object.collection.BitArrayUnstretched;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.ReflectionUtils;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
@ -151,25 +152,33 @@ public final class BukkitAdapter_1_16_1 extends NMSAdapter {
}
public static Chunk ensureLoaded(World nmsWorld, int chunkX, int chunkZ) {
Chunk nmsChunk = nmsWorld.getChunkProvider().getChunkAt(chunkX, chunkZ, false);
final Chunk nmsChunk = nmsWorld.getChunkProvider().getChunkAt(chunkX, chunkZ, false);
if (nmsChunk != null) {
TaskManager.IMP.task(() -> nmsChunk.bukkitChunk.addPluginChunkTicket(WorldEditPlugin.getInstance()));
return nmsChunk;
}
if (Fawe.isMainThread()) {
return nmsWorld.getChunkAt(chunkX, chunkZ);
final Chunk nmsChunkMain = nmsWorld.getChunkAt(chunkX, chunkZ);
TaskManager.IMP.task(() -> nmsChunkMain.bukkitChunk.addPluginChunkTicket(WorldEditPlugin.getInstance()));
return nmsChunkMain;
}
if (PaperLib.isPaper()) {
CraftWorld craftWorld = nmsWorld.getWorld();
CompletableFuture<org.bukkit.Chunk> future = craftWorld.getChunkAtAsync(chunkX, chunkZ, true);
try {
CraftChunk chunk = (CraftChunk) future.get();
final CraftChunk chunk = (CraftChunk) future.get();
TaskManager.IMP.task(() -> chunk.addPluginChunkTicket(WorldEditPlugin.getInstance()));
return chunk.getHandle();
} catch (Throwable e) {
e.printStackTrace();
}
}
// TODO optimize
return TaskManager.IMP.sync(() -> nmsWorld.getChunkAt(chunkX, chunkZ));
return TaskManager.IMP.sync(() -> {
Chunk chunk = nmsWorld.getChunkAt(chunkX, chunkZ);
chunk.bukkitChunk.addPluginChunkTicket(WorldEditPlugin.getInstance());
return chunk;
});
}
public static PlayerChunk getPlayerChunk(WorldServer nmsWorld, final int cx, final int cz) {
@ -187,7 +196,6 @@ public final class BukkitAdapter_1_16_1 extends NMSAdapter {
return;
}
if (playerChunk.hasBeenLoaded()) {
TaskManager.IMP.sync(() -> {
try {
int dirtyBits = fieldDirtyBits.getInt(playerChunk);
if (dirtyBits == 0) {
@ -214,8 +222,6 @@ public final class BukkitAdapter_1_16_1 extends NMSAdapter {
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
});
}
}

View File

@ -609,6 +609,7 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
task.run();
}
}
nmsChunk.bukkitChunk.removePluginChunkTicket(WorldEditPlugin.getInstance());
if (callback == null) {
if (finalizer != null) {
finalizer.run();

View File

@ -11,6 +11,7 @@ import com.boydti.fawe.util.ReflectionUtils;
import com.boydti.fawe.util.TaskManager;
import com.destroystokyo.paper.util.misc.PooledLinkedHashSets;
import com.mojang.datafixers.util.Either;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
@ -163,25 +164,33 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
}
public static Chunk ensureLoaded(World nmsWorld, int chunkX, int chunkZ) {
Chunk nmsChunk = nmsWorld.getChunkProvider().getChunkAt(chunkX, chunkZ, false);
final Chunk nmsChunk = nmsWorld.getChunkProvider().getChunkAt(chunkX, chunkZ, false);
if (nmsChunk != null) {
TaskManager.IMP.task(() -> nmsChunk.bukkitChunk.addPluginChunkTicket(WorldEditPlugin.getInstance()));
return nmsChunk;
}
if (Fawe.isMainThread()) {
return nmsWorld.getChunkAt(chunkX, chunkZ);
final Chunk nmsChunkMain = nmsWorld.getChunkAt(chunkX, chunkZ);
TaskManager.IMP.task(() -> nmsChunkMain.bukkitChunk.addPluginChunkTicket(WorldEditPlugin.getInstance()));
return nmsChunkMain;
}
if (PaperLib.isPaper()) {
CraftWorld craftWorld = nmsWorld.getWorld();
CompletableFuture<org.bukkit.Chunk> future = craftWorld.getChunkAtAsync(chunkX, chunkZ, true);
try {
CraftChunk chunk = (CraftChunk) future.get();
final CraftChunk chunk = (CraftChunk) future.get();
TaskManager.IMP.task(() -> chunk.addPluginChunkTicket(WorldEditPlugin.getInstance()));
return chunk.getHandle();
} catch (Throwable e) {
e.printStackTrace();
}
}
// TODO optimize
return TaskManager.IMP.sync(() -> nmsWorld.getChunkAt(chunkX, chunkZ));
return TaskManager.IMP.sync(() -> {
Chunk chunk = nmsWorld.getChunkAt(chunkX, chunkZ);
chunk.bukkitChunk.addPluginChunkTicket(WorldEditPlugin.getInstance());
return chunk;
});
}
public static PlayerChunk getPlayerChunk(WorldServer nmsWorld, final int chunkX, final int chunkZ) {
@ -199,7 +208,6 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
return;
}
if (playerChunk.hasBeenLoaded()) {
TaskManager.IMP.sync(() -> {
ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair(chunkX, chunkZ);
Optional<Chunk> optional = ((Either) playerChunk.a().getNow(PlayerChunk.UNLOADED_CHUNK)).left();
if (optional.isPresent()) {
@ -209,7 +217,8 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
});
if (lighting) {
boolean trustEdges = true; //This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad)
//This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad)
boolean trustEdges = true;
PacketPlayOutLightUpdate packet = new PacketPlayOutLightUpdate(chunkCoordIntPair, nmsWorld.getChunkProvider().getLightEngine(), trustEdges);
playerChunk.players.a(chunkCoordIntPair, false).forEach(p -> {
p.playerConnection.sendPacket(packet);
@ -220,7 +229,7 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<?> objects =
nmsWorld.getChunkProvider().playerChunkMap.playerViewDistanceNoTickMap.getObjectsInRange(chunkX, chunkZ);
if (objects == null) {
return null;
return;
}
for (Object obj : objects.getBackingSet()) {
if (obj == null) {
@ -233,8 +242,8 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
p.playerConnection.sendPacket(chunkpacket);
if (lighting) {
boolean trustEdges =
true; //This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad)
//This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad)
boolean trustEdges = true;
PacketPlayOutLightUpdate packet =
new PacketPlayOutLightUpdate(chunkCoordIntPair, nmsWorld.getChunkProvider().getLightEngine(), trustEdges);
p.playerConnection.sendPacket(packet);
@ -242,8 +251,6 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
}
}
}
return null;
});
}
}

View File

@ -612,6 +612,7 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks {
task.run();
}
}
nmsChunk.bukkitChunk.removePluginChunkTicket(WorldEditPlugin.getInstance());
if (callback == null) {
if (finalizer != null) {
finalizer.run();

View File

@ -5,12 +5,14 @@ import com.boydti.fawe.FaweCache;
import com.boydti.fawe.bukkit.adapter.DelegateLock;
import com.boydti.fawe.bukkit.adapter.NMSAdapter;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.collection.BitArrayUnstretched;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.ReflectionUtils;
import com.boydti.fawe.util.TaskManager;
import com.destroystokyo.paper.util.misc.PooledLinkedHashSets;
import com.mojang.datafixers.util.Either;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
@ -163,25 +165,33 @@ public final class BukkitAdapter_1_16_4 extends NMSAdapter {
}
public static Chunk ensureLoaded(World nmsWorld, int chunkX, int chunkZ) {
Chunk nmsChunk = nmsWorld.getChunkProvider().getChunkAt(chunkX, chunkZ, false);
final Chunk nmsChunk = nmsWorld.getChunkProvider().getChunkAt(chunkX, chunkZ, false);
if (nmsChunk != null) {
TaskManager.IMP.task(() -> nmsChunk.bukkitChunk.addPluginChunkTicket(WorldEditPlugin.getInstance()));
return nmsChunk;
}
if (Fawe.isMainThread()) {
return nmsWorld.getChunkAt(chunkX, chunkZ);
final Chunk nmsChunkMain = nmsWorld.getChunkAt(chunkX, chunkZ);
TaskManager.IMP.task(() -> nmsChunkMain.bukkitChunk.addPluginChunkTicket(WorldEditPlugin.getInstance()));
return nmsChunkMain;
}
if (PaperLib.isPaper()) {
CraftWorld craftWorld = nmsWorld.getWorld();
CompletableFuture<org.bukkit.Chunk> future = craftWorld.getChunkAtAsync(chunkX, chunkZ, true);
try {
CraftChunk chunk = (CraftChunk) future.get();
final CraftChunk chunk = (CraftChunk) future.get();
TaskManager.IMP.task(() -> chunk.addPluginChunkTicket(WorldEditPlugin.getInstance()));
return chunk.getHandle();
} catch (Throwable e) {
e.printStackTrace();
}
}
// TODO optimize
return TaskManager.IMP.sync(() -> nmsWorld.getChunkAt(chunkX, chunkZ));
return TaskManager.IMP.sync(() -> {
Chunk chunk = nmsWorld.getChunkAt(chunkX, chunkZ);
chunk.bukkitChunk.addPluginChunkTicket(WorldEditPlugin.getInstance());
return chunk;
});
}
public static PlayerChunk getPlayerChunk(WorldServer nmsWorld, final int chunkX, final int chunkZ) {
@ -199,7 +209,6 @@ public final class BukkitAdapter_1_16_4 extends NMSAdapter {
return;
}
if (playerChunk.hasBeenLoaded()) {
TaskManager.IMP.sync(() -> {
ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair(chunkX, chunkZ);
Optional<Chunk> optional = ((Either) playerChunk.a().getNow(PlayerChunk.UNLOADED_CHUNK)).left();
if (optional.isPresent()) {
@ -209,8 +218,11 @@ public final class BukkitAdapter_1_16_4 extends NMSAdapter {
});
if (lighting) {
boolean trustEdges = true; //This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad)
PacketPlayOutLightUpdate packet = new PacketPlayOutLightUpdate(chunkCoordIntPair, nmsWorld.getChunkProvider().getLightEngine(), trustEdges);
//This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad)
boolean trustEdges = true;
PacketPlayOutLightUpdate packet =
new PacketPlayOutLightUpdate(chunkCoordIntPair, nmsWorld.getChunkProvider().getLightEngine(),
trustEdges);
playerChunk.players.a(chunkCoordIntPair, false).forEach(p -> {
p.playerConnection.sendPacket(packet);
});
@ -218,9 +230,10 @@ public final class BukkitAdapter_1_16_4 extends NMSAdapter {
} else if (PaperLib.isPaper()) {
//Require generic here to work with multiple dependencies trying to take control.
PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<?> objects =
nmsWorld.getChunkProvider().playerChunkMap.playerViewDistanceNoTickMap.getObjectsInRange(chunkX, chunkZ);
nmsWorld.getChunkProvider().playerChunkMap.playerViewDistanceNoTickMap
.getObjectsInRange(chunkX, chunkZ);
if (objects == null) {
return null;
return;
}
for (Object obj : objects.getBackingSet()) {
if (obj == null) {
@ -233,17 +246,15 @@ public final class BukkitAdapter_1_16_4 extends NMSAdapter {
p.playerConnection.sendPacket(chunkpacket);
if (lighting) {
boolean trustEdges =
true; //This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad)
PacketPlayOutLightUpdate packet =
new PacketPlayOutLightUpdate(chunkCoordIntPair, nmsWorld.getChunkProvider().getLightEngine(), trustEdges);
//This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad)
boolean trustEdges = true;
PacketPlayOutLightUpdate packet = new PacketPlayOutLightUpdate(chunkCoordIntPair,
nmsWorld.getChunkProvider().getLightEngine(), trustEdges);
p.playerConnection.sendPacket(packet);
}
}
}
}
return null;
});
}
}

View File

@ -612,6 +612,7 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks {
task.run();
}
}
nmsChunk.bukkitChunk.removePluginChunkTicket(WorldEditPlugin.getInstance());
if (callback == null) {
if (finalizer != null) {
finalizer.run();