org.bukkit.inventory.meta.PotionMeta Java Examples
The following examples show how to use
org.bukkit.inventory.meta.PotionMeta.
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: LugolsIodinePotion.java From CraftserveRadiation with Apache License 2.0 | 6 votes |
public PotionMeta convert(PotionMeta potionMeta) { Objects.requireNonNull(potionMeta, "potionMeta"); Duration duration = this.config.duration(); String formattedDuration = this.formatDuration(this.config.duration()); if (this.config.color != null) { potionMeta.setColor(this.config.color); } potionMeta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); potionMeta.setDisplayName(ChatColor.AQUA + this.config.name()); potionMeta.setLore(Collections.singletonList(ChatColor.BLUE + MessageFormat.format(this.config.description(), formattedDuration))); PersistentDataContainer container = potionMeta.getPersistentDataContainer(); container.set(this.potionKey, PersistentDataType.BYTE, TRUE); container.set(this.durationSecondsKey, PersistentDataType.INTEGER, (int) duration.getSeconds()); return potionMeta; }
Example #2
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 #3
Source File: ItemModifyModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@Override public @Nullable ItemModifyModule parse(MapFactory factory, Logger logger, Document doc) throws InvalidXMLException { List<ItemRule> rules = new ArrayList<>(); for (Element elRule : XMLUtils.flattenElements(doc.getRootElement(), "item-mods", "rule")) { MaterialMatcher items = XMLUtils.parseMaterialMatcher(XMLUtils.getRequiredUniqueChild(elRule, "match")); // Always use a PotionMeta so the rule can have potion effects, though it will only apply // those to potion items PotionMeta meta = (PotionMeta) Bukkit.getItemFactory().getItemMeta(Material.POTION); factory.getKits().parseItemMeta(XMLUtils.getRequiredUniqueChild(elRule, "modify"), meta); ItemRule rule = new ItemRule(items, meta); rules.add(rule); } return rules.isEmpty() ? null : new ItemModifyModule(rules); }
Example #4
Source File: PlayerListener.java From WorldGuardExtraFlagsPlugin with MIT License | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event) { Player player = event.getPlayer(); ItemMeta itemMeta = event.getItem().getItemMeta(); if (itemMeta instanceof PotionMeta) { this.plugin.getWorldGuardCommunicator().getSessionManager().get(player).getHandler(GiveEffectsFlagHandler.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects()); } else { Material material = event.getItem().getType(); if (material == Material.MILK_BUCKET) { this.plugin.getWorldGuardCommunicator().getSessionManager().get(player).getHandler(GiveEffectsFlagHandler.class).drinkMilk(player); } } }
Example #5
Source File: RedProtectUtil.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public boolean denyPotion(ItemStack result, Player p) { List<String> Pots = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_potions; if (result != null && Pots.size() > 0 && (result.getType().name().contains("POTION") || result.getType().name().contains("TIPPED"))) { String potname = ""; if (RedProtect.get().bukkitVersion >= 190) { PotionMeta pot = (PotionMeta) result.getItemMeta(); potname = pot.getBasePotionData().getType().name(); } if (RedProtect.get().bukkitVersion <= 180 && Potion.fromItemStack(result) != null) { potname = Potion.fromItemStack(result).getType().name(); } if (Pots.contains(potname)) { RedProtect.get().lang.sendMessage(p, "playerlistener.denypotion"); return true; } } return false; }
Example #6
Source File: ChildrenLeftUnattended.java From UhcCore with GNU General Public License v3.0 | 6 votes |
private void giveTeamReward(Player player){ Wolf wolf = (Wolf) player.getWorld().spawnEntity(player.getLocation(), EntityType.WOLF); wolf.setTamed(true); wolf.setOwner(player); wolf.setAdult(); ItemStack potion = new ItemStack(Material.POTION); PotionMeta meta = (PotionMeta) potion.getItemMeta(); meta.setMainEffect(PotionEffectType.SPEED); PotionEffect potionEffect = new PotionEffect(PotionEffectType.SPEED, 8*60*20, 0); meta.addCustomEffect(potionEffect, true); meta.setDisplayName(ChatColor.WHITE + "Potion of Swiftness"); potion.setItemMeta(meta); player.getWorld().dropItem(player.getLocation(), potion); }
Example #7
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 #8
Source File: ItemModifyModule.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@Override public @Nullable ItemModifyModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException { List<ItemRule> rules = new ArrayList<>(); for(Element elRule : XMLUtils.flattenElements(doc.getRootElement(), "item-mods", "rule")) { MaterialMatcher items = XMLUtils.parseMaterialMatcher(XMLUtils.getRequiredUniqueChild(elRule, "match")); // Always use a PotionMeta so the rule can have potion effects, though it will only apply those to potion items final Element elModify = XMLUtils.getRequiredUniqueChild(elRule, "modify"); final PotionMeta meta = (PotionMeta) Bukkit.getItemFactory().getItemMeta(Material.POTION); context.needModule(ItemParser.class).parseItemMeta(elModify, meta); final boolean defaultAttributes = XMLUtils.parseBoolean(elModify.getAttribute("default-attributes"), false); ItemRule rule = new ItemRule(items, meta, defaultAttributes); rules.add(rule); } return rules.isEmpty() ? null : new ItemModifyModule(rules); }
Example #9
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 #10
Source File: VersionUtils_1_12.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public Color getPotionColor(PotionMeta potionMeta){ if (potionMeta.hasColor()){ return potionMeta.getColor(); } return null; }
Example #11
Source File: JsonItemUtils.java From UhcCore with GNU General Public License v3.0 | 5 votes |
private static ItemMeta parseCustomPotionEffects(ItemMeta meta, JsonArray jsonArray) throws ParseException{ if (meta instanceof PotionMeta){ PotionMeta potionMeta = (PotionMeta) meta; for (JsonElement jsonElement : jsonArray){ JsonObject effect = jsonElement.getAsJsonObject(); potionMeta.addCustomEffect(parsePotionEffect(effect), true); } return potionMeta; }else{ return VersionUtils.getVersionUtils().applySuspiciousStewEffects(meta, jsonArray); } }
Example #12
Source File: JsonItemUtils.java From UhcCore with GNU General Public License v3.0 | 5 votes |
private static ItemMeta parseColor(ItemMeta meta, int color){ if (meta instanceof PotionMeta){ PotionMeta potionMeta = (PotionMeta) meta; VersionUtils.getVersionUtils().setPotionColor(potionMeta, Color.fromRGB(color)); return potionMeta; }else if (meta instanceof LeatherArmorMeta){ LeatherArmorMeta leatherMeta = (LeatherArmorMeta) meta; leatherMeta.setColor(Color.fromBGR(color)); return leatherMeta; } return meta; }
Example #13
Source File: CustomPotion.java From CS-CoreLib with GNU General Public License v3.0 | 5 votes |
@Deprecated public CustomPotion(String name, int durability, String[] lore, PotionEffect effect) { super(Material.POTION, name, (ReflectionUtils.getVersion().startsWith("v1_8_")) ? durability: 0, lore); PotionMeta meta = (PotionMeta) getItemMeta(); if (ReflectionUtils.getVersion().startsWith("v1_8_")) meta.setMainEffect(PotionEffectType.SATURATION); else meta.setMainEffect(effect.getType()); meta.addCustomEffect(effect, true); setItemMeta(meta); }
Example #14
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 #15
Source File: CustomPotion.java From CS-CoreLib with GNU General Public License v3.0 | 5 votes |
public CustomPotion(String name, Color color, PotionEffect effect, String... lore) { super(Material.POTION, name, lore); PotionMeta meta = (PotionMeta) getItemMeta(); meta.setColor(color); meta.addCustomEffect(effect, true); setItemMeta(meta); }
Example #16
Source File: ItemStackParser.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") private void parsePotionEffects() { PotionMeta customPotionMeta = (PotionMeta) this.finalStack.getItemMeta(); for (Object potionEffect : (List<Object>) this.linkedSection.get("effects")) { LinkedHashMap<String, Object> potionEffectSection = (LinkedHashMap<String, Object>) potionEffect; if (!potionEffectSection.containsKey("type")) { continue; } PotionEffectType potionEffectType = null; int duration = 1; int amplifier = 0; potionEffectType = PotionEffectType.getByName(potionEffectSection.get("type").toString().toUpperCase()); if (potionEffectSection.containsKey("duration")) { duration = Integer.parseInt(potionEffectSection.get("duration").toString()) * 20; } if (potionEffectSection.containsKey("amplifier")) { amplifier = Integer.parseInt(potionEffectSection.get("amplifier").toString()) - 1; } if (potionEffectType == null) { continue; } customPotionMeta.addCustomEffect(new PotionEffect(potionEffectType, duration, amplifier), true); } this.finalStack.setItemMeta(customPotionMeta); }
Example #17
Source File: NewItemShop.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
private VillagerTrade getTradingItem(MerchantCategory category, ItemStack stack, Game game, Player player) { for (VillagerTrade trade : category.getOffers()) { if (trade.getItem1().getType() == Material.AIR && trade.getRewardItem().getType() == Material.AIR) { continue; } ItemStack iStack = this.toItemStack(trade, player, game); if (iStack.getType() == Material.ENDER_CHEST && stack.getType() == Material.ENDER_CHEST) { return trade; } else if ((iStack.getType() == Material.POTION || (!BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8") && (iStack.getType().equals(Material.valueOf("TIPPED_ARROW")) || iStack.getType().equals(Material.valueOf("LINGERING_POTION")) || iStack.getType().equals(Material.valueOf("SPLASH_POTION")))))) { if (BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")) { if (iStack.getItemMeta().equals(stack.getItemMeta())) { return trade; } } else { PotionMeta iStackMeta = (PotionMeta) iStack.getItemMeta(); PotionMeta stackMeta = (PotionMeta) stack.getItemMeta(); if (iStackMeta.getBasePotionData().equals(stackMeta.getBasePotionData()) && iStackMeta .getCustomEffects().equals(stackMeta.getCustomEffects())) { return trade; } } } else if (iStack.equals(stack)) { return trade; } } return null; }
Example #18
Source File: RedProtectUtil.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public boolean denyPotion(ItemStack result, World world) { List<String> Pots = RedProtect.get().config.globalFlagsRoot().worlds.get(world.getName()).deny_potions; if (result != null && Pots.size() > 0 && (result.getType().name().contains("POTION") || result.getType().name().contains("TIPPED"))) { String potname = ""; if (RedProtect.get().bukkitVersion >= 190) { PotionMeta pot = (PotionMeta) result.getItemMeta(); potname = pot.getBasePotionData().getType().name(); } if (RedProtect.get().bukkitVersion < 190) { potname = Potion.fromItemStack(result).getType().name(); } return Pots.contains(potname); } return false; }
Example #19
Source File: ItemUtils.java From ShopChest with MIT License | 5 votes |
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 #20
Source File: ItemUtils.java From ShopChest with MIT License | 5 votes |
public static boolean isExtendedPotion(ItemStack itemStack) { if (itemStack.getItemMeta() instanceof PotionMeta) { if (Utils.getMajorVersion() < 9) { return Potion.fromItemStack(itemStack).hasExtendedDuration(); } else { return ((PotionMeta) itemStack.getItemMeta()).getBasePotionData().isExtended(); } } return false; }
Example #21
Source File: SlimefunItemStack.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
public SlimefunItemStack(String id, Color color, PotionEffect effect, String name, String... lore) { super(Material.POTION, im -> { if (name != null) { im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); } if (lore.length > 0) { List<String> lines = new ArrayList<>(); for (String line : lore) { lines.add(ChatColor.translateAlternateColorCodes('&', line)); } im.setLore(lines); } if (im instanceof PotionMeta) { ((PotionMeta) im).setColor(color); ((PotionMeta) im).addCustomEffect(effect, true); if (effect.getType().equals(PotionEffectType.SATURATION)) { im.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); } } }); setItemId(id); }
Example #22
Source File: SlimefunItemConsumeListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onConsume(PlayerItemConsumeEvent e) { Player p = e.getPlayer(); ItemStack item = e.getItem(); SlimefunItem sfItem = SlimefunItem.getByItem(item); if (sfItem != null) { if (Slimefun.hasUnlocked(p, sfItem, true)) { if (sfItem instanceof Juice) { // Fix for Saturation on potions is no longer working for (PotionEffect effect : ((PotionMeta) item.getItemMeta()).getCustomEffects()) { if (effect.getType().equals(PotionEffectType.SATURATION)) { p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, effect.getDuration(), effect.getAmplifier())); break; } } removeGlassBottle(p, item); } else { sfItem.callItemHandler(ItemConsumptionHandler.class, handler -> handler.onConsume(e, p, item)); } } else { e.setCancelled(true); } } }
Example #23
Source File: CoolerListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private boolean consumeJuice(Player p, PlayerBackpack backpack) { Inventory inv = backpack.getInventory(); int slot = -1; for (int i = 0; i < inv.getSize(); i++) { ItemStack stack = inv.getItem(i); if (stack != null && stack.getType() == Material.POTION && stack.hasItemMeta() && stack.getItemMeta().hasDisplayName()) { slot = i; break; } } if (slot >= 0) { PotionMeta im = (PotionMeta) inv.getItem(slot).getItemMeta(); for (PotionEffect effect : im.getCustomEffects()) { p.addPotionEffect(effect); } p.setSaturation(6F); p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_DRINK, 1F, 1F); inv.setItem(slot, null); backpack.markDirty(); return true; } return false; }
Example #24
Source File: AutoBrewer.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private MachineRecipe findRecipe(BlockMenu menu) { ItemStack input1 = menu.getItemInSlot(getInputSlots()[0]); ItemStack input2 = menu.getItemInSlot(getInputSlots()[1]); if (input1 == null || input2 == null) { return null; } if (isPotion(input1.getType()) || isPotion(input2.getType())) { boolean slot = isPotion(input1.getType()); ItemStack ingredient = slot ? input2 : input1; // Reject any named items if (ingredient.hasItemMeta()) { return null; } ItemStack potionItem = slot ? input1 : input2; PotionMeta potion = (PotionMeta) potionItem.getItemMeta(); ItemStack output = brew(ingredient.getType(), potionItem.getType(), potion); if (output == null) { return null; } output.setItemMeta(potion); return new MachineRecipe(30, new ItemStack[] { input1, input2 }, new ItemStack[] { output }); } else { return null; } }
Example #25
Source File: VersionUtils_1_13.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public Color getPotionColor(PotionMeta potionMeta){ if (potionMeta.hasColor()){ return potionMeta.getColor(); } return null; }
Example #26
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 #27
Source File: Potion.java From Kettle with GNU General Public License v3.0 | 5 votes |
/** * Converts this potion to an {@link ItemStack} with the specified amount * and a correct damage value. * * @param amount The amount of the ItemStack * @return The created ItemStack */ public ItemStack toItemStack(int amount) { Material material; if (isSplash()) { material = Material.SPLASH_POTION; } else { material = Material.POTION; } ItemStack itemStack = new ItemStack(material, amount); PotionMeta meta = (PotionMeta) itemStack.getItemMeta(); meta.setBasePotionData(new PotionData(type, level == 2, extended)); itemStack.setItemMeta(meta); return itemStack; }
Example #28
Source File: Potion.java From Kettle with GNU General Public License v3.0 | 5 votes |
/** * Applies the effects of this potion to the given {@link ItemStack}. The * ItemStack must be a potion. * * @param to The itemstack to apply to */ public void apply(ItemStack to) { Validate.notNull(to, "itemstack cannot be null"); Validate.isTrue(to.hasItemMeta(), "given itemstack is not a potion"); Validate.isTrue(to.getItemMeta() instanceof PotionMeta, "given itemstack is not a potion"); PotionMeta meta = (PotionMeta) to.getItemMeta(); meta.setBasePotionData(new PotionData(type, extended, level == 2)); to.setItemMeta(meta); }
Example #29
Source File: InventoryUtils.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public static Collection<PotionEffect> getEffects(ItemStack potion) { if (potion.getItemMeta() instanceof PotionMeta) { PotionMeta meta = (PotionMeta) potion.getItemMeta(); if (meta.hasCustomEffects()) { return meta.getCustomEffects(); } else { return Potion.fromItemStack(potion).getEffects(); } } else { return Collections.emptyList(); } }
Example #30
Source File: PotionClassifier.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public static double getScore(ThrownPotion potion) { double score = 0; for (PotionEffect effect : Iterables.concat( potion.getEffects(), ((PotionMeta) potion.getItem().getItemMeta()).getCustomEffects())) { score += getScore(effect); } return score; }