Solved Storing/Getting ItemStack from config

Discussion in 'Spigot Plugin Development' started by Vhbob, Jan 13, 2018.

Thread Status:
Not open for further replies.
  1. Hello, I am trying to store and retrieve itemstacks from my config file, however it is not working :\ here is my code. Does anyone know whats wrong?

    setting the data:
    Code (Text):
    pl.getConfig().set("items." + slot + ".type", p.getItemInHand());
    retrieving the data:
    Code (Text):
    ItemStack item = pl.getConfig().getItemStack(pl.getConfig().getString("items." + string + ".type"));
    (the string is because it loops through all items in the config)
  2. Well what is the result in the config when you save it?
    Do you call pl.saveConfig() after calling set?
  3. Strahan


    Also, when your IDE tells you something is deprecated you should really look into it and learn the appropriate way to do things. In this case, that would be p.getInventory().getItemInMainHand().
  4. get item in main hand doesnt seem to show up as an option
    I am saving the config.
    Code (Text):
        world: world
        z: 316.56280468677363
        y: 64.0
        x: 274.3837795718901
        name: test
          ==: org.bukkit.inventory.ItemStack
          type: WOOD
          damage: 2
    is what it looks like, the other sections are for different purposes, the itemstack is just under type.
  5. Don't do pl.getConfig().getString() inside of the getItemStack method.
  6. Use serialize for store your itemstack in config
    Code (Text):
    ItemStack item = new ItemStack(Material.DIAMOND_HELMET, 1);
    getConfig().set("", item.serialize());
    item = ItemStack.deserialize(getConfig().getConfigurationSection("").getValues(true));
    // or
    item = getConfig().getItemStack("");
Thread Status:
Not open for further replies.

Share This Page