Java Code Examples for cn.nukkit.level.format.generic.BaseFullChunk#setChunkPacket()

The following examples show how to use cn.nukkit.level.format.generic.BaseFullChunk#setChunkPacket() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void chunkRequestCallback(long timestamp, int x, int z, int subChunkCount, byte[] payload) {
    this.timings.syncChunkSendTimer.startTiming();
    long index = Level.chunkHash(x, z);

    if (this.cacheChunks) {
        BatchPacket data = Player.getChunkCacheFromData(x, z, subChunkCount, payload);
        BaseFullChunk chunk = getChunk(x, z, false);
        if (chunk != null && chunk.getChanges() <= timestamp) {
            chunk.setChunkPacket(data);
        }
        this.sendChunk(x, z, index, data);
        this.timings.syncChunkSendTimer.stopTiming();
        return;
    }

    if (this.chunkSendTasks.contains(index)) {
        for (Player player : this.chunkSendQueue.get(index).values()) {
            if (player.isConnected() && player.usedChunks.containsKey(index)) {
                player.sendChunk(x, z, subChunkCount, payload);
            }
        }

        this.chunkSendQueue.remove(index);
        this.chunkSendTasks.remove(index);
    }
    this.timings.syncChunkSendTimer.stopTiming();
}
 
Example 2
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void chunkRequestCallback(long timestamp, int x, int z, byte[] payload) {
    this.timings.syncChunkSendTimer.startTiming();
    long index = Level.chunkHash(x, z);

    if (this.cacheChunks) {
        BatchPacket data = Player.getChunkCacheFromData(x, z, payload);
        BaseFullChunk chunk = getChunk(x, z, false);
        if (chunk != null && chunk.getChanges() <= timestamp) {
            chunk.setChunkPacket(data);
        }
        this.sendChunk(x, z, index, data);
        this.timings.syncChunkSendTimer.stopTiming();
        return;
    }

    if (this.chunkSendTasks.containsKey(index)) {
        for (Player player : this.chunkSendQueue.get(index).values()) {
            if (player.isConnected() && player.usedChunks.containsKey(index)) {
                player.sendChunk(x, z, payload);
            }
        }

        this.chunkSendQueue.remove(index);
        this.chunkSendTasks.remove(index);
    }
    this.timings.syncChunkSendTimer.stopTiming();
}