Help with error on my plugin

Discussion in 'Plugin Development' started by SantaClawz69, Jul 27, 2015.

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

    SantaClawz69

    So I was making a plugin that gave you armour and if you wore that armour it would give you a potion effect, simple right? But I'm getting a stack trace and I'm not so good with debugging my code because I rarely get bugs. (Not to be cocky but just I usually knew what I was doing but it's just now I'm getting one). In my code there are no errors and on start up there wasn't any errors just when typed in my command /legend it gave me and internal error, here's the stack trace:

    Code:
    [01:08:13 INFO]: SantaClawz69 issued server command: /legend
    [01:08:13 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'lege
    nd' in plugin Legendary_Armour v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spi
    got.jar:git-Spigot-f928e7a-e91aed8]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) ~[spigot.jar:git-Spigot-f928e7a-e91aed8]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServe
    r.java:642) ~[spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:1135) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
    :970) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :45) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :1) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:1
    3) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_45]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [spig
    ot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:7
    18) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
    67) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
    57) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
    :560) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.NullPointerException
            at me.Bryan.LegendaryArmour.Main.onCommand(Main.java:69) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spi
    got.jar:git-Spigot-f928e7a-e91aed8]
            ... 15 more
     
  2. Offline

    SuperSniper

    The error is on the line #69 inside the Main class.
     
  3. Offline

    Asc_Nicholas

    Can you show us what line 69 is?
     
  4. Offline

    SantaClawz69

    @Asc_Nicholas
    Code:
    lore.add(ChatColor.GREEN + "This is the helmet of Apollo Crest");
    Did I do something wrong here?
     
  5. Offline

    cfil360

    @SantaClawz69 lore has likely not been initialized yet. make sure you do
    Code:
    List<String> lore = new ArrayList<String>();
     
  6. Offline

    SantaClawz69

    I have initialized the lore this is what I put

    List<String> lore = AegisHelmMeta.getLore();

    @cfil360
    Here's my whole Main class. I made the plugin into 1 whole class because I was rushing this as fast as possible to get him a beta version out before the main one so here's the Main class:
    http://pastebin.com/ndMSkWx4

    It's pretty messy and such but I hope you can read it. I've just been numbering the lores differently.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  7. Offline

    cfil360

    @SantaClawz69 The lore is likely null. try creating a new one. Most objects don't have a lore by default.
     
  8. Offline

    SantaClawz69

    Okay, I'll try doing that now. Thanks for the help.

    @cfil360
    So I fixed my lore problem but it's saying that I have en error on line 96 which is
    player.getInventory().addItem(AegisChestPlate);
    Is this the wrong way to add a custom itemstack to a player?

    Code:
    [01:38:44 INFO]: SantaClawz69 issued server command: /legend aegis
    [01:38:44 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'lege
    nd' in plugin Legendary_Armour v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spi
    got.jar:git-Spigot-f928e7a-e91aed8]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) ~[spigot.jar:git-Spigot-f928e7a-e91aed8]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServe
    r.java:642) ~[spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:1135) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
    :970) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :45) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :1) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:1
    3) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_45]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [spig
    ot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:7
    18) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
    67) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
    57) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
    :560) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
            at me.Bryan.LegendaryArmour.Main.onCommand(Main.java:96) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spi
    got.jar:git-Spigot-f928e7a-e91aed8]
            ... 15 more
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  9. Offline

    cfil360

    @SantaClawz69 what is line 96. Your code has changed since you posted it.
     
  10. Offline

    SantaClawz69

    @cfil360 Mind you that my /legend command completely works but when I try using my arguments it doesn't work. Giving me the errors you see above.

    @cfil360 It's what I posted above
    player.getInventory().addItem(AegisChestPlate);

    @cfil360 The only things that changed in my code was me deleting my lores, I got fed up with them so I just deleted them and cut em out. Other than that nothing has changed.

    @cfil360 Hahah, nevermind I figured out the problem. In my code instead of args[0] I put args[1] xD

    Thanks for all the help though!!!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  11. Offline

    cfil360

    @SantaClawz69 Make sure you are accessing the argument like this.
    Code:
    args[0]
    This will give you the 1st argument. Trying args[1] Means it is trying to access the second argument.
     
  12. Offline

    SantaClawz69

    @cfil360 My plugin is actually not providing me with the display name I set in place for it as I use the command? Is there a reason why? It's not giving me any errors or anything just not giving me the display name and the potion effect

    @cfil360
    Nvm it is giving me an error. It says line 99: Here's my line 99

    if(player.getInventory().getChestplate().equals(AegisChestPlate)) {

    Code:
    [01:47:02 INFO]: SantaClawz69 issued server command: /legend aegis
    [01:47:02 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'lege
    nd' in plugin Legendary_Armour v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spi
    got.jar:git-Spigot-f928e7a-e91aed8]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) ~[spigot.jar:git-Spigot-f928e7a-e91aed8]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServe
    r.java:642) ~[spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:1135) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
    :970) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :45) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :1) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:1
    3) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_45]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [spig
    ot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:7
    18) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
    67) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
    57) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
    :560) [spigot.jar:git-Spigot-f928e7a-e91aed8]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.NullPointerException
            at me.Bryan.LegendaryArmour.Main.onCommand(Main.java:99) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spi
    got.jar:git-Spigot-f928e7a-e91aed8]
            ... 15 more
    [01:47:52 INFO]: SantaClawz69 has just earned the achievement [Taking Inventory]
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  13. Offline

    cfil360

    @SantaClawz69 You need to do more checks, especially null ones. The player likely doesn't have a chest late on, so there isn't one to compare.
     
  14. Offline

    SantaClawz69

    So would something like this fix my problem?

    Code:
    if(player.getInventory().getChestplate() != null)
    {
    }
    Would something like this work
     
  15. Offline

    cfil360

  16. Offline

    SantaClawz69

    @cfil360 Okay, I'm sorry for all the questions and concerns but now it's just giving me Iron armour, Gold armour and the potion effect but still no display name
     
  17. @SantaClawz69
    When you modify an item's ItemMeta you need to apply the ItemMeta to the itemstack for the values to show. Also, please follow java naming conventions :/.
     
    cfil360 likes this.
  18. Offline

    cfil360

    @SantaClawz69 Make sure you set the item's item-meta.

    Code:
    ItemStack sword = new ItemStack(Material.STONE_SWORD, 1);
    
    ItemMeta meta= sword.getItemMeta();
    
    meta.setDisplayName(ChatColor.RED + "Item");
    
    List<String> lore = new ArrayList<String>();
    lore.add(ChatColor.GREEN + "This item is cool");
    
    meta.setLore(lore);
    sword.setItemMeta(meta);
    pi.addItem(sword);
     
  19. Offline

    SantaClawz69

    @cfil360 Ah I see, but can you give me like an example about the null checking thing for my plugin? I really need to learn that xD
     
  20. Offline

    cfil360

    @SantaClawz69 just search the Internet about null checking. For example checking that the player has an item in hand before checking if the players item is the same as one you are testing for. When something is null most people will return and end the code there.
     
  21. Offline

    SantaClawz69

    @cfil360 Oh I got it, I fixed everything. Thanks for all the help mate. You seriously helped :)
     
Thread Status:
Not open for further replies.

Share This Page