Java Code Examples for org.bukkit.Material#POTION
The following examples show how to use
org.bukkit.Material#POTION .
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: IndicatorListener.java From HoloAPI with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onConsumePotion(PlayerItemConsumeEvent event) { if (Settings.INDICATOR_ENABLE.getValue("potion")) { if (event.getItem().getType() == Material.POTION) { Potion potion = Potion.fromItemStack(event.getItem()); if (potion != null) { this.showPotionHologram(event.getPlayer(), potion.getEffects()); } } else if (event.getItem().getType() == Material.GOLDEN_APPLE) { String msg = Settings.INDICATOR_FORMAT.getValue("potion", "goldenapple"); if (event.getItem().getDurability() == 1) { msg = Settings.INDICATOR_FORMAT.getValue("potion", "godapple"); } Location l = event.getPlayer().getLocation().clone(); l.setY(l.getY() + Settings.INDICATOR_Y_OFFSET.getValue("potion")); HoloAPI.getManager().createSimpleHologram(l, Settings.INDICATOR_TIME_VISIBLE.getValue("potion"), true, msg.replace("%effect%", "Golden Apple")); } } }
Example 2
Source File: BrewingStandContainer.java From Transport-Pipes with MIT License | 6 votes |
@Override public int spaceForItem(TPDirection insertDirection, ItemStack insertion) { if (isInvLocked(cachedBrewingStand)) { return 0; } if (insertion.getType() == Material.POTION || insertion.getType() == Material.SPLASH_POTION || insertion.getType() == Material.LINGERING_POTION) { if (cachedInv.getItem(0) != null && cachedInv.getItem(1) != null && cachedInv.getItem(2) != null) { return 0; } else { return 1; } } else if (insertDirection.isSide() && insertion.getType() == Material.BLAZE_POWDER) { return spaceForItem(cachedInv.getFuel(), insertion); } else if (isBrewingIngredient(insertion.getType())) { return spaceForItem(cachedInv.getIngredient(), insertion); } else { return 0; } }
Example 3
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 4
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 5
Source File: PotionVariable.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
@Override public boolean isValidItem(Player player, ItemStack item) { Material type = item.getType(); if (type != Material.POTION && type != Material.SPLASH_POTION && type != Material.LINGERING_POTION) { player.sendMessage("§cThat must be a must be a potion!"); return false; } return true; }
Example 6
Source File: CraftItemStack.java From Carbon with GNU Lesser General Public License v3.0 | 5 votes |
public static ItemMeta getItemMeta(net.minecraft.server.v1_7_R4.ItemStack item) { if (!hasItemMeta(item)) { return CraftItemFactory.instance().getItemMeta(getType(item)); } Material mat = getType(item); if (mat == Material.WRITTEN_BOOK || mat == Material.BOOK_AND_QUILL) { return new CraftMetaBook(item.tag); } if (mat == Material.SKULL_ITEM) { return new CraftMetaSkull(item.tag); } if (mat == Material.LEATHER_HELMET || mat == Material.LEATHER_CHESTPLATE || mat == Material.LEATHER_LEGGINGS || mat == Material.LEATHER_BOOTS) { return new CraftMetaLeatherArmor(item.tag); } if (mat == Material.POTION) { return new CraftMetaPotion(item.tag); } if (mat == Material.MAP) { return new CraftMetaMap(item.tag); } if (mat == Material.FIREWORK) { return new CraftMetaFirework(item.tag); } if (mat == Material.FIREWORK_CHARGE) { return new CraftMetaCharge(item.tag); } if (mat == Material.ENCHANTED_BOOK) { return new CraftMetaEnchantedBook(item.tag); } if (mat.toString().equals("BANNER")) { return new BannerMeta(item.getData(), item.tag); } return new CraftMetaItem(item.tag); }
Example 7
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 8
Source File: BrewingStandContainer.java From Transport-Pipes with MIT License | 5 votes |
@Override public ItemStack insertItem(TPDirection insertDirection, ItemStack insertion) { if (!isInLoadedChunk()) { return insertion; } if (isInvLocked(cachedBrewingStand)) { return insertion; } if (insertion.getType() == Material.POTION || insertion.getType() == Material.SPLASH_POTION || insertion.getType() == Material.LINGERING_POTION) { if (cachedInv.getItem(0) == null) { cachedInv.setItem(0, insertion); return null; } else if (cachedInv.getItem(1) == null) { cachedInv.setItem(1, insertion); return null; } else if (cachedInv.getItem(2) == null) { cachedInv.setItem(2, insertion); return null; } } else if (insertDirection.isSide() && insertion.getType() == Material.BLAZE_POWDER) { ItemStack oldFuel = cachedInv.getFuel(); cachedInv.setFuel(accumulateItems(oldFuel, insertion)); if (insertion == null || insertion.getAmount() == 0) { insertion = null; } } else if (isBrewingIngredient(insertion.getType())) { ItemStack oldIngredient = cachedInv.getIngredient(); cachedInv.setIngredient(accumulateItems(oldIngredient, insertion)); if (insertion == null || insertion.getAmount() == 0) { insertion = null; } } return insertion; }
Example 9
Source File: CraftItemFactory.java From Carbon with GNU Lesser General Public License v3.0 | 5 votes |
private ItemMeta getItemMeta(Material material, CraftMetaItem meta) { if (material == Material.AIR) { return null; } if (material == Material.WRITTEN_BOOK || material == Material.BOOK_AND_QUILL) { return (meta instanceof CraftMetaBook) ? meta : new CraftMetaBook(meta); } if (material == Material.SKULL_ITEM) { return (meta instanceof CraftMetaSkull) ? meta : new CraftMetaSkull(meta); } if (material == Material.LEATHER_HELMET || material == Material.LEATHER_CHESTPLATE || material == Material.LEATHER_LEGGINGS || material == Material.LEATHER_BOOTS) { return (meta instanceof CraftMetaLeatherArmor) ? meta : new CraftMetaLeatherArmor(meta); } if (material == Material.POTION) { return (meta instanceof CraftMetaPotion) ? meta : new CraftMetaPotion(meta); } if (material == Material.MAP) { return (meta instanceof CraftMetaMap) ? meta : new CraftMetaMap(meta); } if (material == Material.FIREWORK) { return (meta instanceof CraftMetaFirework) ? meta : new CraftMetaFirework(meta); } if (material == Material.FIREWORK_CHARGE) { return (meta instanceof CraftMetaCharge) ? meta : new CraftMetaCharge(meta); } if (material == Material.ENCHANTED_BOOK) { return (meta instanceof CraftMetaEnchantedBook) ? meta : new CraftMetaEnchantedBook(meta); } if (material.toString().equals("BANNER")) { if (meta != null && BannerMeta.class.isAssignableFrom(meta.getClass())) { return meta; } else { return new BannerMeta(meta); } } return new CraftMetaItem(meta); }
Example 10
Source File: ThirstManager.java From Survival-Games with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @EventHandler public void onPlayerDrinkWater(PlayerInteractEvent e) { if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) { if (e.getPlayer().getItemInHand() == new ItemStack(Material.POTION)) { e.getPlayer().getInventory().removeItem(new ItemStack(Material.POTION, 1)); addThirst(e.getPlayer(), 5); e.getPlayer().sendMessage(ChatColor.GREEN + "You drank water."); } } }
Example 11
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 12
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 13
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 14
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 15
Source File: DiscardPotionBottlesMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onDrinkPotion(final PlayerItemConsumeEvent event) { if (event.getItem().getType() == Material.POTION) { event.setReplacement(new ItemStack(Material.AIR)); } }
Example 16
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 17
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 18
Source File: DiscardPotionBottlesMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onDrinkPotion(final PlayerItemConsumeEvent event) { if(event.getItem().getType() == Material.POTION) { event.setReplacement(new ItemStack(Material.AIR)); } }
Example 19
Source File: Potion.java From Kettle with GNU General Public License v3.0 | 4 votes |
public static Potion fromItemStack(ItemStack item) { Validate.notNull(item, "item cannot be null"); if (item.getType() != Material.POTION) throw new IllegalArgumentException("item is not a potion"); return fromDamage(item.getDurability()); }
Example 20
Source File: AutoBrewer.java From Slimefun4 with GNU General Public License v3.0 | 2 votes |
/** * Checks whether a given {@link Material} is a valid Potion material. * * @param mat * The {@link Material} to check * * @return Whether this {@link Material} is a valid potion */ private boolean isPotion(Material mat) { return mat == Material.POTION || mat == Material.SPLASH_POTION || mat == Material.LINGERING_POTION; }