use of com.loohp.interactionvisualizer.objectholders.ChunkPosition in project InteractionVisualizer by LOOHP.
the class PlayerLocationManager method hasPlayerNearby.
public static boolean hasPlayerNearby(Location location) {
World world = location.getWorld();
int chunkX = location.getBlockX() >> 4;
int chunkZ = location.getBlockZ() >> 4;
ChunkPosition chunkpos = new ChunkPosition(world, chunkX, chunkZ);
if (!chunkpos.isLoaded()) {
return false;
}
Set<ChunkPosition> nearby = new HashSet<>();
for (int z = -InteractionVisualizer.tileEntityCheckingRange; z <= InteractionVisualizer.tileEntityCheckingRange; z++) {
for (int x = -InteractionVisualizer.tileEntityCheckingRange; x <= InteractionVisualizer.tileEntityCheckingRange; x++) {
nearby.add(new ChunkPosition(world, chunkX + x, chunkZ + z));
}
}
for (Player player : world.getPlayers()) {
Location playerLocation = player.getLocation();
ChunkPosition playerChunk = new ChunkPosition(world, playerLocation.getBlockX() >> 4, playerLocation.getBlockZ() >> 4);
if (nearby.contains(playerChunk)) {
return true;
}
}
return false;
}
use of com.loohp.interactionvisualizer.objectholders.ChunkPosition in project InteractionVisualizer by LOOHP.
the class TileEntityManager method onBlockExplode.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockExplode(BlockExplodeEvent event) {
Set<ChunkPosition> chunks = new LinkedHashSet<>();
if (TileEntity.isTileEntityType(event.getBlock().getType())) {
chunks.add(getChunk(event.getBlock().getLocation()));
}
for (Block block : event.blockList()) {
if (TileEntity.isTileEntityType(block.getType())) {
chunks.add(getChunk(block.getLocation()));
}
}
Bukkit.getScheduler().runTaskLater(plugin, () -> addTileEntities(chunks), 1);
}
use of com.loohp.interactionvisualizer.objectholders.ChunkPosition in project InteractionVisualizer by LOOHP.
the class TileEntityManager method getAllChunks.
private static Set<ChunkPosition> getAllChunks(Location location) {
Set<ChunkPosition> chunks = new LinkedHashSet<>();
World world = location.getWorld();
int chunkX = location.getBlockX() >> 4;
int chunkZ = location.getBlockZ() >> 4;
for (int z = -InteractionVisualizer.tileEntityCheckingRange; z <= InteractionVisualizer.tileEntityCheckingRange; z++) {
for (int x = -InteractionVisualizer.tileEntityCheckingRange; x <= InteractionVisualizer.tileEntityCheckingRange; x++) {
chunks.add(new ChunkPosition(world, chunkX + x, chunkZ + z));
}
}
return chunks;
}
use of com.loohp.interactionvisualizer.objectholders.ChunkPosition in project InteractionVisualizer by LOOHP.
the class TileEntityManager method getChunk.
private static ChunkPosition getChunk(Location location) {
World world = location.getWorld();
int chunkX = location.getBlockX() >> 4;
int chunkZ = location.getBlockZ() >> 4;
return new ChunkPosition(world, chunkX, chunkZ);
}
use of com.loohp.interactionvisualizer.objectholders.ChunkPosition in project InteractionVisualizer by LOOHP.
the class TileEntityManager method onEntityExplode.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) {
Set<ChunkPosition> chunks = new LinkedHashSet<>();
for (Block block : event.blockList()) {
if (TileEntity.isTileEntityType(block.getType())) {
chunks.add(getChunk(block.getLocation()));
}
}
Bukkit.getScheduler().runTaskLater(plugin, () -> addTileEntities(chunks), 1);
}
Aggregations