Java Code Examples for org.bukkit.entity.LivingEntity#getEquipment()

The following examples show how to use org.bukkit.entity.LivingEntity#getEquipment() . 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: SentinelUtilities.java    From Sentinel with MIT License 7 votes vote down vote up
/**
 * Returns whether an entity is invisible (when invisible targets are ignorable).
 */
public static boolean isInvisible(LivingEntity entity) {
    if (!SentinelPlugin.instance.ignoreInvisible
            || !entity.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
        return false;
    }
    EntityEquipment eq = entity.getEquipment();
    if (eq == null) {
        return true;
    }
    if (SentinelVersionCompat.v1_9) {
        if (!isAir(eq.getItemInMainHand()) || !isAir(eq.getItemInOffHand())) {
            return false;
        }
    }
    else {
        if (!isAir(eq.getItemInHand())) {
            return false;
        }
    }
    return isAir(eq.getBoots()) && isAir(eq.getLeggings()) && isAir(eq.getChestplate()) && isAir(eq.getHelmet());
}
 
Example 2
Source File: ExprArmorSlot.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Slot convert(final LivingEntity e) {
	final EntityEquipment eq = e.getEquipment();
	if (eq == null)
		return null;
	return new EquipmentSlot(eq, slot, explicitSlot);
}
 
Example 3
Source File: SentinelUtilities.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Returns the item held in an entity's hand.
 */
public static ItemStack getHeldItem(LivingEntity entity) {
    if (entity.getEquipment() == null) {
        return null;
    }
    if (SentinelVersionCompat.v1_9) {
        return entity.getEquipment().getItemInMainHand();
    }
    else {
        return entity.getEquipment().getItemInHand();
    }
}
 
Example 4
Source File: SentinelUtilities.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Returns the item held in an entity's offhand.
 */
public static ItemStack getOffhandItem(LivingEntity entity) {
    if (SentinelVersionCompat.v1_9 && entity.getEquipment() != null) {
        return entity.getEquipment().getItemInOffHand();
    }
    else {
        return null;
    }
}
 
Example 5
Source File: SpawnMobEvent.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Void execute(String playerID) throws QuestRuntimeException {
    Location location = loc.getLocation(playerID);
    int a = amount.getInt(playerID);
    for (int i = 0; i < a; i++) {
        Entity entity = location.getWorld().spawnEntity(location, type);
        if (entity instanceof LivingEntity) {
            LivingEntity living = (LivingEntity) entity;
            EntityEquipment eq = living.getEquipment();
            eq.setHelmet(helmet == null ? null : helmet.generate(1));
            eq.setHelmetDropChance(0);
            eq.setChestplate(chestplate == null ? null : chestplate.generate(1));
            eq.setChestplateDropChance(0);
            eq.setLeggings(leggings == null ? null : leggings.generate(1));
            eq.setLeggingsDropChance(0);
            eq.setBoots(boots == null ? null : boots.generate(1));
            eq.setBootsDropChance(0);
            eq.setItemInMainHand(mainHand == null ? null : mainHand.generate(1));
            eq.setItemInMainHandDropChance(0);
            eq.setItemInOffHand(offHand == null ? null : offHand.generate(1));
            eq.setItemInOffHandDropChance(0);
        }
        int j = 0;
        for (Item item : drops) {
            entity.setMetadata("betonquest-drops-" + j,
                    new FixedMetadataValue(BetonQuest.getInstance(), item.getID().getFullID() + ":"
                            + item.getAmount().getInt(playerID)));
            j++;
        }
        if (name != null && entity instanceof LivingEntity) {
            LivingEntity livingEntity = (LivingEntity) entity;
            livingEntity.setCustomName(name);
        }
        if (marked != null) {
            entity.setMetadata("betonquest-marked", new FixedMetadataValue(BetonQuest.getInstance(), marked));
        }
    }
    return null;
}
 
Example 6
Source File: DefaultDropsHandler.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
private List<ItemStack> inventoryItemsConstructor(LivingEntity entity) {

        EntityEquipment equipment = entity.getEquipment();

        if (equipment.getItemInMainHand() != null && !equipment.getItemInMainHand().getType().equals(Material.AIR))
            wornItems.add(equipment.getItemInMainHand());

        if (equipment.getHelmet() != null)
            wornItems.add(equipment.getHelmet());

        if (equipment.getChestplate() != null)
            wornItems.add(equipment.getChestplate());

        if (equipment.getLeggings() != null)
            wornItems.add(equipment.getLeggings());

        if (equipment.getBoots() != null)
            wornItems.add(equipment.getBoots());

        return wornItems;

    }