Adding lore to an item

Discussion in 'Plugin Development' started by Buoobuoo, Nov 24, 2018.

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

    Buoobuoo

    Hey guys, I have a simple enchant plugin, So basically i have a book where when the player presses it, it prompts a gui which then shows all the items that can be enchanted in their inventory, the player then clicks on the item and it will enchant their item.
    Code:
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked();
            ItemStack clicked = event.getCurrentItem();
            if (opened.contains(player)) {
                event.setCancelled(true);
                if (inv.get(player).contains("Items")) {
                    List<ItemStack> items = new ArrayList<ItemStack>();
                    for (int i = 0; i <= 35; i++) {
                        items.add(player.getInventory().getItem(i));
                    }
                    for (ItemStack i : items) {
                        if (i == null)
                            break;
                        if(i.hasItemMeta() && clicked.hasItemMeta()) {
                            if(i.getItemMeta().getLore() == clicked.getItemMeta().getLore())
                                enchantItem(i, ench.get(player));
                        }else if (i.getType() == clicked.getType()) {
                            enchantItem(i, ench.get(player));
                        }
                    }
                    player.closeInventory();
    
    So my problem is, since the player is interacting with a seperate inventory from their own, when they click on the item which is supposed to represent the one in their inventory, if i want to make changes to it there is no way of accessing the ACTUAL item in their inventory, I tried comparing meta etc, but since they are technically two seperate items, it will return false, Also if i am checking lore and enchants straight up it will not be precise as some players might have multiples of the same weapon with exact enchants, lore etc.
     
  2. @Buoobuoo

    You can use event.getSlot() to find out on what slot was clicked. You should print the values to check if the slot is the slot you are looking for. Then use player.getInventory().getItem with the correct slot number and modify that item.
     
Thread Status:
Not open for further replies.

Share This Page