Java Code Examples for org.bukkit.event.entity.CreatureSpawnEvent#isCancelled()

The following examples show how to use org.bukkit.event.entity.CreatureSpawnEvent#isCancelled() . 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: SpawnEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {
    if (event == null || !plugin.getWorldManager().isSkyAssociatedWorld(event.getLocation().getWorld())) {
        return; // Bail out, we don't care
    }
    if (!event.isCancelled() && ADMIN_INITIATED.contains(event.getSpawnReason())) {
        return; // Allow it, the above method would have blocked it if it should be blocked.
    }
    checkLimits(event, event.getEntity().getType(), event.getLocation());
    if (event.getEntity() instanceof WaterMob) {
        Location loc = event.getLocation();
        if (isDeepOceanBiome(loc) && isPrismarineRoof(loc)) {
            loc.getWorld().spawnEntity(loc, EntityType.GUARDIAN);
            event.setCancelled(true);
        }
    }
    if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.BUILD_WITHER && event.getEntity() instanceof Wither) {
        IslandInfo islandInfo = plugin.getIslandInfo(event.getLocation());
        if (islandInfo != null && islandInfo.getLeader() != null) {
            event.getEntity().setCustomName(I18nUtil.tr("{0}''s Wither", islandInfo.getLeader()));
            event.getEntity().setMetadata("fromIsland", new FixedMetadataValue(plugin, islandInfo.getName()));
        }
    }
}
 
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: 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 6
Source File: EntityTracker.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void registerNaturalEntity(CreatureSpawnEvent event) {
    if (event.isCancelled()) return;
    if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL) ||
            event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CUSTOM) &&
                    !ConfigValues.defaultConfig.getBoolean(DefaultConfig.STRICT_SPAWNING_RULES))
        registerNaturalEntity(event.getEntity());
}
 
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 = false)
public void onCreatureSpawn(CreatureSpawnEvent event) {
	if (nmsManager.isNMSEntityBase(event.getEntity())) {
		if (event.isCancelled()) {
			event.setCancelled(false);
		}
	}
}
 
Example 8
Source File: NaturalMobSpawnEventHandler.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onSpawn(CreatureSpawnEvent event) {

    if (getIgnoreMob()) {
        setIgnoreMob(false);
        return;
    }

    if (event.isCancelled()) return;
    /*
    Deal with entities spawned within the plugin
     */
    if (EntityTracker.isEliteMob(event.getEntity())) return;

    if (!ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.NATURAL_MOB_SPAWNING))
        return;
    if (!ConfigValues.validMobsConfig.getBoolean(ValidMobsConfig.ALLOW_AGGRESSIVE_ELITEMOBS))
        return;
    if (!ConfigValues.validWorldsConfig.getBoolean("Valid worlds." + event.getEntity().getWorld().getName()))
        return;
    if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER) && !ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.SPAWNERS_SPAWN_ELITE_MOBS))
        return;
    if (event.getEntity().getCustomName() != null && ConfigValues.defaultConfig.getBoolean(DefaultConfig.PREVENT_ELITE_MOB_CONVERSION_OF_NAMED_MOBS))
        return;

    if (!(event.getSpawnReason() == NATURAL || event.getSpawnReason() == CUSTOM && !ConfigValues.defaultConfig.getBoolean(DefaultConfig.STRICT_SPAWNING_RULES)))
        return;
    if (!EliteMobProperties.isValidEliteMobType(event.getEntityType()))
        return;

    LivingEntity livingEntity = event.getEntity();

    int huntingGearChanceAdder = getHuntingGearBonus(livingEntity);

    Double validChance = (ConfigValues.mobCombatSettingsConfig.getDouble(MobCombatSettingsConfig.AGGRESSIVE_MOB_CONVERSION_PERCENTAGE) +
            huntingGearChanceAdder) / 100;

    if (!(ThreadLocalRandom.current().nextDouble() < validChance))
        return;

    NaturalEliteMobSpawnEventHandler.naturalMobProcessor(livingEntity, event.getSpawnReason());

}
 
Example 9
Source File: SmallTreasureGoblin.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler (priority = EventPriority.HIGHEST)
public void onSpawn(CreatureSpawnEvent event) {

    if (event.isCancelled()) return;
    if (!EventLauncher.verifyPlayerCount()) return;

    if (EliteMobs.validWorldList.contains(event.getEntity().getWorld())) {

        if (entityQueued && (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL) ||
                event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CUSTOM)) &&
                event.getEntity() instanceof Zombie) {

            entityQueued = false;
            initalizeEvent(event.getLocation());

        }

    }

}
 
Example 10
Source File: HologramListener.java    From Holograms with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onCreatureSpawn(CreatureSpawnEvent event) {
    if (event.isCancelled() && plugin.getEntityController().getHologramEntity(event.getEntity()) != null) {
        event.setCancelled(false);
    }
}
 
Example 11
Source File: DeadMoon.java    From EliteMobs with GNU General Public License v3.0 2 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onSpawn(CreatureSpawnEvent event) {

    if (event.isCancelled()) return;

    if (event.getEntity().getWorld().getTime() < 13184 || event.getEntity().getWorld().getTime() > 22800) return;
    if (!event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL)) return;
    if (!(event.getEntity().getType().equals(EntityType.ZOMBIE)) && !(event.getEntity().getType().equals(EntityType.HUSK)))
        return;
    if (!EventLauncher.verifyPlayerCount()) return;

    if (!EliteMobs.validWorldList.contains(event.getEntity().getWorld())) return;

    if (event.getEntity().getWorld().getEnvironment().equals(World.Environment.NETHER) ||
            event.getEntity().getWorld().getEnvironment().equals(World.Environment.THE_END)) return;

    if (MoonPhaseDetector.detectMoonPhase(event.getEntity().getWorld()) != MoonPhaseDetector.moonPhase.NEW_MOON)
        return;

    if (!ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.NATURAL_MOB_SPAWNING) ||
            !ConfigValues.validMobsConfig.getBoolean(ValidMobsConfig.ALLOW_AGGRESSIVE_ELITEMOBS))
        return;


    if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER) && !ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.SPAWNERS_SPAWN_ELITE_MOBS))
        return;

    if (!(event.getSpawnReason() == NATURAL || event.getSpawnReason() == CUSTOM)) return;

    if (!EntityTracker.isEliteMob(event.getEntity()))
        NaturalEliteMobSpawnEventHandler.naturalMobProcessor(event.getEntity(), CreatureSpawnEvent.SpawnReason.NATURAL);

    //add entityQueued
    if (entityQueued && !TheReturned.isTheReturned(event.getEntity())
            && (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL) ||
            event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CUSTOM))) {

        eventOngoing = true;
        entityQueued = false;

        EventMessage.sendEventMessage(event.getEntity(), ConfigValues.eventsConfig.getString(EventsConfig.DEADMOON_ANNOUNCEMENT_MESSAGE));

        ZombieKing.spawnZombieKing(event.getLocation());
        terminateEvent(event.getEntity());

    }

}