下面列出了org.bukkit.event.entity.CreatureSpawnEvent#setCancelled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
}
}
}
}
@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);
}
}
@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()));
}
}
}
@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);
}
}
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = false)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (nmsManager.isNMSEntityBase(event.getEntity())) {
if (event.isCancelled()) {
event.setCancelled(false);
}
}
}
@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());
}
@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);
}
}
@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);
}
}
@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;
}
@EventHandler(ignoreCancelled = true)
public void on(CreatureSpawnEvent event) {
if (isEnabled()) return;
if (event.getEntity().getType() == EntityType.WITCH) {
event.setCancelled(true);
}
}
@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");
}
}
}
@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);
}
}
}
@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);
}
@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());
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.isCancelled() && plugin.getEntityController().getHologramEntity(event.getEntity()) != null) {
event.setCancelled(false);
}
}
@EventHandler(ignoreCancelled = true)
void onSpawn(CreatureSpawnEvent event) {
if (event.getEntityType() == EntityType.VILLAGER && event.getSpawnReason() != SpawnReason.CUSTOM) {
event.setCancelled(true);
}
}
@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;
}
}
/**
* 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());
}
}
@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);
}
}
@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);
}