Java Code Examples for org.bukkit.Material#TIPPED_ARROW

The following examples show how to use org.bukkit.Material#TIPPED_ARROW . 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: SentinelItemHelper.java    From Sentinel with MIT License 6 votes vote down vote up
/**
 * Gets the correct ArrowItem type for the NPC based on inventory items (can be null if the NPC needs ammo but has none).
 */
public ItemStack getArrow() {
    if (!getNPC().hasTrait(Inventory.class)) {
        return sentinel.needsAmmo ? null : new ItemStack(Material.ARROW, 1);
    }
    Inventory inv = getNPC().getTrait(Inventory.class);
    ItemStack[] items = inv.getContents();
    for (ItemStack item : items) {
        if (item != null) {
            Material mat = item.getType();
            if (mat == Material.ARROW
                    || (SentinelVersionCompat.v1_9 && (mat == Material.TIPPED_ARROW || mat == Material.SPECTRAL_ARROW))
                    || (SentinelVersionCompat.v1_14 && mat == Material.FIREWORK_ROCKET)) {
                return item.clone();
            }
        }
    }
    return sentinel.needsAmmo ? null : new ItemStack(Material.ARROW, 1);
}
 
Example 2
Source File: SentinelItemHelper.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Takes an arrow from the NPC's inventory.
 */
public void takeArrow() {
    if (!getNPC().hasTrait(Inventory.class)) {
        return;
    }
    Inventory inv = getNPC().getTrait(Inventory.class);
    ItemStack[] items = inv.getContents();
    for (int i = 0; i < items.length; i++) {
        ItemStack item = items[i];
        if (item != null) {
            Material mat = item.getType();
            if (mat == Material.ARROW
                    || (SentinelVersionCompat.v1_9 && (mat == Material.TIPPED_ARROW || mat == Material.SPECTRAL_ARROW))
                    || (SentinelVersionCompat.v1_14 && mat == Material.FIREWORK_ROCKET)) {
                if (item.getAmount() > 1) {
                    item.setAmount(item.getAmount() - 1);
                    items[i] = item;
                    inv.setContents(items);
                    return;
                }
                else {
                    items[i] = null;
                    inv.setContents(items);
                    return;
                }
            }
        }
    }
}
 
Example 3
Source File: SentinelWeaponHelper.java    From Sentinel with MIT License 4 votes vote down vote up
/**
 * Fires an arrow from the NPC at a target.
 */
public void fireArrow(ItemStack type, Location target, Vector lead) {
    Location launchStart;
    Vector baseVelocity;
    if (SentinelVersionCompat.v1_14 && type.getType() == Material.FIREWORK_ROCKET) {
        launchStart = sentinel.getLivingEntity().getEyeLocation();
        launchStart = launchStart.clone().add(launchStart.getDirection());
        baseVelocity = target.toVector().subtract(launchStart.toVector().add(lead));
        if (baseVelocity.lengthSquared() > 0) {
            baseVelocity = baseVelocity.normalize();
        }
        baseVelocity = baseVelocity.multiply(2);
    }
    else {
        HashMap.SimpleEntry<Location, Vector> start = sentinel.getLaunchDetail(target, lead);
        if (start == null || start.getKey() == null) {
            return;
        }
        launchStart = start.getKey();
        baseVelocity = start.getValue();
    }
    Vector velocity = sentinel.fixForAcc(baseVelocity);
    sentinel.stats_arrowsFired++;
    Entity arrow;
    if (SentinelVersionCompat.v1_9) {
        if (SentinelVersionCompat.v1_14) {
            double length = Math.max(1.0, velocity.length());
            if (type.getType() == Material.FIREWORK_ROCKET) {
                FireworkMeta meta = (FireworkMeta) type.getItemMeta();
                meta.setPower(3);
                arrow = launchStart.getWorld().spawn(launchStart, EntityType.FIREWORK.getEntityClass(), (e) -> {
                    ((Firework) e).setShotAtAngle(true);
                    ((Firework) e).setFireworkMeta(meta);
                    e.setVelocity(velocity);
                });
            }
            else {
                Class toShoot;
                toShoot = type.getType() == Material.SPECTRAL_ARROW ? SpectralArrow.class :
                        (type.getType() == Material.TIPPED_ARROW ? TippedArrow.class : Arrow.class);
                arrow = launchStart.getWorld().spawnArrow(launchStart, velocity.multiply(1.0 / length), (float) length, 0f, toShoot);
                ((Projectile) arrow).setShooter(getLivingEntity());
                ((Arrow) arrow).setPickupStatus(Arrow.PickupStatus.DISALLOWED);
                if (type.getItemMeta() instanceof PotionMeta) {
                    PotionData data = ((PotionMeta) type.getItemMeta()).getBasePotionData();
                    if (data.getType() == null || data.getType() == PotionType.UNCRAFTABLE) {
                        if (SentinelPlugin.debugMe) {
                            sentinel.debug("Potion data '" + data + "' for '" + type.toString() + "' is invalid.");
                        }
                    }
                    else {
                        ((Arrow) arrow).setBasePotionData(data);
                        for (PotionEffect effect : ((PotionMeta) type.getItemMeta()).getCustomEffects()) {
                            ((Arrow) arrow).addCustomEffect(effect, true);
                        }
                    }
                }
            }
        }
        else {
            arrow = launchStart.getWorld().spawnEntity(launchStart,
                    type.getType() == Material.SPECTRAL_ARROW ? EntityType.SPECTRAL_ARROW :
                            (type.getType() == Material.TIPPED_ARROW ? TIPPED_ARROW : EntityType.ARROW));
            arrow.setVelocity(velocity);
            ((Projectile) arrow).setShooter(getLivingEntity());
        }
    }
    else {
        arrow = launchStart.getWorld().spawnEntity(launchStart, EntityType.ARROW);
        ((Projectile) arrow).setShooter(getLivingEntity());
        arrow.setVelocity(velocity);
    }
    if (sentinel.itemHelper.getHeldItem().containsEnchantment(Enchantment.ARROW_FIRE)) {
        arrow.setFireTicks(10000);
    }
    sentinel.useItem();
}