org.bukkit.potion.PotionType Java Examples

The following examples show how to use org.bukkit.potion.PotionType. 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: CraftTippedArrow.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean removeCustomEffect(PotionEffectType effect) {
    int effectId = effect.getId();
    net.minecraft.potion.PotionEffect existing = null;
    for (net.minecraft.potion.PotionEffect mobEffect : getHandle().customPotionEffects) {
        if (Potion.getIdFromPotion(mobEffect.getPotion()) == effectId) {
            existing = mobEffect;
        }
    }
    if (existing == null) {
        return false;
    }
    Validate.isTrue(getBasePotionData().getType() != PotionType.UNCRAFTABLE || !getHandle().customPotionEffects.isEmpty(), "Tipped Arrows must have at least 1 effect");
    getHandle().customPotionEffects.remove(existing);
    getHandle().refreshEffects();
    return true;
}
 
Example #2
Source File: JsonItemUtils.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
private static ItemMeta parseBasePotionEffect(ItemMeta meta, JsonObject jsonObject) throws ParseException{
    PotionMeta potionMeta = (PotionMeta) meta;

    PotionType type;

    try {
        type = PotionType.valueOf(jsonObject.get("type").getAsString());
    }catch (IllegalArgumentException ex){
        throw new ParseException(ex.getMessage());
    }

    JsonElement jsonElement;
    jsonElement = jsonObject.get("extended");
    boolean extended = jsonElement != null && jsonElement.getAsBoolean();
    jsonElement = jsonObject.get("upgraded");
    boolean upgraded = jsonElement != null && jsonElement.getAsBoolean();

    PotionData potionData = new PotionData(type, extended, upgraded);
    potionMeta = VersionUtils.getVersionUtils().setBasePotionEffect(potionMeta, potionData);

    return potionMeta;
}
 
Example #3
Source File: CraftWorld.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public <T extends Arrow> T spawnArrow(Location loc, Vector velocity, float speed, float spread, Class<T> clazz) {
    Validate.notNull(loc, "Can not spawn arrow with a null location");
    Validate.notNull(velocity, "Can not spawn arrow with a null velocity");
    Validate.notNull(clazz, "Can not spawn an arrow with no class");

    EntityArrow arrow;
    if (TippedArrow.class.isAssignableFrom(clazz)) {
        arrow = new EntityTippedArrow(world);
        ((EntityTippedArrow) arrow).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
    } else if (SpectralArrow.class.isAssignableFrom(clazz)) {
        arrow = new EntitySpectralArrow(world);
    } else {
        arrow = new EntityTippedArrow(world);
    }

    arrow.setLocationAndAngles(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
    arrow.shoot(velocity.getX(), velocity.getY(), velocity.getZ(), speed, spread);
    world.spawnEntity(arrow);
    return (T) arrow.getBukkitEntity();
}
 
Example #4
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 #5
Source File: CraftMetaPotion.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
void applyToItem(NBTTagCompound tag) {
    super.applyToItem(tag);

    tag.setString(DEFAULT_POTION.NBT, (this.type.getType() == PotionType.UNCRAFTABLE && emptyType != null) ? emptyType : CraftPotionUtil.fromBukkit(type));

    if (hasColor()) {
        tag.setInteger(POTION_COLOR.NBT, color.asRGB());
    }

    if (customEffects != null) {
        NBTTagList effectList = new NBTTagList();
        tag.setTag(POTION_EFFECTS.NBT, effectList);

        for (PotionEffect effect : customEffects) {
            NBTTagCompound effectData = new NBTTagCompound();
            effectData.setByte(ID.NBT, (byte) effect.getType().getId());
            effectData.setByte(AMPLIFIER.NBT, (byte) effect.getAmplifier());
            effectData.setInteger(DURATION.NBT, effect.getDuration());
            effectData.setBoolean(AMBIENT.NBT, effect.isAmbient());
            effectData.setBoolean(SHOW_PARTICLES.NBT, effect.hasParticles());
            effectList.appendTag(effectData);
        }
    }
}
 
Example #6
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 #7
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 #8
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 #9
Source File: ItemBuilder.java    From Crazy-Crates with MIT License 5 votes vote down vote up
private PotionType getPotionType(PotionEffectType type) {
    if (type != null) {
        if (type.equals(PotionEffectType.FIRE_RESISTANCE)) {
            return PotionType.FIRE_RESISTANCE;
        } else if (type.equals(PotionEffectType.HARM)) {
            return PotionType.INSTANT_DAMAGE;
        } else if (type.equals(PotionEffectType.HEAL)) {
            return PotionType.INSTANT_HEAL;
        } else if (type.equals(PotionEffectType.INVISIBILITY)) {
            return PotionType.INVISIBILITY;
        } else if (type.equals(PotionEffectType.JUMP)) {
            return PotionType.JUMP;
        } else if (type.equals(PotionEffectType.getByName("LUCK"))) {
            return PotionType.valueOf("LUCK");
        } else if (type.equals(PotionEffectType.NIGHT_VISION)) {
            return PotionType.NIGHT_VISION;
        } else if (type.equals(PotionEffectType.POISON)) {
            return PotionType.POISON;
        } else if (type.equals(PotionEffectType.REGENERATION)) {
            return PotionType.REGEN;
        } else if (type.equals(PotionEffectType.SLOW)) {
            return PotionType.SLOWNESS;
        } else if (type.equals(PotionEffectType.SPEED)) {
            return PotionType.SPEED;
        } else if (type.equals(PotionEffectType.INCREASE_DAMAGE)) {
            return PotionType.STRENGTH;
        } else if (type.equals(PotionEffectType.WATER_BREATHING)) {
            return PotionType.WATER_BREATHING;
        } else if (type.equals(PotionEffectType.WEAKNESS)) {
            return PotionType.WEAKNESS;
        }
    }
    return null;
}
 
Example #10
Source File: PotionHandler.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
public void setType(String type) throws InstructionParseException {
    typeE = Existence.REQUIRED;
    try {
        this.type = PotionType.valueOf(type.toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new InstructionParseException("No such potion type: " + type, e);
    }
}
 
Example #11
Source File: CustomPotion.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public CustomPotion(String name, PotionType type, PotionEffect effect, String... lore) {
	super(Material.POTION, name, lore);
	PotionMeta meta = (PotionMeta) getItemMeta();
	meta.setBasePotionData(new PotionData(type));
	meta.addCustomEffect(effect, true);
	setItemMeta(meta);
}
 
Example #12
Source File: ItemUtils.java    From ShopChest with MIT License 5 votes vote down vote up
public static PotionType getPotionEffect(ItemStack itemStack) {
    if (itemStack.getItemMeta() instanceof PotionMeta) {    
        if (Utils.getMajorVersion() < 9) {
            return Potion.fromItemStack(itemStack).getType();
        } else {
            return ((PotionMeta) itemStack.getItemMeta()).getBasePotionData().getType();
        }
    }

    return null;
}
 
Example #13
Source File: Tier2PotionsModule.java    From UHC with MIT License 5 votes vote down vote up
public Tier2PotionsModule(PotionFuelsListener listener) {
    setId("Tier2Potions");

    this.listener = listener;

    final Potion potion = new Potion(PotionType.INSTANT_HEAL);
    potion.setLevel(2);

    this.icon.setType(Material.POTION);
    this.icon.setDurability(potion.toDamageValue());
    this.icon.setWeight(ModuleRegistry.CATEGORY_POTIONS);
    this.iconName = ICON_NAME;
}
 
Example #14
Source File: SplashPotionsModule.java    From UHC with MIT License 5 votes vote down vote up
public SplashPotionsModule(PotionFuelsListener listener) {
    setId("SplashPotions");

    this.listener = listener;

    final Potion potion = new Potion(PotionType.POISON);
    potion.setSplash(true);

    this.icon.setType(Material.POTION);
    this.icon.setDurability(potion.toDamageValue());
    this.icon.setWeight(ModuleRegistry.CATEGORY_POTIONS);
    this.iconName = ICON_NAME;
}
 
Example #15
Source File: PotionName.java    From ShopChest with MIT License 4 votes vote down vote up
public PotionName(PotionItemType potionItemType, PotionType potionType, String localizedName) {
    this.potionItemType = potionItemType;
    this.localizedName = localizedName;
    this.potionType = potionType;
}
 
Example #16
Source File: PotionName.java    From ShopChest with MIT License 4 votes vote down vote up
/**
 * @return Potion Type linked to the Potion name
 */
public PotionType getPotionType() {
    return potionType;
}
 
Example #17
Source File: Instruction.java    From BetonQuest with GNU General Public License v3.0 4 votes vote down vote up
public PotionType getPotion() throws InstructionParseException {
    return getEnum(next(), PotionType.class);
}
 
Example #18
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> cont = (Map<String,Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String,Tag> contents = (Map<String,Tag>)((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag)contents.get("Potion"));
            if (stringTag != null) {
                String tag = stringTag.getValue().replace("minecraft:", "");
                PotionType type = null;
                boolean strong = tag.contains("strong");
                boolean _long = tag.contains("long");
                //Bukkit.getLogger().info("tag = " + tag);
                if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
                    type = PotionType.FIRE_RESISTANCE;
                }else if(tag.equals("harming") || tag.equals("strong_harming")){
                    type = PotionType.INSTANT_DAMAGE;
                }else if(tag.equals("healing") || tag.equals("strong_healing")){
                    type = PotionType.INSTANT_HEAL;
                }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
                    type = PotionType.INVISIBILITY;
                }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
                    type = PotionType.JUMP;
                }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
                    type = PotionType.NIGHT_VISION;
                }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
                    type = PotionType.POISON;
                }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
                    type = PotionType.REGEN;
                }else if(tag.equals("slowness") || tag.equals("long_slowness")){
                    type = PotionType.SLOWNESS;
                }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
                    type = PotionType.SPEED;
                }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
                    type = PotionType.STRENGTH;
                }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
                    type = PotionType.WATER_BREATHING;
                }else if(tag.equals("water")){
                    type = PotionType.WATER;
                }else if(tag.equals("weakness") || tag.equals("long_weakness")){
                    type = PotionType.WEAKNESS;
                }else{
                    return chestItem;
                }
                Potion potion = new Potion(type);
                potion.setHasExtendedDuration(_long);
                potion.setLevel(strong ? 2 : 1);
                chestItem = potion.toItemStack(chestItem.getAmount());
            }
        }
    }

    return chestItem;
}
 
Example #19
Source File: Instruction.java    From BetonQuest with GNU General Public License v3.0 4 votes vote down vote up
public PotionType getPotion(String string) throws InstructionParseException {
    return getEnum(string, PotionType.class);
}
 
Example #20
Source File: AutoBrewer.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
private ItemStack brew(Material input, Material potionType, PotionMeta potion) {
    PotionData data = potion.getBasePotionData();

    if (data.getType() == PotionType.WATER) {
        if (input == Material.FERMENTED_SPIDER_EYE) {
            potion.setBasePotionData(new PotionData(PotionType.WEAKNESS, false, false));
            return new ItemStack(potionType);
        }
        else if (input == Material.NETHER_WART) {
            potion.setBasePotionData(new PotionData(PotionType.AWKWARD, false, false));
            return new ItemStack(potionType);
        }
        else if (potionType == Material.POTION && input == Material.GUNPOWDER) {
            return new ItemStack(Material.SPLASH_POTION);
        }
        else if (potionType == Material.SPLASH_POTION && input == Material.DRAGON_BREATH) {
            return new ItemStack(Material.LINGERING_POTION);
        }
        else {
            return null;
        }

    }
    else if (input == Material.FERMENTED_SPIDER_EYE) {
        potion.setBasePotionData(new PotionData(fermentations.get(data.getType()), false, false));
        return new ItemStack(potionType);
    }
    else if (input == Material.REDSTONE) {
        potion.setBasePotionData(new PotionData(data.getType(), true, data.isUpgraded()));
        return new ItemStack(potionType);
    }
    else if (input == Material.GLOWSTONE_DUST) {
        potion.setBasePotionData(new PotionData(data.getType(), data.isExtended(), true));
        return new ItemStack(potionType);
    }
    else if (data.getType() == PotionType.AWKWARD && potionRecipes.containsKey(input)) {
        potion.setBasePotionData(new PotionData(potionRecipes.get(input), false, false));
        return new ItemStack(potionType);
    }
    else {
        return null;
    }
}
 
Example #21
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> cont = (Map<String,Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String,Tag> contents = (Map<String,Tag>)((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag)contents.get("Potion"));
            if (stringTag != null) {
                String tag = stringTag.getValue().replace("minecraft:", "");
                PotionType type = null;
                boolean strong = tag.contains("strong");
                boolean _long = tag.contains("long");
                //Bukkit.getLogger().info("tag = " + tag);
                if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
                    type = PotionType.FIRE_RESISTANCE;
                }else if(tag.equals("harming") || tag.equals("strong_harming")){
                    type = PotionType.INSTANT_DAMAGE;
                }else if(tag.equals("healing") || tag.equals("strong_healing")){
                    type = PotionType.INSTANT_HEAL;
                }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
                    type = PotionType.INVISIBILITY;
                }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
                    type = PotionType.JUMP;
                }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
                    type = PotionType.NIGHT_VISION;
                }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
                    type = PotionType.POISON;
                }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
                    type = PotionType.REGEN;
                }else if(tag.equals("slowness") || tag.equals("long_slowness")){
                    type = PotionType.SLOWNESS;
                }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
                    type = PotionType.SPEED;
                }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
                    type = PotionType.STRENGTH;
                }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
                    type = PotionType.WATER_BREATHING;
                }else if(tag.equals("water")){
                    type = PotionType.WATER;
                }else if(tag.equals("weakness") || tag.equals("long_weakness")){
                    type = PotionType.WEAKNESS;
                }else{
                    return chestItem;
                }
                Potion potion = new Potion(type);
                potion.setHasExtendedDuration(_long);
                potion.setLevel(strong ? 2 : 1);
                chestItem = potion.toItemStack(chestItem.getAmount());
            }
        }
    }

    return chestItem;
}
 
Example #22
Source File: Vampire.java    From AnnihilationPro with MIT License 4 votes vote down vote up
@Override
protected Loadout getFinalLoadout()
{
	return new Loadout().addStoneSword().addWoodPick().addWoodAxe()
			.addItem(new Potion(PotionType.NIGHT_VISION).toItemStack(1));
}
 
Example #23
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> cont = (Map<String,Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String,Tag> contents = (Map<String,Tag>)((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag)contents.get("Potion"));
            if (stringTag != null) {
                String tag = stringTag.getValue().replace("minecraft:", "");
                PotionType type = null;
                boolean strong = tag.contains("strong");
                boolean _long = tag.contains("long");
                //Bukkit.getLogger().info("tag = " + tag);
                if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
                    type = PotionType.FIRE_RESISTANCE;
                }else if(tag.equals("harming") || tag.equals("strong_harming")){
                    type = PotionType.INSTANT_DAMAGE;
                }else if(tag.equals("healing") || tag.equals("strong_healing")){
                    type = PotionType.INSTANT_HEAL;
                }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
                    type = PotionType.INVISIBILITY;
                }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
                    type = PotionType.JUMP;
                }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
                    type = PotionType.NIGHT_VISION;
                }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
                    type = PotionType.POISON;
                }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
                    type = PotionType.REGEN;
                }else if(tag.equals("slowness") || tag.equals("long_slowness")){
                    type = PotionType.SLOWNESS;
                }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
                    type = PotionType.SPEED;
                }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
                    type = PotionType.STRENGTH;
                }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
                    type = PotionType.WATER_BREATHING;
                }else if(tag.equals("water")){
                    type = PotionType.WATER;
                }else if(tag.equals("weakness") || tag.equals("long_weakness")){
                    type = PotionType.WEAKNESS;
                }else{
                    return chestItem;
                }
                Potion potion = new Potion(type);
                potion.setHasExtendedDuration(_long);
                potion.setLevel(strong ? 2 : 1);
                chestItem = potion.toItemStack(chestItem.getAmount());
            }
        }
    }

    return chestItem;
}
 
Example #24
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> cont = (Map<String,Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String,Tag> contents = (Map<String,Tag>)((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag)contents.get("Potion"));
            if (stringTag != null) {
                String tag = stringTag.getValue().replace("minecraft:", "");
                PotionType type = null;
                boolean strong = tag.contains("strong");
                boolean _long = tag.contains("long");
                //Bukkit.getLogger().info("tag = " + tag);
                if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
                    type = PotionType.FIRE_RESISTANCE;
                }else if(tag.equals("harming") || tag.equals("strong_harming")){
                    type = PotionType.INSTANT_DAMAGE;
                }else if(tag.equals("healing") || tag.equals("strong_healing")){
                    type = PotionType.INSTANT_HEAL;
                }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
                    type = PotionType.INVISIBILITY;
                }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
                    type = PotionType.JUMP;
                }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
                    type = PotionType.NIGHT_VISION;
                }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
                    type = PotionType.POISON;
                }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
                    type = PotionType.REGEN;
                }else if(tag.equals("slowness") || tag.equals("long_slowness")){
                    type = PotionType.SLOWNESS;
                }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
                    type = PotionType.SPEED;
                }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
                    type = PotionType.STRENGTH;
                }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
                    type = PotionType.WATER_BREATHING;
                }else if(tag.equals("water")){
                    type = PotionType.WATER;
                }else if(tag.equals("weakness") || tag.equals("long_weakness")){
                    type = PotionType.WEAKNESS;
                }else{
                    return chestItem;
                }
                Potion potion = new Potion(type);
                potion.setHasExtendedDuration(_long);
                potion.setLevel(strong ? 2 : 1);
                chestItem = potion.toItemStack(chestItem.getAmount());
            }
        }
    }

    return chestItem;
}
 
Example #25
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) itemTags).getValue().get("tag").getValue();
    StringTag stringTag = ((StringTag)contents.get("Potion"));
    if (stringTag != null) {
        String tag = stringTag.getValue().replace("minecraft:", "");
        PotionType type = null;
        boolean strong = tag.contains("strong");
        boolean _long = tag.contains("long");
        //Bukkit.getLogger().info("tag = " + tag);
        if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
            type = PotionType.FIRE_RESISTANCE;
        }else if(tag.equals("harming") || tag.equals("strong_harming")){
            type = PotionType.INSTANT_DAMAGE;
        }else if(tag.equals("healing") || tag.equals("strong_healing")){
            type = PotionType.INSTANT_HEAL;
        }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
            type = PotionType.INVISIBILITY;
        }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
            type = PotionType.JUMP;
        }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
            type = PotionType.NIGHT_VISION;
        }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
            type = PotionType.POISON;
        }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
            type = PotionType.REGEN;
        }else if(tag.equals("slowness") || tag.equals("long_slowness")){
            type = PotionType.SLOWNESS;
        }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
            type = PotionType.SPEED;
        }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
            type = PotionType.STRENGTH;
        }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
            type = PotionType.WATER_BREATHING;
        }else if(tag.equals("water")){
            type = PotionType.WATER;
        }else if(tag.equals("weakness") || tag.equals("long_weakness")){
            type = PotionType.WEAKNESS;
        }else{
            return chestItem;
        }
        Potion potion = new Potion(type);
        potion.setHasExtendedDuration(_long);
        potion.setLevel(strong ? 2 : 1);
        chestItem = potion.toItemStack(chestItem.getAmount());
    }

    return chestItem;
}
 
Example #26
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> cont = (Map<String,Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String,Tag> contents = (Map<String,Tag>)((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag)contents.get("Potion"));
            if (stringTag != null) {
                String tag = stringTag.getValue().replace("minecraft:", "");
                PotionType type = null;
                boolean strong = tag.contains("strong");
                boolean _long = tag.contains("long");
                //Bukkit.getLogger().info("tag = " + tag);
                if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
                    type = PotionType.FIRE_RESISTANCE;
                }else if(tag.equals("harming") || tag.equals("strong_harming")){
                    type = PotionType.INSTANT_DAMAGE;
                }else if(tag.equals("healing") || tag.equals("strong_healing")){
                    type = PotionType.INSTANT_HEAL;
                }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
                    type = PotionType.INVISIBILITY;
                }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
                    type = PotionType.JUMP;
                }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
                    type = PotionType.NIGHT_VISION;
                }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
                    type = PotionType.POISON;
                }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
                    type = PotionType.REGEN;
                }else if(tag.equals("slowness") || tag.equals("long_slowness")){
                    type = PotionType.SLOWNESS;
                }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
                    type = PotionType.SPEED;
                }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
                    type = PotionType.STRENGTH;
                }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
                    type = PotionType.WATER_BREATHING;
                }else if(tag.equals("water")){
                    type = PotionType.WATER;
                }else if(tag.equals("weakness") || tag.equals("long_weakness")){
                    type = PotionType.WEAKNESS;
                }else{
                    return chestItem;
                }
                Potion potion = new Potion(type);
                potion.setHasExtendedDuration(_long);
                potion.setLevel(strong ? 2 : 1);
                chestItem = potion.toItemStack(chestItem.getAmount());
            }
        }
    }

    return chestItem;
}
 
Example #27
Source File: UMaterial.java    From TradePlus with GNU General Public License v3.0 4 votes vote down vote up
public static UMaterial matchPotion(ItemStack potion) {
  if(potion != null && potion.getItemMeta() instanceof PotionMeta) {
    final PotionMeta p = (PotionMeta) potion.getItemMeta();
    final List<PotionEffect> ce = p.getCustomEffects();
    if(ce.size() == 0) {
      final String base;
      final PotionEffectType t;
      final int l, max;
      final boolean extended;
      if(EIGHT) {
        final Potion po = Potion.fromItemStack(potion);
        base = po.isSplash() ? "SPLASH_POTION_" : "POTION_";
        final Collection<PotionEffect> e = po.getEffects();
        t = e.size() > 0 ? ((PotionEffect) e.toArray()[0]).getType() : null;
        l = po.getLevel();
        final PotionType ty = po.getType();
        max = ty != null ? ty.getMaxLevel() : 0;
        extended = po.hasExtendedDuration();
      } else {
        final org.bukkit.potion.PotionData pd = p.getBasePotionData();
        final PotionType type = pd.getType();
        base = potion.getType().name() + "_";
        t = type.getEffectType();
        l = type.isUpgradeable() && pd.isUpgraded() ? 2 : 1;
        max = type.getMaxLevel();
        extended = type.isExtendable() && pd.isExtended();
      }
      final String a = t != null ? t.getName() : null,
          type = a != null ? a.equals("SPEED") ? "SWIFTNESS"
                                 : a.equals("SLOW") ? "SLOWNESS"
                                       : a.equals("INCREASE_DAMAGE") ? "STRENGTH"
                                             : a.equals("HEAL") ? "HEALING"
                                                   : a.equals("HARM") ? "HARMING"
                                                         : a.equals("JUMP") ? "LEAPING"
                                                               : a : null;
      if(type != null) {
        final String g = base + type + (max != 1 && l <= max ? "_" + l : "") + (extended ? "_EXTENDED" : "");
        return valueOf(g);
      } else {
        return UMaterial.POTION;
      }
    }
  }
  return null;
}
 
Example #28
Source File: Loadout.java    From AnnihilationPro with MIT License 4 votes vote down vote up
@SuppressWarnings("deprecation")
public Loadout addHealthPotion1()
{
	return addItem(KitUtils.addSoulbound((new Potion(PotionType.INSTANT_HEAL, 1, false,false).toItemStack(1))));
}
 
Example #29
Source File: LugolsIodinePotion.java    From CraftserveRadiation with Apache License 2.0 4 votes vote down vote up
public Recipe(boolean enabled, Material ingredient, PotionType basePotion) {
    this.enabled = enabled;
    this.ingredient = Objects.requireNonNull(ingredient, "ingredient");
    this.basePotion = Objects.requireNonNull(basePotion, "basePotion");
}
 
Example #30
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();
}