How would I move item's persistent data to other item?

Discussion in 'Plugin Development' started by BasicallyIAmFox, Nov 26, 2022.

Thread Status:
Not open for further replies.
  1. Offline

    BasicallyIAmFox

    So, in a nutshell, I want item to change whenever player joins but save item's persistent data (except display name, lore and similar that accessible not just through getPersistentDataContainer()).
    My current code:
    Code:
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            event.getPlayer().updateInventory();
            event.getPlayer().getInventory().forEach(x -> {
                if (x == null)
                    return;
    
                String id = null;
                try {
                    id = x.getItemMeta().getPersistentDataContainer().get(ItemManager.ID_KEY, PersistentDataType.STRING);
                }
                catch (Exception ignored) {
                }
                if (ItemManager.items.containsKey(id)) {
                    int count = x.getAmount();
                    x = ItemManager.items.get(id).getStack().clone();
                    x.setAmount(count);
                }
            });
        }
    This code currently saves just item amount, which is nice and all, but I would still like to save item's persistent data (ie custom Enchantments or whatever custom data I'll put on those items)
     
  2. Offline

    timtower Administrator Administrator Moderator

    Save them in a FileConfiguration, even has a getItemstack method.
     
  3. Offline

    BasicallyIAmFox

    huh? how would i make/add a FileConfiguration thingy and save them there?
     
    Last edited: Nov 26, 2022
  4. Offline

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page