private int getProtectionFactor(Entity entity) { if (!(entity instanceof LivingEntity)) { return 0; } LivingEntity livingEntity = (LivingEntity) entity; int level = 0; if (livingEntity.getEquipment() != null) { for (ItemStack stack : livingEntity.getEquipment().getArmorContents()) { if (stack != null) { int stackLevel = stack.getEnchantmentLevel(Enchantment.PROTECTION_EXPLOSIONS); if (stackLevel > level) { level = stackLevel; } } } } return level << 1; }
/** * Get the item in the inventory. * * <p>Slot 0 is the item in the hand. * * <p>Slot 1 to 4 is armor (boots to helmet). * * @return The item in that slot. */ private ItemStack getItem(int slot) { EntityEquipment equipment = entity.getEquipment(); if (equipment == null) { return null; } if (slot == 0) { return equipment.getItemInMainHand(); } else if (slot == 1) { return equipment.getItemInOffHand(); } else { return equipment.getArmorContents()[slot - 2]; } }
/** * Gets the inventory with the equipment worn by the living entity. * * @return the living entity's inventory */ public EntityEquipment getEquipment() { return entity.getEquipment(); }
@Override public MCEntityEquipment getEquipment() { if(le.getEquipment() == null) { return null; } return new BukkitMCEntityEquipment(le.getEquipment()); }
/** * Returns the item held in an entity's hand. */ public static ItemStack getHeldItem(LivingEntity entity) { if (SentinelTarget.v1_9) { return entity.getEquipment().getItemInMainHand(); } else { return entity.getEquipment().getItemInHand(); } }
public void setArmor(final ItemStack[] armor) { this.newArmor = armor; final ItemStack[] actualArmor = new ItemStack[4]; for (int i = 0; i < 4; i++) { if (armor[i] == null) { actualArmor[i] = this.oldArmor[i]; } else { actualArmor[i] = armor[i]; } } this.entity.getEquipment().setArmorContents(actualArmor); }
private void updateArmor(final TempArmor next) { final ItemStack[] armor = next.newArmor; final ItemStack[] actualArmor = new ItemStack[4]; for (int i = 0; i < 4; i++) { if (armor[i] == null) { actualArmor[i] = next.oldArmor[i]; } else { actualArmor[i] = armor[i]; } } this.entity.getEquipment().setArmorContents(actualArmor); }
private EntityEquipment getEquipmentFromEntity(Entity entity) { if (entity instanceof Player) { return new PlayerEquipmentWrapper((Player) entity); } else if (entity instanceof LivingEntity) { return ((LivingEntity) entity).getEquipment(); } else if (entity instanceof ArmorStand) return new ArmorStandEquipmentWrapper((ArmorStand) entity); throw new RuntimeException("Unsupported entity equipment"); }
protected static boolean hasArmor(LivingEntity target) { for (ItemStack itemStack : target.getEquipment().getArmorContents()) { if (itemStack != null && ItemUtils.isArmor(itemStack)) { return true; } } return false; }
@Override public PowerResult<Double> hit(Player player, ItemStack stack, LivingEntity entity, double damage, EntityDamageByEntityEvent event) { if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost(); if (rand.nextInt(chance) != 0) return PowerResult.noop(); if (entity instanceof Skeleton || entity instanceof Zombie) { if (entity.getEquipment().getHelmet() == null || entity.getEquipment().getHelmet().getType() == Material.AIR) { entity.getEquipment().setHelmet(new ItemStack(Material.CARVED_PUMPKIN)); entity.getEquipment().setHelmetDropChance((float) drop); } } return PowerResult.ok(damage); }
private DMob(LivingEntity entity, DGameWorld gameWorld) { gameWorld.addDMob(this); this.entity = entity; /* Remove DropChance of equipment */ if (!isExternalMob()) { this.entity.getEquipment().setHelmetDropChance(0); this.entity.getEquipment().setChestplateDropChance(0); this.entity.getEquipment().setLeggingsDropChance(0); this.entity.getEquipment().setBootsDropChance(0); this.entity.getEquipment().setItemInHandDropChance(0); if (Version.isAtLeast(Version.MC1_9)) { this.entity.getEquipment().setItemInOffHandDropChance(0); } } DMobSpawnEvent event = new DMobSpawnEvent(this, entity); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { gameWorld.removeDMob(this); } }
/** * Handle the effects of the Impact ability * * @param target The {@link LivingEntity} being affected by Impact */ public void impactCheck(LivingEntity target) { int durabilityDamage = getImpactDurabilityDamage(); for (ItemStack armor : target.getEquipment().getArmorContents()) { if (armor != null && ItemUtils.isArmor(armor)) { if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_STATIC_CHANCE, SubSkillType.AXES_ARMOR_IMPACT, getPlayer())) { SkillUtils.handleDurabilityChange(armor, durabilityDamage, Axes.impactMaxDurabilityModifier); } } } }
/** * Removes the ball from the hands of an entity. */ @Override public void deGrab() { if (this.isGrabbed() && this.interactionEntity != null) { final LivingEntity livingEntity = (LivingEntity) this.interactionEntity; livingEntity.getEquipment().setItemInHand(null); this.grabbed = false; final ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); try { SkinHelper.setItemStackSkin(itemStack, this.ballMeta.getSkin()); } catch (final Exception e1) { Bukkit.getLogger().log(Level.WARNING, "Failed to degrab entity.", e1); } this.setHelmet(itemStack); final Vector vector = this.getDirection(livingEntity).normalize().multiply(3); this.teleport(livingEntity.getLocation().add(vector)); } }
/** * Removes the ball from the hands of an entity. */ @Override public void deGrab() { if (this.isGrabbed() && this.interactionEntity != null) { final LivingEntity livingEntity = (LivingEntity) this.interactionEntity; livingEntity.getEquipment().setItemInHand(null); this.grabbed = false; final ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); try { SkinHelper.setItemStackSkin(itemStack, this.ballMeta.getSkin()); } catch (final Exception e1) { Bukkit.getLogger().log(Level.WARNING, "Failed to degrab entity.", e1); } this.setHelmet(itemStack); final Vector vector = this.getDirection(livingEntity).normalize().multiply(3); this.teleport(livingEntity.getLocation().add(vector)); } }
/** * Removes the ball from the hands of an entity. */ @Override public void deGrab() { if (this.isGrabbed() && this.interactionEntity != null) { final LivingEntity livingEntity = (LivingEntity) this.interactionEntity; livingEntity.getEquipment().setItemInHand(null); this.grabbed = false; final ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); try { SkinHelper.setItemStackSkin(itemStack, this.ballMeta.getSkin()); } catch (final Exception e1) { Bukkit.getLogger().log(Level.WARNING, "Failed to degrab entity.", e1); } this.setHelmet(itemStack); final Vector vector = this.getDirection(livingEntity).normalize().multiply(3); this.teleport(livingEntity.getLocation().add(vector)); } }
/** * Removes the ball from the hands of an entity. */ @Override public void deGrab() { if (this.isGrabbed() && this.interactionEntity != null) { final LivingEntity livingEntity = (LivingEntity) this.interactionEntity; livingEntity.getEquipment().setItemInHand(null); this.grabbed = false; final ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); try { SkinHelper.setItemStackSkin(itemStack, this.ballMeta.getSkin()); } catch (final Exception e1) { Bukkit.getLogger().log(Level.WARNING, "Failed to degrab entity.", e1); } this.setHelmet(itemStack); final Vector vector = this.getDirection(livingEntity).normalize().multiply(3); this.teleport(livingEntity.getLocation().add(vector)); } }
/** * Removes the ball from the hands of an entity. */ @Override public void deGrab() { if (this.isGrabbed() && this.interactionEntity != null) { final LivingEntity livingEntity = (LivingEntity) this.interactionEntity; livingEntity.getEquipment().setItemInHand(null); this.grabbed = false; final ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); try { SkinHelper.setItemStackSkin(itemStack, this.ballMeta.getSkin()); } catch (final Exception e1) { Bukkit.getLogger().log(Level.WARNING, "Failed to degrab entity.", e1); } this.setHelmet(itemStack); final Vector vector = this.getDirection(livingEntity).normalize().multiply(3); this.teleport(livingEntity.getLocation().add(vector)); } }
/** * Removes the ball from the hands of an entity. */ @Override public void deGrab() { if (this.isGrabbed() && this.interactionEntity != null) { final LivingEntity livingEntity = (LivingEntity) this.interactionEntity; livingEntity.getEquipment().setItemInHand(null); this.grabbed = false; final ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); try { SkinHelper.setItemStackSkin(itemStack, this.ballMeta.getSkin()); } catch (final Exception e1) { Bukkit.getLogger().log(Level.WARNING, "Failed to degrab entity.", e1); } this.setHelmet(itemStack); final Vector vector = this.getDirection(livingEntity).normalize().multiply(3); this.teleport(livingEntity.getLocation().add(vector)); } }
/** * Removes the ball from the hands of an entity. */ @Override public void deGrab() { if (this.isGrabbed() && this.interactionEntity != null) { final LivingEntity livingEntity = (LivingEntity) this.interactionEntity; livingEntity.getEquipment().setItemInHand(null); this.grabbed = false; final ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); try { SkinHelper.setItemStackSkin(itemStack, this.ballMeta.getSkin()); } catch (final Exception e1) { Bukkit.getLogger().log(Level.WARNING, "Failed to degrab entity.", e1); } this.setHelmet(itemStack); final Vector vector = this.getDirection(livingEntity).normalize().multiply(3); this.teleport(livingEntity.getLocation().add(vector)); } }
/** * Removes the ball from the hands of an entity. */ @Override public void deGrab() { if (this.isGrabbed() && this.interactionEntity != null) { final LivingEntity livingEntity = (LivingEntity) this.interactionEntity; livingEntity.getEquipment().setItemInHand(null); this.grabbed = false; final ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); try { SkinHelper.setItemStackSkin(itemStack, this.ballMeta.getSkin()); } catch (final Exception e1) { Bukkit.getLogger().log(Level.WARNING, "Failed to degrab entity.", e1); } this.setHelmet(itemStack); final Vector vector = this.getDirection(livingEntity).normalize().multiply(3); this.teleport(livingEntity.getLocation().add(vector)); } }