Help with lores (Probably a stupid question)

Discussion in 'Plugin Development' started by Saracen147, Apr 22, 2016.

Thread Status:
Not open for further replies.
  1. Hey there, I am creating a Custom Enchant plugin and all I need help with is when a player clicks a book on a item (all checks have been done) it adds a lore to the item WITHOUT removing any other the previous lores. This is the code I have right now for it:

    Code:
     
    ItemStack stack = e.getCurrentItem();
    
                        ItemMeta stackMeta = item.getItemMeta();
    
                        List<String> gettingLore = e.getCurrentItem().getItemMeta().getLore();
    
                         
    
                        oldLore = gettingLore.toString();
    
                         
    
                       
    
                    int size = e.getCurrentItem().getItemMeta().getLore().size();
    
                    e.getCurrentItem().getItemMeta().getLore().add(size,lore1);
    
    I get this error in console:
    Code:
    org.bukkit.event.EventException
    
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1710) [craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        at net.minecraft.server.v1_8_R3.PacketPlayInSetCreativeSlot.a(SourceFile:23) [craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        at net.minecraft.server.v1_8_R3.PacketPlayInSetCreativeSlot.a(SourceFile:9) [craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_65]
    
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_65]
    
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_65]
    
    Caused by: java.lang.NullPointerException
    
        at me.bradley.CE.Books.playerInventoryClick(Books.java:97) ~[?:?]
    
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_65]
    
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_65]
    
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_65]
    
        at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_65]
    
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[craftbukkit_server.jar:git-Bukkit-18fbb24]
    
        ... 15 more
    
    
    Thanks for your help!
     
  2. Offline

    mine-care

  3. Ok, I have tried this in many ways but none work. Can you push me in the right direction of what I need to try to do?

    EDIT: Furthermore I have read through your link and I have made sure that nothing is 'null' and that I have not tried to change anything that is null.
     
  4. Offline

    mcdorli

    Post the error line
     
  5. Offline

    Konato_K

    @Saracen147 If an item has no lore the lore returned by ItemMeta#getLore is null, you need to check first if the ItemMeta#hasLore
     
  6. List<String> lore = new ArrayList<String>();
    lore.add("Hi");

    ItemStack apple = new ItemStack(Material.APPLE);
    ItemMeta appleMeta = apple.getItemMeta();

    appleMeta.setLore(lore);
    apple.setItemMeta(appleMeta);


    The lore will be 'Hi' and if you want to add color, do:
    lore.add(ChatColor.(Color in Caps) + "Hi");
    or
    lore.add(ChatColor.translateAlternateColorcodes('&', "&(VALUE)Hi"));

    The default color is a italicized purple.
     
  7. Offline

    mine-care

Thread Status:
Not open for further replies.

Share This Page