当前位置: 首页>>代码示例>>Java>>正文


Java Potion.fromItemStack方法代码示例

本文整理汇总了Java中org.bukkit.potion.Potion.fromItemStack方法的典型用法代码示例。如果您正苦于以下问题:Java Potion.fromItemStack方法的具体用法?Java Potion.fromItemStack怎么用?Java Potion.fromItemStack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.potion.Potion的用法示例。


在下文中一共展示了Potion.fromItemStack方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setMainPotionEffect

import org.bukkit.potion.Potion; //导入方法依赖的package包/类
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;
}
 
开发者ID:shawlaf,项目名称:Banmanager,代码行数:18,代码来源:ItemBuilder.java

示例2: denyPotion

import org.bukkit.potion.Potion; //导入方法依赖的package包/类
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;
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:19,代码来源:RPUtil.java

示例3: onConsumePotion

import org.bukkit.potion.Potion; //导入方法依赖的package包/类
@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"));
        }
    }
}
 
开发者ID:DSH105,项目名称:HoloAPI,代码行数:20,代码来源:IndicatorListener.java

示例4: onPlayerConsume

import org.bukkit.potion.Potion; //导入方法依赖的package包/类
/**
 * 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.
        }
    }
}
 
开发者ID:Tribalforge,项目名称:AntiPotionField,代码行数:26,代码来源:PlayerEventRegionsHandler.java

示例5: testValidity

import org.bukkit.potion.Potion; //导入方法依赖的package包/类
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;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:28,代码来源:PotionLimitListener.java

示例6: isExtendedPotion

import org.bukkit.potion.Potion; //导入方法依赖的package包/类
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;
}
 
开发者ID:EpicEricEE,项目名称:ShopChest,代码行数:14,代码来源:ItemUtils.java

示例7: use

import org.bukkit.potion.Potion; //导入方法依赖的package包/类
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;
    }
}
 
开发者ID:WaywardRealms,项目名称:Wayward,代码行数:37,代码来源:ItemSkill.java

示例8: toPotion

import org.bukkit.potion.Potion; //导入方法依赖的package包/类
public Potion toPotion(int amount) {
    return Potion.fromItemStack(this.toItemStack(amount));
}
 
开发者ID:Pershonkey,项目名称:McMMOPlus,代码行数:4,代码来源:AlchemyPotion.java


注:本文中的org.bukkit.potion.Potion.fromItemStack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。