1.8.8 Error with kits plugin

Discussion in 'Spigot Plugin Development' started by erikgamer07, Mar 6, 2020.

  1. Hello! As you have seen in the title, I'm currently making a kits plugin. I have 1 file for each kit. I execute this code when a arena starts:
    Code (Java):
        public static void giveKit(Player p, String kit) {

            YamlConfiguration config = Main.getInstance().getKitConfig(kit.replace("_", "").replace(" ", "_"));

            for(String item : config.getStringList("contents.")) {

                ItemStack mat = new ItemStack(Material.matchMaterial(item));

            if(item.contains("helmet")) {
                p.getInventory().setHelmet(mat);
            } else if(item.contains("chestplate")) {
                p.getInventory().setChestplate(mat);
            } else if(item.contains("leggings")) {
                p.getInventory().setLeggings(mat);
            } else if(item.contains("boots")) {
                p.getInventory().setBoots(mat);
            } else {

                p.getInventory().addItem(mat);

            }

        }
    }
    The yml file:
    Code (YAML):
    contents:
    - diamond_chestplate
    - golden_apple
    material
    : bread
    price
    : 100
     
    I have made many debugs to see if the config that the method "getKitConfig" gives me the correct file and debugs everywhere, no Works. I don't know why this isn't working... Can you help me?

    Thanks!
     
  2. As far as i know for config items isnt it supposed to be Material.valueOf(String)? and the types sohuld be written in capital letters
     
  3. First: No, I have many plugins using matchMaterial(String).
    Second: No, all Works well in my other plugins using it. And the debugs inside the for loop of the string list doesn't send anything. Looks like the contents stringlist is empty.
     
  4. First off using,

    This inst the right way of doing this. Just because " It works " doesn't mean you should do it like that. I'm not even sure if its even going to return the string back for you.

    Using
    Is what you should be doing. As well you should do item.toUpprecase();

    I don't know what problem your having. Players not getting items? Player getting some items? config returns nul? Item returns null? IllegalException?
     
    • Agree Agree x 1
  5. No errors in console, player don't gets any item because seems like the config is empty but in the file isn't.
     
  6. Have you tried troubleshooting?

    Send the player a message with the contents of each variable after they are set. So, something like:

    Code (Java):

        public static void giveKit(Player p, String kit) {

    p.sendMessage(kit)

            YamlConfiguration config = Main.getInstance().getKitConfig(kit.replace("_", "").replace(" ", "_"));

    p.sendMessage(config path)

            for(String item : config.getStringList("contents.")) {

    p.sendMessage(item)

                ItemStack mat = new ItemStack(Material.matchMaterial(item));

            if(item.contains("helmet")) {
                p.getInventory().setHelmet(mat);
            } else if(item.contains("chestplate")) {
                p.getInventory().setChestplate(mat);
            } else if(item.contains("leggings")) {
                p.getInventory().setLeggings(mat);
            } else if(item.contains("boots")) {
                p.getInventory().setBoots(mat);
            } else {

                p.getInventory().addItem(mat);

            }

        }
    }