Java Code Examples for org.bukkit.potion.PotionType#UNCRAFTABLE

The following examples show how to use org.bukkit.potion.PotionType#UNCRAFTABLE . 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: CraftMetaPotion.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
CraftMetaPotion(Map<String, Object> map) {
    super(map);
    type = CraftPotionUtil.toBukkit(SerializableMeta.getString(map, DEFAULT_POTION.BUKKIT, true));
    if (type.getType() == PotionType.UNCRAFTABLE) {
        emptyType = SerializableMeta.getString(map, DEFAULT_POTION.BUKKIT + "-empty", true);
    }
    Color color = SerializableMeta.getObject(Color.class, map, POTION_COLOR.BUKKIT, true);
    if (color != null) {
        setColor(color);
    }

    Iterable<?> rawEffectList = SerializableMeta.getObject(Iterable.class, map, POTION_EFFECTS.BUKKIT, true);
    if (rawEffectList == null) {
        return;
    }

    for (Object obj : rawEffectList) {
        if (!(obj instanceof PotionEffect)) {
            throw new IllegalArgumentException("Object in effect list is not valid. " + obj.getClass());
        }
        addCustomEffect((PotionEffect) obj, true);
    }
}
 
Example 2
Source File: CraftMetaPotion.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
int applyHash() {
    final int original;
    int hash = original = super.applyHash();
    if (type.getType() != PotionType.UNCRAFTABLE) {
        hash = 73 * hash + type.hashCode();
    } else if (emptyType != null) {
        hash = 73 * hash + emptyType.hashCode();
    }
    if (hasColor()) {
        hash = 73 * hash + color.hashCode();
    }
    if (hasCustomEffects()) {
        hash = 73 * hash + customEffects.hashCode();
    }
    return original != hash ? CraftMetaPotion.class.hashCode() ^ hash : hash;
}
 
Example 3
Source File: CraftMetaPotion.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
Builder<String, Object> serialize(Builder<String, Object> builder) {
    super.serialize(builder);
    if (type.getType() != PotionType.UNCRAFTABLE) {
        builder.put(DEFAULT_POTION.BUKKIT, CraftPotionUtil.fromBukkit(type));
    } else if (this.emptyType != null) {
        builder.put(DEFAULT_POTION.BUKKIT + "-empty", emptyType);
    }

    if (hasColor()) {
        builder.put(POTION_COLOR.BUKKIT, getColor());
    }

    if (hasCustomEffects()) {
        builder.put(POTION_EFFECTS.BUKKIT, ImmutableList.copyOf(this.customEffects));
    }

    return builder;
}
 
Example 4
Source File: CraftPotionUtil.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static PotionData toBukkit(String type) {
    if (type == null) {
        return new PotionData(PotionType.UNCRAFTABLE, false, false);
    }
    if (type.startsWith("minecraft:")) {
        type = type.substring(10);
    }
    PotionType potionType = null;
    potionType = extendable.inverse().get(type);
    if (potionType != null) {
        return new PotionData(potionType, true, false);
    }
    potionType = upgradeable.inverse().get(type);
    if (potionType != null) {
        return new PotionData(potionType, false, true);
    }
    potionType = regular.inverse().get(type);
    if (potionType != null) {
        return new PotionData(potionType, false, false);
    }
    return new PotionData(PotionType.UNCRAFTABLE, false, false);
}
 
Example 5
Source File: CraftMetaPotion.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
boolean isPotionEmpty() {
    return (type.getType() == PotionType.UNCRAFTABLE) && !(hasCustomEffects() || hasColor()) && emptyType == null;
}
 
Example 6
Source File: PotionEffectUtils.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Checks if given string represents a known potion type and returns that type.
 * Unused currently, will be used soon (TM).
 * @param name Name of potion type
 * @return
 */
@Nullable
public static PotionType checkPotionType(String name) {
	switch (name) {
		case "uncraftable":
		case "empty":
			return PotionType.UNCRAFTABLE;
		case "mundane":
			return PotionType.MUNDANE;
		case "thick":
			return PotionType.THICK;
		case "night vision":
		case "darkvision":
			return PotionType.NIGHT_VISION;
		case "invisibility":
			return PotionType.INVISIBILITY;
		case "leaping":
		case "jump boost":
			return PotionType.JUMP;
		case "fire resistance":
		case "fire immunity":
			return PotionType.FIRE_RESISTANCE;
		case "swiftness":
		case "speed":
			return PotionType.SPEED;
		case "slowness":
			return PotionType.SLOWNESS;
		case "water breathing":
			return PotionType.WATER_BREATHING;
		case "instant health":
		case "healing":
		case "health":
			return PotionType.INSTANT_HEAL;
		case "instant damage":
		case "harming":
		case "damage":
			return PotionType.INSTANT_DAMAGE;
		case "poison":
			return PotionType.POISON;
		case "regeneration":
		case "regen":
			return PotionType.REGEN;
		case "strength":
			return PotionType.STRENGTH;
		case "weakness":
			return PotionType.WEAKNESS;
		case "luck":
			return PotionType.LUCK;
	}
	
	return null;
}
 
Example 7
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();
}