Search in sources :

Example 1 with ChunkPosition

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;
}
Also used : Player(org.bukkit.entity.Player) ChunkPosition(com.loohp.interactionvisualizer.objectholders.ChunkPosition) World(org.bukkit.World) HashSet(java.util.HashSet) Location(org.bukkit.Location)

Example 2 with ChunkPosition

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ChunkPosition(com.loohp.interactionvisualizer.objectholders.ChunkPosition) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 3 with ChunkPosition

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ChunkPosition(com.loohp.interactionvisualizer.objectholders.ChunkPosition) World(org.bukkit.World)

Example 4 with ChunkPosition

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);
}
Also used : ChunkPosition(com.loohp.interactionvisualizer.objectholders.ChunkPosition) World(org.bukkit.World)

Example 5 with ChunkPosition

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ChunkPosition(com.loohp.interactionvisualizer.objectholders.ChunkPosition) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ChunkPosition (com.loohp.interactionvisualizer.objectholders.ChunkPosition)5 LinkedHashSet (java.util.LinkedHashSet)3 World (org.bukkit.World)3 Block (org.bukkit.block.Block)2 EventHandler (org.bukkit.event.EventHandler)2 HashSet (java.util.HashSet)1 Location (org.bukkit.Location)1 Player (org.bukkit.entity.Player)1