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;
}
use of com.denizenscript.denizen.nms.abstracts.BlockLight 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.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;
}
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.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