Help creating a list with ItemStacks

Discussion in 'Spigot Plugin Development' started by brandonlea, Nov 21, 2019.

  1. Hello, I wanted to know the best way to make a list of Tools and Armour thanks
  2. A list in code, or some sort of list in game that a player interacts with?
  3. That the players can intertact with
  4. You should create a List or a Set with Material as values
    then on player interact event check if player is holding
    itemstack with material in the list/set
    if set/list contains Material then cancel event
  5. I was going to do that but it's going to be messy lol
  6. Show us, than we can better help ya
  7. Code (Text):
    package com.brandonlea.Upgradeable.Utils;

    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;

    import java.util.ArrayList;

    public class getItems {

        private static ArrayList<ItemStack> tools = new ArrayList<>();
        private static ArrayList<ItemStack> armours = new ArrayList<>();

        public static void setTools() {
            tools.add(new ItemStack(Material.WOODEN_AXE));
            tools.add(new ItemStack(Material.WOODEN_HOE));
            tools.add(new ItemStack(Material.WOODEN_PICKAXE));
            tools.add(new ItemStack(Material.WOODEN_SHOVEL));
            tools.add(new ItemStack(Material.WOODEN_SWORD));
            tools.add(new ItemStack(Material.GOLDEN_AXE));
            tools.add(new ItemStack(Material.GOLDEN_HOE));
            tools.add(new ItemStack(Material.GOLDEN_PICKAXE));
            tools.add(new ItemStack(Material.GOLDEN_SHOVEL));
            tools.add(new ItemStack(Material.GOLDEN_SWORD));
            tools.add(new ItemStack(Material.IRON_AXE));
            tools.add(new ItemStack(Material.IRON_HOE));
            tools.add(new ItemStack(Material.IRON_PICKAXE));
            tools.add(new ItemStack(Material.IRON_SHOVEL));
            tools.add(new ItemStack(Material.IRON_SWORD));
            tools.add(new ItemStack(Material.DIAMOND_AXE));
            tools.add(new ItemStack(Material.DIAMOND_HOE));
            tools.add(new ItemStack(Material.DIAMOND_PICKAXE));
            tools.add(new ItemStack(Material.DIAMOND_SHOVEL));
            tools.add(new ItemStack(Material.DIAMOND_SWORD));
   = tools;

        public static void setArmours() {
            armours.add(new ItemStack(Material.LEATHER_HELMET));
            armours.add(new ItemStack(Material.LEATHER_CHESTPLATE));
            armours.add(new ItemStack(Material.LEATHER_LEGGINGS));
            armours.add(new ItemStack(Material.LEATHER_BOOTS));
            armours.add(new ItemStack(Material.GOLDEN_HELMET));
            armours.add(new ItemStack(Material.GOLDEN_CHESTPLATE));
            armours.add(new ItemStack(Material.GOLDEN_LEGGINGS));
            armours.add(new ItemStack(Material.GOLDEN_BOOTS));
            armours.add(new ItemStack(Material.IRON_HELMET));
            armours.add(new ItemStack(Material.IRON_CHESTPLATE));
            armours.add(new ItemStack(Material.IRON_LEGGINGS));
            armours.add(new ItemStack(Material.IRON_BOOTS));
            armours.add(new ItemStack(Material.DIAMOND_HELMET));
            armours.add(new ItemStack(Material.DIAMOND_CHESTPLATE));
            armours.add(new ItemStack(Material.DIAMOND_LEGGINGS));
            tools.add(new ItemStack(Material.DIAMOND_BOOTS));
            getItems.armours = armours;

        public static ArrayList<ItemStack> getArmours() {
            return armours;

        public static ArrayList<ItemStack> getTools() {
            return tools;
  8. Did not even seems messy. I think you can do it like that.
    • Like Like x 1
  9. You can shrink this using a for loop and enum - string conversion