Java 类org.bukkit.potion.Potion 实例源码

项目:Banmanager    文件:ItemBuilder.java   
public ItemBuilder setMainPotionEffect(PotionType type, boolean extendedDurability, int level, boolean splash) {
    if (! (meta instanceof PotionMeta))
        return this;

    Potion potion = Potion.fromItemStack(stack);
    potion.setType(type);

    if (! type.isInstant())
        potion.setHasExtendedDuration(extendedDurability);

    potion.setLevel(level);
    potion.setSplash(splash);

    potion.apply(stack);

    return this;
}
项目:WorldGuardExtraFlagsPlugin    文件:PlayerListener.java   
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event)
{
    Player player = event.getPlayer();

    if (!WorldGuardUtils.hasBypass(player))
    {
        ItemMeta itemMeta = event.getItem().getItemMeta();
        if (itemMeta instanceof PotionMeta)
        {
            WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects());
        }
        else
        {
            Material material = event.getItem().getType();
            if (material == Material.MILK_BUCKET)
            {
                WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkMilk(player);
            }
        }
    }
}
项目:Banmanager    文件:ItemBuilder.java   
public ItemBuilder setMainPotionEffect(PotionType type, boolean extendedDurability, int level, boolean splash) {
    if (! (meta instanceof PotionMeta))
        return this;

    Potion potion = Potion.fromItemStack(stack);
    potion.setType(type);

    if (! type.isInstant())
        potion.setHasExtendedDuration(extendedDurability);

    potion.setLevel(level);
    potion.setSplash(splash);

    potion.apply(stack);

    return this;
}
项目:LuckyBlocksBukkit    文件:LuckyBlocksActionController.java   
public void LuckyPotion(BlockBreakEvent event){
    Location loc = event.getBlock().getLocation();
    World world = loc.getWorld();
    ItemStack energyPotion = new ItemStack(Material.POTION, 1);
    PotionMeta energyPotionMeta = (PotionMeta) energyPotion.getItemMeta();
    energyPotionMeta.setDisplayName("§6Lucky Potion");
    List<String> lore = new ArrayList<String>();
    lore.add("§6"+ LuckyBlocksMainController.instance.language.getString("POTION_DURATION"));
    energyPotionMeta.setLore(lore);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.SPEED, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.ABSORPTION, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.HEAL, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.JUMP, 20*60, 3), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 20*60, 3), true);
    energyPotion.setItemMeta(energyPotionMeta);
    Potion po = new Potion((byte) 8258);
    po.apply(energyPotion);
    world.dropItemNaturally(loc,energyPotion);
}
项目:LuckyBlocksBukkit    文件:LuckyBlocksActionController.java   
public void LuckyPotion(BlockBreakEvent event){
    Location loc = event.getBlock().getLocation();
    World world = loc.getWorld();
    ItemStack energyPotion = new ItemStack(Material.POTION, 1);
    PotionMeta energyPotionMeta = (PotionMeta) energyPotion.getItemMeta();
    energyPotionMeta.setDisplayName("§6Lucky Potion");
    List<String> lore = new ArrayList<String>();
    lore.add("§6"+ LuckyBlocksMainController.instance.language.getString("POTION_DURATION"));
    energyPotionMeta.setLore(lore);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.SPEED, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.ABSORPTION, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.HEAL, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20*60, 1), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.JUMP, 20*60, 3), true);
    energyPotionMeta.addCustomEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 20*60, 3), true);
    energyPotion.setItemMeta(energyPotionMeta);
    Potion po = new Potion((byte) 8258);
    po.apply(energyPotion);
    world.dropItemNaturally(loc,energyPotion);
}
项目:RedProtect    文件:RPUtil.java   
public static boolean denyPotion(ItemStack result, Player p){
    List<String> Pots = RPConfig.getStringList("server-protection.deny-potions");
    if (result != null && Pots.size() > 0 && (result.getType().name().contains("POTION") || result.getType().name().contains("TIPPED"))){
        String potname = "";
        if (RedProtect.get().version >= 190){
            PotionMeta pot = (PotionMeta) result.getItemMeta();
            potname = pot.getBasePotionData().getType().name();
        }
        if (RedProtect.get().version <= 180 && Potion.fromItemStack(result) != null){
            potname = Potion.fromItemStack(result).getType().name();
        }           
        if (Pots.contains(potname)){                
            RPLang.sendMessage(p, "playerlistener.denypotion");
            return true;
        }                       
    }
    return false;
}
项目:HoloAPI    文件:IndicatorListener.java   
@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"));
        }
    }
}
项目:NucleusFramework    文件:PotionConverter.java   
@Nullable
@Override
protected Potion onConvert(@Nullable Object value) {

    if (value instanceof String) {
        value = TextUtils.parseShort((String) value, Short.MIN_VALUE);
        if (value == new Short(Short.MIN_VALUE))
            return null;
    }
    else if (value instanceof Number) {
        value = ((Number)value).shortValue();
    }

    if (value instanceof Short) {
        return new Potion((Short) value);
    }

    return null;
}
项目:AntiPotionField    文件:PlayerEventRegionsHandler.java   
/**
 * Checks to see if the player is attempting to drink a potion, and checks
 * the potion to see if it is allowed.
 *
 * @param event The PlayerItemConsumeEvent involving the player.
 */
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerConsume(PlayerItemConsumeEvent event) {
    if (event.getItem().getType() != Material.POTION) {
        return;
    }
    // Check the type of potion in the player's hand
    Potion potion = Potion.fromItemStack(event.getItem());
    Collection<PotionEffect> effects = potion.getEffects();

    for (PotionEffect e : effects) {
        if (!(Util.canUsePotion(event.getPlayer(), e.getType()))) {
            // If we get here, we cancel this event and all is done.
            event.setCancelled(true);
            event.getPlayer().sendMessage(ChatColor.RED + "You cannot use that potion here!");
            Util.removeDisallowedEffects(event.getPlayer());
            return; // We don't need to check any more.
        }
    }
}
项目:BKgLib    文件:NBTUtils.java   
public static NBTTagList potionToNBTEffectsList(ItemStack potion) {
    NBTTagCompound tag = getItemStackTag(potion);
    if (tag.hasKey("CustomPotionEffects")) {
        return tag.getList("CustomPotionEffects").clone();
    }
    // Fallback to default potion effect.
    Collection<PotionEffect> effects = Potion.fromItemStack(potion).getEffects();
    NBTTagList effectList = new NBTTagList();
    for (PotionEffect effect : effects) {
        NBTTagCompound effectTag = new NBTTagCompound();
        effectTag.setByte("Id", (byte)effect.getType().getId());
        effectTag.setByte("Amplifier", (byte)effect.getAmplifier());
        effectTag.setInt("Duration", effect.getDuration());
        effectList.add(effectTag);
    }
    return effectList;
}
项目:Warzone    文件:ItemFactory.java   
public static ItemStack createPotion(PotionType potionType, int level, String name) {
    Potion potion = new Potion(potionType);
    potion.setLevel(level);

    ItemStack itemStack = potion.toItemStack(1);
    ItemMeta meta = itemStack.getItemMeta();
    meta.setDisplayName(name);
    itemStack.setItemMeta(meta);

    return itemStack;
}
项目:ProjectAres    文件:GlobalItemParser.java   
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;
}
项目:ProjectAres    文件:PotionClassificationTest.java   
@Before
public void setUp() {
    CraftBukkitRuntime.load();
    if(Potion.getBrewer() == null) {
        Potion.setPotionBrewer(new CraftPotionBrewer());
    }
}
项目:SurvivalAPI    文件:DropMyEffectsModule.java   
/**
 * Drop player's potion effect on his death
 *
 * @param event Event
 */
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event)
{
    for (PotionEffect potionEffect : event.getEntity().getActivePotionEffects())
    {
        if (this.blacklist.contains(potionEffect.getType()))
            continue;

        if (PotionType.getByEffect(potionEffect.getType()) == null)
            continue;

        if(potionEffect.getDuration() > 10000)
            continue;

        Potion potion = new Potion(PotionType.getByEffect(potionEffect.getType()), potionEffect.getAmplifier() + 1);
        ItemStack stack = potion.toItemStack(1);

        PotionMeta meta = (PotionMeta) stack.getItemMeta();
        meta.clearCustomEffects();
        meta.addCustomEffect(new PotionEffect(potionEffect.getType(), potionEffect.getDuration(), potionEffect.getAmplifier()), true);

        stack.setItemMeta(meta);

        event.getDrops().add(stack);
        event.getEntity().removePotionEffect(potionEffect.getType());
    }
}
项目:HCFCore    文件:PotionLimitListener.java   
private boolean testValidity(ItemStack[] contents) {
    for (ItemStack stack : contents) {
        if (stack != null && stack.getType() == Material.POTION && stack.getDurability() != 0) {
            Potion potion = Potion.fromItemStack(stack);

            // Just to be safe, null check this.
            if (potion == null)
                continue;

            PotionType type = potion.getType();

            // Mundane potions etc, can return a null type
            if (type == null)
                continue;

            // is 33s poison, allow
            if (type == PotionType.POISON && !potion.hasExtendedDuration() && potion.getLevel() == 1) {
                continue;
            }

            if (potion.getLevel() > getMaxLevel(type)) {
                return false;
            }
        }
    }
    return true;
}
项目:HCFCore    文件:PotionLimitListener.java   
private boolean testValidity(ItemStack[] contents) {
    for (ItemStack stack : contents) {
        if (stack != null && stack.getType() == Material.POTION && stack.getDurability() != 0) {
            Potion potion = Potion.fromItemStack(stack);

            // Just to be safe, null check this.
            if (potion == null)
                continue;

            PotionType type = potion.getType();

            // Mundane potions etc, can return a null type
            if (type == null)
                continue;

            // is 33s poison, allow
            if (type == PotionType.POISON && !potion.hasExtendedDuration() && potion.getLevel() == 1) {
                continue;
            }

            if (potion.getLevel() > getMaxLevel(type)) {
                return false;
            }
        }
    }
    return true;
}
项目:DoubleRunner    文件:DoubleRunnerGameLoop.java   
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
    if (event.getItem() != null && event.getItem().getType() == Material.POTION && Potion.fromItemStack(event.getItem()).getType() == PotionType.POISON && !this.game.isPvPActivated())
    {
        event.getPlayer().sendMessage(ChatColor.RED + "Vous ne pouvez pas utiliser cet objet hors du PvP.");

        event.setCancelled(true);
        event.getPlayer().updateInventory();
    }
}
项目:Skript    文件:PotionEffectUtils.java   
public static short guessData(final ThrownPotion p) {
    if (p.getEffects().size() == 1) {
        final PotionEffect e = p.getEffects().iterator().next();
        final Potion d = new Potion(PotionType.getByEffect(e.getType())).splash();
        return d.toDamageValue();
    }
    return 0;
}
项目:RedProtect    文件:RPUtil.java   
public static boolean denyPotion(ItemStack result){
    List<String> Pots = RPConfig.getStringList("server-protection.deny-potions");
    if (result != null && Pots.size() > 0 && (result.getType().name().contains("POTION") || result.getType().name().contains("TIPPED"))){
        String potname = "";
        if (RedProtect.get().version >= 190){
            PotionMeta pot = (PotionMeta) result.getItemMeta();
            potname = pot.getBasePotionData().getType().name();
        }
        if (RedProtect.get().version < 190 && Potion.fromItemStack(result) != null && Potion.fromItemStack(result).getType() != null){
            potname = Potion.fromItemStack(result).getType().name();
        }
return Pots.contains(potname);
    }
    return false;
 }
项目:ShopChest    文件:ItemUtils.java   
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;
}
项目:ShopChest    文件:ItemUtils.java   
public static boolean isExtendedPotion(ItemStack itemStack) {
    if (itemStack.getItemMeta() instanceof PotionMeta) {
        if (Utils.getMajorVersion() >= 9) {
            PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
            return potionMeta.getBasePotionData().isExtended();
        } else {
            Potion potion = Potion.fromItemStack(itemStack);
            return potion.hasExtendedDuration();
        }
    }

    return false;
}
项目:ShopChest    文件:LanguageUtils.java   
/**
 * @param itemStack Potion Item whose base effect name should be looked up
 * @return Localized Name of the Base Potion Effect
 */
public static String getPotionEffectName(ItemStack itemStack) {
    if (itemStack == null) return null;
    if (!(itemStack.getItemMeta() instanceof PotionMeta)) return "";

    PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
    PotionType potionType;
    boolean upgraded;

    if (Utils.getMajorVersion() < 9) {
        potionType = Potion.fromItemStack(itemStack).getType();
        upgraded = Potion.fromItemStack(itemStack).getLevel() == 2;
    } else {
        potionType = potionMeta.getBasePotionData().getType();
        upgraded = potionMeta.getBasePotionData().isUpgraded();
    }

    String potionEffectString = formatDefaultString(potionType.toString());
    String upgradeString = upgraded ? "II" : "";

    for (PotionEffectName potionEffectName : potionEffectNames) {
        if (potionEffectName.getEffect() == potionType) {
            potionEffectString = potionEffectName.getLocalizedName();
        }
    }

    return potionEffectString + (upgradeString.length() > 0 ? " " + upgradeString : "");
}
项目:MiniMiniGames    文件:PotionBuilder.java   
public Potion build() {
   Potion potion = new Potion(type);
   potion.setLevel(this.level);
   if(potion.isSplash()) {
      potion.setHasExtendedDuration(this.extended);
   }
   return potion;
}
项目:MiniMiniGames    文件:ItemBuilder.java   
public ItemBuilder setPotion(Potion potion) {
   if (this.mat != Material.POTION) {
      this.mat = Material.POTION;
   }
   this.potion = potion;
   return this;
}
项目:defend-the-village    文件:GemShop.java   
public ItemStack createPotion(PotionType poti, String nombre, Integer valor) {
    ItemStack poti2 = new Potion(poti).splash().toItemStack(3);
    ItemMeta meta = (ItemMeta) poti2.getItemMeta();
    ArrayList<String> lore = new ArrayList<String>();
    lore.add("" + valor + " gemas.");
    meta.setLore(lore);
    meta.setDisplayName(nombre);
    poti2.setItemMeta(meta);

    return poti2;
}
项目:BGDCore    文件:ItemBuilder.java   
/**
 * Sets the potion.
 *
 * @param potion the potion
 * @return the item builder
 */
public ItemBuilder setPotion(Potion potion) {
    if (this.type != Material.POTION) {
        this.type = Material.POTION;
    }
    this.potion = potion;
    return this;
}
项目:McMMOPlus    文件:FishingManager.java   
private void handleTraps() {
    Player player = getPlayer();

    if (Permissions.trapsBypass(player)) {
        return;
    }

    if (Misc.getRandom().nextBoolean()) {
        player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.Boom"));

        TNTPrimed tnt = (TNTPrimed) player.getWorld().spawnEntity(fishingCatch.getLocation(), EntityType.PRIMED_TNT);
        fishingCatch.setPassenger(tnt);

        Vector velocity = fishingCatch.getVelocity();
        double magnitude = velocity.length();
        fishingCatch.setVelocity(velocity.multiply((magnitude + 1) / magnitude));

        tnt.setMetadata(mcMMO.tntsafeMetadataKey, mcMMO.metadataValue);
        tnt.setFuseTicks(3 * Misc.TICK_CONVERSION_FACTOR);
    }
    else {
        player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.Poison"));

        ThrownPotion thrownPotion = player.getWorld().spawn(fishingCatch.getLocation(), ThrownPotion.class);
        thrownPotion.setItem(new Potion(PotionType.POISON).splash().toItemStack(1));

        fishingCatch.setPassenger(thrownPotion);
    }
}
项目:NucleusFramework    文件:PotionNames.java   
/**
 * Get a full potion name including characteristics.
 *
 * @param potion  The potion ID.
 */
public static String getFull(Potion potion) {
    PreCon.notNull(potion);

    int potionId = _handler.getPotionId(
            potion.getType(), potion.getLevel(), potion.isSplash(), potion.hasExtendedDuration());

    return getFull(potionId);
}
项目:NucleusFramework    文件:PotionUtils.java   
/**
 * Get {@link Potion} for the result of the specified potion recipe.
 *
 * @param ingredient  The potion ingredient.
 * @param bottle      The potion target.
 *
 * @return  The potion or null if not a valid recipe.
 */
@Nullable
public static Potion getPotionFromRecipe(ItemStack ingredient, ItemStack bottle) {
    int potionId = getPotionIdFromRecipe(ingredient, bottle);
    if (potionId == -1)
        return null;

    return new Potion(potionId);
}
项目:NucleusFramework    文件:ItemStackUtils.java   
/**
 * Gets the display name of an {@link ItemStack}. Returns empty string if
 * the item has no display name.
 *
 * @param stack       The {@link ItemStack} to get a display name from.
 * @param nameResult  Specify how a missing display name should be returned.
 */
@Nullable
public static String getDisplayName(ItemStack stack, DisplayNameOption nameResult) {
    PreCon.notNull(stack);

    ItemMeta meta = stack.getItemMeta();
    if (meta == null || !meta.hasDisplayName()) {

        switch (nameResult) {
            case REQUIRED:

                if (meta instanceof PotionMeta) {
                    Potion potion = new Potion(stack.getDurability());
                    return PotionNames.getSimple(potion);
                }

                String materialName = NamedMaterialData.getAlternate(stack.getData());
                if (materialName == null) {
                    materialName = stack.getType().name().toLowerCase();
                }

                String spaced = PATTERN_REPLACE_UNDERSCORE.matcher(materialName).replaceAll(" ");
                return TextUtils.titleCase(spaced);

            case OPTIONAL:
                // fall through

            default:
                return null;
        }
    }

    return meta.getDisplayName();
}
项目:Wayward    文件:ItemSkill.java   
public boolean use(Fight fight, Character attacking, Character defending, ItemStack weapon) {
    Player attackingPlayer = attacking.getPlayer().getPlayer();
    Player defendingPlayer = defending.getPlayer().getPlayer();
    if (weapon.getType().isEdible() || weapon.getType() == Material.POTION) {
        switch (weapon.getType()) {
            case GOLDEN_APPLE:
                attackingPlayer.getInventory().removeItem(weapon);
                defending.setHealth(Math.min(defending.getHealth() + 10, defending.getMaxHealth()));
                defendingPlayer.setHealth(defending.getHealth());
                fight.sendMessage(ChatColor.YELLOW + (attacking.isNameHidden() ? ChatColor.MAGIC + attacking.getName() + ChatColor.RESET : attacking.getName()) + ChatColor.YELLOW + " fed " + (defending.isNameHidden() ? ChatColor.MAGIC + defending.getName() + ChatColor.RESET : defending.getName()) + ChatColor.YELLOW + " a golden carrot, healing 5 HP.");
                return true;
            case POTION:
                if (weapon.hasItemMeta()) {
                    if (weapon.getItemMeta().hasDisplayName()) {
                        if (weapon.getItemMeta().getDisplayName().equalsIgnoreCase("Masheek")) {
                            attackingPlayer.getInventory().removeItem(weapon);
                            defending.setMana(Math.min(defending.getMana() + 5, defending.getMaxMana()));
                            fight.sendMessage(ChatColor.YELLOW + (attacking.isNameHidden() ? ChatColor.MAGIC + attacking.getName() + ChatColor.RESET : attacking.getName()) + ChatColor.YELLOW + " used a bottle of Masheek on " + (defending.isNameHidden() ? ChatColor.MAGIC + defending.getName() + ChatColor.RESET : defending.getName()) + ChatColor.YELLOW + ", replenishing 5 mana.");
                            return true;
                        }
                    }
                }
                attackingPlayer.getInventory().removeItem(weapon);
                Potion potion = Potion.fromItemStack(weapon);
                potion.apply(defendingPlayer);
                fight.sendMessage(ChatColor.YELLOW + (attacking.isNameHidden() ? ChatColor.MAGIC + attacking.getName() + ChatColor.RESET : attacking.getName()) + ChatColor.YELLOW + " used a potion on " + (defending.isNameHidden() ? ChatColor.MAGIC + defending.getName() + ChatColor.RESET : defending.getName()));
                return true;
            default:
                fight.sendMessage(ChatColor.YELLOW + (attacking.isNameHidden() ? ChatColor.MAGIC + attacking.getName() + ChatColor.RESET : attacking.getName()) + ChatColor.YELLOW + " fed something to " + (defending.isNameHidden() ? ChatColor.MAGIC + defending.getName() + ChatColor.RESET : defending.getName()) + ChatColor.YELLOW + " but it had no effect.");
                return true;
        }
    } else {
        fight.sendMessage(ChatColor.YELLOW + (attacking.isNameHidden() ? ChatColor.MAGIC + attacking.getName() + ChatColor.RESET : attacking.getName()) + ChatColor.YELLOW + " attempted to use a " + weapon.getType().toString().toLowerCase().replace('_', ' ') + " on " + (defending.isNameHidden() ? ChatColor.MAGIC + defending.getName() + ChatColor.RESET : defending.getName()) + ChatColor.YELLOW + " but it didn't seem to do anything.");
        return true;
    }
}
项目:TerraCraftTools    文件:NoInvisibilityPotions.java   
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.hasItem() && !event.getPlayer().isOp()
            && (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
            || event.getAction().equals(Action.RIGHT_CLICK_AIR))) {
        if (event.getItem().getType().equals(Material.POTION)) {
            for (PotionEffect pe : Potion.getBrewer().getEffectsFromDamage((int) event.getItem().getDurability())) {
                if (pe.getType().equals(PotionEffectType.INVISIBILITY)) {
                    event.setCancelled(true);
                    event.getPlayer().sendMessage(ChatColor.DARK_RED + "You cannot use invisibility potions.");
                }
            }
        }
    }
}
项目:ZvP    文件:PotionLayer.java   
/**
    * This parses an Potion into an instance of PotionLayer. This lets you get the potion type, if the potion is strong, if the potion is long, if the potion is lingering, and if the potion is a
    * splash potion.
    * 
    * @param item
    * @return {@link PotionLayer}. If it fails to parse, or the item argument is not a valid potion this will return null.
    * @throws Exception
    */
   @Deprecated
   private static PotionLayer fromPotion(Potion potion) throws Exception {
PotionType type = PotionType.match(potion.getType());
if (type == null) {
    throw new Exception("no enum for " + potion.getType().name());
}
return new PotionLayer(type, potion.getLevel() > 1, potion.hasExtendedDuration(), false, potion.isSplash());
   }
项目:MCPBukkit    文件:CraftThrownPotion.java   
public Collection<PotionEffect> getEffects() {
    if (effects == null) {
        effects = Potion.getBrewer().getEffectsFromDamage(getHandle().func_70196_i());
    }

    return effects;
}
项目:BKgLib    文件:NBTUtils.java   
public static ItemStack potionFromNBTEffectsList(NBTTagList effects) {
    NBTTagCompound tag = new NBTTagCompound();
    tag.setList("CustomPotionEffects", effects.clone());
    NBTTagCompound data = new NBTTagCompound();
    data.setShort("id", (short) Material.POTION.getId());
    data.setByte("Count", (byte) 1);
    data.setShort("Damage", (short) (new Potion(PotionType.SPEED, 1)).toDamageValue());
    data.setCompound("tag", tag);
    return itemStackFromNBTData(data);
}
项目:Uranium    文件:CraftThrownPotion.java   
public Collection<PotionEffect> getEffects() {
    return Potion.getBrewer().getEffectsFromDamage(getHandle().getPotionDamage());
}
项目:Uranium    文件:CraftEffect.java   
public static <T> int getDataValue(Effect effect, T data) {
    int datavalue;
    switch(effect) {
    case POTION_BREAK:
        datavalue = ((Potion) data).toDamageValue() & 0x3F;
        break;
    case RECORD_PLAY:
        Validate.isTrue(((Material) data).isRecord(), "Invalid record type!");
        datavalue = ((Material) data).getId();
        break;
    case SMOKE:
        switch((BlockFace) data) { // TODO: Verify (Where did these values come from...?)
        case SOUTH_EAST:
            datavalue = 0;
            break;
        case SOUTH:
            datavalue = 1;
            break;
        case SOUTH_WEST:
            datavalue = 2;
            break;
        case EAST:
            datavalue = 3;
            break;
        case UP:
        case SELF:
            datavalue = 4;
            break;
        case WEST:
            datavalue = 5;
            break;
        case NORTH_EAST:
            datavalue = 6;
            break;
        case NORTH:
            datavalue = 7;
            break;
        case NORTH_WEST:
            datavalue = 8;
            break;
        default:
            throw new IllegalArgumentException("Bad smoke direction!");
        }
        break;
    case STEP_SOUND:
        Validate.isTrue(((Material) data).isBlock(), "Material is not a block!");
        datavalue = ((Material) data).getId();
        break;
    default:
        datavalue = 0;
    }
    return datavalue;
}
项目:ProjectAres    文件:PotionUtils.java   
public static Collection<PotionEffect> effects(PotionData data) {
    return Potion.getBrewer().getEffects(data.getType(), data.isUpgraded(), data.isExtended());
}
项目:AlphaLibary    文件:PotionBreakData.java   
public PotionBreakData(Potion potion) {
    super(potion);
}
项目:ThermosRebased    文件:CraftThrownPotion.java   
public Collection<PotionEffect> getEffects() {
    return Potion.getBrewer().getEffectsFromDamage(getHandle().getPotionDamage());
}