org.bukkit.inventory.ItemStack.setItemMeta()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中org.bukkit.inventory.ItemStack.setItemMeta()方法的一些代码示例,展示了ItemStack.setItemMeta()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ItemStack.setItemMeta()方法的具体详情如下:
包路径:org.bukkit.inventory.ItemStack
类名称:ItemStack
方法名:setItemMeta

ItemStack.setItemMeta介绍

暂无

代码示例

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
public ItemStack getResult(ItemStack[] matrix) {
  ItemStack original = null;
  int copies = 0;
  for (ItemStack item : matrix) {
    if (item == null) {
      continue;
    }
    switch (item.getType()) {
      case WRITTEN_BOOK:
        if (original != null) {
          return null; // Only one original allowed
        }
        original = item;
        break;
      case BOOK_AND_QUILL:
        copies += 1;
        break;
      default:
        return null; // Wrong item in matrix
    }
  }
  if (original == null || copies == 0) {
    return null;
  }
  ItemStack ret = new ItemStack(Material.WRITTEN_BOOK, copies);
  ret.setItemMeta(original.getItemMeta());
  return ret;
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
  GlowBanner state = (GlowBanner) block.getState();
  ItemStack drop = new ItemStack(Material.BANNER, 1);
  BannerMeta meta = (BannerMeta) drop.getItemMeta();
  meta.setPatterns(state.getPatterns());
  drop.setItemMeta(meta);
  drop.setDurability(state.getBaseColor().getDyeData());
  return Arrays.asList(drop);
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
  public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
    GlowSkull skull = (GlowSkull) block.getState();

    ItemStack drop = new ItemStack(Material.SKULL_ITEM, 1);
    if (skull.hasOwner()) {
      SkullMeta meta = (SkullMeta) drop.getItemMeta();
      meta.setOwner(skull.getOwner());
      drop.setItemMeta(meta);
    }
    drop.setDurability((short) skull.getSkullType().ordinal());

    return Arrays.asList(drop);
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

FireworkMeta firework = (FireworkMeta) ret.getItemMeta();
  FireworkEffectMeta charge = (FireworkEffectMeta) item.getItemMeta();
  if (!charge.hasEffect()) {
    continue;
ret.setItemMeta(firework);

代码示例来源:origin: GlowstoneMC/Glowstone

private boolean bleachBanner(GlowPlayer player, GlowBlock block) {
  // fired when a player bleaches a banner using the cauldron
  if (player.getGameMode() == GameMode.CREATIVE) {
    return false;
  }
  if (block.getData() > LEVEL_EMPTY) {
    ItemStack inHand = player.getItemInHand();
    BannerMeta meta = (BannerMeta) inHand.getItemMeta();
    List<Pattern> layers = meta.getPatterns();
    if (layers == null || layers.isEmpty()) {
      return false;
    }
    if (!setCauldronLevel(block, block.getData() - 1, player,
        CauldronLevelChangeEvent.ChangeReason.BANNER_WASH)) {
      return false;
    }
    meta.setPatterns(layers);
    inHand.setItemMeta(meta);
    return true;
  } else {
    return false;
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

LeatherArmorMeta meta = (LeatherArmorMeta) armor.getItemMeta();
Color base = meta.getColor();
if (meta.getColor() == GlowItemFactory.instance().getDefaultLeatherColor()) {
LeatherArmorMeta retMeta = (LeatherArmorMeta) ret.getItemMeta();
retMeta.setColor(newColor);
ret.setItemMeta(retMeta);

代码示例来源:origin: GlowstoneMC/Glowstone

private boolean bleachLeatherArmor(GlowPlayer player, GlowBlock block) {
  // fired when a player bleaches a leather armor piece using the cauldron
  if (block.getData() > LEVEL_EMPTY) {
    if (!setCauldronLevel(block, block.getData() - 1, player,
        CauldronLevelChangeEvent.ChangeReason.ARMOR_WASH)) {
      return false;
    }
    ItemStack inHand = player.getItemInHand();
    LeatherArmorMeta im = (LeatherArmorMeta) inHand.getItemMeta();
    im.setColor(GlowItemFactory.instance().getDefaultLeatherColor());
    inHand.setItemMeta(im);
    return true;
  } else {
    return false;
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

/**
   * Sets the name of the next item to be modified on this anvil.
   *
   * @param name the item name
   */
  public void setRenameText(String name) {
    renameText = name;
    if (renameText.isEmpty()) {
      setItem(FIRST_ITEM_SLOT, getFirstItem());
      setItem(SECOND_ITEM_SLOT, getSecondItem());
    } else {
      ItemStack result = getFirstItem().clone();
      if (!InventoryUtil.isEmpty(result)) {
        if (Objects.equals(result.getItemMeta().getDisplayName(), name)) {
          setItem(RESULT_SLOT, InventoryUtil.createEmptyStack());
        }
        // rename the item
        ItemMeta m = result.getItemMeta();
        m.setDisplayName(ChatColor.ITALIC + renameText);
        result.setItemMeta(m);
        setItem(RESULT_SLOT, result);
      }
    }
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

FireworkEffectMeta meta = (FireworkEffectMeta) charge.getItemMeta();
meta.setEffect(effect);
charge.setItemMeta(meta);

代码示例来源:origin: GlowstoneMC/Glowstone

FireworkEffectMeta meta = (FireworkEffectMeta) charge.getItemMeta();
FireworkEffect old = meta.getEffect();
ret.setItemMeta(meta);

代码示例来源:origin: GlowstoneMC/Glowstone

try {
  if (isBook) {
    EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta();
    meta.addStoredEnchant(enchantment.getKey(), enchantment.getValue(),
      true); //TODO is true correct here?
    item.setItemMeta(meta);
  } else {
    item.addUnsafeEnchantment(enchantment.getKey(), enchantment.getValue());

代码示例来源:origin: GlowstoneMC/Glowstone

return;
ItemMeta meta = item.getItemMeta();
if (!(meta instanceof BookMeta)) {
  return;
  return;
ItemMeta handMeta = inHand.getItemMeta();
if (!(handMeta instanceof BookMeta)) {
  return;
inHand.setItemMeta(handBook);
session.getPlayer().setItemInHand(inHand);
break;
  return;
ItemMeta meta = item.getItemMeta();
if (!(meta instanceof BookMeta)) {
  return;
handBook.setPages(book.getPages());
inHand.setType(Material.WRITTEN_BOOK);
inHand.setItemMeta(handBook);
session.getPlayer().setItemInHand(inHand);
break;

代码示例来源:origin: GlowstoneMC/Glowstone

BannerMeta meta = (BannerMeta) banner.getItemMeta();
List<Pattern> layers = meta.getPatterns();
meta.setPatterns(layers);
result = banner.clone();
result.setItemMeta(meta);
return result;

代码示例来源:origin: me.lucko/helper

public ItemStackBuilder transformMeta(Consumer<ItemMeta> meta) {
  ItemMeta m = this.itemStack.getItemMeta();
  if (m != null) {
    meta.accept(m);
    this.itemStack.setItemMeta(m);
  }
  return this;
}

代码示例来源:origin: garbagemule/MobArena

private void makeUnbreakable(ItemStack stack) {
  ItemMeta meta = stack.getItemMeta();
  meta.setUnbreakable(true);
  stack.setItemMeta(meta);
}

代码示例来源:origin: Bkm016/TabooLib

public static ItemStack enchant(ItemStack i, Enchantment e, int l) {
  ItemMeta meta = i.getItemMeta();
  meta.addEnchant(e, l, false);
  i.setItemMeta(meta);
  return i;
}

代码示例来源:origin: stackoverflow.com

ItemStack wand = new ItemStack(Material.STICK); //create the ItemStack
ItemMeta meta = wand.getItemMeta(); //get the ItemMeta

List<String> lore = new ArrayList<String>(); //create a List<String> for the lore
lore.add(ChatColor.GRAY + "Staff Wand"); //add "§7Staff Wand" to the lore

meta.setLore(lore); //set the ItemMeta's lore to the List<String>
wand.setItemMeta(meta); //set the ItemStack's meta.

代码示例来源:origin: io.github.bedwarsrel/BedwarsRel-Common

@SuppressWarnings("unchecked")
private void parseLore() {
 List<String> lores = new ArrayList<String>();
 ItemMeta im = this.finalStack.getItemMeta();
 for (Object lore : (List<String>) this.linkedSection.get("lore")) {
  lores.add(ChatColor.translateAlternateColorCodes('&', lore.toString()));
 }
 im.setLore(lores);
 this.finalStack.setItemMeta(im);
}

代码示例来源:origin: BedwarsRel/BedwarsRel

@SuppressWarnings("unchecked")
private void parseLore() {
 List<String> lores = new ArrayList<String>();
 ItemMeta im = this.finalStack.getItemMeta();
 for (Object lore : (List<String>) this.linkedSection.get("lore")) {
  lores.add(ChatColor.translateAlternateColorCodes('&', lore.toString()));
 }
 im.setLore(lores);
 this.finalStack.setItemMeta(im);
}

代码示例来源:origin: stackoverflow.com

String[] kits = getConfig().getString("Kits." + args[0] + ".Items").split(",");
String[] itemNames = getConfig().getString("Kits." + args[0] + ".names").split(",");

for (int i = 0; i < kits.length; i++) {

  String[] singleKits = kits[i].split("-");

  ItemStack kit = new ItemStack(Integer.valueOf(singleKits[0]), Integer.valueOf(singleKits[1]));
  ItemMeta kitDisplayName = kit.getItemMeta();

  kitDisplayName.setDisplayName(itemNames[i]);
  kit.setItemMeta(kitDisplayName);
}

相关文章