本文整理汇总了Java中org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL属性的典型用法代码示例。如果您正苦于以下问题:Java SpawnReason.NATURAL属性的具体用法?Java SpawnReason.NATURAL怎么用?Java SpawnReason.NATURAL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason
的用法示例。
在下文中一共展示了SpawnReason.NATURAL属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreatureSpawn
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.getSpawnReason() != SpawnReason.NATURAL) { //TODO: Should check for Custom instead of checking against natural?
return;
}
EntityType type = event.getEntityType();
World world = event.getLocation().getWorld();
PluginConfig worldConfig = plugin.getConfig(world);
if (plugin.isActive(world) && plugin.isFeatureEnabled(world, Feature.MORE_SPAWNING) && worldConfig.getStringList(Config.FEATURE_MORE_SPAWNING_MOBS).contains(type.getName().toUpperCase())) {
for (int i = 0; i < Math.max(worldConfig.getInt(Config.FEATURE_MORE_SPAWNING_MULTIPLIER), 1); ++i) {
for (BloodMoonEntityType bloodMoonEntity : BloodMoonEntityType.values()) {
if (type == bloodMoonEntity.getEntityType()) {
bloodMoonEntity.spawnEntity(event.getLocation().add((random.nextDouble() * 3) - 1.5, (random.nextDouble() * 3) - 1.5, (random.nextDouble() * 3) - 1.5));
return;
}
}
}
}
}
示例2: onCreatureSpawn
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event)
{
Entity entity = event.getEntity();
Location location = event.getLocation();
Point pos = new Point(location.getBlockX(), location.getBlockZ());
ZoneWorld world = plugin.getWorld(entity.getWorld());
Zone zone = world.findZone(pos);
if (zone == null || zone.hasHostiles()) {
return;
}
if (!allowedMobs.contains(event.getEntityType()) &&
event.getSpawnReason() == SpawnReason.NATURAL) {
event.setCancelled(true);
}
}
示例3: onCreatureSpawn
@EventHandler(priority = EventPriority.MONITOR)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if(this.module.getConfig().getBoolean("mob-money.enabled", true) && event.getSpawnReason() == SpawnReason.NATURAL) {
event.getEntity().setMetadata("natural", new MetadataValueAdapter(Bukkit.getServer().getPluginManager().getPlugin(this.module.getManager().getImplementationName())) {
@Override
public void invalidate() {
}
@Override
public Object value() {
return true;
}
});
}
}
示例4: onSpawn
@EventHandler(priority = EventPriority.HIGH)
public void onSpawn(CreatureSpawnEvent event) {
for (int i = 0; i < SGApi.getMultiWorldManager().getWorlds().size(); i++) {
if (SGApi.getMultiWorldManager().getWorlds().get(i).getWorld() == event.getLocation().getWorld()) {
if (event.getSpawnReason() == SpawnReason.NATURAL)
event.setCancelled(true);
}
}
}
示例5: onNaturalSpawn
@EventHandler(priority= EventPriority.HIGHEST, ignoreCancelled = true)
private void onNaturalSpawn(CreatureSpawnEvent event) {
if (event.getSpawnReason() != SpawnReason.NATURAL)
return;
IArena arena = PVStarAPI.getArenaManager().getArena(event.getLocation());
if (arena == null)
return;
if (!arena.getSettings().isMobSpawnEnabled())
event.setCancelled(true);
}
示例6: onCreatureSpawn
/**
* Handles mob spawning.<br>
* Checks if an arena allows mob spawning before letting a mob spawn inside it.
* @param event The {@link org.bukkit.event.entity.CreatureSpawnEvent} event.
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.getSpawnReason() == SpawnReason.NATURAL) {
Arena arena = ultimateGames.getArenaManager().getLocationArena(event.getLocation());
if (arena != null && !arena.allowMobSpawning()) {
event.setCancelled(true);
}
}
}
示例7: onEntitySpawn
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntitySpawn(CreatureSpawnEvent event) {
//do nothing for non-natural spawns
if (event.getSpawnReason() != SpawnReason.NATURAL)
return;
if (ConfigData.managedWorld == null || event.getLocation().getWorld() != ConfigData.managedWorld)
return;
//when an animal naturally spawns, grow grass around it
Entity entity = event.getEntity();
if (entity instanceof Animals && ConfigData.regrowGrass)
this.regrow(entity.getLocation().getBlock(), 4);
//when a monster spawns, sometimes spawn animals too
if (entity instanceof Monster && ConfigData.respawnAnimals) {
//only do this if the spawn is in the newest region
if (!Region.getOpenRegion().equals(Region.fromLocation(entity.getLocation())))
return;
//if it's on grass, there's a 1/100 chance it will also spawn a group of animals
Block underBlock = event.getLocation().getBlock().getRelative(BlockFace.DOWN);
if (underBlock.getType() == Material.GRASS && --this.respawnAnimalCounter == 0) {
this.respawnAnimalCounter = 100;
//check the chunk for other animals
Chunk chunk = entity.getLocation().getChunk();
Entity[] entities = chunk.getEntities();
for (int i = 0; i < entities.length; i++) {
if (entity instanceof Animals)
return;
}
EntityType animalType = null;
//decide what to spawn based on the type of monster
if (entity instanceof Creeper)
animalType = EntityType.COW;
else if (entity instanceof Zombie)
animalType = EntityType.CHICKEN;
else if (entity instanceof Spider)
animalType = EntityType.PIG;
else if (entity instanceof Enderman)
animalType = EntityType.SHEEP;
//spawn an animal at the entity's location and regrow some grass
if (animalType != null) {
entity.getWorld().spawnEntity(entity.getLocation(), animalType);
entity.getWorld().spawnEntity(entity.getLocation(), animalType);
this.regrow(entity.getLocation().getBlock(), 4);
}
}
}
}