Java Code Examples for org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason#CUSTOM

The following examples show how to use org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason#CUSTOM . 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: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
    if (event.isCancelled() || event.getSpawnReason() == SpawnReason.CUSTOM) {
        return;
    }

    for (String gameName : Main.getGameNames()) {
        Game game = Main.getGame(gameName);
        if (game.getStatus() != GameStatus.DISABLED)
            // prevent creature spawn everytime, not just in game
            if (/*(game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) &&*/ game.getOriginalOrInheritedPreventSpawningMobs()) {
                if (GameCreator.isInArea(event.getLocation(), game.getPos1(), game.getPos2())) {
                    event.setCancelled(true);
                    return;
                    //}
                } else /*if (game.getStatus() == GameStatus.WAITING) {*/
                    if (game.getLobbyWorld() == event.getLocation().getWorld()) {
                        if (event.getLocation().distanceSquared(game.getLobbySpawn()) <= Math
                                .pow(Main.getConfigurator().config.getInt("prevent-lobby-spawn-mobs-in-radius"), 2)) {
                            event.setCancelled(true);
                            return;
                        }
                    }
            }
    }
}
 
Example 2
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
    if (event.isCancelled() || event.getSpawnReason() == SpawnReason.CUSTOM) {
        return;
    }

    for (String gameName : Main.getGameNames()) {
        Game game = Main.getGame(gameName);
        if (game.getStatus() != GameStatus.DISABLED)
            // prevent creature spawn everytime, not just in game
            if (/*(game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) &&*/ game.getOriginalOrInheritedPreventSpawningMobs()) {
                if (GameCreator.isInArea(event.getLocation(), game.getPos1(), game.getPos2())) {
                    event.setCancelled(true);
                    return;
                    //}
                } else /*if (game.getStatus() == GameStatus.WAITING) {*/
                    if (game.getLobbyWorld() == event.getLocation().getWorld()) {
                        if (event.getLocation().distanceSquared(game.getLobbySpawn()) <= Math
                                .pow(Main.getConfigurator().config.getInt("prevent-lobby-spawn-mobs-in-radius"), 2)) {
                            event.setCancelled(true);
                            return;
                        }
                    }
            }
    }
}
 
Example 3
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onBedWarsSpawnIsCancelled(CreatureSpawnEvent event) {
    if (!event.isCancelled()) {
        return;
    }
    // Fix for uSkyBlock plugin
    if (event.getSpawnReason() == SpawnReason.CUSTOM && Main.getInstance().isEntityInGame(event.getEntity())) {
        event.setCancelled(false);
    }
}
 
Example 4
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onBedWarsSpawnIsCancelled(CreatureSpawnEvent event) {
    if (!event.isCancelled()) {
        return;
    }
    // Fix for uSkyBlock plugin
    if (event.getSpawnReason() == SpawnReason.CUSTOM && Main.getInstance().isEntityInGame(event.getEntity())) {
        event.setCancelled(false);
    }
}
 
Example 5
Source File: BlockVillagerSpawnListener.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
void onSpawn(CreatureSpawnEvent event) {
	if (event.getEntityType() == EntityType.VILLAGER && event.getSpawnReason() != SpawnReason.CUSTOM) {
		event.setCancelled(true);
	}
}