use of com.denizenscript.denizen.nms.abstracts.BlockLight in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method checkIfLightsBrokenByPacket.
public static void checkIfLightsBrokenByPacket(PacketPlayOutLightUpdate packet, World world) {
if (doNotCheck) {
return;
}
try {
int cX = PACKETPLAYOUTLIGHTUPDATE_CHUNKX.getInt(packet);
int cZ = PACKETPLAYOUTLIGHTUPDATE_CHUNKZ.getInt(packet);
int bitMask = PACKETPLAYOUTLIGHTUPDATE_BLOCKLIGHT_BITMASK.getInt(packet);
List<byte[]> blockData = (List<byte[]>) PACKETPLAYOUTLIGHTUPDATE_BLOCKLIGHT_DATA.get(packet);
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
IChunkAccess chk = world.getChunkAt(cX, cZ, ChunkStatus.FULL, false);
if (!(chk instanceof Chunk)) {
return;
}
List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((Chunk) 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((Chunk) chk), 3);
}
}, 1);
} catch (Exception ex) {
Debug.echoError(ex);
}
}
use of com.denizenscript.denizen.nms.abstracts.BlockLight 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.getChunkAt(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);
}
}
use of com.denizenscript.denizen.nms.abstracts.BlockLight 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.nms.abstracts.BlockLight 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.nms.abstracts.BlockLight in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method createLight.
public static BlockLight createLight(Location location, int lightLevel, long ticks) {
location = location.getBlock().getLocation();
BlockLight blockLight;
if (lightsByLocation.containsKey(location)) {
blockLight = lightsByLocation.get(location);
if (blockLight.removeTask != null) {
blockLight.removeTask.cancel();
blockLight.removeTask = null;
}
if (blockLight.updateTask != null) {
blockLight.updateTask.cancel();
blockLight.updateTask = null;
}
blockLight.removeLater(ticks);
} else {
blockLight = new BlockLightImpl(location, ticks);
lightsByLocation.put(location, blockLight);
if (!lightsByChunk.containsKey(blockLight.chunkCoord)) {
lightsByChunk.put(blockLight.chunkCoord, new ArrayList<>());
}
lightsByChunk.get(blockLight.chunkCoord).add(blockLight);
}
blockLight.intendedLevel = lightLevel;
blockLight.update(lightLevel, true);
return blockLight;
}
Aggregations