Don't Know Error

Discussion in 'Plugin Development' started by FuZioN720, May 27, 2013.

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

    FuZioN720

    Hello i just made a event on Left_Click_Block but i'm getting an error. The error is when i hit a block with nothing in my hand. I have code so when i have specific item with a display it creates a double chest, this works. But when i try to hit the block without an item in my hand it gives an error. If i hit the ground with a shovel or something other then the specific item it works fine just when i hit the ground with nothing.

    Here is the error:
    Code:
    C:\Users\Timmy\Documents\Files\Local Host>java -Xms1024M -Xmx1024M -jar craftbuk
    kit.jar -o true
    229 recipes
    27 achievements
    17:27:34 [INFO] Starting minecraft server version 1.5.2
    17:27:34 [INFO] Loading properties
    17:27:34 [INFO] Default game type: CREATIVE
    17:27:34 [INFO] Generating keypair
    17:27:34 [INFO] Starting Minecraft server on *:25565
    17:27:34 [INFO] This server is running CraftBukkit version git-Bukkit-1.5.1-R0.2
    -14-g7d19b67-b2767jnks (MC: 1.5.2) (Implementing API version 1.5.2-R0.1-SNAPSHOT
    )
    17:27:34 [INFO] [BetterCast] Loading BetterCast v1.3
    17:27:34 [INFO] [UltimateRPG] Loading UltimateRPG v1.0
    17:27:34 [INFO] [ScoreboardMOTD] Loading ScoreboardMOTD v1.0
    17:27:34 [INFO] [RpgFriends] Loading RpgFriends v1.0
    17:27:34 [INFO] Preparing level "world"
    17:27:35 [INFO] Preparing start region for level 0 (Seed: -2819586645922029152)
    17:27:35 [INFO] ----- Bukkit Auto Updater -----
    17:27:35 [INFO] It appears that you're running a Development Build, when you've
    specified in bukkit.yml that you prefer to run Recommended Builds.
    17:27:35 [INFO] If you would like to be kept informed about new Development Buil
    d releases, it is recommended that you change 'preferred-channel' in your bukkit
    .yml to 'dev'.
    17:27:35 [INFO] With that set, you will be told whenever a new version is availa
    ble for download, so that you can always keep up to date and secure with the lat
    est fixes.
    17:27:35 [INFO] If you would like to disable this warning, simply set 'suggest-c
    hannels' to false in bukkit.yml.
    17:27:35 [INFO] ----- ------------------- -----
    17:27:36 [INFO] Preparing spawn area: 91%
    17:27:36 [INFO] Preparing start region for level 1 (Seed: -2819586645922029152)
    17:27:36 [INFO] [BetterCast] Enabling BetterCast v1.3
    17:27:36 [INFO] [BetterCast] Enabled!
    17:27:36 [INFO] [UltimateRPG] Enabling UltimateRPG v1.0
    17:27:36 [INFO] Plugin enabled.
    17:27:36 [INFO] [ScoreboardMOTD] Enabling ScoreboardMOTD v1.0
    17:27:36 [INFO] [ScoreBoard MOTD] Enabled!
    17:27:36 [INFO] [RpgFriends] Enabling RpgFriends v1.0
    17:27:36 [INFO] [RpgFriends] Rpg Friends has been enabled!
    17:27:36 [INFO] Server permissions file permissions.yml is empty, ignoring it
    17:27:36 [INFO] Done (1.851s)! For help, type "help" or "?"
    17:27:36 [INFO] Starting GS4 status listener
    17:27:36 [INFO] Starting remote control listener
    17:27:36 [INFO] Query running on 0.0.0.0:25565
    17:27:36 [WARNING] No rcon password set in 'C:\Users\Timmy\Documents\Files\Local
    Host\server.properties', rcon disabled!
    17:27:42 [INFO] xXFuZioN360Xx[/127.0.0.1:63509] logged in with entity id 191 at
    ([world] 301.4507849689614, 63.0, -181.04911382764018)
    17:27:51 [SEVERE] Could not pass event PlayerInteractEvent to UltimateRPG v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:427)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:186)
            at net.minecraft.server.v1_5_R3.PlayerInteractManager.dig(PlayerInteract
    Manager.java:108)
            at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java
    :541)
            at net.minecraft.server.v1_5_R3.Packet14BlockDig.handle(SourceFile:46)
            at net.minecraft.server.v1_5_R3.NetworkManager.b(NetworkManager.java:292
    )
            at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java
    :109)
            at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
            at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:5
    81)
            at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:2
    26)
            at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:4
    77)
            at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java
    :410)
            at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:5
    73)
    Caused by: java.lang.NullPointerException
            at plugins.xxfuzion360xx.UltimateRPG.UltimateRPG.onPlayerInteract(Ultima
    teRPG.java:487)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:425)
            ... 16 more
    >
    Here is where it is in the code:
    Code:java
    1.  
    2. if ((event.getAction() == Action.LEFT_CLICK_BLOCK) &&
    3.  


    here is that whole if statement:
    Code:java
    1.  
    2. if ((event.getAction() == Action.LEFT_CLICK_BLOCK) &&
    3. (player.getItemInHand().getItemMeta().hasDisplayName()) &&
    4. (player.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.DARK_PURPLE + "" + ChatColor.BOLD +"Hearthstone"))) {
    5. event.getClickedBlock().getLocation().add(0,1,0).getBlock().setType(Material.CHEST);
    6. event.getClickedBlock().getLocation().add(1,1,0).getBlock().setType(Material.CHEST);
    7. player.sendMessage(ChatColor.GREEN + "Shop Created!");
    8. event.setCancelled(true);
    9. }
    10.  


    here is the whole event:
    Code:java
    1.  
    2. @SuppressWarnings({ "unchecked", "deprecation" })
    3. @EventHandler(priority=EventPriority.LOW)
    4. public void onPlayerInteract(PlayerInteractEvent event)
    5. {
    6. Player player = event.getPlayer();
    7.  
    8. if ((event.getAction() == Action.RIGHT_CLICK_AIR) &&
    9. (player.getItemInHand().getItemMeta().hasDisplayName()) &&
    10. (player.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.DARK_PURPLE + "" + ChatColor.BOLD +"Hearthstone"))) {
    11. try {
    12. player.teleport(getHearthstone(player));
    13. player.sendMessage("You have been teleported to your Hearthstone's location.");
    14. } catch (Exception e) {
    15. player.sendMessage("You might not have set your Hearthstone location.");
    16. }
    17.  
    18. }
    19.  
    20. if ((player.getItemInHand() == null) &&
    21. (event.getAction() == Action.LEFT_CLICK_BLOCK)){
    22. event.setCancelled(true);
    23. return;
    24. }
    25.  
    26. if ((event.getAction() == Action.LEFT_CLICK_BLOCK) &&
    27. (player.getItemInHand().getItemMeta().hasDisplayName()) &&
    28. (player.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.DARK_PURPLE + "" + ChatColor.BOLD +"Hearthstone"))) {
    29. event.getClickedBlock().getLocation().add(0,1,0).getBlock().setType(Material.CHEST);
    30. event.getClickedBlock().getLocation().add(1,1,0).getBlock().setType(Material.CHEST);
    31. player.sendMessage(ChatColor.GREEN + "Shop Created!");
    32. event.setCancelled(true);
    33. }
    34.  
    35. if (event.getClickedBlock() == null) return;
    36. Block block = event.getClickedBlock();
    37.  
    38. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    39. if (block.getType() == Material.ENDER_CHEST) {
    40. player.sendMessage("Bank chest opened.");
    41. int s = 0;
    42.  
    43. event.setCancelled(true);
    44. Inventory inv = Bukkit.createInventory(player, getConfig().getInt("Options.default-bankslots"), player.getName() + "'s Bank");
    45. if (getConfig().isSet("Players." + event.getPlayer().getName() + ".bankinv")) {
    46. for (@SuppressWarnings("unused") ItemStack i : inv.getContents()) {
    47. if (getConfig().getString("Players." + event.getPlayer().getName() + ".bankinv.slot" + s) != "nothing") {
    48. String[] d = getConfig().getString("Players." + event.getPlayer().getName() + ".bankinv.slot" + s).split(",");
    49. if (d[0].startsWith("Bank Cheque")) {
    50. ItemStack is = new ItemStack(Material.PAPER, Integer.parseInt(d[1]));
    51. ItemMeta im = is.getItemMeta();
    52. im.setDisplayName(d[0]);
    53. @SuppressWarnings("rawtypes")
    54. ArrayList lore = new ArrayList();
    55. lore.add(ChatColor.GOLD + "This can be cashed in for Gold");
    56. lore.add(ChatColor.GOLD + "by left clicking on a bank sign.");
    57. im.setLore(lore);
    58. is.setItemMeta(im);
    59. inv.setItem(s, is);
    60. } else {
    61. inv.setItem(s, returnItem(d[0], Integer.parseInt(d[1]), Short.parseShort(d[2])));
    62. }
    63. s++;
    64. }
    65. }
    66. }
    67. player.openInventory(inv);
    68. }
    69. if (block.getType() == Material.CHEST) {
    70. if (!getConfig().isSet("Players." + player.getName() + ".Looted")) {
    71. upd("Players." + player.getName() + ".Looted", "0,0,0,world_");
    72. }
    73. Chest chest = (Chest)block.getState();
    74. Inventory inv = chest.getInventory();
    75. Location loc = block.getLocation();
    76. String blockloc = loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + "," + loc.getWorld().getName();
    77. if (!getConfig().getString("Players." + player.getName() + ".Looted").contains(blockloc + "_")) {
    78. if (getConfig().isSet("Loot." + blockloc))
    79. for (String item : getConfig().getString("Loot." + blockloc).split(","))
    80. try {
    81. inv.addItem(new ItemStack[] { returnItem(item, 1, Short.parseShort("0")) });
    82. }
    83. catch (Exception localException1) {
    84. }
    85. else for (String item : getConfig().getString("Loot.defaultloot").split(","))
    86. try {
    87. inv.addItem(new ItemStack[] { returnItem(item, 1, Short.parseShort("0")) });
    88. }
    89. catch (Exception localException2)
    90. {
    91. } upd("Players." + player.getName() + ".Looted", getConfig().getString(new StringBuilder("Players.").append(player.getName()).append(".Looted").toString()) + blockloc + "_");
    92. }
    93. }
    94. if (block.getType() == Material.ANVIL) {
    95. event.setCancelled(true);
    96. if (money(player) >= getConfig().getInt("Options.Anvil.Price")) {
    97. rmoney(player, getConfig().getInt("Options.Anvil.Price"));
    98. player.getItemInHand().setDurability((short)(player.getItemInHand().getDurability() - getConfig().getInt("Options.Anvil.DuraToAdd")));
    99. player.sendMessage("Weapon durability increase by " + getConfig().getInt("Options.Anvil.DuraToAdd") + " for " + getConfig().getInt("Options.Anvil.Price") + " Gold.");
    100. } else {
    101. player.sendMessage("This weapon can't be fixed because you don't have enough Gold.");
    102. player.sendMessage("It costs " + getConfig().getInt("Options.Anvil.Price") + " Gold to repair.");
    103. }
    104. }
    105. if ((block.getType() == Material.WALL_SIGN) || (block.getType() == Material.SIGN_POST)) {
    106. Sign sign = (Sign)block.getState();
    107. if (sign.getLine(0).equalsIgnoreCase("[buy]")) {
    108. if (money(player) >= Integer.parseInt(sign.getLine(2)))
    109. try {
    110. rmoney(player, Integer.parseInt(sign.getLine(2)));
    111. player.getInventory().addItem(new ItemStack[] { returnItem(sign.getLine(1), 1, Short.parseShort("0")) });
    112. player.sendMessage("You bought " + sign.getLine(1) + " for " + sign.getLine(2) + " Gold.");
    113. } catch (Exception e) {
    114. player.sendMessage("There was problem trying to buy this item.");
    115. }
    116. else {
    117. player.sendMessage("You don't have enough to buy this item.");
    118. }
    119. }
    120. if (sign.getLine(0).equalsIgnoreCase("[hearthstone]")) {
    121. try {
    122. player.sendMessage("You set Hearthstone to " + sign.getLine(1) + ".");
    123. Location loc = player.getLocation();
    124. String loca = loc.getWorld().getName() + "," + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ();
    125. upd("Players." + player.getName() + ".hearthstone", loca);
    126. } catch (Exception e) {
    127. player.sendMessage("There was a problem setting your Hearthstone here.");
    128. }
    129. }
    130. if ((sign.getLine(0).equalsIgnoreCase("[bank]")) &&
    131. (sign.getLine(1).equalsIgnoreCase("bank cheque"))) {
    132. if (money(player) >= Integer.parseInt(sign.getLine(2))) {
    133. rmoney(player, Integer.parseInt(sign.getLine(2)));
    134. ItemStack is = new ItemStack(Material.PAPER, 1);
    135. ItemMeta im = is.getItemMeta();
    136. im.setDisplayName("Bank Cheque of " + sign.getLine(2) + " Gold");
    137. @SuppressWarnings("rawtypes")
    138. ArrayList lore = new ArrayList();
    139. lore.add(ChatColor.GOLD + "This can be cashed in for Gold");
    140. lore.add(ChatColor.GOLD + "by left clicking on a bank sign.");
    141. im.setLore(lore);
    142. is.setItemMeta(im);
    143. player.getInventory().addItem(new ItemStack[] { is });
    144. player.sendMessage("Bank Cheque created and stored in your inventory.");
    145. player.updateInventory();
    146. } else {
    147. player.sendMessage("You don't have " + sign.getLine(2) + " Gold, so you can't create a Cheque.");
    148. }
    149. }
    150. }
    151.  
    152. }
    153.  
    154. if ((event.getAction() == Action.LEFT_CLICK_BLOCK) && (
    155. (block.getType() == Material.WALL_SIGN) || (block.getType() == Material.SIGN_POST))) {
    156. Sign sign = (Sign)block.getState();
    157. if ((sign.getLine(0).equalsIgnoreCase("[bank]")) &&
    158. (sign.getLine(1).equalsIgnoreCase("bank cheque")) &&
    159. (player.getItemInHand() != null))
    160. try {
    161. if ((player.getItemInHand().getItemMeta().hasDisplayName()) &&
    162. (player.getItemInHand().getItemMeta().getDisplayName().startsWith("Bank Cheque"))) {
    163. String[] d = player.getItemInHand().getItemMeta().getDisplayName().split(" ");
    164. try {
    165. amoney(player, Integer.parseInt(d[3]));
    166. if (player.getItemInHand().getAmount() > 1)
    167. player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1);
    168. else {
    169. player.setItemInHand(new ItemStack(Material.AIR));
    170. }
    171. player.updateInventory();
    172. player.sendMessage("Thank you cashing this cheque.");
    173. } catch (Exception e) {
    174. player.sendMessage("There was an error trying to cash your cheque.");
    175. }
    176. }
    177. }
    178. catch (Exception localException3)
    179. {
    180. }
    181. }
    182. }
    183.  


    know one knows?

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

    Polaris29

    FuZioN720 It could be because you're using "player.getItemInHand().getItemMeta().hasDisplayName()" without checking to see if the item in hand is null or not.
    To fix this, you could try putting if (player.getItemInHand() != null) { } around that statement.
     
  3. Offline

    FuZioN720

    Polaris29 Thanks but it is still saying that there is an error on that same line.
     
  4. Offline

    Jamesthatguy

    Line 487. What is it?
     
  5. Offline

    ZeusAllMighty11

    Why are you using Try Catch blocks without catching?
     
  6. Offline

    FuZioN720

    Jamesthatguy line 487 is
    Code:java
    1. (player.getItemInHand().getItemMeta().hasDisplayName()) &&


    TheGreenGamerHD What do you mean Where do i do that?
     
  7. Offline

    ZeusAllMighty11

    line 178 is your catch
     
  8. Offline

    FuZioN720

    TheGreenGamerHD I am catching it fine that part of the code works its just the part were the error is something is null
     
  9. Offline

    ZeusAllMighty11

    If you don't catch anything don't bother using try catch
     
  10. Offline

    FuZioN720

    So your saying get rid of the try and catch where it catch's
    Code:java
    1. catch (Exception localException3)
     
  11. Offline

    Jamesthatguy

    Try putting the item in hand to an itemstack and phrase the statement like so
    Code:
    if ([itemstacknamehere].hasItemMeta() == true){
     
  12. Offline

    FuZioN720

    Jamesthatguy So you mean
    Code:
    if([ChatColor.DARK_PURPLE + "" + ChatColor.BOLD +"Hearthstone"].hasItemMeta() == true){
    or
    Code:
    if(Material.NETHER_STAR.hasItemMeta() == true){
     
  13. Offline

    Jamesthatguy

    No, I would recommend using an item stack for efficiency. For instance, when the event is triggered I would get item in hand and if the item is a nether star I would then cast it to an item stack that I will call "j" for example purposes. I would then to
    Code:
     if (j.hasItemMeta() == true){}
    None of the methods you purposed would work because your not casting it to anything. On the first one your technically saying if the chat color is dark purple and its contains "Hearthstone" string and has an itemmeta? You would only get errors. Similar problem with the second. Use my method.
     
    FuZioN720 likes this.
  14. Offline

    FuZioN720

    @jamesthathguy Ok so is this what you mean i now have this:
    Code:java
    1.  
    2. if ((event.getAction() == Action.RIGHT_CLICK_AIR)){
    3. ItemStack item = player.getItemInHand();
    4. if(item.getType().equals(Material.NETHER_STAR)){
    5. if (item.hasItemMeta() == true){
    6. if (item.getItemMeta().getDisplayName().equals(ChatColor.DARK_PURPLE + "" + ChatColor.BOLD +"Hearthstone")){
    7. //code
    8. }
    9. }
    10. }
    11.  


    Jamesthatguy Thanks now i fixed it.

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

Share This Page