當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。