Java Code Examples for org.bukkit.event.entity.CreatureSpawnEvent#getEntityType()

The following examples show how to use org.bukkit.event.entity.CreatureSpawnEvent#getEntityType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityListener.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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);
            }
        }
}
 
Example 2
Source File: CreatureForceSpawnListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 3
Source File: BlockVillagerSpawnListener.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
void onSpawn(CreatureSpawnEvent event) {
	if (event.getEntityType() == EntityType.VILLAGER && event.getSpawnReason() != SpawnReason.CUSTOM) {
		event.setCancelled(true);
	}
}