Search in sources :

Example 1 with TileEntityRemovedEvent

use of com.loohp.interactionvisualizer.api.events.TileEntityRemovedEvent in project InteractionVisualizer by LOOHP.

the class TileEntityManager method addTileEntities.

private static synchronized void addTileEntities(ChunkPosition chunk) {
    NMSTileEntitySet<?, ?> list = NMS.getInstance().getTileEntities(chunk, false);
    Set<Block> blocks = byChunk.get(chunk);
    if (blocks == null) {
        blocks = new LinkedHashSet<>();
        byChunk.put(chunk, blocks);
    }
    Map<Block, TileEntityType> newBlocks = new LinkedHashMap<>();
    if (list != null) {
        for (TileEntity tile : list) {
            if (tile != null) {
                Block block = tile.getBlock();
                TileEntityType type = tile.getType();
                active.get(type).add(block);
                newBlocks.put(block, type);
                blocks.add(block);
            }
        }
    }
    Iterator<Block> itr = blocks.iterator();
    while (itr.hasNext()) {
        Block block = itr.next();
        TileEntityType type = newBlocks.get(block);
        if (type == null) {
            itr.remove();
            for (TileEntityType t : tileEntityTypes) {
                if (active.get(t).remove(block)) {
                    Bukkit.getPluginManager().callEvent(new TileEntityRemovedEvent(block, t));
                }
            }
        } else {
            for (TileEntityType t : tileEntityTypes) {
                if (!t.equals(type)) {
                    if (active.get(t).remove(block)) {
                        Bukkit.getPluginManager().callEvent(new TileEntityRemovedEvent(block, t));
                    }
                }
            }
        }
    }
}
Also used : TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) TileEntityRemovedEvent(com.loohp.interactionvisualizer.api.events.TileEntityRemovedEvent) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) Block(org.bukkit.block.Block) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

TileEntityRemovedEvent (com.loohp.interactionvisualizer.api.events.TileEntityRemovedEvent)1 TileEntity (com.loohp.interactionvisualizer.objectholders.TileEntity)1 TileEntityType (com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType)1 LinkedHashMap (java.util.LinkedHashMap)1 Block (org.bukkit.block.Block)1