Java Code Examples for org.bukkit.event.entity.CreatureSpawnEvent#getSpawnReason()
The following examples show how to use
org.bukkit.event.entity.CreatureSpawnEvent#getSpawnReason() .
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 |
@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 |
@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: MobFeature.java From VoxelGamesLibv2 with MIT License | 6 votes |
@EventHandler public void onSpawn(@Nonnull CreatureSpawnEvent event) { if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM || event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) { return; } if (!denySpawn) { return; } if (!event.getLocation().getWorld().getName().equals(worldName)) { return; } if (blacklist.length != 0) { if (Arrays.stream(blacklist).anyMatch(m -> m.equals(event.getEntityType()))) { event.setCancelled(true); } } else if (whitelist.length != 0) { if (Arrays.stream(whitelist).noneMatch(m -> m.equals(event.getEntityType()))) { event.setCancelled(true); } } else { event.setCancelled(true); } }
Example 4
Source File: DMobListener.java From DungeonsXL with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onCreatureSpawn(CreatureSpawnEvent event) { World world = event.getLocation().getWorld(); EditWorld editWorld = plugin.getEditWorld(world); GameWorld gameWorld = plugin.getGameWorld(world); if (editWorld != null || gameWorld != null) { switch (event.getSpawnReason()) { case CHUNK_GEN: case JOCKEY: case MOUNT: case NATURAL: event.setCancelled(true); } } }
Example 5
Source File: SpawnEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@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 6
Source File: SpawnEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onPhantomSpawn(CreatureSpawnEvent event) { if (!(event.getEntity() instanceof Phantom) || event.getSpawnReason() != CreatureSpawnEvent.SpawnReason.NATURAL) { return; } World spawnWorld = event.getEntity().getWorld(); if (!phantomsInOverworld && plugin.getWorldManager().isSkyWorld(spawnWorld)) { event.setCancelled(true); } if (!phantomsInNether && plugin.getWorldManager().isSkyNether(spawnWorld)) { event.setCancelled(true); } }
Example 7
Source File: WorldListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@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 8
Source File: MobsMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void checkSpawn(final CreatureSpawnEvent event) { if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM || event.getEntity() instanceof ArmorStand) { return; } QueryResponse response = this.mobsFilter.query( new EntitySpawnQuery(event, event.getEntity(), event.getSpawnReason())); event.setCancelled(response.isDenied()); }
Example 9
Source File: OwnedMobTracker.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSlimeSplit(CreatureSpawnEvent event) { switch (event.getSpawnReason()) { case SLIME_SPLIT: Slime parent = splitter.get(); if (parent != null) { MobInfo info = resolveEntity(parent); if (info != null) { entities().trackEntity(event.getEntity(), info); } } break; } }
Example 10
Source File: WorldListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@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 11
Source File: OwnedMobTracker.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSlimeSplit(CreatureSpawnEvent event) { switch(event.getSpawnReason()) { case SLIME_SPLIT: Slime parent = splitter.get(); if(parent != null) { MobInfo info = resolveEntity(parent); if(info != null) { entities().trackEntity(event.getEntity(), info); } } break; } }
Example 12
Source File: EntityListener.java From Carbon with GNU Lesser General Public License v3.0 | 5 votes |
/** * Change rabbit's color and age depending on chance. * @param evt */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onRabbitSpawned(CreatureSpawnEvent evt) { if (evt.getEntityType() == Carbon.injector().rabbitEntity) if (evt.getSpawnReason() == CreatureSpawnEvent.SpawnReason.DISPENSE_EGG || evt.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG || evt.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NATURAL || evt.getSpawnReason() == CreatureSpawnEvent.SpawnReason.BREEDING || evt.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER) { Rabbit rabbit = (Rabbit)evt.getEntity(); if (evt.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG && rabbit.hasParent()) { rabbit.setRabbitType(rabbit.getParent().getRabbitType()); return; } int type = Utilities.random.nextInt(6); boolean isKiller = Utilities.random.nextInt(1000) == 999; if (evt.getSpawnReason() != CreatureSpawnEvent.SpawnReason.DISPENSE_EGG && evt.getSpawnReason() != CreatureSpawnEvent.SpawnReason.SPAWNER_EGG && evt.getSpawnReason() != CreatureSpawnEvent.SpawnReason.BREEDING && evt.getSpawnReason() != CreatureSpawnEvent.SpawnReason.SPAWNER) { boolean isBaby = Utilities.random.nextInt(4) == 3; if (isBaby) { rabbit.setBaby(); } } if (isKiller) { rabbit.setRabbitType(EntityRabbit.TYPE_KILLER); } else { rabbit.setRabbitType(type); } } }
Example 13
Source File: ListenerMobCombat.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onSpawn(CreatureSpawnEvent e) { LivingEntity entity = e.getEntity(); SpawnReason spawnReason = e.getSpawnReason(); FixedMetadataValue fixedValue = new FixedMetadataValue(this.expansion.getPlugin().getPlugin(), spawnReason); entity.setMetadata("combatlogx_spawn_reason", fixedValue); }
Example 14
Source File: NetherTerraFormEvents.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
/** * Comes AFTER the SpawnEvents{@link #onCreatureSpawn(CreatureSpawnEvent)} - so cancelled will have effect * @param e */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onCreatureSpawn(CreatureSpawnEvent e) { if (!spawnEnabled || e.getSpawnReason() != CreatureSpawnEvent.SpawnReason.NATURAL) { return; } if (!plugin.getWorldManager().isSkyNether(e.getLocation().getWorld())) { return; } if (e.getLocation().getBlockY() > plugin.getWorldManager().getNetherWorld().getMaxHeight()) { // Block spawning above nether... e.setCancelled(true); return; } if (e.getEntity() instanceof PigZombie) { Block block = e.getLocation().getBlock().getRelative(BlockFace.DOWN); if (isNetherFortressWalkway(block)) { e.setCancelled(true); double p = RND.nextDouble(); if (p <= chanceWither && block.getRelative(BlockFace.UP, 3).getType() == Material.AIR) { WitherSkeleton mob = (WitherSkeleton) e.getLocation().getWorld().spawnEntity( e.getLocation(), EntityType.WITHER_SKELETON); mob.getEquipment().setItemInMainHand(new ItemStack(Material.STONE_SWORD, 1)); } else if (p <= chanceWither+chanceBlaze) { e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.BLAZE); } else if (p <= chanceWither+chanceBlaze+chanceSkeleton) { e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.SKELETON); } else { e.setCancelled(false); // Spawn PigZombie } } } }
Example 15
Source File: BlockVillagerSpawnListener.java From Shopkeepers with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) void onSpawn(CreatureSpawnEvent event) { if (event.getEntityType() == EntityType.VILLAGER && event.getSpawnReason() != SpawnReason.CUSTOM) { event.setCancelled(true); } }
Example 16
Source File: MobModule.java From CardinalPGM with MIT License | 4 votes |
@EventHandler public void onMobSpawn(CreatureSpawnEvent event) { if (event.getSpawnReason() != CreatureSpawnEvent.SpawnReason.CUSTOM && filter.evaluate(event, event.getSpawnReason(), event.getEntityType(), event.getEntity()).equals(FilterState.DENY)) event.setCancelled(true); }
Example 17
Source File: EntityLimits.java From askyblock with GNU General Public License v2.0 | 4 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onVillagerSpawn(final CreatureSpawnEvent e) { // If not an villager if (!(e.getEntity() instanceof Villager)) { return; } if (DEBUG3) { plugin.getLogger().info("Villager spawn event! " + e.getEventName()); plugin.getLogger().info("Reason:" + e.getSpawnReason().toString()); plugin.getLogger().info("Entity:" + e.getEntityType().toString()); } // Only cover overworld if (!e.getEntity().getWorld().equals(ASkyBlock.getIslandWorld())) { return; } // If there's no limit - leave it if (Settings.villagerLimit <= 0) { return; } // We only care about villagers breeding, being cured or coming from a spawn egg, etc. if (e.getSpawnReason() != SpawnReason.SPAWNER && e.getSpawnReason() != SpawnReason.BREEDING && e.getSpawnReason() != SpawnReason.DISPENSE_EGG && e.getSpawnReason() != SpawnReason.SPAWNER_EGG && e.getSpawnReason() != SpawnReason.CURED) { return; } Island island = plugin.getGrid().getProtectedIslandAt(e.getLocation()); if (island == null || island.getOwner() == null || island.isSpawn()) { // No island, no limit return; } int limit = Settings.villagerLimit * Math.max(1,plugin.getPlayers().getMembers(island.getOwner()).size()); //plugin.getLogger().info("DEBUG: villager limit = " + limit); //long time = System.nanoTime(); int pop = island.getPopulation(); //plugin.getLogger().info("DEBUG: time = " + ((System.nanoTime() - time)*0.000000001)); if (pop >= limit) { plugin.getLogger().warning( "Island at " + island.getCenter().getBlockX() + "," + island.getCenter().getBlockZ() + " hit the island villager limit of " + limit); //plugin.getLogger().info("Stopped villager spawning on island " + island.getCenter()); // Get all players in the area List<Entity> players = e.getEntity().getNearbyEntities(10,10,10); for (Entity player: players) { if (player instanceof Player) { Player p = (Player) player; Util.sendMessage(p, ChatColor.RED + plugin.myLocale(island.getOwner()).villagerLimitError.replace("[number]", String.valueOf(limit))); } } plugin.getMessages().tellTeam(island.getOwner(), ChatColor.RED + plugin.myLocale(island.getOwner()).villagerLimitError.replace("[number]", String.valueOf(limit))); if (e.getSpawnReason().equals(SpawnReason.CURED)) { // Easter Egg. Or should I say Easter Apple? ItemStack goldenApple = new ItemStack(Material.GOLDEN_APPLE); // Nerfed //goldenApple.setDurability((short)1); e.getLocation().getWorld().dropItemNaturally(e.getLocation(), goldenApple); } e.setCancelled(true); } }
Example 18
Source File: NaturalMobSpawnEventHandler.java From EliteMobs with GNU General Public License v3.0 | 4 votes |
@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 19
Source File: MobsMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) public void checkSpawn(final CreatureSpawnEvent event) { if(event.getSpawnReason() != CreatureSpawnEvent.SpawnReason.CUSTOM) { event.setCancelled(mobsFilter.query(new EntitySpawnQuery(event, event.getEntity(), event.getSpawnReason())).isDenied()); } }
Example 20
Source File: DeadMoon.java From EliteMobs with GNU General Public License v3.0 | 2 votes |
@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()); } }