下面列出了org.bukkit.event.entity.CreatureSpawnEvent#isCancelled ( ) 实例代码,或者点击链接到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 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(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(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(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(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());
}
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = false)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (nmsManager.isNMSEntityBase(event.getEntity())) {
if (event.isCancelled()) {
event.setCancelled(false);
}
}
}
@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());
}
@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());
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.isCancelled() && plugin.getEntityController().getHologramEntity(event.getEntity()) != null) {
event.setCancelled(false);
}
}
@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());
}
}