Java Code Examples for org.bukkit.event.entity.CreatureSpawnEvent#setCancelled()
The following examples show how to use
org.bukkit.event.entity.CreatureSpawnEvent#setCancelled() .
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: 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 3
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 4
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 5
Source File: MainListener.java From HolographicDisplays with GNU General Public License v3.0 | 5 votes |
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = false) public void onCreatureSpawn(CreatureSpawnEvent event) { if (nmsManager.isNMSEntityBase(event.getEntity())) { if (event.isCancelled()) { event.setCancelled(false); } } }
Example 6
Source File: BukkitPlotListener.java From PlotMe-Core with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onCreatureSpawn(CreatureSpawnEvent event) { Location location = BukkitUtil.adapt(event.getLocation()); if (manager.isPlotWorld(location)) { PlotId id = manager.getPlotId(location); if (id != null) { event.setCancelled(true); } } }
Example 7
Source File: NetherSpawning.java From askyblock with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onSkeletonSpawn(final CreatureSpawnEvent e) { if (DEBUG) plugin.getLogger().info("DEBUG: " + e.getEventName()); if (!Settings.hackSkeletonSpawners) { return; } if (!hasWitherSkeleton) { // Only if this type of Entity exists return; } // Check for spawn reason if (e.getSpawnReason().equals(SpawnReason.SPAWNER) && e.getEntityType().equals(EntityType.SKELETON)) { if (!Settings.createNether || !Settings.newNether || ASkyBlock.getNetherWorld() == null) { return; } // Check world if (!e.getLocation().getWorld().equals(ASkyBlock.getNetherWorld())) { return; } if (random.nextDouble() < WITHER_SKELETON_SPAWN_CHANCE) { if (DEBUG) plugin.getLogger().info("DEBUG: Wither Skelly spawned"); e.setCancelled(true); e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.WITHER_SKELETON); } else { if (DEBUG) plugin.getLogger().info("DEBUG: Standard Skelly spawned"); } } }
Example 8
Source File: WitchesModule.java From UHC with MIT License | 5 votes |
@EventHandler(ignoreCancelled = true) public void on(CreatureSpawnEvent event) { if (isEnabled()) return; if (event.getEntity().getType() == EntityType.WITCH) { event.setCancelled(true); } }
Example 9
Source File: CreatureForceSpawnListener.java From Shopkeepers with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) void onCreatureSpawn(CreatureSpawnEvent event) { if (nextSpawnLocation == null) return; if (event.getEntityType() == nextEntityType && event.getLocation().equals(nextSpawnLocation)) { event.setCancelled(false); } else { // this shouldn't normally be reached.. Log.debug("Shopkeeper entity-spawning seems to be out of sync: spawn-force was activated for an entity of type " + nextEntityType.name() + " at location " + nextSpawnLocation.toString() + ", but a (different) entity of type " + event.getEntityType().name() + " was spawned at location " + event.getLocation().toString() + "."); } nextSpawnLocation = null; nextEntityType = null; }
Example 10
Source File: EntityListener.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onEntitySpawn(CreatureSpawnEvent ese) { if (BedwarsRel.getInstance().getGameManager() == null) { return; } if (ese.getLocation() == null) { return; } if (ese.getLocation().getWorld() == null) { return; } Game game = BedwarsRel.getInstance().getGameManager().getGameByLocation(ese.getLocation()); if (game == null) { return; } if (game.getState() == GameState.STOPPED) { return; } if (ese.getEntityType().equals(EntityType.CREEPER) || ese.getEntityType().equals(EntityType.CAVE_SPIDER) || ese.getEntityType().equals(EntityType.SPIDER) || ese.getEntityType().equals(EntityType.ZOMBIE) || ese.getEntityType().equals(EntityType.SKELETON) || ese.getEntityType().equals(EntityType.SILVERFISH)) { ese.setCancelled(true); } }
Example 11
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 12
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 13
Source File: HologramListener.java From Holograms with MIT License | 4 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onCreatureSpawn(CreatureSpawnEvent event) { if (event.isCancelled() && plugin.getEntityController().getHologramEntity(event.getEntity()) != null) { event.setCancelled(false); } }
Example 14
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 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: BlockListener.java From civcraft with GNU General Public License v2.0 | 4 votes |
@EventHandler(priority = EventPriority.NORMAL) public void onCreatureSpawnEvent(CreatureSpawnEvent event) { if (War.isWarTime()) { if (!event.getSpawnReason().equals(SpawnReason.BREEDING)){ event.setCancelled(true); return; } } if (event.getEntity().getType().equals(EntityType.CHICKEN)) { if (event.getSpawnReason().equals(SpawnReason.EGG)) { event.setCancelled(true); return; } NBTTagCompound compound = new NBTTagCompound(); if (compound.getBoolean("IsChickenJockey")) { event.setCancelled(true); return; } } if (event.getEntity().getType().equals(EntityType.IRON_GOLEM) && event.getSpawnReason().equals(SpawnReason.BUILD_IRONGOLEM)) { event.setCancelled(true); return; } if (MobLib.isMobLibEntity(event.getEntity())) { return; } if (event.getEntity().getType().equals(EntityType.ZOMBIE) || event.getEntity().getType().equals(EntityType.SKELETON) || event.getEntity().getType().equals(EntityType.BAT) || event.getEntity().getType().equals(EntityType.CAVE_SPIDER) || event.getEntity().getType().equals(EntityType.SPIDER) || event.getEntity().getType().equals(EntityType.CREEPER) || event.getEntity().getType().equals(EntityType.WOLF) || event.getEntity().getType().equals(EntityType.SILVERFISH) || event.getEntity().getType().equals(EntityType.OCELOT) || event.getEntity().getType().equals(EntityType.WITCH) || event.getEntity().getType().equals(EntityType.ENDERMAN)) { event.setCancelled(true); return; } if (event.getSpawnReason().equals(SpawnReason.SPAWNER)) { event.setCancelled(true); return; } }
Example 17
Source File: EntityLimits.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Prevents mobs spawning naturally at spawn or in an island * * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onNaturalMobSpawn(final CreatureSpawnEvent e) { // if grid is not loaded yet, return. if (plugin.getGrid() == null) { return; } // If not in the right world, return if (!IslandGuard.inWorld(e.getEntity())) { return; } // Deal with natural spawning if (e.getSpawnReason().equals(SpawnReason.NATURAL) || e.getSpawnReason().equals(SpawnReason.CHUNK_GEN) || e.getSpawnReason().equals(SpawnReason.DEFAULT) || e.getSpawnReason().equals(SpawnReason.MOUNT) || e.getSpawnReason().equals(SpawnReason.JOCKEY) || e.getSpawnReason().equals(SpawnReason.NETHER_PORTAL)) { if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) { if (!actionAllowed(e.getLocation(), SettingsFlag.MONSTER_SPAWN)) { if (DEBUG3) plugin.getLogger().info("Natural monster spawn cancelled."); // Mobs not allowed to spawn e.setCancelled(true); return; } } else if (e.getEntity() instanceof Animals) { if (!actionAllowed(e.getLocation(), SettingsFlag.MOB_SPAWN)) { // Animals are not allowed to spawn if (DEBUG2) plugin.getLogger().info("Natural animal spawn cancelled."); e.setCancelled(true); return; } } } if (DEBUG2) { plugin.getLogger().info("Mob spawn allowed " + e.getEventName()); plugin.getLogger().info(e.getSpawnReason().toString()); plugin.getLogger().info(e.getEntityType().toString()); } }
Example 18
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 19
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 20
Source File: SpawnControl.java From EliteMobs with GNU General Public License v3.0 | 3 votes |
@EventHandler public void onSpawn(CreatureSpawnEvent event) { if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CUSTOM)) return; if (!event.getLocation().getWorld().getName().equals(ConfigValues.adventurersGuildConfig.getString(AdventurersGuildConfig.GUILD_WORLD_NAME))) return; event.setCancelled(true); }