need help with null error.

Discussion in 'Plugin Development' started by SandKastle, Jul 6, 2013.

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

    SandKastle

    So my plugin, it adds new recipes and when someone doesnt have the right permission it sets the result to null. if the person tries to click the item again after the result is null it comes up with an error log, is there a work around this?

    Source:
    Code:java
    1. package me.sandkastle.craftablehorsearmor;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.Server;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.EventPriority;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.inventory.CraftItemEvent;
    11. import org.bukkit.inventory.ItemStack;
    12. import org.bukkit.inventory.ShapedRecipe;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class Main extends JavaPlugin implements Listener{
    16. public void onEnable(){
    17. Server server = getServer();
    18. getServer().getPluginManager().registerEvents(this, this);
    19.  
    20. ShapedRecipe iha = new ShapedRecipe(new ItemStack(417));
    21. iha.shape(new String[] { " I", "IBI", "III" });
    22. iha.setIngredient('I', Material.IRON_INGOT);
    23. iha.setIngredient('B', Material.WOOL, 15);
    24.  
    25. ShapedRecipe gha = new ShapedRecipe(new ItemStack(418));
    26. gha.shape(new String[] { " I", "IBI", "III" });
    27. gha.setIngredient('I', Material.GOLD_INGOT);
    28. gha.setIngredient('B', Material.WOOL, 14);
    29.  
    30. ShapedRecipe dha = new ShapedRecipe(new ItemStack(419));
    31. dha.shape(new String[] { " I", "IBI", "III" });
    32. dha.setIngredient('I', Material.DIAMOND);
    33. dha.setIngredient('B', Material.WOOL, 11);
    34.  
    35. ShapedRecipe saddle = new ShapedRecipe(new ItemStack(329));
    36. saddle.shape(new String[] { "III", "IBI" });
    37. saddle.setIngredient('I', Material.LEATHER);
    38. saddle.setIngredient('B', Material.IRON_INGOT);
    39.  
    40. ShapedRecipe tag = new ShapedRecipe(new ItemStack(421));
    41. tag.shape(new String[] { " I", " B ", "B " });
    42. tag.setIngredient('I', Material.STRING);
    43. tag.setIngredient('B', Material.PAPER);
    44.  
    45. server.addRecipe(iha);
    46. server.addRecipe(gha);
    47. server.addRecipe(dha);
    48. server.addRecipe(saddle);
    49. server.addRecipe(tag);
    50. }
    51.  
    52. @EventHandler(priority=EventPriority.HIGHEST)
    53. public void onItemEvent(CraftItemEvent e) {
    54. Player p = (Player)e.getView().getPlayer();
    55. if ((!p.hasPermission("cha.saddle")) && (e.getInventory().getResult().getTypeId() == 329)) {
    56. p.sendMessage(ChatColor.RED + "You don't have permission to craft a saddle!");
    57. e.getInventory().setResult(null);
    58. }
    59.  
    60. else if ((!p.hasPermission("cha.iha")) && (e.getInventory().getResult().getTypeId() == 417)) {
    61. p.sendMessage(ChatColor.RED + "You don't have permission to craft iron horse armor!");
    62. e.getInventory().setResult(null);
    63. }
    64.  
    65. else if ((!p.hasPermission("cha.gha")) && (e.getInventory().getResult().getTypeId() == 418)) {
    66. p.sendMessage(ChatColor.RED + "You don't have permission to craft gold horse armor!");
    67. e.getInventory().setResult(null);
    68. }
    69.  
    70. else if ((!p.hasPermission("cha.dha")) && (e.getInventory().getResult().getTypeId() == 419)) {
    71. p.sendMessage(ChatColor.RED + "You don't have permission to craft diamond horse armor!");
    72. e.getInventory().setResult(null);
    73. }
    74.  
    75. else if ((!p.hasPermission("cha.tag")) && (e.getInventory().getResult().getTypeId() == 421)) {
    76. p.sendMessage(ChatColor.RED + "You don't have permission to craft a nametag!");
    77. e.getInventory().setResult(null);
    78. }
    79. }
    80. }


    error:
    Code:java
    1. 23:17:40 [SEVERE] Could not pass event CraftItemEvent to CraftableHorseArmor v1.
    2. 1
    3. org.bukkit.event.EventException
    4. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    5. va:427)
    6. at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    7. a:62)
    8. at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    9. ava:477)
    10. at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    11. ava:462)
    12. at net.minecraft.server.v1_6_R1.PlayerConnection.a(PlayerConnection.java
    13. :1385)
    14. at net.minecraft.server.v1_6_R1.Packet102WindowClick.handle(SourceFile:3
    15. 1)
    16. at net.minecraft.server.v1_6_R1.NetworkManager.b(NetworkManager.java:293
    17. )
    18. at net.minecraft.server.v1_6_R1.PlayerConnection.d(PlayerConnection.java
    19. :118)
    20. at net.minecraft.server.v1_6_R1.ServerConnection.b(SourceFile:37)
    21. at net.minecraft.server.v1_6_R1.DedicatedServerConnection.b(SourceFile:3
    22. 0)
    23. at net.minecraft.server.v1_6_R1.MinecraftServer.t(MinecraftServer.java:5
    24. 90)
    25. at net.minecraft.server.v1_6_R1.DedicatedServer.t(DedicatedServer.java:2
    26. 26)
    27. at net.minecraft.server.v1_6_R1.MinecraftServer.s(MinecraftServer.java:4
    28. 86)
    29. at net.minecraft.server.v1_6_R1.MinecraftServer.run(MinecraftServer.java
    30. :419)
    31. at net.minecraft.server.v1_6_R1.ThreadServerApplication.run(SourceFile:5
    32. 82)
    33. Caused by: java.lang.NullPointerException
    34. at me.sandkastle.craftablehorsearmor.Main.onItemEvent(Main.java:55)
    35. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    36. at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    37. at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    38. at java.lang.reflect.Method.invoke(Unknown Source)
    39. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    40. va:425)
    41. ... 14 more
     
  2. Offline

    Minnymin3

    Don't double post.
     
  3. Offline

    Joeisi

    Yes the solution is to look at your original post and look at my workaround and try it.
     
  4. Offline

    SandKastle


    i saw, thank you :).
     
  5. Offline

    Joeisi

    So did it work?

    Edit to the below:

    Don't argue. It's double posting. We were already trying to solve it on the original thread.
     
  6. Offline

    SandKastle


    its not double posting, both errors are different, though this one came up later in the thread its still a different error.


    yes, i dont understand it all that much on how, but it will come to me sometime :3

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

    Minnymin3

    SandKastle
    You already posted the error in another thread and were getting help there. ∴ you double posted.
     
  8. Offline

    SandKastle


    well its to late now.
     
  9. Offline

    Compressions

    SandKastle The terms and conditions are here for a reason. Follow the rules.
     
    Minnymin3 and xTrollxDudex like this.
  10. Offline

    SandKastle

    If i tried to argue it wasnt double posting then i didnt think it was breaking the rules. You are keeping this thread alive after ive been already been told it was.
     
  11. Offline

    Compressions

    SandKastle So my reminder of the rules for you is bumping after posting it 5 minutes later?
     
  12. Offline

    SandKastle


    After ive already been reminded, it is.


    Trying to edit it after ive replied, sigh. But this was posted 25 minutes ago.

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

    Compressions

    SandKastle I beg to differ. You joined here Wednesday and need to learn the rules of the Bukkit Forums. I am reminding you to abide by the rules. Your argument is like a police officer telling citizens to buckle their seatbelt, and you decide that their advice is unimportant because the advice has been introduced before and renders no use.

    SandKastle Actually I edited it before I saw your reply.

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

    SandKastle


    actually i didnt join here 3 days, ago. This is a new account i made with the name im going to be used from now on. But what you just said, a seat belt is something that can be cahnged on the go it should be a headlight being out because you cant change it on the road, like this post i cant delete it now. So a police officer stops me and tells me my headlight is out, then 5 minutes later another officer tells me the exact same thing and i render it unimportant because i have already heard it and will change it later.


    EDIT: I actually joined november 2011
     
  15. Offline

    Compressions

    SandKastle Whatever metaphor will work for you. The point is, you responded with "We'll it's too late now". Lets bring that into the police officer dilemma lol...
     
  16. Offline

    Joeisi

    Stop arguing and let the thread die. This thread is too off topic.
     
  17. Offline

    SandKastle


    its in my nature to argue and i think its fun :3 but i guess i will.


    Police: YO DAWG WHO YOU THINK YOU IS? Well thats my last post on this thread, have a nice life.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page