Java Code Examples for org.bukkit.potion.Potion#fromItemStack()

The following examples show how to use org.bukkit.potion.Potion#fromItemStack() . 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: RedProtectUtil.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
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 2
Source File: IndicatorListener.java    From HoloAPI with GNU General Public License v3.0 6 votes vote down vote up
@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 3
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;
}