當前位置: 首頁>>代碼示例>>Java>>正文


Java SpawnReason.NATURAL屬性代碼示例

本文整理匯總了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;
                }
            }
        }
    }
}
 
開發者ID:Samistine,項目名稱:BloodMoon,代碼行數:21,代碼來源:MoreSpawningListener.java

示例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);
    }
}
 
開發者ID:EmilHernvall,項目名稱:tregmine,代碼行數:21,代碼來源:ZoneEntityListener.java

示例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;
            }
        });
    }
}
 
開發者ID:Steveice10,項目名稱:Peacecraft,代碼行數:15,代碼來源:EconomyListener.java

示例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);
		}
	}
}
 
開發者ID:SurvivalGamesDevTeam,項目名稱:TheSurvivalGames,代碼行數:9,代碼來源:MobSpawnListener.java

示例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);
}
 
開發者ID:JCThePants,項目名稱:PV-Star,代碼行數:13,代碼來源:MobEventListener.java

示例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);
        }
    }
}
 
開發者ID:UltimateGames,項目名稱:UltimateGames,代碼行數:14,代碼來源:ArenaListener.java

示例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);
            }
        }
    }
}
 
開發者ID:RoyalDev,項目名稱:PopulationDensity,代碼行數:54,代碼來源:EntityEventHandler.java


注:本文中的org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。