Add lore to a repaired item

Discussion in 'Spigot Plugin Development' started by phsdsd, Jan 14, 2018.

  1. Hello,I am trying add lore to a repaired item, But I'm not getting any success, lore does not go in the item.


    Code (Text):
    @EventHandler
        public void onInventoryClick(InventoryClickEvent e){
           
            // check whether the event has been cancelled by another plugin
        HumanEntity ent = e.getWhoClicked();
         if (!ent.getName().equalsIgnoreCase("Hidrogeni0")) return;
        // not really necessary
        if(ent instanceof Player){
        Player player = (Player)ent;
        Inventory inv = e.getInventory();
       
        // see if we are talking about an anvil here
        if(inv instanceof AnvilInventory){
        AnvilInventory anvil = (AnvilInventory)inv;
        InventoryView view = e.getView();
        int rawSlot = e.getRawSlot();
       
        // compare raw slot to the inventory view to make sure we are in the upper inventory
        if(rawSlot == view.convertSlot(rawSlot)){
          // 2 = result slot
        if(rawSlot == 2){
          // all three items in the anvil inventory
        ItemStack[] items = anvil.getContents();
       
        // item in the left slot
        ItemStack item1 = items[0];
       
        // item in the right slot
        ItemStack item2 = items[1];
       
        // I do not know if this is necessary
        if(item1 != null && item2 != null){
        int id1 = item1.getTypeId();
        int id2 = item2.getTypeId();
       
        // if the player is repairing something the ids will be the same
        if(id1 != 0 && id1 == id2){
          // item in the result slot
        ItemStack item3 = e.getCurrentItem();
       
        // check if there is an item in the result slot
        if(item3 != null){
        ItemMeta meta = item3.getItemMeta();
       
        // meta data could be null
        if(meta != null){
          // get the repairable interface to obtain the repair cost
        if(meta instanceof Repairable){
        Repairable repairable = (Repairable)meta;
        repairable.setRepairCost(repairable.getRepairCost() * 10);
        int repairCost = repairable.getRepairCost();
        // can the player afford to repair the item
        if(player.getLevel() >= repairCost){
        // success
                ItemStack iitem = e.getCurrentItem();
                ItemMeta im = iitem.getItemMeta();
                List<String> lor2 = new ArrayList<>();
                lor2.add("Remaining repairs: 3");
                im.setLore(lor2);
                item3.setItemMeta(meta);
               
        }else{
        // bugger
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
     
  2. Code (Text):
                ItemStack iitem = e.getCurrentItem();
                ItemMeta im = iitem.getItemMeta();
                List<String> lor2 = new ArrayList<>();
                lor2.add("Remaining repairs: 3");
                im.setLore(lor2);
                item3.setItemMeta(meta);
    Should not be iitem.setItemMeta(im); ?
     

Share This Page