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


Java PotionMeta.setBasePotionData方法代碼示例

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


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

示例1: addPotion

import org.bukkit.inventory.meta.PotionMeta; //導入方法依賴的package包/類
/**
 * Turn an ItemStack with a Material of POTION into a functional potion
 * @param typeName PotionType string representing the potion type. (Matches Bukkit PotionType enum.)
 * @param upgraded Boolean specifying a level two potion if true
 * @param extended Is this an extended duration potion?
 */
public void addPotion(String typeName, boolean upgraded, boolean extended) {
    Material mat = this.item.getType();
    Set<Material> types = new HashSet<>();
    types.add(Material.POTION);
    types.add(Material.SPLASH_POTION);
    types.add(Material.LINGERING_POTION);
    types.add(Material.TIPPED_ARROW);
    if (!types.contains(mat)) return;
    try {
        PotionType type = PotionType.valueOf(typeName.toUpperCase());
        PotionData pd = new PotionData(type, extended, upgraded);
        PotionMeta meta = (PotionMeta) this.item.getItemMeta();
        meta.setBasePotionData(pd);
        this.item.setItemMeta(meta);
    } catch (Exception ex) {
        Bukkit.getLogger().warning(String.format("Kit configuration error: %s", ex.getMessage()));
    }
}
 
開發者ID:redwallhp,項目名稱:AthenaGM,代碼行數:25,代碼來源:MapInfoKitItem.java

示例2: potionMain

import org.bukkit.inventory.meta.PotionMeta; //導入方法依賴的package包/類
/**
 * Sets this item's main effect, assuming it is a potion.
 * <p />
 * <b>UNSAFE</b>
 *
 * @param effectType effect type to set
 *
 * @return this item builder instance, for chaining
 * @see ItemBuilder#potionMain(PotionData) 
 */
@Deprecated
public ItemBuilder potionMain(PotionEffectType effectType) {
  if (isPotionMeta()) {
    try {
      PotionMeta potionMeta = (PotionMeta) this.itemMeta;
      if (potionMeta.setMainEffect(effectType) == false) {
        potionMeta.setBasePotionData(new PotionData(potionTypeFromLegacy(effectType), false, false));
      }
    } catch (Exception e) {
      if (!this.failSilently) {
        e.printStackTrace();
      }
    }
  }
  return this;
}
 
開發者ID:SupaHam,項目名稱:SupaCommons,代碼行數:27,代碼來源:ItemBuilder.java

示例3: splashPotion

import org.bukkit.inventory.meta.PotionMeta; //導入方法依賴的package包/類
public static ItemStack splashPotion(PotionType type, boolean extended, boolean upgraded, String name, String... lores) {
    ItemStack potion = new ItemStack(Material.SPLASH_POTION, 1);
    PotionMeta meta = (PotionMeta) potion.getItemMeta();
    meta.setBasePotionData(new PotionData(type, extended, upgraded));
    potion.setItemMeta(meta);
    return potion;
}
 
開發者ID:upperlevel,項目名稱:uppercore,代碼行數:8,代碼來源:GuiUtil.java

示例4: processMeta

import org.bukkit.inventory.meta.PotionMeta; //導入方法依賴的package包/類
@Override
public void processMeta(Player player, ItemMeta m) {
    super.processMeta(player, m);
    PotionMeta meta = (PotionMeta) m;
    if(type != null)
        meta.setBasePotionData(new PotionData(type));
    if(customColor != null)
        meta.setColor(customColor.resolve(player));
    meta.clearCustomEffects();
    for(PotionEffect e : customEffects)
        meta.addCustomEffect(e, true);
}
 
開發者ID:upperlevel,項目名稱:uppercore,代碼行數:13,代碼來源:PotionCustomItem.java

示例5: parseItem

import org.bukkit.inventory.meta.PotionMeta; //導入方法依賴的package包/類
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;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:51,代碼來源:GlobalItemParser.java

示例6: CustomPotion

import org.bukkit.inventory.meta.PotionMeta; //導入方法依賴的package包/類
public CustomPotion(String name, PotionType type, PotionEffect effect, String... lore) {
	super(Material.POTION, name, 0, lore);
	PotionMeta meta = (PotionMeta) getItemMeta();
	meta.setBasePotionData(new PotionData(type));
	meta.addCustomEffect(effect, true);
	setItemMeta(meta);
}
 
開發者ID:TheBusyBiscuit,項目名稱:CS-CoreLib,代碼行數:8,代碼來源:CustomPotion.java

示例7: build

import org.bukkit.inventory.meta.PotionMeta; //導入方法依賴的package包/類
@Override
public ItemStack build(ItemStack stack) {
  if(valid) {
    PotionMeta meta = (PotionMeta)stack.getItemMeta();
    if(color != null) meta.setColor(color);
    customEffects.forEach((effect)->meta.addCustomEffect(effect, true));
    PotionData data = new PotionData(PotionType.valueOf(type), extended, upgraded);
    meta.setBasePotionData(data);
    stack.setItemMeta(meta);
  }
  return stack;
}
 
開發者ID:TheNewEconomy,項目名稱:TNE-Bukkit,代碼行數:13,代碼來源:SerialPotionData.java

示例8: change

import org.bukkit.inventory.meta.PotionMeta; //導入方法依賴的package包/類
@Override
public void change(Event e, Object[] delta, @NotNull Changer.ChangeMode mode) {
	ItemStack i = item.getSingle(e);
	if (i == null) {
		return;
	}
	if (PotionUtils.isPotionItem(i)) {
		PotionMeta meta = (PotionMeta) i.getItemMeta();
		PotionEffect potionEffect = (meta.getBasePotionData().getType() != PotionType.UNCRAFTABLE)
			? PotionUtils.getEffectByEffectType(meta, effectType.getSingle(e))
			: PotionUtils.fromPotionData(meta.getBasePotionData());
		if (potionEffect == null) {
			return;
		}
		if (meta.getBasePotionData().getType() != PotionType.UNCRAFTABLE) {
			meta.removeCustomEffect(effectType.getSingle(e));
		} else {
			meta.setBasePotionData(PotionUtils.emptyPotionData());
		}
		Number number = (Number) delta[0];
		switch (mode) {
			case ADD:
				meta.addCustomEffect(new PotionEffect(
					potionEffect.getType(),
					potionEffect.getDuration(),
					potionEffect.getAmplifier() + number.intValue(),
					potionEffect.isAmbient(),
					potionEffect.hasParticles(),
					potionEffect.getColor()
				), true);
				break;
			case SET:
				meta.addCustomEffect(new PotionEffect(
					potionEffect.getType(),
					potionEffect.getDuration(),
					number.intValue(),
					potionEffect.isAmbient(),
					potionEffect.hasParticles(),
					potionEffect.getColor()
				), true);
				break;
			case REMOVE:
				meta.addCustomEffect(new PotionEffect(
					potionEffect.getType(),
					potionEffect.getDuration(),
					(potionEffect.getAmplifier() - number.intValue() > 0)
						? potionEffect.getAmplifier() - number.intValue()
						: potionEffect.getAmplifier(),
					potionEffect.isAmbient(),
					potionEffect.hasParticles(),
					potionEffect.getColor()
				), true);
				break;
		}
	}
}
 
開發者ID:Syst3ms,項目名稱:QuarSK,代碼行數:57,代碼來源:SExprItemEffectTypeAmplifier.java

示例9: change

import org.bukkit.inventory.meta.PotionMeta; //導入方法依賴的package包/類
@Override
public void change(Event e, Object[] delta, @NotNull Changer.ChangeMode mode) {
	ItemStack i = item.getSingle(e);
	if (i == null) {
		return;
	}
	if (PotionUtils.isPotionItem(i)) {
		PotionMeta meta = (PotionMeta) i.getItemMeta();
		PotionEffect potionEffect = (meta.getBasePotionData().getType() != PotionType.UNCRAFTABLE)
			? PotionUtils.getEffectByEffectType(meta, effectType.getSingle(e))
			: PotionUtils.fromPotionData(meta.getBasePotionData());
		if (potionEffect == null) {
			return;
		}
		if (meta.getBasePotionData().getType() != PotionType.UNCRAFTABLE) {
			meta.removeCustomEffect(effectType.getSingle(e));
		} else {
			meta.setBasePotionData(PotionUtils.emptyPotionData());
		}
		Timespan timespan = (Timespan) delta[0];
		switch (mode) {
			case ADD:
				meta.addCustomEffect(new PotionEffect(
					potionEffect.getType(),
					potionEffect.getDuration() + Math.toIntExact(timespan.getTicks_i()),
					potionEffect.getAmplifier(),
					potionEffect.isAmbient(),
					potionEffect.hasParticles(),
					potionEffect.getColor()
				), true);
				break;
			case SET:
				meta.addCustomEffect(new PotionEffect(
					potionEffect.getType(),
					Math.toIntExact(timespan.getTicks_i()),
					potionEffect.getAmplifier(),
					potionEffect.isAmbient(),
					potionEffect.hasParticles(),
					potionEffect.getColor()
				), true);
				break;
			case REMOVE:
				meta.addCustomEffect(new PotionEffect(
					potionEffect.getType(),
					(potionEffect.getDuration() - Math.toIntExact(timespan.getTicks_i()) > 0)
						? potionEffect.getDuration() - Math.toIntExact(timespan.getTicks_i())
						: potionEffect.getDuration(),
					potionEffect.getAmplifier(),
					potionEffect.isAmbient(),
					potionEffect.hasParticles(),
					potionEffect.getColor()
				), true);
				break;
		}
	}
}
 
開發者ID:Syst3ms,項目名稱:QuarSK,代碼行數:57,代碼來源:SExprItemEffectTypeDuration.java


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