Rewriting changing lores - PlayerClickEvent

Discussion in 'Spigot Plugin Development' started by SobkySK, May 9, 2015.

  1. Hi, I am trying to create some plugin. I have "MagicStick" When I Click right - Plugin Enable and it doing effect. But I want that it has "health" or "stamina" . I have in Config.yml set health. So I want that healt was in this iten as Lore for example: Uses: 10 And when I click lore change to 9 and after next click to 8 etc. How I do it?

    Here is video where is used this thing:
     
    #1 SobkySK, May 9, 2015
    Last edited: May 9, 2015
  2. @SobkyLuckSK assuming you have the ItemStack
    • Get the lore
    • Find which entry has the Uses
    • Remove the entry
    • Parse the uses
    • Subtract 1
    • Add a new uses entry
     
  3. I have this:
    Code (Text):
    String itemName = ChatColor.AQUA + "" +ChatColor.BOLD+"Magic Stick";
                            List<String> lores = new ArrayList<String>();
                            lores.add(ChatColor.GOLD+"Right "+ChatColor.DARK_RED+"-"+ChatColor.DARK_GREEN+" Enable/Disable");
                            lores.add(ChatColor.GOLD+"Left "+ChatColor.DARK_RED+"-"+ChatColor.DARK_GREEN+" Select effect");
                            lores.add(ChatColor.GOLD+"Uses "+ChatColor.DARK_RED+"-"+ChatColor.DARK_GREEN+" Here is Uses");
                            ItemStack myItem = new ItemStack(Material.STICK);
                            ItemMeta im = myItem.getItemMeta();
                            im.setDisplayName(itemName);
                            im.setLore(lores);
                            myItem.setItemMeta(im);
                            PlayerInventory inventory = player.getInventory();
                            inventory.addItem(myItem);
    But how i change it?