下面列出了org.bukkit.event.world.ChunkUnloadEvent#getChunk ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
}
}
}
@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();
}
}
}
@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?
}
@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;
}
}
}
}
@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;
}
}
}
}
@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);
}
}
}
@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);
}
}
@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);
}
}
}