org.bukkit.event.entity.CreatureSpawnEvent#getEntityType ( )源码实例Demo

下面列出了org.bukkit.event.entity.CreatureSpawnEvent#getEntityType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Carbon   文件: EntityListener.java
/**
 * 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);
            }
        }
}
 
源代码2 项目: Shopkeepers   文件: CreatureForceSpawnListener.java
@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;
}
 
源代码3 项目: Shopkeepers   文件: BlockVillagerSpawnListener.java
@EventHandler(ignoreCancelled = true)
void onSpawn(CreatureSpawnEvent event) {
	if (event.getEntityType() == EntityType.VILLAGER && event.getSpawnReason() != SpawnReason.CUSTOM) {
		event.setCancelled(true);
	}
}