org.bukkit.inventory.meta.ItemMeta Java Examples

The following examples show how to use org.bukkit.inventory.meta.ItemMeta. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Game.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Location makeSpectator(GamePlayer gamePlayer, boolean leaveItem) {
    Player player = gamePlayer.player;
    gamePlayer.isSpectator = true;
    gamePlayer.teleport(specSpawn, () -> {
        player.setAllowFlight(true);
        player.setFlying(true);
        player.setGameMode(GameMode.SPECTATOR);

        if (leaveItem) {
            int leavePosition = Main.getConfigurator().config.getInt("hotbar.leave", 8);
            if (leavePosition >= 0 && leavePosition <= 8) {
                ItemStack leave = Main.getConfigurator().readDefinedItem("leavegame", "SLIME_BALL");
                ItemMeta leaveMeta = leave.getItemMeta();
                leaveMeta.setDisplayName(i18n("leave_from_game_item", false));
                leave.setItemMeta(leaveMeta);
                gamePlayer.player.getInventory().setItem(leavePosition, leave);
            }
        }
    });

    return specSpawn;
}
 
Example #2
Source File: API.java    From MineableSpawners with MIT License 6 votes vote down vote up
public ItemStack getSpawnerFromEntityType(EntityType entityType) {
    ItemStack item = new ItemStack(Objects.requireNonNull(XMaterial.SPAWNER.parseMaterial()));
    ItemMeta meta = item.getItemMeta();

    String mobFormatted = Chat.uppercaseStartingLetters(entityType.name().toString());
    meta.setDisplayName(plugin.getConfigurationHandler().getMessage("global", "name").replace("%mob%", mobFormatted));
    List<String> newLore = new ArrayList<>();
    if (plugin.getConfigurationHandler().getList("global", "lore") != null && plugin.getConfigurationHandler().getBoolean("global", "lore-enabled")) {
        for (String line : plugin.getConfigurationHandler().getList("global", "lore")) {
            newLore.add(Chat.format(line).replace("%mob%", mobFormatted));
        }
        meta.setLore(newLore);
    }
    item.setItemMeta(meta);

    return plugin.getNmsHandler().setType(item, entityType);
}
 
Example #3
Source File: EnchantManager.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static ItemStack addEnchant(ItemStack item, CEnchantment ce, int level) {
    ItemMeta im = item.getItemMeta();
    List<String> lore = new ArrayList<String>();
    if (im.hasLore()) {
        lore = im.getLore();
        if (maxEnchants < enchantments.size()) {
            int counter = maxEnchants;
            for (String s : lore)
                if (containsEnchantment(s)) {
                    counter--;
                    if (counter <= 0) {
                        return item;
                    }
                }
        }
    }
    if (level > ce.getEnchantmentMaxLevel())
        level = ce.getEnchantmentMaxLevel();
    lore.add(ce.getDisplayName() + " " + intToLevel(level));
    im.setLore(lore);
    item.setItemMeta(im);
    item.addUnsafeEnchantment(glowEnchantment, 0);
    return item;
}
 
Example #4
Source File: SkyBlockMenu.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public Inventory displayLogGUI(final Player player) {
    List<String> lores = new ArrayList<>();
    String title = "\u00a79" + tr("Island Log");
    Inventory menu = Bukkit.createInventory(new UltimateHolder(player, title, MenuType.DEFAULT), 9, title);
    ItemMeta meta4 = sign.getItemMeta();
    meta4.setDisplayName("\u00a79\u00a7l" + tr("Island Log"));
    addLore(lores, tr("\u00a7eClick here to return to\n\u00a7ethe main island screen."));
    meta4.setLore(lores);
    sign.setItemMeta(meta4);
    menu.addItem(new ItemStack[]{sign});
    lores.clear();
    ItemStack menuItem = new ItemStack(Material.WRITABLE_BOOK, 1);
    meta4 = menuItem.getItemMeta();
    meta4.setDisplayName(tr("\u00a7e\u00a7lIsland Log"));
    for (String log : plugin.getIslandInfo(player).getLog()) {
        lores.add(log);
    }
    meta4.setLore(lores);
    menuItem.setItemMeta(meta4);
    menu.setItem(8, menuItem);
    lores.clear();
    return menu;
}
 
Example #5
Source File: Sharpness.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean applyMod(Player player, ItemStack tool, boolean isCommand) {
	ItemMeta meta = tool.getItemMeta();

	if (meta != null) {
		if (ToolType.AXE.contains(tool.getType()) || ToolType.SWORD.contains(tool.getType())) {
			meta.addEnchant(Enchantment.DAMAGE_ALL, modManager.getModLevel(tool, this), true);
		} else if (ToolType.BOW.contains(tool.getType()) || ToolType.CROSSBOW.contains(tool.getType())) {
			meta.addEnchant(Enchantment.ARROW_DAMAGE, modManager.getModLevel(tool, this), true);
		} else if (ToolType.TRIDENT.contains(tool.getType())) {
			meta.addEnchant(Enchantment.DAMAGE_ALL, modManager.getModLevel(tool, this), true);
			meta.addEnchant(Enchantment.IMPALING, modManager.getModLevel(tool, this), true);
		}

		tool.setItemMeta(meta);
	}

	return true;
}
 
Example #6
Source File: ItemStackBuilder.java    From AstralEdit with Apache License 2.0 6 votes vote down vote up
/**
 * Adds lore after the index of a lore line
 *
 * @param index index
 * @param lore  lore
 * @return builder
 */
public ItemStackBuilder addLore(int index, String... lore) {
    final ItemMeta itemMeta = this.getItemMeta();
    final List<String> data = new ArrayList<>();
    for (int i = 0; i < itemMeta.getLore().size(); i++) {
        data.add(itemMeta.getLore().get(0));
        if (i == index) {
            for (final String s : lore) {
                data.add(ChatColor.translateAlternateColorCodes('&', s));
            }
        }
    }
    itemMeta.setLore(data);
    this.setItemMeta(itemMeta);
    return this;
}
 
Example #7
Source File: ItemData.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a plain copy of this ItemData. It will have same material,
 * amount of 1 and same block values. Tags will also be copied, with
 * following exceptions:
 * <ul>
 * <li>Damage: 1.13 tag-damage is only used for actual durability.
 * Present on 1.12 and older versions.
 * <li>Name: custom names made with anvil do not change item type
 * </ul>
 * @return A modified copy of this item data.
 */
public ItemData aliasCopy() {
	ItemData data = new ItemData();
	data.stack = new ItemStack(type, 1);
	
	if (stack.hasItemMeta()) {
		ItemMeta meta = stack.getItemMeta(); // Creates a copy
		meta.setDisplayName(null); // Clear display name
		data.stack.setItemMeta(meta);
	}
	if (!itemDataValues) {
		ItemUtils.setDamage(data.stack, 0); // Set to undamaged
	}
	
	data.type = type;
	data.blockValues = blockValues;
	data.itemForm = itemForm;
	return data;
}
 
Example #8
Source File: AcidInventory.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * If the player filled up the bucket themselves
 * 
 * @param e - event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBucketFill(PlayerBucketFillEvent e) {
    if (DEBUG)
        plugin.getLogger().info("Player filled the bucket");
    if (e.getPlayer().getWorld().getName().equalsIgnoreCase(Settings.worldName)) {
        if (DEBUG)
            plugin.getLogger().info("Correct world");
        if (Settings.acidDamage > 0D && Settings.acidBottle) {
            ItemStack item = e.getItemStack();
            if (item.getType().equals(Material.WATER_BUCKET) || item.getType().equals(Material.POTION)) {
                ItemMeta meta = item.getItemMeta();
                meta.setDisplayName(plugin.myLocale(e.getPlayer().getUniqueId()).acidBucket);
                lore = Arrays.asList(plugin.myLocale(e.getPlayer().getUniqueId()).acidLore.split("\n"));
                meta.setLore(lore);
                item.setItemMeta(meta);
            }
        }
    }
}
 
Example #9
Source File: Fiery.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean applyMod(Player player, ItemStack tool, boolean isCommand) {
	ItemMeta meta = tool.getItemMeta();

	if (meta != null) {
		if (ToolType.BOW.contains(tool.getType()) || ToolType.CROSSBOW.contains(tool.getType())) {
			meta.addEnchant(Enchantment.ARROW_FIRE, modManager.getModLevel(tool, this), true);
		} else if (ToolType.SWORD.contains(tool.getType()) || ToolType.AXE.contains(tool.getType())) {
			meta.addEnchant(Enchantment.FIRE_ASPECT, modManager.getModLevel(tool, this), true);
		}

		tool.setItemMeta(meta);
	}

	return true;
}
 
Example #10
Source File: SelectorLayout.java    From SonarPet with GNU General Public License v3.0 6 votes vote down vote up
public static ItemStack getSelectorItem() {
    YAMLConfig config = ConfigOptions.instance.getConfig();
    String name = config.getString("petSelector.item.name", "&aPets");
    int materialId = config.getInt("petSelector.item.materialId", Material.BONE.getId());
    int materialData = config.getInt("petSelector.item.materialData", 0);
    List<String> lore = config.config().getStringList("petSelector.item.lore");
    if (lore == null) {
        lore = new ArrayList<String>();
    }
    ItemStack i = new ItemStack(materialId, 1, (short) materialData);
    ItemMeta meta = i.getItemMeta();
    meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
    ArrayList<String> loreList = new ArrayList<String>();
    if (lore.size() > 0) {
        for (String s : lore) {
            loreList.add(ChatColor.translateAlternateColorCodes('&', s));
        }
    }
    if (!loreList.isEmpty()) {
        meta.setLore(loreList);
    }
    i.setItemMeta(meta);
    return i;
}
 
Example #11
Source File: SkinsGUI.java    From SkinsRestorerX with GNU General Public License v3.0 6 votes vote down vote up
private void setSkin(ItemStack head, String b64stringtexture) {
    GameProfile profile = new GameProfile(UUID.randomUUID(), null);
    PropertyMap propertyMap = profile.getProperties();
    if (propertyMap == null) {
        throw new IllegalStateException("Profile doesn't contain a property map");
    }
    propertyMap.put("textures", new Property("textures", b64stringtexture));
    ItemMeta headMeta = head.getItemMeta();
    Class<?> headMetaClass = headMeta.getClass();
    try {
        ReflectionUtil.getField(headMetaClass, "profile", GameProfile.class, 0).set(headMeta, profile);
    } catch (IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
    head.setItemMeta(headMeta);
}
 
Example #12
Source File: ModManager.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Checks the durability of the Tool
 *
 * @param cancellable the Event (implements Cancelable)
 * @param player      the Player
 * @param tool        the Tool
 * @return false: if broken; true: if enough durability
 */
public boolean durabilityCheck(@NotNull Cancellable cancellable, @NotNull Player player, @NotNull ItemStack tool) {
	ItemMeta meta = tool.getItemMeta();

	if (meta instanceof Damageable) {
		if (config.getBoolean("UnbreakableTools", true)
				&& tool.getType().getMaxDurability() - ((Damageable) meta).getDamage() <= 2) {
			cancellable.setCancelled(true);

			if (config.getBoolean("Sound.OnBreaking", true)) {
				player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 0.5F, 0.5F);
			}
			return false;
		}
	}
	return true;
}
 
Example #13
Source File: SetGui.java    From WildernessTp with MIT License 6 votes vote down vote up
public static void OpenSet(Player p) {

        ItemStack close = new ItemStack(Material.REDSTONE_BLOCK, 1);
        ItemMeta meta = close.getItemMeta();
        meta.setDisplayName("Close");
        ArrayList<String> lore = new ArrayList<>();
        lore.add("Click to close the inventory and return to normal gameplay");
        meta.setLore(lore);
        close.setItemMeta(meta);
        Inventory set = Bukkit.createInventory(p, 27, "WildTp");
        p.openInventory(set);
        set.setItem(0, MainGui.makeItem(Material.valueOf(MainGui.getMaterials().get("Book")), "MinX", Collections.singletonList("Click to set the minx")));
        set.setItem(2, MainGui.makeItem(Material.valueOf(MainGui.getMaterials().get("Book")), "MaxX", Collections.singletonList("Click to set the maxx")));
        set.setItem(4, MainGui.makeItem(Material.valueOf(MainGui.getMaterials().get("Book")), "MinZ", Collections.singletonList("Click to set the minz")));
        set.setItem(6, MainGui.makeItem(Material.valueOf(MainGui.getMaterials().get("Book")), "MaxZ", Collections.singletonList("Click to set the maxz")));
        set.setItem(8, MainGui.makeItem(Material.valueOf(MainGui.getMaterials().get("Watch")), "Cooldown", Collections.singletonList("Click me to set the cooldown for the command")));
        set.setItem(10, MainGui.makeItem(Material.GOLD_BLOCK, "Cost", Collections.singletonList("Click me to set the cost for the command")));
        set.setItem(12, MainGui.makeItem(Material.valueOf(MainGui.getMaterials().get("Watch")), "Wait", Collections.singletonList("Click to set the wait before telepoting happens")));
        set.setItem(14, MainGui.makeItem(Material.valueOf(MainGui.getMaterials().get("Watch")), "Retries", Collections.singletonList("Click to set the number of retries if a location is unsuitable")));
        set.setItem(16, MainGui.makeItem(Material.valueOf(MainGui.getMaterials().get("Watch")), "Do Retry", Collections.singletonList("Click to set true or false for doing retries")));
        set.setItem(18, MainGui.makeItem(Material.MAP, "Distance", Arrays.asList("Click to set the distance the plugin checks for a claim")));
        set.setItem(24, MainGui.backItem());
        set.setItem(26, close);
    }
 
Example #14
Source File: ExtendedIconMenu.java    From ChestCommands with GNU General Public License v3.0 5 votes vote down vote up
public void refresh(Player player, Inventory inventory) {
	try {
		for (int i = 0; i < icons.length; i++) {
			if (icons[i] != null && icons[i] instanceof ExtendedIcon) {
				ExtendedIcon extIcon = (ExtendedIcon) icons[i];

				if (extIcon.hasViewPermission() || extIcon.hasVariables()) {
					// Then we have to refresh it
					if (extIcon.canViewIcon(player)) {

						if (inventory.getItem(i) == null) {
							ItemStack newItem = ItemUtils.hideAttributes(extIcon.createItemstack(player));
							inventory.setItem(i, newItem);
						} else {
							// Performance, only update name and lore
							ItemStack oldItem = ItemUtils.hideAttributes(inventory.getItem(i));
							ItemMeta meta = oldItem.getItemMeta();
							meta.setDisplayName(extIcon.calculateName(player));
							meta.setLore(extIcon.calculateLore(player));
							oldItem.setItemMeta(meta);
						}

					} else {
						inventory.setItem(i, null);
					}
				}
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
		player.sendMessage(ChatColor.RED + "An internal error occurred while refreshing the menu. The staff should check the console for errors.");
	}
}
 
Example #15
Source File: Sweeping.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean applyMod(Player player, ItemStack tool, boolean isCommand) {
	ItemMeta meta = tool.getItemMeta();

	if (meta != null) {
		meta.addEnchant(Enchantment.SWEEPING_EDGE, modManager.getModLevel(tool, this), true);

		tool.setItemMeta(meta);
	}

	return true;
}
 
Example #16
Source File: CustomItem.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
@Deprecated
public CustomItem(Material type, String name, int durability, List<String> lore) {
	super(new ItemStack(type));
	ItemMeta im = getItemMeta();
	im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
	im.setLore(lore);
	setItemMeta(im);
	setDurability((short) durability);
}
 
Example #17
Source File: CustomItem.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
static String getItemName(ItemStack item) {
	if (item != null) {
		ItemMeta meta = item.getItemMeta();
		if (meta != null) {
			if (meta instanceof BookMeta) {
				return ((BookMeta) meta).getTitle();
			} else {
				return meta.getDisplayName();
			}
		}
	}
	return null;
}
 
Example #18
Source File: Methods.java    From Crazy-Auctions with MIT License 5 votes vote down vote up
public static ItemStack makeItem(Material material, int amount, int type, String name) {
    ItemStack item = new ItemStack(material, amount, (short) type);
    ItemMeta m = item.getItemMeta();
    m.setDisplayName(color(name));
    item.setItemMeta(m);
    return item;
}
 
Example #19
Source File: Utils.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if the given item matches the specified attributes.
 * 
 * @param item
 *            the item
 * @param type
 *            The item type.
 * @param data
 *            The data value/durability. If -1 is is ignored.
 * @param displayName
 *            The displayName. If null or empty it is ignored.
 * @param lore
 *            The item lore. If null or empty it is ignored.
 * @return <code>true</code> if the item has similar attributes
 */
public static boolean isSimilar(ItemStack item, Material type, short data, String displayName, List<String> lore) {
	if (item == null) return false;
	if (item.getType() != type) return false;
	if (data != -1 && item.getDurability() != data) return false;

	ItemMeta itemMeta = null;
	// compare display name:
	if (displayName != null && !displayName.isEmpty()) {
		if (!item.hasItemMeta()) return false;
		itemMeta = item.getItemMeta();
		if (itemMeta == null) return false;

		if (!itemMeta.hasDisplayName() || !displayName.equals(itemMeta.getDisplayName())) {
			return false;
		}
	}

	// compare lore:
	if (lore != null && !lore.isEmpty()) {
		if (itemMeta == null) {
			if (!item.hasItemMeta()) return false;
			itemMeta = item.getItemMeta();
			if (itemMeta == null) return false;
		}

		if (!itemMeta.hasLore() || !lore.equals(itemMeta.getLore())) {
			return false;
		}
	}

	return true;
}
 
Example #20
Source File: Utils.java    From ShopChest with MIT License 5 votes vote down vote up
/**
 * Check if two items are similar to each other
 * @param itemStack1 The first item
 * @param itemStack2 The second item
 * @return {@code true} if the given items are similar or {@code false} if not
 */
public static boolean isItemSimilar(ItemStack itemStack1, ItemStack itemStack2) {
    if (itemStack1 == null || itemStack2 == null) {
        return false;
    }

    ItemMeta itemMeta1 = itemStack1.getItemMeta();
    ItemMeta itemMeta2 = itemStack2.getItemMeta();

    if (itemMeta1 instanceof BookMeta && itemMeta2 instanceof BookMeta) {
        BookMeta bookMeta1 = (BookMeta) itemStack1.getItemMeta();
        BookMeta bookMeta2 = (BookMeta) itemStack2.getItemMeta();

        if ((getMajorVersion() == 9 && getRevision() == 1) || getMajorVersion() == 8) {
            CustomBookMeta.Generation generation1 = CustomBookMeta.getGeneration(itemStack1);
            CustomBookMeta.Generation generation2 = CustomBookMeta.getGeneration(itemStack2);

            if (generation1 == null) CustomBookMeta.setGeneration(itemStack1, CustomBookMeta.Generation.ORIGINAL);
            if (generation2 == null) CustomBookMeta.setGeneration(itemStack2, CustomBookMeta.Generation.ORIGINAL);
        } else {
            if (bookMeta1.getGeneration() == null) bookMeta1.setGeneration(BookMeta.Generation.ORIGINAL);
            if (bookMeta2.getGeneration() == null) bookMeta2.setGeneration(BookMeta.Generation.ORIGINAL);
        }

        itemStack1.setItemMeta(bookMeta1);
        itemStack2.setItemMeta(bookMeta2);

        itemStack1 = decode(encode(itemStack1));
        itemStack2 = decode(encode(itemStack2));
    }

    return itemStack1.isSimilar(itemStack2);
}
 
Example #21
Source File: Tools.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Inventory getEnchantmentMenu(Player p, String name) {
    if (!p.isOp() && !p.hasPermission("ce.ench.*")) {
        Inventory lInv = getNextInventory(name);
        Inventory enchantments = Bukkit.createInventory(null, lInv.getSize(), lInv.getTitle());
        enchantments.setContents(lInv.getContents());
        for (int i = 0; i < enchantments.getSize() - 2; i++) {
            ItemStack checkItem = enchantments.getItem(i);
            if (checkItem == null || checkItem.getType().equals(Material.AIR))
                continue;
            ItemStack item = enchantments.getItem(i);
            ItemMeta im = item.getItemMeta();
            List<String> lore = new ArrayList<String>();
            if (im.hasLore())
                lore = im.getLore();
            for (CEnchantment ce : EnchantManager.getEnchantments()) {
                if (im.getDisplayName().equals(ce.getDisplayName()))
                    if (!checkPermission(ce, p)) {
                        lore.add(ChatColor.RED + "You are not permitted to use this");
                        break;
                    }
            }
            im.setLore(lore);
            item.setItemMeta(im);
            enchantments.setItem(i, item);
        }
        return enchantments;
    }

    return getNextInventory(name);
}
 
Example #22
Source File: ItemUtils.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets damage/durability of an item, or 0 if it does not have damage.
 * @param stack Item.
 * @return Damage.
 */
@SuppressWarnings("deprecation")
public static int getDamage(ItemStack stack) {
	if (damageMeta) {
		ItemMeta meta = stack.getItemMeta();
		if (meta instanceof Damageable)
			return ((Damageable) meta).getDamage();
		return 0; // Not damageable item
	} else {
		return stack.getDurability();
	}
}
 
Example #23
Source File: DataHandler.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
public static <T, Z> boolean hasTag(@NotNull ItemStack item, @NotNull String key, PersistentDataType<T, Z> dataType, boolean useMinecraft) {
    ItemMeta meta = item.getItemMeta();
    if (meta == null) return false;
    PersistentDataContainer container = meta.getPersistentDataContainer();

    return container.has((useMinecraft ? NamespacedKey.minecraft(key) : new NamespacedKey(MineTinker.getPlugin(), key)), dataType);
}
 
Example #24
Source File: Announcer.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates the buttons to group changes.
 */
public void updateButtons() {
    int groupCount = 0;

    buttons = new ArrayList<>(dGroups.size());
    do {
        String name = ChatColor.DARK_GRAY + "EMPTY GROUP";
        int playerCount = 0;
        List<String> lore = new ArrayList<>();

        DGroup dGroup = dGroups.get(groupCount);
        if (!plugin.getGroupCache().contains(dGroup)) {
            dGroups.set(groupCount, null);

        } else if (dGroup != null) {
            name = ChatColor.AQUA + dGroup.getName();
            playerCount = dGroup.getMembers().size();
            for (Player player : dGroup.getMembers().getOnlinePlayers()) {
                lore.add((dGroup.getLeader().equals(player) ? ChatColor.GOLD : ChatColor.GRAY) + player.getName());
            }
        }

        boolean full = playerCount >= maxPlayersPerGroup;

        Color color = plugin.getMainConfig().getGroupColorPriority(groupCount);
        ItemStack button = color.getWoolMaterial().toItemStack();
        ItemMeta meta = button.getItemMeta();
        meta.setDisplayName(name + (full ? ChatColor.DARK_RED : ChatColor.GREEN) + " [" + playerCount + "/" + maxPlayersPerGroup + "]");
        meta.setLore(lore);
        button.setItemMeta(meta);
        buttons.add(button);

        groupCount++;
    } while (groupCount != maxGroupsPerGame);
}
 
Example #25
Source File: ExhibitionFrame.java    From NyaaUtils with MIT License 5 votes vote down vote up
private void encodeItem() {
    if (frame == null) return;
    if (baseItem == null || baseItem.getType() == AIR) return;
    if (!itemSet) {
        frame.setItem(baseItem.clone());
        return;
    }
    if (descriptions == null) descriptions = new ArrayList<>();
    if (ownerUUID == null) ownerUUID = "";
    if (ownerName == null) ownerName = "";
    List<String> metaList = new ArrayList<>();
    metaList.add(MAGIC_TITLE + Integer.toString(3 + descriptions.size()));
    metaList.add(ownerUUID);
    metaList.add(ownerName);
    for (String line : descriptions) {
        metaList.add(base64(line));
    }
    metaList.add(MAGIC_TITLE);

    ItemStack item = baseItem.clone();
    ItemMeta meta = item.getItemMeta();
    if (meta.hasLore()) {
        metaList.addAll(meta.getLore());
    }
    meta.setLore(metaList);
    item.setItemMeta(meta);
    frame.setItem(item);
}
 
Example #26
Source File: DataHandler.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
public static <T, Z> void setTag(@NotNull ItemStack item, @NotNull String key, Z value, PersistentDataType<T, Z> dataType, boolean useMinecraft) {
    ItemMeta meta = item.getItemMeta();
    if (meta == null) return;

    PersistentDataContainer container = meta.getPersistentDataContainer();
    container.set((useMinecraft ? NamespacedKey.minecraft(key) : new NamespacedKey(MineTinker.getPlugin(), key)), dataType, value);
    item.setItemMeta(meta);
}
 
Example #27
Source File: PaginatedPane.java    From IF with The Unlicense 5 votes vote down vote up
/**
 * This method creates a list of ItemStacks all with the given {@code material} and the display names.
 * After that it calls {@link #populateWithItemStacks(List)}
 * This method also translates the color char {@code &} for all names.
 *
 * @param displayNames The display names for all the items
 * @param material The material to use for the {@link org.bukkit.inventory.ItemStack}s
 */
@Contract("null, _ -> fail")
public void populateWithNames(@NotNull List<String> displayNames, @Nullable Material material) {
	if(material == null || material == Material.AIR) return;

	populateWithItemStacks(displayNames.stream().map(name -> {
		ItemStack itemStack = new ItemStack(material);
		ItemMeta itemMeta = itemStack.getItemMeta();
		itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
		itemStack.setItemMeta(itemMeta);
		return itemStack;
	}).collect(Collectors.toList()));
}
 
Example #28
Source File: ItemParser.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void parseCustomNBT(Element el, ItemMeta meta) throws InvalidXMLException {
    super.parseCustomNBT(el, meta);

    Node.tryAttr(el, "projectile").ifPresent(rethrowConsumer(node -> {
        fdc.reference(node, ProjectileDefinition.class);
        Projectiles.setProjectileId(meta, node.getValue());
    }));
}
 
Example #29
Source File: Thor.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@Override
protected ItemStack specialItem()
{
	ItemStack hammer  = KitUtils.addSoulbound(new ItemStack(Material.GOLD_AXE));			
	ItemMeta meta = hammer.getItemMeta();
	meta.setDisplayName(getSpecialItemName()+" "+ChatColor.GREEN+"READY");
	hammer.setItemMeta(meta);
	return hammer;
}
 
Example #30
Source File: JsonItemUtils.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
private static ItemMeta parseLore(ItemMeta meta, JsonArray jsonArray){
    Iterator<JsonElement> lines = jsonArray.iterator();
    List<String> lore = new ArrayList<>();
    while (lines.hasNext()){
        lore.add(ChatColor.translateAlternateColorCodes('&', lines.next().getAsString()));
    }
    meta.setLore(lore);
    return meta;
}