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

The following examples show how to use org.bukkit.potion.Potion#hasExtendedDuration() . 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: 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;
}