下面列出了怎么用org.bukkit.event.entity.EntitySpawnEvent的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFalling(EntitySpawnEvent event) {
final Entity entity = event.getEntity();
final World world = entity.getWorld();
if (entity instanceof FallingBlock) {
// add owner
final Location location = entity.getLocation();
final Block block = world.getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(location.getWorld().getUID());
final GDChunk gdChunk = claimWorldManager.getChunk(location.getChunk());
final UUID ownerUniqueId = gdChunk.getBlockOwnerUUID(block.getLocation());
if (ownerUniqueId != null) {
final GDEntity gdEntity = new GDEntity(event.getEntity().getEntityId());
gdEntity.setOwnerUUID(ownerUniqueId);
gdEntity.setNotifierUUID(ownerUniqueId);
EntityTracker.addTempEntity(gdEntity);
}
}
}
@EventHandler
public void onEntitySpawn(EntitySpawnEvent event) {
final Entity entity = event.getEntity();
final Location location = entity.getLocation();
final IslandManager islandManager = IridiumSkyblock.getIslandManager();
final Island island = islandManager.getIslandViaLocation(location);
if (island == null) return;
if (!IridiumSkyblock.getConfiguration().blockedEntities.contains(event.getEntityType())) return;
IridiumSkyblock.getInstance().entities.put(entity.getUniqueId(), island);
monitorEntity(entity);
}
@EventHandler
public void onSpawnMerge(EntitySpawnEvent event) {
if (!ConfigValues.validWorldsConfig.getBoolean("Valid worlds." + event.getEntity().getWorld().getName()))
return;
validateEntityType(event.getEntity());
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onFallBlockPlace(EntitySpawnEvent e) {
if (e.getEntityType().equals(EntityType.FALLING_BLOCK)) {
Region r = RedProtect.get().rm.getTopRegion(e.getLocation());
if (r != null && !r.allowGravity()) {
e.getEntity().remove();
}
}
}
@EventHandler
public void onMobSpawn(EntitySpawnEvent event) {
WorldClimateEngine worldEngine = ClimateEngine.getInstance().getClimateEngine(event.getLocation().getWorld().getUID());
if (worldEngine != null && worldEngine.isEffectEnabled(ClimateEffectType.MOB_SPAWN_RATE)) {
MobDistribution distribution = worldEngine.getEntityFitnessModel().getEntityFitnessMap().get(event.getEntityType());
if (distribution != null) {
double chance = distribution.getValue(worldEngine.getTemperature());
double random = GlobalWarming.getInstance().getRandom().nextDouble();
if (chance / 100.f <= random) {
//Cancel the mob:
event.setCancelled(true);
//Spawn an alternative, if available:
String alternative = distribution.getAlternate();
if (alternative != null && !alternative.isEmpty()) {
try {
//Spawn:
Entity entity = event.getLocation().getWorld().spawn(
event.getLocation(),
EntityType.fromName(alternative).getEntityClass());
//Make it a baby, if possible (for fun):
if (entity instanceof Ageable) {
((Ageable) entity).setBaby();
} else switch (entity.getType()) {
case PHANTOM:
((Phantom) entity).setSize(1);
break;
case ZOMBIE:
case DROWNED:
case HUSK:
case PIG_ZOMBIE:
case ZOMBIE_VILLAGER:
((Zombie) entity).setBaby(true);
break;
}
} catch (Exception e) {
GlobalWarming.getInstance().getLogger().warning(String.format(
"Error spawning alternate mob: [%s]",
distribution.getAlternate()));
}
}
}
}
}
}
@EventHandler
public void armorStandStop(EntitySpawnEvent event)
{
if(event.getEntityType() == EntityType.ARMOR_STAND)
event.setCancelled(true);
}
@EventHandler
public void onSpawnChange(EntitySpawnEvent spawnEvent) {
checkSafety(spawnEvent);
}
@EventHandler
public void onSpawnChange(EntitySpawnEvent spawnEvent) {
checkSafety(spawnEvent);
}
@EventHandler
public void onSpawn(EntitySpawnEvent event) {
if (!DeadMoon.eventOngoing) return;
if (event.getEntity() instanceof LivingEntity && theReturnedList.contains(event.getEntity()))
spawnTheReturned((Zombie) event.getEntity());
}