下面列出了org.bukkit.event.entity.CreatureSpawnEvent#getEntityType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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);
}
}
}
@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)
void onSpawn(CreatureSpawnEvent event) {
if (event.getEntityType() == EntityType.VILLAGER && event.getSpawnReason() != SpawnReason.CUSTOM) {
event.setCancelled(true);
}
}