org.bukkit.event.world.ChunkUnloadEvent Java Examples

The following examples show how to use org.bukkit.event.world.ChunkUnloadEvent. 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: EntityLimits.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent event) {
    if (!Settings.saveEntities || !IslandGuard.inWorld(event.getWorld())) {
        return;
    }
    // Delete the chunk data
    entities.set(event.getWorld().getName() + "." + event.getChunk().getX() + "." + event.getChunk().getZ() , null);
    // Create new entry
    Arrays.stream(event.getChunk().getEntities()).filter(x -> x.hasMetadata("spawnLoc")).forEach(entity -> {
        // Get the meta data
        entity.getMetadata("spawnLoc").stream().filter(y -> y.getOwningPlugin().equals(plugin)).forEach(v -> {
            entities.set(event.getWorld().getName() + "." 
                    + event.getChunk().getX() + "." + event.getChunk().getZ() + "." 
                    + entity.getUniqueId().toString(), v.asString());            
        });
    });
    Util.saveYamlFile(entities, "entitylimits.yml", true);
}
 
Example #3
Source File: BonusGoodieManager.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void OnChunkUnload(ChunkUnloadEvent event) {
	
	BonusGoodie goodie;
	
	for (Entity entity : event.getChunk().getEntities()) {
		if (!(entity instanceof Item)) {
			continue;
		}
		
		goodie = CivGlobal.getBonusGoodie(((Item)entity).getItemStack());
		if (goodie == null) {
			continue;
		}
		
		goodie.replenish(((Item)entity).getItemStack(), (Item)entity, null, null);
	}
}
 
Example #4
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 #5
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 #6
Source File: WorldEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onChunkUnload(ChunkUnloadEvent event) {
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getWorld().getUID())) {
        return;
    }

    final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getWorld().getUID());
    final GDChunk gdChunk = claimWorldManager.getChunk(event.getChunk());
    if (gdChunk != null) {
        if (gdChunk.getTrackedShortPlayerPositions().size() > 0) {
            gdChunk.saveChunkTrackingData();
        }
        claimWorldManager.removeChunk(gdChunk.getChunkKey());
    }
}
 
Example #7
Source File: MainListener.java    From HolographicDisplays with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent event) {
	for (Entity entity : event.getChunk().getEntities()) {
		if (!entity.isDead()) {
			NMSEntityBase entityBase = nmsManager.getNMSEntityBase(entity);
			
			if (entityBase != null) {
				((CraftHologram) entityBase.getHologramLine().getParent()).despawnEntities();
			}
		}
	}
}
 
Example #8
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onChunkUnloadEvent(ChunkUnloadEvent event) {
	Boolean persist = CivGlobal.isPersistChunk(event.getChunk());		
	if (persist != null && persist == true) {
		event.setCancelled(true);
	}
}
 
Example #9
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);
        }
    }
}
 
Example #10
Source File: ChunkListener.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onUnload(ChunkUnloadEvent unload) {
  Game game = BedwarsRel.getInstance().getGameManager()
      .getGameByChunkLocation(unload.getChunk().getX(),
          unload.getChunk().getZ());
  if (game == null) {
    return;
  }

  if (game.getState() != GameState.RUNNING) {
    return;
  }

  unload.setCancelled(true);
}
 
Example #11
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 #12
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 #13
Source File: ChunkListener.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent e) {
    final Map<Location, Shop> inChunk = plugin.getShopManager().getShops(e.getChunk());
    if (inChunk == null) {
        return;
    }
    for (Shop shop : inChunk.values()) {
        if (shop.isLoaded()) {
            shop.onUnload();
        }
    }
}
 
Example #14
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 #15
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 #16
Source File: KeepLobbyLoadedEvent.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
    public void onChunkUnload(ChunkUnloadEvent e){
        LobbyManager.getInstance();
		if(LobbyManager.lobbychunks.contains(e.getChunk())){
//			e.setCancelled(true)
//			TODO find a alternative way to keep the lobby chunks loaded
			SurvivalGames.debug("[KeepLobbyLoadedEvent] Lobby Chunk unloading");
        }
        //System.out.println("Chunk unloading");
    }
 
Example #17
Source File: EntityRemoveListener.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent e) {
    if (sm.getCustomConfig().getStringList("no-stack-worlds")
            .contains(e.getWorld().getName())) {
        return;
    }

    for (Entity entity : e.getChunk().getEntities()) {
        cleanupEntity(entity);
    }
}
 
Example #18
Source File: ThreadSafetyListener.java    From LagMonitor with MIT License 4 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent chunkUnloadEvent) {
    checkSafety(chunkUnloadEvent);
}
 
Example #19
Source File: WorldListener.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
void onChunkUnload(ChunkUnloadEvent event) {
	plugin.unloadShopkeepersInChunk(event.getChunk());
}
 
Example #20
Source File: BlockListener.java    From ObsidianDestroyer with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onChunkUnload(ChunkUnloadEvent event) {
    ChunkManager.getInstance().unloadChunk(event.getChunk());
}
 
Example #21
Source File: Events.java    From ThinkMap with Apache License 2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent event) {
    // Save the chunk in its current state and use it instead of loading
    // the chunk
    plugin.getChunkManager(event.getWorld()).deactivateChunk(event.getChunk());
}
 
Example #22
Source File: SignPlaceholders.java    From VoxelGamesLibv2 with MIT License 4 votes vote down vote up
@EventHandler
public void chunkUnload(@Nonnull ChunkUnloadEvent event) {
    Arrays.stream(event.getChunk().getTileEntities())
            .filter(blockState -> blockState instanceof Sign)
            .forEach(sign -> lastSeenSigns.remove(sign.getLocation()));
}
 
Example #23
Source File: SkullPlaceHolders.java    From VoxelGamesLibv2 with MIT License 4 votes vote down vote up
@EventHandler
public void chunkUnload(@Nonnull ChunkUnloadEvent event) {
    Arrays.stream(event.getChunk().getTileEntities())
            .filter(blockState -> blockState instanceof Skull)
            .forEach(sign -> lastSeenSkulls.remove(sign.getLocation()));
}
 
Example #24
Source File: ProtectionHandler.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
    public void onChunkUnload(ChunkUnloadEvent event) {
//        System.out.println("chunk unloaded: " + event.getChunk().getX() + ", " + event.getChunk().getZ());
        UnloadedInventoryHandler.getInstance().updateInventoriesInChunk(event.getChunk());
    }
 
Example #25
Source File: WorthListener.java    From factions-top with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void recalculate(ChunkUnloadEvent event) {
    plugin.getWorthManager().recalculate(event.getChunk(), RecalculateReason.UNLOAD);
}
 
Example #26
Source File: ThreadSafetyListener.java    From LagMonitor with MIT License 4 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent chunkUnloadEvent) {
    checkSafety(chunkUnloadEvent);
}
 
Example #27
Source File: ChunkUnloadMetadataPurge.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onUnload(ChunkUnloadEvent event) {
    EntityTracker.chunkWiper(event);
}
 
Example #28
Source File: EntityTracker.java    From EliteMobs with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Wipes a chunk clean of all relevant plugin entities and data.
 *
 * @param event ChunkUnloadEvent to be cleared
 */
public static void chunkWiper(ChunkUnloadEvent event) {
    for (Entity entity : event.getChunk().getEntities())
        wipeEntity(entity);
}