當前位置: 首頁>>代碼示例>>Java>>正文


Java Potion.toItemStack方法代碼示例

本文整理匯總了Java中org.bukkit.potion.Potion.toItemStack方法的典型用法代碼示例。如果您正苦於以下問題:Java Potion.toItemStack方法的具體用法?Java Potion.toItemStack怎麽用?Java Potion.toItemStack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.potion.Potion的用法示例。


在下文中一共展示了Potion.toItemStack方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createPotion

import org.bukkit.potion.Potion; //導入方法依賴的package包/類
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;
}
 
開發者ID:WarzoneMC,項目名稱:Warzone,代碼行數:12,代碼來源:ItemFactory.java

示例2: onPlayerDeath

import org.bukkit.potion.Potion; //導入方法依賴的package包/類
/**
 * 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());
    }
}
 
開發者ID:SamaGames,項目名稱:SurvivalAPI,代碼行數:33,代碼來源:DropMyEffectsModule.java

示例3: setPotion

import org.bukkit.potion.Potion; //導入方法依賴的package包/類
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> cont = (Map<String,Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String,Tag> contents = (Map<String,Tag>)((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag)contents.get("Potion"));
            if (stringTag != null) {
                String tag = stringTag.getValue().replace("minecraft:", "");
                PotionType type = null;
                boolean strong = tag.contains("strong");
                boolean _long = tag.contains("long");
                //Bukkit.getLogger().info("tag = " + tag);
                if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
                    type = PotionType.FIRE_RESISTANCE;
                }else if(tag.equals("harming") || tag.equals("strong_harming")){
                    type = PotionType.INSTANT_DAMAGE;
                }else if(tag.equals("healing") || tag.equals("strong_healing")){
                    type = PotionType.INSTANT_HEAL;
                }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
                    type = PotionType.INVISIBILITY;
                }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
                    type = PotionType.JUMP;
                }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
                    type = PotionType.NIGHT_VISION;
                }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
                    type = PotionType.POISON;
                }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
                    type = PotionType.REGEN;
                }else if(tag.equals("slowness") || tag.equals("long_slowness")){
                    type = PotionType.SLOWNESS;
                }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
                    type = PotionType.SPEED;
                }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
                    type = PotionType.STRENGTH;
                }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
                    type = PotionType.WATER_BREATHING;
                }else if(tag.equals("water")){
                    type = PotionType.WATER;
                }else if(tag.equals("weakness") || tag.equals("long_weakness")){
                    type = PotionType.WEAKNESS;
                }else{
                    return chestItem;
                }
                Potion potion = new Potion(type);
                potion.setHasExtendedDuration(_long);
                potion.setLevel(strong ? 2 : 1);
                chestItem = potion.toItemStack(chestItem.getAmount());
            }
        }
    }

    return chestItem;
}
 
開發者ID:tastybento,項目名稱:acidisland,代碼行數:57,代碼來源:NMSHandler.java

示例4: setPotion

import org.bukkit.potion.Potion; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) itemTags).getValue().get("tag").getValue();
    StringTag stringTag = ((StringTag)contents.get("Potion"));
    if (stringTag != null) {
        String tag = stringTag.getValue().replace("minecraft:", "");
        PotionType type = null;
        boolean strong = tag.contains("strong");
        boolean _long = tag.contains("long");
        //Bukkit.getLogger().info("tag = " + tag);
        if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
            type = PotionType.FIRE_RESISTANCE;
        }else if(tag.equals("harming") || tag.equals("strong_harming")){
            type = PotionType.INSTANT_DAMAGE;
        }else if(tag.equals("healing") || tag.equals("strong_healing")){
            type = PotionType.INSTANT_HEAL;
        }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
            type = PotionType.INVISIBILITY;
        }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
            type = PotionType.JUMP;
        }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
            type = PotionType.NIGHT_VISION;
        }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
            type = PotionType.POISON;
        }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
            type = PotionType.REGEN;
        }else if(tag.equals("slowness") || tag.equals("long_slowness")){
            type = PotionType.SLOWNESS;
        }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
            type = PotionType.SPEED;
        }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
            type = PotionType.STRENGTH;
        }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
            type = PotionType.WATER_BREATHING;
        }else if(tag.equals("water")){
            type = PotionType.WATER;
        }else if(tag.equals("weakness") || tag.equals("long_weakness")){
            type = PotionType.WEAKNESS;
        }else{
            return chestItem;
        }
        Potion potion = new Potion(type);
        potion.setHasExtendedDuration(_long);
        potion.setLevel(strong ? 2 : 1);
        chestItem = potion.toItemStack(chestItem.getAmount());
    }

    return chestItem;
}
 
開發者ID:tastybento,項目名稱:acidisland,代碼行數:53,代碼來源:NMSHandler.java

示例5: parseItemStack

import org.bukkit.potion.Potion; //導入方法依賴的package包/類
@Nullable
private ItemStack parseItemStack() throws InvalidItemStackStringException {

    _buffer.setLength(0);

    if (current() == ',')
        next();

    if (!canParse())
        return null;

    skipEmpty();

    ItemStack stack;
    Material material;
    short data = 0;
    int amount = 1;
    Potion potion;
    List<ItemMetaValue> metaObjects = new ArrayList<>(15);

    String rawMaterial = parseMaterial();
    if (rawMaterial.isEmpty())
        return null;

    material = Converters.MATERIAL.convert(rawMaterial);
    if (material == null) {
        throw new InvalidItemStackStringException(_itemString);
    }

    if (current() == ':') {
        next();
        data = parseData();
    }

    if (current() == ';') {
        next();
        amount = parseAmount();
    }

    if (current() == '{') {
        next();
        parseMeta(metaObjects);
    }

    // handle special cases
    if (material == Material.POTION && (potion = Converters.POTION.convert(data)) != null) {
        stack = potion.toItemStack(amount);
    }
    else {
        // set stack data
        stack = new ItemStack(material, amount);
        stack.setDurability(data);
    }

    for (ItemMetaValue meta : metaObjects) {

        IItemMetaHandler handler = Nucleus.getItemMetaHandlers().getHandler(meta.getName());
        if (handler == null)
            continue;

        handler.apply(stack, meta);
    }

    return stack;
}
 
開發者ID:JCThePants,項目名稱:NucleusFramework,代碼行數:66,代碼來源:ItemDeserializer.java


注:本文中的org.bukkit.potion.Potion.toItemStack方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。