Search in sources :

Example 6 with EntityType

use of org.bukkit.entity.EntityType in project InfernalMobs by NyaaCat.

the class AbilityMounted method onMobSpawn.

@Override
public void onMobSpawn(InfernalMobSpawnEvent ev) {
    if (!ConfigReader.isEnabledRider(ev.mobEntity.getType()) && ev.reason != InfernalSpawnReason.COMMAND)
        return;
    EntityType mounteeType = Helper.randomItem(ConfigReader.getMounteeTypes());
    LivingEntity mounteeEntity = (LivingEntity) ev.mobEntity.getWorld().spawn(ev.mobEntity.getLocation(), mounteeType.getEntityClass());
    InfernalMobs.instance.mobManager.unnaturallySpawned.put(mounteeEntity.getUniqueId(), true);
    mounteeEntity.addPassenger(ev.mobEntity);
    if (mounteeEntity instanceof Horse) {
        ((Horse) mounteeEntity).setColor(Helper.randomItem(Arrays.asList(Horse.Color.values())));
        ((Horse) mounteeEntity).setStyle(Helper.randomItem(Arrays.asList(Horse.Style.values())));
        ((Horse) mounteeEntity).setTamed(true);
        if (ConfigReader.isHorseMounteeNeedSaddle()) {
            ((Horse) mounteeEntity).getInventory().setSaddle(new ItemStack(Material.SADDLE));
        }
        if (ev.mob.abilityList.contains(EnumAbilities.ARMOURED) && ConfigReader.isArmouredMounteeNeedArmour()) {
            ((Horse) mounteeEntity).getInventory().setArmor(new ItemStack(Material.DIAMOND_BARDING));
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) Horse(org.bukkit.entity.Horse) ItemStack(org.bukkit.inventory.ItemStack)

Example 7 with EntityType

use of org.bukkit.entity.EntityType in project CitizensAPI by CitizensDev.

the class SimpleNPCDataStore method loadInto.

@Override
public void loadInto(NPCRegistry registry) {
    for (DataKey key : root.getKey("npc").getIntegerSubKeys()) {
        int id = Integer.parseInt(key.name());
        if (!key.keyExists("name")) {
            Messaging.logTr(LOAD_NAME_NOT_FOUND, id);
            continue;
        }
        String unparsedEntityType = key.getString("traits.type", "PLAYER");
        EntityType type = matchEntityType(unparsedEntityType);
        if (type == null) {
            Messaging.logTr(LOAD_UNKNOWN_NPC_TYPE, unparsedEntityType);
            continue;
        }
        NPC npc = registry.createNPC(type, !key.getString("uuid", "").isEmpty() ? UUID.fromString(key.getString("uuid")) : UUID.randomUUID(), id, key.getString("name"));
        npc.load(key);
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) DataKey(net.citizensnpcs.api.util.DataKey)

Example 8 with EntityType

use of org.bukkit.entity.EntityType in project CitizensAPI by CitizensDev.

the class RequirementsProcessor method process.

@Override
public void process(CommandSender sender, CommandContext context, Annotation instance, Object[] methodArgs) throws CommandException {
    Requirements requirements = (Requirements) instance;
    NPC npc = (methodArgs.length >= 3 && methodArgs[2] instanceof NPC) ? (NPC) methodArgs[2] : null;
    boolean canRedefineSelected = context.hasValueFlag("id") && sender.hasPermission("npc.select");
    String error = Messaging.tr(CommandMessages.MUST_HAVE_SELECTED);
    if (canRedefineSelected) {
        npc = CitizensAPI.getNPCRegistry().getById(context.getFlagInteger("id"));
        if (methodArgs.length >= 3) {
            methodArgs[2] = npc;
        }
        if (npc == null) {
            error += ' ' + Messaging.tr(CommandMessages.ID_NOT_FOUND, context.getFlagInteger("id"));
        }
    }
    if (requirements.selected() && npc == null) {
        throw new RequirementMissingException(error);
    }
    if (requirements.ownership() && npc != null && !sender.hasPermission("citizens.admin") && !npc.getTrait(Owner.class).isOwnedBy(sender)) {
        throw new RequirementMissingException(Messaging.tr(CommandMessages.MUST_BE_OWNER));
    }
    if (npc == null)
        return;
    for (Class<? extends Trait> clazz : requirements.traits()) {
        if (!npc.hasTrait(clazz)) {
            throw new RequirementMissingException(Messaging.tr(CommandMessages.MISSING_TRAIT, clazz.getSimpleName()));
        }
    }
    Set<EntityType> types = Sets.newEnumSet(Arrays.asList(requirements.types()), EntityType.class);
    if (types.contains(EntityType.UNKNOWN)) {
        types = EnumSet.allOf(EntityType.class);
    }
    types.removeAll(Sets.newHashSet(requirements.excludedTypes()));
    EntityType type = npc.getTrait(MobType.class).getType();
    if (!types.contains(type)) {
        throw new RequirementMissingException(Messaging.tr(CommandMessages.REQUIREMENTS_INVALID_MOB_TYPE, type.name().toLowerCase().replace('_', ' ')));
    }
    if (requirements.livingEntity() && !type.isAlive()) {
        throw new RequirementMissingException(Messaging.tr(CommandMessages.REQUIREMENTS_MUST_BE_LIVING_ENTITY, methodArgs));
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) EntityType(org.bukkit.entity.EntityType) Owner(net.citizensnpcs.api.trait.trait.Owner) RequirementMissingException(net.citizensnpcs.api.command.exception.RequirementMissingException) MobType(net.citizensnpcs.api.trait.trait.MobType)

Example 9 with EntityType

use of org.bukkit.entity.EntityType in project MagicPlugin by elBukkit.

the class EntityController method loadProperties.

public void loadProperties(ConfigurationSection properties) {
    preventMeleeDamage = properties.getBoolean("prevent_melee_damage", false);
    meleeDamageReduction = properties.getDouble("melee_damage_reduction", 0);
    keepWandsOnDeath = properties.getBoolean("keep_wands_on_death", true);
    preventWandMeleeDamage = properties.getBoolean("prevent_wand_melee_damage", true);
    ageDroppedItems = properties.getInt("age_dropped_items", 0);
    ConfigurationSection entityReduction = properties.getConfigurationSection("entity_damage_reduction");
    if (entityReduction != null) {
        Set<String> keys = entityReduction.getKeys(false);
        entityDamageReduction = new HashMap<>();
        for (String key : keys) {
            try {
                EntityType entityType = EntityType.valueOf(key.toUpperCase());
                entityDamageReduction.put(entityType, entityReduction.getDouble(key));
            } catch (Exception ex) {
                controller.getLogger().warning("Invalid entity type found in entity_damage_reduction: " + key);
            }
        }
    } else {
        entityDamageReduction = null;
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 10 with EntityType

use of org.bukkit.entity.EntityType in project MagicPlugin by elBukkit.

the class FamiliarSpell method onCast.

@SuppressWarnings("deprecation")
@Override
public SpellResult onCast(ConfigurationSection parameters) {
    spawnCount = 0;
    Target target = getTarget();
    if (!target.hasTarget()) {
        return SpellResult.NO_TARGET;
    }
    Block originalTarget = target.getBlock();
    Block targetBlock = originalTarget;
    LivingEntity targetEntity = null;
    boolean track = parameters.getBoolean("track", true);
    boolean loot = parameters.getBoolean("loot", false);
    boolean setTarget = parameters.getBoolean("set_target", true);
    double spawnRange = parameters.getInt("spawn_range", 0);
    String entityName = parameters.getString("name", "");
    if (hasFamiliar() && track) {
        // Dispel familiars if you target them and cast
        boolean isFamiliar = target.hasEntity() && isFamiliar(target.getEntity());
        if (isFamiliar) {
            checkListener();
            releaseFamiliar(target.getEntity());
            return SpellResult.DEACTIVATE;
        }
        releaseFamiliars();
    }
    if (target.hasEntity()) {
        targetBlock = targetBlock.getRelative(BlockFace.SOUTH);
        Entity e = target.getEntity();
        if (e instanceof LivingEntity) {
            targetEntity = (LivingEntity) e;
        }
    }
    targetBlock = targetBlock.getRelative(BlockFace.UP);
    Location centerLoc = targetBlock.getLocation();
    Location caster = getLocation();
    if (spawnRange > 0) {
        double distanceSquared = targetBlock.getLocation().distanceSquared(caster);
        if (spawnRange * spawnRange < distanceSquared) {
            Vector direction = caster.getDirection().normalize().multiply(spawnRange);
            centerLoc = caster.clone().add(direction);
            for (int i = 0; i < spawnRange; i++) {
                Material blockType = centerLoc.getBlock().getType();
                if (blockType == Material.AIR || blockType == Material.WATER || blockType != Material.STATIONARY_WATER) {
                    break;
                }
                centerLoc = centerLoc.add(0, 1, 0);
            }
        }
    }
    EntityType famType = null;
    int famCount = parameters.getInt("count", 1);
    String famTypeName = parameters.getString("type", null);
    if (famTypeName != null && !famTypeName.isEmpty()) {
        try {
            famType = EntityType.valueOf(famTypeName.toUpperCase());
        } catch (Throwable ex) {
            sendMessage("Unknown entity type: " + famTypeName);
            return SpellResult.FAIL;
        }
    }
    if (originalTarget.getType() == Material.WATER || originalTarget.getType() == Material.STATIONARY_WATER) {
        famType = EntityType.SQUID;
    }
    boolean spawnBaby = parameters.getBoolean("baby", false);
    List<LivingEntity> newFamiliars = new ArrayList<>();
    for (int i = 0; i < famCount; i++) {
        EntityType entityType = famType;
        if (entityType == null) {
            String randomType = RandomUtils.weightedRandom(entityTypeProbability);
            try {
                entityType = EntityType.fromName(randomType);
            } catch (Throwable ex) {
                sendMessage("Unknown entity type: " + randomType);
                return SpellResult.FAIL;
            }
        }
        if (parameters.contains("reason")) {
            String reasonText = parameters.getString("reason").toUpperCase();
            try {
                spawnReason = CreatureSpawnEvent.SpawnReason.valueOf(reasonText);
            } catch (Exception ex) {
                sendMessage("Unknown spawn reason: " + reasonText);
                return SpellResult.FAIL;
            }
        }
        final Location targetLoc = centerLoc.clone();
        if (famCount > 1) {
            targetLoc.setX(targetLoc.getX() + rand.nextInt(2 * famCount) - famCount);
            targetLoc.setZ(targetLoc.getZ() + rand.nextInt(2 * famCount) - famCount);
        }
        targetLoc.setPitch(caster.getPitch());
        targetLoc.setYaw(caster.getYaw());
        if (entityType != null) {
            final LivingEntity entity = spawnFamiliar(targetLoc, entityType, targetBlock.getLocation(), targetEntity, setTarget);
            if (entity != null) {
                if (entityName != null && !entityName.isEmpty()) {
                    entity.setCustomName(entityName);
                }
                if (!loot) {
                    entity.setMetadata("nodrops", new FixedMetadataValue(mage.getController().getPlugin(), true));
                }
                if (spawnBaby && entity instanceof Ageable) {
                    Ageable ageable = (Ageable) entity;
                    ageable.setBaby();
                }
                entity.teleport(targetLoc);
                newFamiliars.add(entity);
                spawnCount++;
                registerForUndo(entity);
            }
        }
    }
    registerForUndo();
    if (track) {
        setFamiliars(newFamiliars);
        checkListener();
    }
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ArrayList(java.util.ArrayList) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) Material(org.bukkit.Material) Ageable(org.bukkit.entity.Ageable) LivingEntity(org.bukkit.entity.LivingEntity) EntityType(org.bukkit.entity.EntityType) Target(com.elmakers.mine.bukkit.utility.Target) Block(org.bukkit.block.Block) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

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