Getting item details from config?

Discussion in 'Plugin Development' started by TheMinecraftKnight, Mar 11, 2017.

Thread Status:
Not open for further replies.
  1. I'm trying to make a GUI with customizable items in slots, it isn't really working.
    When running the command, this code runs to generate the GUI:
    Code:
        public void openGui(Player player) {
            for(int x = 0; x < 27; x++) {
                player.sendMessage(""+(short) config.getInt(x+".ItemData"));
                if(config.getConfigurationSection("Items.maingui").contains(String.valueOf(x))) {
                    mainItems = new ItemStack(Material.getMaterial(config.getString(x+".Material")),
                            1,
                            (short) config.getInt(x+".ItemData"));
                    createDisplay(mainItems, mainGui, x, config.getString(x+".Name"), config.getStringList(x+".Lore"));
                }
            }
            player.openInventory(mainGui);
        }
    The createDisplay method is from a tutorial.
    Apparently line 94: (short) config.getInt(x+".ItemData")); is a null pointer exception, despite it existing
    Here is my config file:
    Code:
    GuiTitle: '&6&lJobs GUI'
    AdminGuiTitle: '&c&lJobs Admin GUI'
    Items:
      maingui:
        2:
          Material: DIAMOND_SWORD
          ItemData: 0
          Name: '&3&lDiamond Sword'
          Lore:
             - 'This is a sword!'
             - 'Change me!'
    Any help?

    EDIT: FIXED
    I did a silly and only applied @timtower 's advice to the item data. Silly me :p
     
    Last edited: Mar 11, 2017
  2. Offline

    timtower Administrator Administrator Moderator

  3. Full path to what, and where?
    EDIT: Oh, I see what you mean. Thanks
    EDIT2: @timtower I'm using this now and it still isn't working :/
    (short) config.getInt("Items.maingui." + x + ".ItemData"))
    EDIT3:
    I've found the problem. It for some reason thinks that "ItemData: 0" in the config is a string, and so it can't find the number part. I tried getting the string and using Short.parseShort but it didn't work.
    Any ideas?
     
    Last edited: Mar 11, 2017
  4. Offline

    Zombie_Striker

    mine-care likes this.
Thread Status:
Not open for further replies.

Share This Page