use of com.bergerkiller.bukkit.common.protocol.CommonPacket in project BKCommonLib by bergerhealer.
the class WorldUtil method queueChunkSend.
/**
* Queue a chunk for resending to all players that are in range of it.
* Use this method to update chunk data after doing changes to its raw structure.
*
* @param player to send chunk data for
* @param chunkX - coordinate of the chunk
* @param chunkZ - coordinate of the chunk
* @return True if players were nearby, False if not
*/
public static boolean queueChunkSend(org.bukkit.World world, int chunkX, int chunkZ) {
Object playerChunkMap = CommonNMS.getHandle(world).getPlayerChunkMap().getRaw();
Object chunk = NMSPlayerChunkMap.getChunk.invoke(playerChunkMap, chunkX, chunkZ);
if (chunk != null && !NMSPlayerChunk.players.get(chunk).isEmpty()) {
// Simply remove and re-add the players to the chunk. Does an instant chunk resend, though.
// This doesn't work because block updates disable in the chunk permanently
/*
List<Player> old_players = new ArrayList<Player>(NMSPlayerChunk.players.get(chunk));
for (Player player : old_players) {
NMSPlayerChunk.removePlayer.invoke(chunk, Conversion.toEntityHandle.convert(player));
}
for (Player player : old_players) {
NMSPlayerChunk.addPlayer.invoke(chunk, Conversion.toEntityHandle.convert(player));
}
*/
// This method sends 64 block changes to trigger a chunk resend
// It doesn't really work because entities disappear
// NMSPlayerChunk.dirtySectionMask.set(chunk, 65535); // all chunk sections
// NMSPlayerChunk.dirtyCount.set(chunk, 64); // 64 triggers a full chunk re-send
// NMSPlayerChunkMap.markForUpdate.invoke(playerChunkMap, chunk); // tell main chunk map to update
// Manual resend because none of the above work without bugs
// We use 0x1FFFF instead of 0xFFFF to avoid sending biome data, as that despawns the entities
// The 0x10000 is an ignored mask as it is outside of the range of chunk slices.
Object chunkHandle = NMSPlayerChunk.chunk.getInternal(chunk);
if (chunkHandle != null) {
List<Player> old_players = new ArrayList<Player>(NMSPlayerChunk.players.get(chunk));
CommonPacket packet = PacketType.OUT_MAP_CHUNK.newInstance(chunkHandle, 0x1FFFF);
for (Player player : old_players) {
PacketUtil.sendPacket(player, packet);
}
}
return true;
} else {
return false;
}
}
use of com.bergerkiller.bukkit.common.protocol.CommonPacket in project BKCommonLib by bergerhealer.
the class PacketUtil method sendChunk.
/**
* Sends all the packets required to properly display a chunk to a player.
* To only send (Tile)Entity related information, use a 'sendPayload' of
* False.
*
* @param player to send to
* @param chunk to send the information of
* @param sendPayload - whether the block data is sent
*/
@Deprecated
public static void sendChunk(final Player player, final org.bukkit.Chunk chunk, boolean sendPayload) {
final Object chunkHandle = Conversion.toChunkHandle.convert(chunk);
// Send payload
if (sendPayload) {
sendPacket(player, PacketType.OUT_MAP_CHUNK.newInstance(chunk));
//sendPacket(player, PacketType.OUT_MAP_CHUNK_BULK.newInstance(Arrays.asList(chunk)));
}
// Tile entities
CommonPacket packet;
for (Object tile : NMSChunk.tileEntities.get(chunkHandle).values()) {
if ((packet = NMSTileEntity.getUpdatePacket(tile)) != null) {
PacketUtil.sendPacket(player, packet);
}
}
// Entity spawn messages
CommonUtil.nextTick(new Runnable() {
public void run() {
WorldUtil.getTracker(player.getWorld()).spawnEntities(player, chunk);
}
});
}
Aggregations