spigot-gillesm / RPGChest-Premium

The best configurable chest system
2 stars 0 forks source link

Question about 'Key' item stacks changing #18

Closed eccentricdevotion closed 4 years ago

eccentricdevotion commented 4 years ago

I develop a Spigot plugin called GameModeInventories (separate inventories per game mode) - https://dev.bukkit.org/projects/gamemodeinventories - a user has reported that key items from the RPGChest plugin become unusable after switching inventories.

I don't have access to the premium plugin, but have tested iron ingot item stacks that have all of the following:

Is there anything else special about these keys that I should be aware of to make them compatible with my plugin?

spigot-gillesm commented 4 years ago

Hello

The keys contain indeed these custom attributes you said. There shouldn’t be any other change on this items. If for some reason your fix isn’t working don’t hesitate to send me private messages via Discord

eccentricdevotion commented 4 years ago

Will see what my user reports, but in my testing GMI handles all the above attributes without issues in its current state, so no fix needed AFAIK.

spigot-gillesm commented 4 years ago

Hey! Sorry for the delay. I don't know if the problem persists but here is the code to get the ItemStack copy of a ContainerKey of RPGChest:

    public static ItemStack getKey(String name) {

        final YamlConfiguration items = RPGChest.fileManager.keys;

        if(!items.contains(name))
            return null;

        final ConfigurationSection itemSection = items.getConfigurationSection(name);

        final ItemStack item = new ItemStack(Material.valueOf(itemSection.getString("Material")));
        final ItemMeta itemMeta = item.getItemMeta();

        if(itemSection.contains("Displayed name"))
            itemMeta.setDisplayName(Common.colorize(itemSection.getString("Displayed name")));

        if(itemSection.contains("Lore")) {

            final List<String> configLore = itemSection.getStringList("Lore");
            final List<String> itemLore = new ArrayList<>();

            for(final String line : configLore)
                itemLore.add(Common.colorize(line));

            itemMeta.setLore(itemLore);

        }

        if(itemSection.getBoolean("Glowing")) {

            itemMeta.addEnchant(Enchantment.ARROW_DAMAGE, 1, true);
            itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);

        }

        if(itemSection.contains("Flags"))
            for(final String flagName : itemSection.getStringList("Flags"))
                if(ItemManager.validFlags.contains(flagName))
                    itemMeta.addItemFlags(ItemFlag.valueOf(flagName));

        item.setItemMeta(itemMeta);

        return item;

    }
eccentricdevotion commented 4 years ago

Thanks for the code, it basically the same as I was testing with. I haven't heard back from the original reporter, so they either don't really care, or it's not actually a GMI issue. Feel free to close this ticket, if it is ever resolved on my end I'll let you know what the solution was.

spigot-gillesm commented 4 years ago

Alright thank you!

eccentricdevotion commented 4 years ago

Turned out to not be my plugin, but when you use a chat color formatting character to add an empty line in the key lore - such as §0 - it gets stripped out when using the pick block (middle mouse) button in an inventory, making the key invalid. diff Possibly caused by this plugin: https://www.spigotmc.org/resources/creative-nbt-copy-control.13598/, but I think it's probably a Minecraft / Spigot behaviour...