use of com.denizenscript.denizen.utilities.blocks.ChunkCoordinate in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method checkIfLightsBrokenByPacket.
public static void checkIfLightsBrokenByPacket(ClientboundLightUpdatePacket packet, Level world) {
if (doNotCheck) {
return;
}
try {
int cX = packet.getX();
int cZ = packet.getZ();
BitSet bitMask = packet.getBlockYMask();
List<byte[]> blockData = packet.getBlockUpdates();
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
ChunkAccess chk = world.getChunk(cX, cZ, ChunkStatus.FULL, false);
if (!(chk instanceof LevelChunk)) {
return;
}
List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) chk).bukkitChunk));
if (lights == null) {
return;
}
boolean any = false;
for (BlockLight light : lights) {
if (((BlockLightImpl) light).checkIfChangedBy(bitMask, blockData)) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
any = true;
}
}
if (any) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates((LevelChunk) chk), 3);
}
}, 1);
} catch (Exception ex) {
Debug.echoError(ex);
}
}
use of com.denizenscript.denizen.utilities.blocks.ChunkCoordinate in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method checkIfLightsBrokenByPacket.
public static void checkIfLightsBrokenByPacket(ClientboundLightUpdatePacket packet, Level world) {
if (doNotCheck) {
return;
}
try {
int cX = packet.getX();
int cZ = packet.getZ();
BitSet bitMask = packet.getLightData().getBlockYMask();
List<byte[]> blockData = packet.getLightData().getBlockUpdates();
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
ChunkAccess chk = world.getChunk(cX, cZ, ChunkStatus.FULL, false);
if (!(chk instanceof LevelChunk)) {
return;
}
List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) chk).bukkitChunk));
if (lights == null) {
return;
}
boolean any = false;
for (BlockLight light : lights) {
if (((BlockLightImpl) light).checkIfChangedBy(bitMask, blockData)) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
any = true;
}
}
if (any) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates((LevelChunk) chk), 3);
}
}, 1);
} catch (Exception ex) {
Debug.echoError(ex);
}
}
use of com.denizenscript.denizen.utilities.blocks.ChunkCoordinate in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method checkIfLightsBrokenByPacket.
public static void checkIfLightsBrokenByPacket(PacketPlayOutBlockChange packet, World world) {
try {
BlockPosition pos = (BlockPosition) PACKETPLAYOUTBLOCKCHANGE_POSITION.get(packet);
int chunkX = pos.getX() >> 4;
int chunkZ = pos.getZ() >> 4;
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
Chunk chunk = world.getChunkAt(chunkX, chunkZ);
boolean any = false;
for (Vector vec : RELATIVE_CHUNKS) {
IChunkAccess other = world.getChunkAt(chunkX + vec.getBlockX(), chunkZ + vec.getBlockZ(), ChunkStatus.FULL, false);
if (other instanceof Chunk) {
List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((Chunk) other).bukkitChunk));
if (lights != null) {
any = true;
for (BlockLight light : lights) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
}
}
}
}
if (any) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates(chunk), 3);
}
}, 1);
} catch (Exception ex) {
Debug.echoError(ex);
}
}
use of com.denizenscript.denizen.utilities.blocks.ChunkCoordinate in project Denizen-For-Bukkit by DenizenScript.
the class DenizenNetworkManagerImpl method processShowFakeForPacket.
public boolean processShowFakeForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
if (FakeBlock.blocks.isEmpty()) {
return false;
}
try {
if (packet instanceof ClientboundLevelChunkWithLightPacket) {
FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUUID());
if (map == null) {
return false;
}
int chunkX = ((ClientboundLevelChunkWithLightPacket) packet).getX();
int chunkZ = ((ClientboundLevelChunkWithLightPacket) packet).getZ();
ChunkCoordinate chunkCoord = new ChunkCoordinate(chunkX, chunkZ, player.getLevel().getWorld().getName());
List<FakeBlock> blocks = FakeBlock.getFakeBlocksFor(player.getUUID(), chunkCoord);
if (blocks == null || blocks.isEmpty()) {
return false;
}
ClientboundLevelChunkWithLightPacket newPacket = FakeBlockHelper.handleMapChunkPacket(player.getBukkitEntity().getWorld(), (ClientboundLevelChunkWithLightPacket) packet, chunkX, chunkZ, blocks);
oldManager.send(newPacket, genericfuturelistener);
return true;
} else if (packet instanceof ClientboundSectionBlocksUpdatePacket) {
FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUUID());
if (map == null) {
return false;
}
SectionPos coord = (SectionPos) SECTIONPOS_MULTIBLOCKCHANGE.get(packet);
ChunkCoordinate coordinateDenizen = new ChunkCoordinate(coord.getX(), coord.getZ(), player.getLevel().getWorld().getName());
if (!map.byChunk.containsKey(coordinateDenizen)) {
return false;
}
ClientboundSectionBlocksUpdatePacket newPacket = new ClientboundSectionBlocksUpdatePacket(copyPacket(packet));
LocationTag location = new LocationTag(player.getLevel().getWorld(), 0, 0, 0);
short[] originalOffsetArray = (short[]) OFFSETARRAY_MULTIBLOCKCHANGE.get(newPacket);
BlockState[] originalDataArray = (BlockState[]) BLOCKARRAY_MULTIBLOCKCHANGE.get(newPacket);
short[] offsetArray = Arrays.copyOf(originalOffsetArray, originalOffsetArray.length);
BlockState[] dataArray = Arrays.copyOf(originalDataArray, originalDataArray.length);
OFFSETARRAY_MULTIBLOCKCHANGE.set(newPacket, offsetArray);
BLOCKARRAY_MULTIBLOCKCHANGE.set(newPacket, dataArray);
for (int i = 0; i < offsetArray.length; i++) {
short offset = offsetArray[i];
BlockPos pos = coord.relativeToBlockPos(offset);
location.setX(pos.getX());
location.setY(pos.getY());
location.setZ(pos.getZ());
FakeBlock block = map.byLocation.get(location);
if (block != null) {
dataArray[i] = FakeBlockHelper.getNMSState(block);
}
}
oldManager.send(newPacket, genericfuturelistener);
return true;
} else if (packet instanceof ClientboundBlockUpdatePacket) {
BlockPos pos = ((ClientboundBlockUpdatePacket) packet).getPos();
LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
if (block != null) {
ClientboundBlockUpdatePacket newPacket = new ClientboundBlockUpdatePacket(((ClientboundBlockUpdatePacket) packet).getPos(), FakeBlockHelper.getNMSState(block));
oldManager.send(newPacket, genericfuturelistener);
return true;
}
} else if (packet instanceof ClientboundBlockBreakAckPacket) {
ClientboundBlockBreakAckPacket origPack = (ClientboundBlockBreakAckPacket) packet;
BlockPos pos = origPack.pos();
LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
if (block != null) {
ClientboundBlockBreakAckPacket newPacket = new ClientboundBlockBreakAckPacket(origPack.pos(), FakeBlockHelper.getNMSState(block), origPack.action(), false);
oldManager.send(newPacket, genericfuturelistener);
return true;
}
}
} catch (Throwable ex) {
Debug.echoError(ex);
}
return false;
}
use of com.denizenscript.denizen.utilities.blocks.ChunkCoordinate in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method checkIfLightsBrokenByPacket.
public static void checkIfLightsBrokenByPacket(ClientboundBlockUpdatePacket packet, Level world) {
try {
BlockPos pos = packet.getPos();
int chunkX = pos.getX() >> 4;
int chunkZ = pos.getZ() >> 4;
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
LevelChunk chunk = world.getChunk(chunkX, chunkZ);
boolean any = false;
for (Vector vec : RELATIVE_CHUNKS) {
ChunkAccess other = world.getChunk(chunkX + vec.getBlockX(), chunkZ + vec.getBlockZ(), ChunkStatus.FULL, false);
if (other instanceof LevelChunk) {
List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) other).bukkitChunk));
if (lights != null) {
any = true;
for (BlockLight light : lights) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
}
}
}
}
if (any) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates(chunk), 3);
}
}, 1);
} catch (Exception ex) {
Debug.echoError(ex);
}
}
Aggregations