Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Help' started by DevPazzo, Feb 14, 2020.
Easiest thing to do would be just write the whole ItemStack to the config, as it implements ConfigurationSerializable. So you could read/write it like:
ItemStack item = getConfig().getItemStack("myitem");
if (item == null) return;
That will save the item, its lore, enchants, everything.
ItemMeta also implements ConfigurationSerializable, so you can write it directly to the config. Just retrieve it as an Object with a generic "get" call to getConfig() then check to ensure it's an ItemMeta, then you can do whatever with it. I suppose that's extra steps that may be unnecessary, but I like to treat any external input as suspect.
Well, is the code in the graphic switcher.java? If so, it's saying the config isn't returning anything. I've never seen a getConfig call annotated like that (path: "lore"). I have to assume you are using something to make that work, as when I try it won't even compile but perhaps just for testing use a regular string in there, like getConfig().getStringList("lore"); Also why do you read the lore into a List then when it comes time to apply it, read the config again instead of the List you just made? That makes the List rather pointless.
Also this is not what writing ItemMeta to the config looks like anyway. You're still dealing with individual parts of a meta. What I mean is like:
ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
ItemMeta im = sword.getItemMeta();
im.setLore(new ArrayList<String>(Arrays.asList("This makes bacon quite well","Nice and sharp")));
im.addEnchant(Enchantment.DAMAGE_ALL, 50, true);
getConfig().set("pigsticker", im); <--- This saves the ItemMeta to the config, with all the settings
Object loadedMeta = getConfig().get("pigsticker"); <-- Load as object as there is no getItemMeta()
if (!(loadedMeta instanceof ItemMeta)) return; <-- Check if it's actually an ItemMeta
You could just do ItemMeta loadedMeta = (ItemMeta)getConfig().get("pigsticker"); but I don't like blind casts.