Java Code Examples for org.bukkit.event.world.ChunkUnloadEvent#getChunk()

The following examples show how to use org.bukkit.event.world.ChunkUnloadEvent#getChunk() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleChunkManager.java    From EntityAPI with GNU Lesser General Public License v3.0 7 votes vote down vote up
@EventHandler
public void onUnload(ChunkUnloadEvent event) {
    Chunk unloadedChunk = event.getChunk();
    for (Entity entity : unloadedChunk.getEntities()) {
        if (entity instanceof LivingEntity) {
            Object handle = BukkitUnwrapper.getInstance().unwrap(entity);
            if (handle instanceof ControllableEntityHandle) {
                ControllableEntity controllableEntity = ((ControllableEntityHandle) handle).getControllableEntity();
                if (controllableEntity != null && controllableEntity.isSpawned()) {
                    this.SPAWN_QUEUE.add(new EntityChunkData(controllableEntity, entity.getLocation()));
                    controllableEntity.despawn(DespawnReason.CHUNK_UNLOAD);
                }
            }
        }
    }
}
 
Example 2
Source File: HologramListener.java    From Holograms with MIT License 6 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
    Chunk chunk = event.getChunk();
    for (Entity entity : chunk.getEntities()) {
        HologramEntity hologramEntity = plugin.getEntityController().getHologramEntity(entity);
        if (hologramEntity != null) {
            hologramEntity.remove();
        }
    }
    Collection<Hologram> holograms = plugin.getHologramManager().getActiveHolograms().values();
    for (Hologram holo : holograms) {
        Location loc = holo.getLocation();
        int chunkX = (int) Math.floor(loc.getBlockX() / 16.0D);
        int chunkZ = (int) Math.floor(loc.getBlockZ() / 16.0D);
        if (chunkX == chunk.getX() && chunkZ == chunk.getZ()) {
            holo.despawn();
        }
    }
}
 
Example 3
Source File: EventListener.java    From iDisguise with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onChunkUnload(ChunkUnloadEvent event) {
	final Chunk chunk = event.getChunk();
	final List<Integer> entityIds = new ArrayList<Integer>();
	for(Entity entity : chunk.getEntities()) {
		if(entity instanceof LivingEntity) {
			entityIds.add(entity.getEntityId());
		}
	}
	Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
		
		public void run() {
			if(!chunk.isLoaded()) {
				for(int entityId : entityIds) {
					EntityIdList.removeEntity(entityId);
				}
			}
		}
		
	}, 40L); // TODO: increase delay?
}
 
Example 4
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent unload) {
    if (unload instanceof Cancellable) {
        Chunk chunk = unload.getChunk();

        for (String name : Main.getGameNames()) {
            Game game = Main.getGame(name);
            if (game.getStatus() != GameStatus.DISABLED && game.getStatus() != GameStatus.WAITING
                    && GameCreator.isChunkInArea(chunk, game.getPos1(), game.getPos2())) {
                ((Cancellable) unload).setCancelled(false);
                return;
            }
        }
    }
}
 
Example 5
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent unload) {
    if (unload instanceof Cancellable) {
        Chunk chunk = unload.getChunk();

        for (String name : Main.getGameNames()) {
            Game game = Main.getGame(name);
            if (game.getStatus() != GameStatus.DISABLED && game.getStatus() != GameStatus.WAITING
                    && GameCreator.isChunkInArea(chunk, game.getPos1(), game.getPos2())) {
                ((Cancellable) unload).setCancelled(false);
                return;
            }
        }
    }
}
 
Example 6
Source File: ConveyorEffect.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
    Chunk chunk = event.getChunk();
    for (Region r : new HashMap<>(carts).keySet()) {
        StorageMinecart sm = carts.get(r);
        if (Util.isWithinChunk(chunk, sm.getLocation())) {
            carts.remove(r);
            orphanCarts.put(r, sm);
        }
    }
}
 
Example 7
Source File: WorldListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onChunkUnloadEvent(ChunkUnloadEvent event)
{
	World world = event.getWorld();
	Chunk chunk = event.getChunk();
	
	if (!this.plugin.getWorldGuardCommunicator().doUnloadChunkFlagCheck(world, chunk))
	{
		event.setCancelled(true);
	}
}
 
Example 8
Source File: BukkitQueue_0.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public static void onChunkUnload(ChunkUnloadEvent event) {
    Chunk chunk = event.getChunk();
    long pair = MathMan.pairInt(chunk.getX(), chunk.getZ());
    Long lastLoad = keepLoaded.get(pair);
    if (lastLoad != null) {
        if (Fawe.get().getTimer().getTickStart() - lastLoad < 10000) {
            event.setCancelled(true);
        } else {
            keepLoaded.remove(pair);
        }
    }
}