Problems With ItemLores

Discussion in 'Spigot Plugin Help' started by Karatechimp29, May 27, 2015.

  1. So i'm making a fairly advanced plugin, gui based, and i need to change the lore depending if the event is toggled or not:

    Here is my custominventory:

    Code (Text):
        ArrayList<String> disabled = new ArrayList<String>();
        ArrayList<String> enabled = new ArrayList<String>();

        private void openGUI(Player player)
        {
            Inventory inv = Bukkit.createInventory(null, 9, ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Gui-Options.Title")));

            ItemStack waterBreathing = new ItemStack(Material.POTION);
            ItemMeta waterBreathingMeta = waterBreathing.getItemMeta();
            disabled.add(ChatColor.DARK_GRAY+"Status: "+ChatColor.DARK_RED+"Disabled");
            waterBreathingMeta.setLore(disabled);
           
            waterBreathingMeta.setDisplayName(ChatColor.AQUA + "Water Breathing");
            waterBreathing.setItemMeta(waterBreathingMeta);


            inv.setItem(1, waterBreathing);

            player.openInventory(inv);
        }
    My Click Event:

    Code (Text):
        @EventHandler
        public void onClick(InventoryClickEvent ev)
        {
            if(ev.getInventory() != null)
            {
                if(ev.getInventory().getSize() == 9)
                {
                    if(ev.getInventory().getTitle().equals(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Gui-Options.Title"))));
                    {
                        ev.setCancelled(true);
                       
                        if(ev.getRawSlot() == 1)
                        {
                           
                        }
                    }
                }
            }
        }
    so where i have the "if(ev.getRawSlot() == 1)" i want a toggle like option. so if waterbreathing is off the lore should be
    Code (Text):
    ChatColor.DARK_GRAY+"Status: "+ChatColor.DARK_RED+"Disabled"
    and if waterbreathing is on the lore should be
    Code (Text):
    ChatColor.DARK_GRAY+"Status: "+ChatColor.GREEN+"Enabled"
    im not sure how to do this, any help would be great!!
     
  2. you may create another item, which has the disabled lore and just replace them if the player clicks in his inventory. You can also replace the lore if the player clicks on it.

    Create a Arraylist where the players, which have waterbreathing disabled and just check if the player opens the inventory if the List contains the player -> disabled Item if not -> enabled item.
     
  3. How might you suggest i do this? chuck me an example?

    cheers!
     
  4. sure :D
     
  5. that wont work for my setup as i have already defined what items in the gui i want and i dont want to touch my config any more. i just want a simple replace lore to enabled if the player has the waterbreathing effect and vice versa...
     
  6. Code (Java):
      @EventHandler
        public void onClick(InventoryClickEvent ev)
        {
            if(ev.getInventory() != null)
            {
                if(ev.getInventory().getSize() == 9)
                {
                    if(ev.getInventory().getTitle().equals(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Gui-Options.Title"))));
                    {
                        ev.setCancelled(true);
                       
                        if(ev.getRawSlot() == 1)
                        {
                           /* ItemMeta meta = <Item>.getItemMeta();
                                meta.setLore(<loreYouWantToSet>);
                                <Item>.setItemMeta(meta);*/

                        }
                    }
                }
            }
        }
     
  7. Ok I'll try that tomorrow morning. In all theory this will call my meta that I created above with the item stacks? And hopefully fix something I have not mentioned, when I open the gui on the command I have created for every time I open it the lore duplicates itself. So If I opened the gui 5 times I would get 5 of the same lore. Not sure why. Hoping this just calls my already created metas and by the looks of things I can scrap the array list..... Thanks a ton if this works, fingers crossed!
     
  8. ok so i tried what you provided and here is my result:

    Code (Text):
                            ItemMeta meta = waterBreathing.getItemMeta();
                            meta.setLore(ChatColor.DARK_GRAY+"Status: "+ChatColor.RED+"Disabled");
                            waterBreathing.setItemMeta(meta);
    every spot i write 'waterBreathing', as thats the itemstack name, i get errors saying that it cannot be resolved :(

    as well as saying that "setLore" is not applicable....

    any help would be great, THANKS!!!
     
  9. the Lore is an ArrayList ->
    Code (Java):

    ArrayList<String> lore = new ArrayList<>();
    lore.add(ChatColor.DARK_GRAY+"Status: "+ChatColor.RED+"Disabled");
    //now you can apply the lore to the itemStack
    ItemMeta meta = waterBreathing.getItemMeta();
    meta.setLore(lore);
    waterBreathing.setItemMeta(meta);