类org.bukkit.inventory.meta.PotionMeta源码实例Demo

下面列出了怎么用org.bukkit.inventory.meta.PotionMeta的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: CraftserveRadiation   文件: LugolsIodinePotion.java
public PotionMeta convert(PotionMeta potionMeta) {
    Objects.requireNonNull(potionMeta, "potionMeta");

    Duration duration = this.config.duration();
    String formattedDuration = this.formatDuration(this.config.duration());

    if (this.config.color != null) {
        potionMeta.setColor(this.config.color);
    }
    potionMeta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
    potionMeta.setDisplayName(ChatColor.AQUA + this.config.name());
    potionMeta.setLore(Collections.singletonList(ChatColor.BLUE + MessageFormat.format(this.config.description(), formattedDuration)));

    PersistentDataContainer container = potionMeta.getPersistentDataContainer();
    container.set(this.potionKey, PersistentDataType.BYTE, TRUE);
    container.set(this.durationSecondsKey, PersistentDataType.INTEGER, (int) duration.getSeconds());
    return potionMeta;
}
 
源代码2 项目: PGM   文件: ItemModifyModule.java
@Override
public @Nullable ItemModifyModule parse(MapFactory factory, Logger logger, Document doc)
    throws InvalidXMLException {
  List<ItemRule> rules = new ArrayList<>();
  for (Element elRule : XMLUtils.flattenElements(doc.getRootElement(), "item-mods", "rule")) {
    MaterialMatcher items =
        XMLUtils.parseMaterialMatcher(XMLUtils.getRequiredUniqueChild(elRule, "match"));

    // Always use a PotionMeta so the rule can have potion effects, though it will only apply
    // those to potion items
    PotionMeta meta = (PotionMeta) Bukkit.getItemFactory().getItemMeta(Material.POTION);
    factory.getKits().parseItemMeta(XMLUtils.getRequiredUniqueChild(elRule, "modify"), meta);

    ItemRule rule = new ItemRule(items, meta);
    rules.add(rule);
  }

  return rules.isEmpty() ? null : new ItemModifyModule(rules);
}
 
源代码3 项目: ActionHealth   文件: ActionHelper.java
public List<String> getName(ItemStack itemStack) {
    List<String> possibleMaterials = new ArrayList<>();

    String name = itemStack.getType().name();
    possibleMaterials.add(name);

    if (itemStack.hasItemMeta()) {
        ItemMeta itemMeta = itemStack.getItemMeta();
        if (itemMeta instanceof PotionMeta) {
            PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();

            PotionData potionData = potionMeta.getBasePotionData();
            possibleMaterials.add(potionData.getType().getEffectType().getName() + "_" + name);

            if (potionMeta.hasCustomEffects()) {
                for (PotionEffect potionEffect : potionMeta.getCustomEffects()) {
                    possibleMaterials.add(potionEffect.getType().getName() + "_" + name);
                }
            }
        }
    }

    return possibleMaterials;
}
 
源代码4 项目: ProjectAres   文件: ItemModifyModule.java
@Override
public @Nullable ItemModifyModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException {
    List<ItemRule> rules = new ArrayList<>();
    for(Element elRule : XMLUtils.flattenElements(doc.getRootElement(), "item-mods", "rule")) {
        MaterialMatcher items = XMLUtils.parseMaterialMatcher(XMLUtils.getRequiredUniqueChild(elRule, "match"));

        // Always use a PotionMeta so the rule can have potion effects, though it will only apply those to potion items
        final Element elModify = XMLUtils.getRequiredUniqueChild(elRule, "modify");
        final PotionMeta meta = (PotionMeta) Bukkit.getItemFactory().getItemMeta(Material.POTION);
        context.needModule(ItemParser.class).parseItemMeta(elModify, meta);
        final boolean defaultAttributes = XMLUtils.parseBoolean(elModify.getAttribute("default-attributes"), false);

        ItemRule rule = new ItemRule(items, meta, defaultAttributes);
        rules.add(rule);
    }

    return rules.isEmpty() ? null : new ItemModifyModule(rules);
}
 
源代码5 项目: UhcCore   文件: ChildrenLeftUnattended.java
private void giveTeamReward(Player player){
    Wolf wolf = (Wolf) player.getWorld().spawnEntity(player.getLocation(), EntityType.WOLF);
    wolf.setTamed(true);
    wolf.setOwner(player);
    wolf.setAdult();

    ItemStack potion = new ItemStack(Material.POTION);
    PotionMeta meta = (PotionMeta) potion.getItemMeta();
    meta.setMainEffect(PotionEffectType.SPEED);
    PotionEffect potionEffect = new PotionEffect(PotionEffectType.SPEED, 8*60*20, 0);
    meta.addCustomEffect(potionEffect, true);

    meta.setDisplayName(ChatColor.WHITE + "Potion of Swiftness");

    potion.setItemMeta(meta);

    player.getWorld().dropItem(player.getLocation(), potion);
}
 
源代码6 项目: UhcCore   文件: JsonItemUtils.java
private static ItemMeta parseBasePotionEffect(ItemMeta meta, JsonObject jsonObject) throws ParseException{
    PotionMeta potionMeta = (PotionMeta) meta;

    PotionType type;

    try {
        type = PotionType.valueOf(jsonObject.get("type").getAsString());
    }catch (IllegalArgumentException ex){
        throw new ParseException(ex.getMessage());
    }

    JsonElement jsonElement;
    jsonElement = jsonObject.get("extended");
    boolean extended = jsonElement != null && jsonElement.getAsBoolean();
    jsonElement = jsonObject.get("upgraded");
    boolean upgraded = jsonElement != null && jsonElement.getAsBoolean();

    PotionData potionData = new PotionData(type, extended, upgraded);
    potionMeta = VersionUtils.getVersionUtils().setBasePotionEffect(potionMeta, potionData);

    return potionMeta;
}
 
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event)
{
	Player player = event.getPlayer();
	
	ItemMeta itemMeta = event.getItem().getItemMeta();
	if (itemMeta instanceof PotionMeta)
	{
		this.plugin.getWorldGuardCommunicator().getSessionManager().get(player).getHandler(GiveEffectsFlagHandler.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects());
	}
	else
	{
		Material material = event.getItem().getType();
		if (material == Material.MILK_BUCKET)
		{
			this.plugin.getWorldGuardCommunicator().getSessionManager().get(player).getHandler(GiveEffectsFlagHandler.class).drinkMilk(player);
		}
	}
}
 
源代码8 项目: RedProtect   文件: RedProtectUtil.java
public boolean denyPotion(ItemStack result, Player p) {
    List<String> Pots = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_potions;
    if (result != null && Pots.size() > 0 && (result.getType().name().contains("POTION") || result.getType().name().contains("TIPPED"))) {
        String potname = "";
        if (RedProtect.get().bukkitVersion >= 190) {
            PotionMeta pot = (PotionMeta) result.getItemMeta();
            potname = pot.getBasePotionData().getType().name();
        }
        if (RedProtect.get().bukkitVersion <= 180 && Potion.fromItemStack(result) != null) {
            potname = Potion.fromItemStack(result).getType().name();
        }
        if (Pots.contains(potname)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.denypotion");
            return true;
        }
    }
    return false;
}
 
private boolean onPotion(Player sender) {
    ItemStack itemStack = new ItemStack(Material.POTION);
    PotionMeta itemMeta = Objects.requireNonNull((PotionMeta) itemStack.getItemMeta());
    itemMeta.setBasePotionData(new PotionData(potion.getConfig().getRecipe().getBasePotion()));
    itemStack.setItemMeta(potion.convert(itemMeta));
    sender.getInventory().addItem(itemStack);
    return true;
}
 
源代码10 项目: PGM   文件: PotionClassifier.java
public static double getScore(ThrownPotion potion) {
  double score = 0;

  for (PotionEffect effect :
      Iterables.concat(
          potion.getEffects(),
          ((PotionMeta) potion.getItem().getItemMeta()).getCustomEffects())) {
    score += getScore(effect);
  }

  return score;
}
 
源代码11 项目: PGM   文件: InventoryUtils.java
public static Collection<PotionEffect> getEffects(ItemStack potion) {
  if (potion.getItemMeta() instanceof PotionMeta) {
    PotionMeta meta = (PotionMeta) potion.getItemMeta();
    if (meta.hasCustomEffects()) {
      return meta.getCustomEffects();
    } else {
      return Potion.fromItemStack(potion).getEffects();
    }
  } else {
    return Collections.emptyList();
  }
}
 
源代码12 项目: Kettle   文件: Potion.java
/**
 * Applies the effects of this potion to the given {@link ItemStack}. The
 * ItemStack must be a potion.
 *
 * @param to The itemstack to apply to
 */
public void apply(ItemStack to) {
    Validate.notNull(to, "itemstack cannot be null");
    Validate.isTrue(to.hasItemMeta(), "given itemstack is not a potion");
    Validate.isTrue(to.getItemMeta() instanceof PotionMeta, "given itemstack is not a potion");
    PotionMeta meta = (PotionMeta) to.getItemMeta();
    meta.setBasePotionData(new PotionData(type, extended, level == 2));
    to.setItemMeta(meta);
}
 
源代码13 项目: Kettle   文件: Potion.java
/**
 * Converts this potion to an {@link ItemStack} with the specified amount
 * and a correct damage value.
 *
 * @param amount The amount of the ItemStack
 * @return The created ItemStack
 */
public ItemStack toItemStack(int amount) {
    Material material;
    if (isSplash()) {
        material = Material.SPLASH_POTION;
    } else {
        material = Material.POTION;
    }
    ItemStack itemStack = new ItemStack(material, amount);
    PotionMeta meta = (PotionMeta) itemStack.getItemMeta();
    meta.setBasePotionData(new PotionData(type, level == 2, extended));
    itemStack.setItemMeta(meta);
    return itemStack;
}
 
源代码14 项目: UhcCore   文件: VersionUtils_1_13.java
@Override
public JsonObject getBasePotionEffect(PotionMeta potionMeta) {
    PotionData potionData = potionMeta.getBasePotionData();
    JsonObject baseEffect = new JsonObject();
    baseEffect.addProperty("type", potionData.getType().name());

    if (potionData.isUpgraded()) {
        baseEffect.addProperty("upgraded", true);
    }
    if (potionData.isExtended()) {
        baseEffect.addProperty("extended", true);
    }
    return baseEffect;
}
 
源代码15 项目: UhcCore   文件: VersionUtils_1_13.java
@Nullable
@Override
public Color getPotionColor(PotionMeta potionMeta){
    if (potionMeta.hasColor()){
        return potionMeta.getColor();
    }

    return null;
}
 
源代码16 项目: UhcCore   文件: VersionUtils_1_12.java
@Override
public JsonObject getBasePotionEffect(PotionMeta potionMeta) {
    PotionData potionData = potionMeta.getBasePotionData();
    JsonObject baseEffect = new JsonObject();
    baseEffect.addProperty("type", potionData.getType().name());

    if (potionData.isUpgraded()) {
        baseEffect.addProperty("upgraded", true);
    }
    if (potionData.isExtended()) {
        baseEffect.addProperty("extended", true);
    }
    return baseEffect;
}
 
源代码17 项目: UhcCore   文件: VersionUtils_1_12.java
@Nullable
@Override
public Color getPotionColor(PotionMeta potionMeta){
    if (potionMeta.hasColor()){
        return potionMeta.getColor();
    }

    return null;
}
 
源代码18 项目: UhcCore   文件: JsonItemUtils.java
private static ItemMeta parseCustomPotionEffects(ItemMeta meta, JsonArray jsonArray) throws ParseException{
    if (meta instanceof PotionMeta){
        PotionMeta potionMeta = (PotionMeta) meta;

        for (JsonElement jsonElement : jsonArray){
            JsonObject effect = jsonElement.getAsJsonObject();
            potionMeta.addCustomEffect(parsePotionEffect(effect), true);
        }

        return potionMeta;
    }else{
        return VersionUtils.getVersionUtils().applySuspiciousStewEffects(meta, jsonArray);
    }
}
 
源代码19 项目: UhcCore   文件: JsonItemUtils.java
private static ItemMeta parseColor(ItemMeta meta, int color){
    if (meta instanceof PotionMeta){
        PotionMeta potionMeta = (PotionMeta) meta;
        VersionUtils.getVersionUtils().setPotionColor(potionMeta, Color.fromRGB(color));
        return potionMeta;
    }else if (meta instanceof LeatherArmorMeta){
        LeatherArmorMeta leatherMeta = (LeatherArmorMeta) meta;
        leatherMeta.setColor(Color.fromBGR(color));
        return leatherMeta;
    }

    return meta;
}
 
源代码20 项目: CS-CoreLib   文件: CustomPotion.java
@Deprecated
public CustomPotion(String name, int durability, String[] lore, PotionEffect effect) {
	super(Material.POTION, name, (ReflectionUtils.getVersion().startsWith("v1_8_")) ? durability: 0, lore);
	PotionMeta meta = (PotionMeta) getItemMeta();
	if (ReflectionUtils.getVersion().startsWith("v1_8_")) meta.setMainEffect(PotionEffectType.SATURATION);
	else meta.setMainEffect(effect.getType());
	meta.addCustomEffect(effect, true);
	setItemMeta(meta);
}
 
源代码21 项目: CS-CoreLib   文件: CustomPotion.java
public CustomPotion(String name, PotionType type, PotionEffect effect, String... lore) {
	super(Material.POTION, name, lore);
	PotionMeta meta = (PotionMeta) getItemMeta();
	meta.setBasePotionData(new PotionData(type));
	meta.addCustomEffect(effect, true);
	setItemMeta(meta);
}
 
源代码22 项目: CS-CoreLib   文件: CustomPotion.java
public CustomPotion(String name, Color color, PotionEffect effect, String... lore) {
	super(Material.POTION, name, lore);
	PotionMeta meta = (PotionMeta) getItemMeta();
	meta.setColor(color);
	meta.addCustomEffect(effect, true);
	setItemMeta(meta);
}
 
源代码23 项目: BedwarsRel   文件: ItemStackParser.java
@SuppressWarnings("unchecked")
private void parsePotionEffects() {
  PotionMeta customPotionMeta = (PotionMeta) this.finalStack.getItemMeta();
  for (Object potionEffect : (List<Object>) this.linkedSection.get("effects")) {
    LinkedHashMap<String, Object> potionEffectSection =
        (LinkedHashMap<String, Object>) potionEffect;

    if (!potionEffectSection.containsKey("type")) {
      continue;
    }

    PotionEffectType potionEffectType = null;
    int duration = 1;
    int amplifier = 0;

    potionEffectType =
        PotionEffectType.getByName(potionEffectSection.get("type").toString().toUpperCase());

    if (potionEffectSection.containsKey("duration")) {
      duration = Integer.parseInt(potionEffectSection.get("duration").toString()) * 20;
    }

    if (potionEffectSection.containsKey("amplifier")) {
      amplifier = Integer.parseInt(potionEffectSection.get("amplifier").toString()) - 1;
    }

    if (potionEffectType == null) {
      continue;
    }

    customPotionMeta.addCustomEffect(new PotionEffect(potionEffectType, duration, amplifier),
        true);
  }

  this.finalStack.setItemMeta(customPotionMeta);
}
 
源代码24 项目: BedwarsRel   文件: NewItemShop.java
private VillagerTrade getTradingItem(MerchantCategory category, ItemStack stack, Game game,
    Player player) {
  for (VillagerTrade trade : category.getOffers()) {
    if (trade.getItem1().getType() == Material.AIR
        && trade.getRewardItem().getType() == Material.AIR) {
      continue;
    }
    ItemStack iStack = this.toItemStack(trade, player, game);
    if (iStack.getType() == Material.ENDER_CHEST && stack.getType() == Material.ENDER_CHEST) {
      return trade;
    } else if ((iStack.getType() == Material.POTION
        || (!BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")
        && (iStack.getType().equals(Material.valueOf("TIPPED_ARROW"))
        || iStack.getType().equals(Material.valueOf("LINGERING_POTION"))
        || iStack.getType().equals(Material.valueOf("SPLASH_POTION")))))) {
      if (BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")) {
        if (iStack.getItemMeta().equals(stack.getItemMeta())) {
          return trade;
        }
      } else {
        PotionMeta iStackMeta = (PotionMeta) iStack.getItemMeta();
        PotionMeta stackMeta = (PotionMeta) stack.getItemMeta();
        if (iStackMeta.getBasePotionData().equals(stackMeta.getBasePotionData()) && iStackMeta
            .getCustomEffects().equals(stackMeta.getCustomEffects())) {
          return trade;
        }
      }
    } else if (iStack.equals(stack)) {
      return trade;
    }
  }

  return null;
}
 
源代码25 项目: RedProtect   文件: RedProtectUtil.java
public boolean denyPotion(ItemStack result, World world) {
    List<String> Pots = RedProtect.get().config.globalFlagsRoot().worlds.get(world.getName()).deny_potions;
    if (result != null && Pots.size() > 0 && (result.getType().name().contains("POTION") || result.getType().name().contains("TIPPED"))) {
        String potname = "";
        if (RedProtect.get().bukkitVersion >= 190) {
            PotionMeta pot = (PotionMeta) result.getItemMeta();
            potname = pot.getBasePotionData().getType().name();
        }
        if (RedProtect.get().bukkitVersion < 190) {
            potname = Potion.fromItemStack(result).getType().name();
        }
        return Pots.contains(potname);
    }
    return false;
}
 
源代码26 项目: 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;
}
 
源代码27 项目: ShopChest   文件: ItemUtils.java
public static boolean isExtendedPotion(ItemStack itemStack) {
    if (itemStack.getItemMeta() instanceof PotionMeta) {
        if (Utils.getMajorVersion() < 9) {
            return Potion.fromItemStack(itemStack).hasExtendedDuration();
        } else {
            return ((PotionMeta) itemStack.getItemMeta()).getBasePotionData().isExtended();
        }
    }

    return false;
}
 
源代码28 项目: Slimefun4   文件: SlimefunItemStack.java
public SlimefunItemStack(String id, Color color, PotionEffect effect, String name, String... lore) {
    super(Material.POTION, im -> {
        if (name != null) {
            im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
        }

        if (lore.length > 0) {
            List<String> lines = new ArrayList<>();

            for (String line : lore) {
                lines.add(ChatColor.translateAlternateColorCodes('&', line));
            }

            im.setLore(lines);
        }

        if (im instanceof PotionMeta) {
            ((PotionMeta) im).setColor(color);
            ((PotionMeta) im).addCustomEffect(effect, true);

            if (effect.getType().equals(PotionEffectType.SATURATION)) {
                im.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
            }
        }
    });

    setItemId(id);
}
 
源代码29 项目: Slimefun4   文件: SlimefunItemConsumeListener.java
@EventHandler
public void onConsume(PlayerItemConsumeEvent e) {
    Player p = e.getPlayer();
    ItemStack item = e.getItem();
    SlimefunItem sfItem = SlimefunItem.getByItem(item);

    if (sfItem != null) {
        if (Slimefun.hasUnlocked(p, sfItem, true)) {
            if (sfItem instanceof Juice) {
                // Fix for Saturation on potions is no longer working

                for (PotionEffect effect : ((PotionMeta) item.getItemMeta()).getCustomEffects()) {
                    if (effect.getType().equals(PotionEffectType.SATURATION)) {
                        p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, effect.getDuration(), effect.getAmplifier()));
                        break;
                    }
                }

                removeGlassBottle(p, item);
            }
            else {
                sfItem.callItemHandler(ItemConsumptionHandler.class, handler -> handler.onConsume(e, p, item));
            }
        }
        else {
            e.setCancelled(true);
        }
    }
}
 
源代码30 项目: Slimefun4   文件: CoolerListener.java
private boolean consumeJuice(Player p, PlayerBackpack backpack) {
    Inventory inv = backpack.getInventory();
    int slot = -1;

    for (int i = 0; i < inv.getSize(); i++) {
        ItemStack stack = inv.getItem(i);

        if (stack != null && stack.getType() == Material.POTION && stack.hasItemMeta() && stack.getItemMeta().hasDisplayName()) {
            slot = i;
            break;
        }
    }

    if (slot >= 0) {
        PotionMeta im = (PotionMeta) inv.getItem(slot).getItemMeta();

        for (PotionEffect effect : im.getCustomEffects()) {
            p.addPotionEffect(effect);
        }

        p.setSaturation(6F);
        p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_DRINK, 1F, 1F);
        inv.setItem(slot, null);
        backpack.markDirty();
        return true;
    }

    return false;
}
 
 类所在包
 同包方法