use of com.bergerkiller.bukkit.common.wrappers.BlockStateChange in project BKCommonLib by bergerhealer.
the class BlockStateChangePacketHandler_1_9_3 method enable.
@Override
public void enable() {
register(PacketType.OUT_TILE_ENTITY_DATA, (player, commonPacket, listener) -> {
final PacketPlayOutTileEntityDataHandle packet = PacketPlayOutTileEntityDataHandle.createHandle(commonPacket.getHandle());
CommonTagCompound metadata = packet.getData();
if (metadata != null) {
// There's metadata, nothing special needs to be done
BlockStateChange change = BlockStateChange.deferred(packet.getPosition(), packet.getType(), LogicUtil.constantSupplier(metadata), () -> true);
// Handle it, if false, cancel the packet entirely
if (!listener.onBlockChange(player, change)) {
return false;
}
} else {
// Initialize metadata on first use
final DeferredSupplier<CommonTagCompound> metadataSupplier = DeferredSupplier.of(CommonTagCompound::new);
BlockStateChange change = BlockStateChange.deferred(packet.getPosition(), packet.getType(), metadataSupplier, metadataSupplier::isInitialized);
// Handle it, if false, cancel the packet entirely
if (!listener.onBlockChange(player, change)) {
return false;
}
// If metadata was created and it's not empty, apply it to the packet
if (metadataSupplier.isInitialized() && !metadataSupplier.get().isEmpty()) {
packet.setData(metadataSupplier.get());
}
}
return true;
});
register(PacketType.OUT_MAP_CHUNK, (player, commonPacket, listener) -> {
PacketPlayOutMapChunkHandle packet = PacketPlayOutMapChunkHandle.createHandle(commonPacket.getHandle());
Iterator<BlockStateChange> iter = packet.getBlockStates().iterator();
while (iter.hasNext()) {
BlockStateChange change = iter.next();
if (!listener.onBlockChange(player, change)) {
iter.remove();
}
}
return true;
});
}
use of com.bergerkiller.bukkit.common.wrappers.BlockStateChange in project BKCommonLib by bergerhealer.
the class PacketPlayOutMapChunkHandle method setBlockStates.
public void setBlockStates(List<BlockStateChange> states) {
List<BlockStateChange> baseStates = this.getBlockStates();
int count = states.size();
int limit = Math.min(count, baseStates.size());
for (int i = 0; i < limit; i++) {
BlockStateChange change = states.get(i);
if (baseStates.get(i) != change) {
baseStates.set(i, change);
}
}
for (int i = limit; i < count; i++) {
baseStates.add(states.get(i));
}
while (baseStates.size() > count) {
baseStates.remove(baseStates.size() - 1);
}
}
Aggregations