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

The following examples show how to use org.bukkit.event.world.ChunkLoadEvent#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: HologramListener.java    From Holograms with MIT License 6 votes vote down vote up
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
    Chunk chunk = event.getChunk();
    if (chunk == null || !chunk.isLoaded()) {
        return;
    }

    Collection<Hologram> holograms = plugin.getHologramManager().getActiveHolograms().values();
    for (Hologram holo : holograms) {
        int chunkX = (int) Math.floor(holo.getLocation().getBlockX() / 16.0D);
        int chunkZ = (int) Math.floor(holo.getLocation().getBlockZ() / 16.0D);
        if (chunkX == chunk.getX() && chunkZ == chunk.getZ()) {
            plugin.getServer().getScheduler().runTaskLater(plugin, holo::spawn, 10L);
        }
    }
}
 
Example 2
Source File: InvisibleBlock.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
    final Chunk chunk = event.getChunk();
    Bukkit.getScheduler().runTask(GameHandler.getGameHandler().getPlugin(), new Runnable() {
        @Override
        public void run() {
            for (Block block36 : chunk.getBlocks(Material.getMaterial(36))) {
                block36.setType(Material.AIR);
                block36.setMetadata("block36", new FixedMetadataValue(GameHandler.getGameHandler().getPlugin(), true));
            }
            for (Block door : chunk.getBlocks(Material.IRON_DOOR_BLOCK)) {
                if (door.getRelative(BlockFace.DOWN).getType() != Material.IRON_DOOR_BLOCK
                        && door.getRelative(BlockFace.UP).getType() != Material.IRON_DOOR_BLOCK)
                    door.setType(Material.BARRIER);
            }
        }
    });
}
 
Example 3
Source File: ConveyorEffect.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
    Chunk chunk = event.getChunk();
    for (Region r : new HashMap<>(orphanCarts).keySet()) {
        StorageMinecart sm = orphanCarts.get(r);
        if (Util.isWithinChunk(chunk, sm.getLocation())) {
            carts.put(r, sm);
            orphanCarts.remove(r);
        }
    }
}
 
Example 4
Source File: ChunkListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Prevent FireWorks from loading chunks
 * @param event
 */
@EventHandler(priority = EventPriority.LOWEST)
public void onChunkLoad(ChunkLoadEvent event) {
    if (!Settings.IMP.TICK_LIMITER.FIREWORKS_LOAD_CHUNKS) {
        Chunk chunk = event.getChunk();
        Entity[] entities = chunk.getEntities();
        World world = chunk.getWorld();

        Exception e = new Exception();
        int start = 14;
        int end = 22;
        int depth = Math.min(end, getDepth(e));

        for (int frame = start; frame < depth; frame++) {
            StackTraceElement elem = getElement(e, frame);
            if (elem == null) return;
            String className = elem.getClassName();
            int len = className.length();
            if (className != null) {
                if (len > 15 && className.charAt(len - 15) == 'E' && className.endsWith("EntityFireworks")) {
                    for (Entity ent : world.getEntities()) {
                        if (ent.getType() == EntityType.FIREWORK) {
                            Vector velocity = ent.getVelocity();
                            double vertical = Math.abs(velocity.getY());
                            if (Math.abs(velocity.getX()) > vertical || Math.abs(velocity.getZ()) > vertical) {
                                Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled rogue FireWork at " + ent.getLocation());
                                ent.remove();
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 5
Source File: MainListener.java    From HolographicDisplays with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler (priority = EventPriority.MONITOR)
public void onChunkLoad(ChunkLoadEvent event) {
	Chunk chunk = event.getChunk();
	
	// Other plugins could call this event wrongly, check if the chunk is actually loaded.
	if (chunk.isLoaded()) {
		
		// In case another plugin loads the chunk asynchronously always make sure to load the holograms on the main thread.
		if (Bukkit.isPrimaryThread()) {
			processChunkLoad(chunk);
		} else {
			Bukkit.getScheduler().runTask(HolographicDisplays.getInstance(), () -> processChunkLoad(chunk));
		}
	}
}
 
Example 6
Source File: WorldListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
void onChunkLoad(ChunkLoadEvent event) {
	final Chunk chunk = event.getChunk();
	Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
		public void run() {
			if (chunk.isLoaded()) {
				plugin.loadShopkeepersInChunk(chunk);
			}
		}
	}, 2);
}
 
Example 7
Source File: SimpleChunkManager.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
private void onLoad(ChunkLoadEvent event) {
    Chunk loadedChunk = event.getChunk();
    for (EntityChunkData entityChunkData : SPAWN_QUEUE) {
        if (loadedChunk == entityChunkData.getRespawnLocation().getChunk()) {
            if (entityChunkData.getControllableEntity().spawn(entityChunkData.getRespawnLocation()) == SpawnResult.FAILED) {
                throw new ControllableEntitySpawnException();
            }
        }
    }
}
 
Example 8
Source File: BukkitQueue_0.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public static void onChunkLoad(ChunkLoadEvent event) {
    Chunk chunk = event.getChunk();
    long pair = MathMan.pairInt(chunk.getX(), chunk.getZ());
    keepLoaded.putIfAbsent(pair, Fawe.get().getTimer().getTickStart());
}