org.bukkit.potion.PotionData Java Examples
The following examples show how to use
org.bukkit.potion.PotionData.
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: PotionHandler.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
public boolean checkBase(PotionData base) { switch (typeE) { case WHATEVER: return true; case REQUIRED: if (base.getType() != type) { return false; } if (extendedE == Existence.REQUIRED && base.isExtended() != extended) { return false; } return upgradedE != Existence.REQUIRED || base.isUpgraded() == upgraded; default: return false; } }
Example #2
Source File: ActionHelper.java From ActionHealth with MIT License | 6 votes |
public List<String> getName(ItemStack itemStack) { List<String> possibleMaterials = new ArrayList<>(); String name = itemStack.getType().name(); possibleMaterials.add(name); if (itemStack.hasItemMeta()) { ItemMeta itemMeta = itemStack.getItemMeta(); if (itemMeta instanceof PotionMeta) { PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta(); PotionData potionData = potionMeta.getBasePotionData(); possibleMaterials.add(potionData.getType().getEffectType().getName() + "_" + name); if (potionMeta.hasCustomEffects()) { for (PotionEffect potionEffect : potionMeta.getCustomEffects()) { possibleMaterials.add(potionEffect.getType().getName() + "_" + name); } } } } return possibleMaterials; }
Example #3
Source File: CraftPotionUtil.java From Kettle with GNU General Public License v3.0 | 6 votes |
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 #4
Source File: JsonItemUtils.java From UhcCore with GNU General Public License v3.0 | 6 votes |
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 #5
Source File: CraftWorld.java From Kettle with GNU General Public License v3.0 | 6 votes |
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 #6
Source File: VersionUtils_1_13.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@Override public JsonObject getBasePotionEffect(PotionMeta potionMeta) { PotionData potionData = potionMeta.getBasePotionData(); JsonObject baseEffect = new JsonObject(); baseEffect.addProperty("type", potionData.getType().name()); if (potionData.isUpgraded()) { baseEffect.addProperty("upgraded", true); } if (potionData.isExtended()) { baseEffect.addProperty("extended", true); } return baseEffect; }
Example #7
Source File: PotionUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public static Collection<PotionEffect> effects(@Nullable PotionData potion, @Nullable Collection<PotionEffect> customEffects) { final ImmutableList.Builder<PotionEffect> builder = ImmutableList.builder(); if(potion != null) { builder.addAll(effects(potion)); } if(customEffects != null) { builder.addAll(customEffects); } return builder.build(); }
Example #8
Source File: CustomPotion.java From CS-CoreLib with GNU General Public License v3.0 | 5 votes |
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 #9
Source File: RadiationCommandHandler.java From CraftserveRadiation with Apache License 2.0 | 5 votes |
private boolean onPotion(Player sender) { ItemStack itemStack = new ItemStack(Material.POTION); PotionMeta itemMeta = Objects.requireNonNull((PotionMeta) itemStack.getItemMeta()); itemMeta.setBasePotionData(new PotionData(potion.getConfig().getRecipe().getBasePotion())); itemStack.setItemMeta(potion.convert(itemMeta)); sender.getInventory().addItem(itemStack); return true; }
Example #10
Source File: CraftPotionUtil.java From Kettle with GNU General Public License v3.0 | 5 votes |
public static String fromBukkit(PotionData data) { String type; if (data.isUpgraded()) { type = upgradeable.get(data.getType()); } else if (data.isExtended()) { type = extendable.get(data.getType()); } else { type = regular.get(data.getType()); } Preconditions.checkNotNull(type, "Unknown potion type from data " + data); return "minecraft:" + type; }
Example #11
Source File: VersionUtils_1_12.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@Override public JsonObject getBasePotionEffect(PotionMeta potionMeta) { PotionData potionData = potionMeta.getBasePotionData(); JsonObject baseEffect = new JsonObject(); baseEffect.addProperty("type", potionData.getType().name()); if (potionData.isUpgraded()) { baseEffect.addProperty("upgraded", true); } if (potionData.isExtended()) { baseEffect.addProperty("extended", true); } return baseEffect; }
Example #12
Source File: VersionUtils_1_12.java From UhcCore with GNU General Public License v3.0 | 4 votes |
@Override public PotionMeta setBasePotionEffect(PotionMeta potionMeta, PotionData potionData) { potionMeta.setBasePotionData(potionData); return potionMeta; }
Example #13
Source File: VersionUtils_1_13.java From UhcCore with GNU General Public License v3.0 | 4 votes |
@Override public PotionMeta setBasePotionEffect(PotionMeta potionMeta, PotionData potionData) { potionMeta.setBasePotionData(potionData); return potionMeta; }
Example #14
Source File: VersionUtils_1_8.java From UhcCore with GNU General Public License v3.0 | 4 votes |
@Override public PotionMeta setBasePotionEffect(PotionMeta potionMeta, PotionData potionData){ return potionMeta; }
Example #15
Source File: GlobalItemParser.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public ItemStack parseItem(Element el, Material type, short damage) throws InvalidXMLException { int amount = XMLUtils.parseNumber(el.getAttribute("amount"), Integer.class, 1); // If the item is a potion with non-zero damage, and there is // no modern potion ID, decode the legacy damage value. final Potion legacyPotion; if(type == Material.POTION && damage > 0 && el.getAttribute("potion") == null) { try { legacyPotion = Potion.fromDamage(damage); } catch(IllegalArgumentException e) { throw new InvalidXMLException("Invalid legacy potion damage value " + damage + ": " + e.getMessage(), el, e); } // If the legacy splash bit is set, convert to a splash potion if(legacyPotion.isSplash()) { type = Material.SPLASH_POTION; legacyPotion.setSplash(false); } // Potions always have damage 0 damage = 0; } else { legacyPotion = null; } ItemStack itemStack = new ItemStack(type, amount, damage); if(itemStack.getType() != type) { throw new InvalidXMLException("Invalid item/block", el); } final ItemMeta meta = itemStack.getItemMeta(); if(meta != null) { // This happens if the item is "air" parseItemMeta(el, meta); // If we decoded a legacy potion, apply it now, but only if there are no custom effects. // This emulates the old behavior of custom effects overriding default effects. if(legacyPotion != null) { final PotionMeta potionMeta = (PotionMeta) meta; if(!potionMeta.hasCustomEffects()) { potionMeta.setBasePotionData(new PotionData(legacyPotion.getType(), legacyPotion.hasExtendedDuration(), legacyPotion.getLevel() == 2)); } } itemStack.setItemMeta(meta); } return itemStack; }
Example #16
Source File: ItemData.java From Skript with GNU General Public License v3.0 | 4 votes |
/** * Compares {@link ItemMeta}s for {@link #matchAlias(ItemData)}. * Note that this does NOT compare everything; only the most * important bits. * @param first Meta of this item. * @param second Meta of given item. * @return Match quality of metas. * Lowest is {@link MatchQuality#SAME_MATERIAL}. */ private static MatchQuality compareItemMetas(ItemMeta first, ItemMeta second) { MatchQuality quality = MatchQuality.EXACT; // Lowered as we go on // Display name String ourName = first.hasDisplayName() ? first.getDisplayName() : null; String theirName = second.hasDisplayName() ? second.getDisplayName() : null; if (!Objects.equals(ourName, theirName)) { quality = ourName != null ? MatchQuality.SAME_MATERIAL : quality; } // Lore List<String> ourLore = first.hasLore() ? first.getLore() : null; List<String> theirLore = second.hasLore() ? second.getLore() : null; if (!Objects.equals(ourLore, theirLore)) { quality = ourLore != null ? MatchQuality.SAME_MATERIAL : quality; } // Enchantments Map<Enchantment, Integer> ourEnchants = first.getEnchants(); Map<Enchantment, Integer> theirEnchants = second.getEnchants(); if (!Objects.equals(ourEnchants, theirEnchants)) { quality = !ourEnchants.isEmpty() ? MatchQuality.SAME_MATERIAL : quality; } // Item flags Set<ItemFlag> ourFlags = first.getItemFlags(); Set<ItemFlag> theirFlags = second.getItemFlags(); if (!Objects.equals(ourFlags, theirFlags)) { quality = !ourFlags.isEmpty() ? MatchQuality.SAME_MATERIAL : quality; } // Potion data if (second instanceof PotionMeta) { if (!(first instanceof PotionMeta)) { return MatchQuality.DIFFERENT; // Second is a potion, first is clearly not } // Compare potion type, including extended and level 2 attributes PotionData ourPotion = ((PotionMeta) first).getBasePotionData(); PotionData theirPotion = ((PotionMeta) second).getBasePotionData(); return !Objects.equals(ourPotion, theirPotion) ? MatchQuality.SAME_MATERIAL : quality; } return quality; }
Example #17
Source File: ItemBuilder.java From Crazy-Crates with MIT License | 4 votes |
/** * Builder the item from all the information that was given to the builder. * @return The result of all the info that was given to the builder as an ItemStack. */ public ItemStack build() { if (nbtItem != null) { referenceItem = nbtItem.getItem(); } ItemStack item = referenceItem != null ? referenceItem : new ItemStack(material); if (item.getType() != Material.AIR) { if (isHead) {//Has to go 1st due to it removing all data when finished. if (isHash) {//Sauce: https://github.com/deanveloper/SkullCreator if (isURL) { SkullCreator.itemWithUrl(item, player); } else { SkullCreator.itemWithBase64(item, player); } } } item.setAmount(amount); ItemMeta itemMeta = item.getItemMeta(); itemMeta.setDisplayName(getUpdatedName()); itemMeta.setLore(getUpdatedLore()); if (version.isSame(Version.v1_8_R3)) { if (isHead && !isHash && player != null && !player.equals("")) { SkullMeta skullMeta = (SkullMeta) itemMeta; skullMeta.setOwner(player); } } if (version.isNewer(Version.v1_10_R1)) { itemMeta.setUnbreakable(unbreakable); } if (version.isNewer(Version.v1_12_R1)) { if (itemMeta instanceof org.bukkit.inventory.meta.Damageable) { ((org.bukkit.inventory.meta.Damageable) itemMeta).setDamage(damage); } } else { item.setDurability((short) damage); } if (isPotion && (potionType != null || potionColor != null)) { PotionMeta potionMeta = (PotionMeta) itemMeta; if (potionType != null) { potionMeta.setBasePotionData(new PotionData(potionType)); } if (potionColor != null) { potionMeta.setColor(potionColor); } } if (isLeatherArmor && armorColor != null) { LeatherArmorMeta leatherMeta = (LeatherArmorMeta) itemMeta; leatherMeta.setColor(armorColor); } if (isBanner && !patterns.isEmpty()) { BannerMeta bannerMeta = (BannerMeta) itemMeta; bannerMeta.setPatterns(patterns); } if (isShield && !patterns.isEmpty()) { BlockStateMeta shieldMeta = (BlockStateMeta) itemMeta; Banner banner = (Banner) shieldMeta.getBlockState(); banner.setPatterns(patterns); banner.update(); shieldMeta.setBlockState(banner); } if (useCustomModelData) { itemMeta.setCustomModelData(customModelData); } itemFlags.forEach(itemMeta :: addItemFlags); item.setItemMeta(itemMeta); hideFlags(item); item.addUnsafeEnchantments(enchantments); addGlow(item); NBTItem nbt = new NBTItem(item); if (isHead) { if (!isHash && player != null && !player.equals("") && version.isNewer(Version.v1_8_R3)) { nbt.setString("SkullOwner", player); } } if (isMobEgg) { if (entityType != null) { nbt.addCompound("EntityTag").setString("id", "minecraft:" + entityType.name()); } } if (version.isOlder(Version.v1_11_R1)) { if (unbreakable) { nbt.setBoolean("Unbreakable", true); nbt.setInteger("HideFlags", 4); } } if (!crateName.isEmpty()) { nbt.setString("CrazyCrates-Crate", crateName); } return nbt.getItem(); } else { return item; } }
Example #18
Source File: SentinelWeaponHelper.java From Sentinel with MIT License | 4 votes |
/** * 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(); }
Example #19
Source File: PotionHandler.java From BetonQuest with GNU General Public License v3.0 | 4 votes |
public PotionData getBase() { return new PotionData(type, extended, upgraded); }
Example #20
Source File: QuestItem.java From BetonQuest with GNU General Public License v3.0 | 4 votes |
/** * @return the base data of the potion */ public PotionData getBaseEffect() { return potion.getBase(); }
Example #21
Source File: AutoBrewer.java From Slimefun4 with GNU General Public License v3.0 | 4 votes |
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 #22
Source File: PotionUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public static Collection<PotionEffect> effects(PotionData data) { return Potion.getBrewer().getEffects(data.getType(), data.isUpgraded(), data.isExtended()); }
Example #23
Source File: CraftMetaPotion.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public PotionData getBasePotionData() { return type; }
Example #24
Source File: CraftMetaPotion.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public void setBasePotionData(PotionData data) { Validate.notNull(data, "PotionData cannot be null"); this.type = data; }
Example #25
Source File: CraftAreaEffectCloud.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public PotionData getBasePotionData() { return CraftPotionUtil.toBukkit(getHandle().getType()); }
Example #26
Source File: CraftAreaEffectCloud.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public void setBasePotionData(PotionData data) { Validate.notNull(data, "PotionData cannot be null"); getHandle().setType(CraftPotionUtil.fromBukkit(data)); }
Example #27
Source File: CraftTippedArrow.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public PotionData getBasePotionData() { return CraftPotionUtil.toBukkit(getHandle().getType()); }
Example #28
Source File: CraftTippedArrow.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public void setBasePotionData(PotionData data) { Validate.notNull(data, "PotionData cannot be null"); Validate.isTrue(data.getType() != PotionType.UNCRAFTABLE || !getHandle().customPotionEffects.isEmpty(), "Tipped Arrows must have at least 1 effect"); getHandle().setType(CraftPotionUtil.fromBukkit(data)); }
Example #29
Source File: PotionMeta.java From Kettle with GNU General Public License v3.0 | 2 votes |
/** * Returns the potion data about the base potion * * @return a PotionData object */ PotionData getBasePotionData();
Example #30
Source File: PotionMeta.java From Kettle with GNU General Public License v3.0 | 2 votes |
/** * Sets the underlying potion data * * @param data PotionData to set the base potion state to */ void setBasePotionData(PotionData data);