Search in sources :

Example 1 with EntityType

use of org.bukkit.entity.EntityType in project Denizen-For-Bukkit by DenizenScript.

the class BiomeNMS_v1_11_R1 method getSpawnableEntities.

private List<EntityType> getSpawnableEntities(EnumCreatureType creatureType) {
    List<EntityType> entityTypes = new ArrayList<EntityType>();
    for (BiomeBase.BiomeMeta meta : biomeBase.getMobs(creatureType)) {
        // TODO: verifyme!
        String n = EntityTypes.getName(meta.b).a();
        EntityType et = EntityType.fromName(n);
        if (et == null) {
            et = EntityType.valueOf(n.toUpperCase(Locale.ENGLISH));
        }
        entityTypes.add(et);
    }
    return entityTypes;
}
Also used : EntityType(org.bukkit.entity.EntityType) ArrayList(java.util.ArrayList)

Example 2 with EntityType

use of org.bukkit.entity.EntityType in project Denizen-For-Bukkit by DenizenScript.

the class StatisticCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element action = scriptEntry.getElement("action");
    dList players = scriptEntry.getdObject("players");
    Element statistic = scriptEntry.getElement("statistic");
    Element amount = scriptEntry.getElement("amount");
    dMaterial material = scriptEntry.getdObject("material");
    dEntity entity = scriptEntry.getdObject("entity");
    dB.report(scriptEntry, getName(), action.debug() + statistic.debug() + amount.debug() + players.debug() + (material != null ? material.debug() : entity != null ? entity.debug() : ""));
    Action act = Action.valueOf(action.asString().toUpperCase());
    Statistic stat = Statistic.valueOf(statistic.asString().toUpperCase());
    int amt = amount.asInt();
    switch(stat.getType()) {
        case BLOCK:
        case ITEM:
            Material mat = material.getMaterial();
            switch(act) {
                case ADD:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.incrementStatistic(stat, mat, amt);
                    }
                    break;
                case TAKE:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.decrementStatistic(stat, mat, amt);
                    }
                    break;
                case SET:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.setStatistic(stat, mat, amt);
                    }
                    break;
            }
            break;
        case ENTITY:
            EntityType ent = entity.getBukkitEntityType();
            switch(act) {
                case ADD:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.incrementStatistic(stat, ent, amt);
                    }
                    break;
                case TAKE:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.decrementStatistic(stat, ent, amt);
                    }
                    break;
                case SET:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.setStatistic(stat, ent, amt);
                    }
                    break;
            }
            break;
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) Statistic(org.bukkit.Statistic) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) Material(org.bukkit.Material)

Example 3 with EntityType

use of org.bukkit.entity.EntityType in project Glowstone by GlowstoneMC.

the class ItemSpawn method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc) {
    Location location = against.getLocation().add(face.getModX(), face.getModY(), face.getModZ());
    // TODO: change mob spawner when clicked by monster egg
    if (holding.hasItemMeta() && holding.getItemMeta() instanceof GlowMetaSpawn) {
        GlowMetaSpawn meta = (GlowMetaSpawn) holding.getItemMeta();
        EntityType type = meta.getSpawnedType();
        CompoundTag tag = meta.getEntityTag();
        if (type != null) {
            GlowEntity entity = against.getWorld().spawn(location.add(0.5, 0, 0.5), EntityRegistry.getEntity(type), SpawnReason.SPAWNER_EGG);
            if (tag != null) {
                EntityStorage.load(entity, tag);
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) GlowEntity(net.glowstone.entity.GlowEntity) GlowMetaSpawn(net.glowstone.inventory.GlowMetaSpawn) CompoundTag(net.glowstone.util.nbt.CompoundTag) Location(org.bukkit.Location)

Example 4 with EntityType

use of org.bukkit.entity.EntityType in project Essentials by drtshock.

the class SpawnEggProvider method tryProvider.

@Override
public boolean tryProvider() {
    try {
        EntityType type = EntityType.CREEPER;
        ItemStack is = createEggItem(type);
        EntityType readType = getSpawnedType(is);
        return type == readType;
    } catch (Throwable t) {
        return false;
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) ItemStack(org.bukkit.inventory.ItemStack)

Example 5 with EntityType

use of org.bukkit.entity.EntityType in project BKCommonLib by bergerhealer.

the class CommonEventFactory method handleCreaturePreSpawn.

/**
 * Handles the spawning of creatures on the server
 *
 * @param world
 * @param x
 * @param y
 * @param z
 * @param inputTypes to process and fire events for
 * @return a list of mobs to spawn
 */
public List<BiomeMetaHandle> handleCreaturePreSpawn(World world, int x, int y, int z, List<BiomeMetaHandle> inputTypes) {
    // Shortcuts
    if (LogicUtil.nullOrEmpty(inputTypes) || !CommonUtil.hasHandlers(CreaturePreSpawnEvent.getHandlerList())) {
        return inputTypes;
    }
    // Start processing the elements
    creaturePreSpawnMobs.clear();
    for (BiomeMetaHandle inputMeta : inputTypes) {
        final EntityType oldEntityType = CommonEntityType.byNMSEntityClass(inputMeta.getEntityClass()).entityType;
        // Set up the event
        creaturePreSpawnEvent.cancelled = false;
        creaturePreSpawnEvent.spawnLocation.setWorld(world);
        creaturePreSpawnEvent.spawnLocation.setX(x);
        creaturePreSpawnEvent.spawnLocation.setY(y);
        creaturePreSpawnEvent.spawnLocation.setZ(z);
        creaturePreSpawnEvent.spawnLocation.setYaw(0.0f);
        creaturePreSpawnEvent.spawnLocation.setPitch(0.0f);
        creaturePreSpawnEvent.entityType = oldEntityType;
        creaturePreSpawnEvent.minSpawnCount = inputMeta.getMinSpawnCount();
        creaturePreSpawnEvent.maxSpawnCount = inputMeta.getMaxSpawnCount();
        // Raise it and handle spawn cancel
        if (CommonUtil.callEvent(creaturePreSpawnEvent).isCancelled() || (creaturePreSpawnEvent.minSpawnCount == 0 && creaturePreSpawnEvent.maxSpawnCount == 0)) {
            continue;
        }
        // Handle a possibly changed entity type
        final Class<?> entityClass;
        if (oldEntityType == creaturePreSpawnEvent.entityType) {
            entityClass = inputMeta.getEntityClass();
        } else {
            entityClass = CommonEntityType.byEntityType(creaturePreSpawnEvent.entityType).nmsType.getType();
        }
        // Unknown or unsupported Entity Type - ignore spawning
        if (entityClass == null) {
            continue;
        }
        // Add element to buffer
        final BiomeMetaHandle outputMeta = creaturePreSpawnMobs.add();
        outputMeta.setEntityClass(entityClass);
        outputMeta.setMinSpawnCount(creaturePreSpawnEvent.minSpawnCount);
        outputMeta.setMaxSpawnCount(creaturePreSpawnEvent.maxSpawnCount);
        outputMeta.setChance(inputMeta.getChance());
    }
    return creaturePreSpawnMobs;
}
Also used : CommonEntityType(com.bergerkiller.bukkit.common.entity.CommonEntityType) EntityType(org.bukkit.entity.EntityType) BiomeMetaHandle(com.bergerkiller.generated.net.minecraft.server.BiomeBaseHandle.BiomeMetaHandle)

Aggregations

EntityType (org.bukkit.entity.EntityType)109 ArrayList (java.util.ArrayList)29 ItemStack (org.bukkit.inventory.ItemStack)28 Material (org.bukkit.Material)23 Player (org.bukkit.entity.Player)23 Entity (org.bukkit.entity.Entity)19 Location (org.bukkit.Location)17 IOException (java.io.IOException)16 File (java.io.File)13 LivingEntity (org.bukkit.entity.LivingEntity)13 EventHandler (org.bukkit.event.EventHandler)12 PotionType (org.bukkit.potion.PotionType)12 HashMap (java.util.HashMap)10 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)9 Block (org.bukkit.block.Block)8 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)8 World (org.bukkit.World)7 SpawnEgg (org.bukkit.material.SpawnEgg)7 UUID (java.util.UUID)5 Biome (org.bukkit.block.Biome)5