[solved] Client crashing from NPE, plugin causing it?

Discussion in 'Plugin Development' started by ZeusAllMighty11, Sep 2, 2012.

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

    ZeusAllMighty11 Retired Staff

    I looked and tried diff things, I really can't find it..


    Code:java
    1.  
    2. package me.zeus.SaveDaVillagers;
    3.  
    4. import java.util.HashMap;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.entity.Arrow;
    9. import org.bukkit.entity.Entity;
    10. import org.bukkit.entity.HumanEntity;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.entity.Villager;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    16.  
    17. public class villagerListener implements Listener {
    18.  
    19. public final HashMap<String, Integer> violationLevel = new HashMap<String, Integer>();
    20.  
    21. @EventHandler
    22. public void onVillagerHit(final EntityDamageByEntityEvent e) {
    23. final Entity victim = e.getEntity();
    24. final Entity hitter = e.getDamager();
    25.  
    26. if (hitter instanceof Player) {
    27. if (victim instanceof Villager) {
    28. if (hitter instanceof Player) {
    29.  
    30.  
    31. e.setCancelled(true);
    32.  
    33. if (violationLevel.get(((HumanEntity) hitter).getName()) == null) {
    34. violationLevel.put(((HumanEntity) hitter).getName(), 0);
    35.  
    36. ((Player) hitter)
    37. .kickPlayer("You are not allowed to kill villagers! (hit) Next time, your violation level raises!");
    38.  
    39. System.out.print(violationLevel);
    40.  
    41. } else {
    42. violationLevel.put(((HumanEntity) hitter).getName(),
    43. violationLevel.get(((HumanEntity) hitter)
    44. .getName()) + 1);
    45.  
    46. ((Player) hitter)
    47. .kickPlayer("You are not allowed to kill villagers! (hit) "
    48. + "Violation Level: "
    49. + violationLevel.get(((HumanEntity) hitter)
    50. .getName()));
    51.  
    52. System.out.print(violationLevel);
    53.  
    54. }
    55.  
    56. Bukkit.broadcastMessage(ChatColor.GREEN + "[SDV] "
    57. + ChatColor.RED + "Player: " + ChatColor.AQUA
    58. + ((HumanEntity) hitter).getName() + ChatColor.RED
    59. + " has attemped to " + ChatColor.YELLOW + "hit"
    60. + ChatColor.RED + " a villager! \n" + ChatColor.GREEN
    61. + "[SDV] " + ChatColor.DARK_RED + "Violation Level: "
    62. + ChatColor.GOLD
    63. + violationLevel.get(((HumanEntity) hitter).getName()));
    64.  
    65. }
    66. }
    67. }
    68. }
    69.  
    70. @EventHandler
    71. public void onVillagerShot(final EntityDamageByEntityEvent event) {
    72. if (event.getEntity() instanceof Villager
    73. && event.getDamager() instanceof Arrow) {
    74. if (((Arrow) event.getDamager()).getShooter() instanceof Player) {
    75. final HumanEntity shooter = (HumanEntity) ((Arrow) event
    76. .getDamager()).getShooter();
    77. event.setCancelled(true);
    78.  
    79. if (violationLevel.get(shooter.getName()) == null) {
    80. violationLevel.put(shooter.getName(), 0);
    81.  
    82. ((Player) shooter)
    83. .kickPlayer("You are not allowed to kill villagers! (bow) Next time, your violation level raises!");
    84. System.out.print(violationLevel);
    85.  
    86. } else {
    87. violationLevel.put(shooter.getName(),
    88. violationLevel.get(shooter.getName()) + 1);
    89.  
    90. System.out.print(violationLevel);
    91.  
    92. ((Player) shooter)
    93. .kickPlayer("You are not allowed to kill villagers! (bow) Violation Level: "
    94. + violationLevel.get(shooter.getName()));
    95.  
    96. }
    97.  
    98. Bukkit.broadcastMessage(ChatColor.GREEN + "[SDV] "
    99. + ChatColor.RED + "Player: " + ChatColor.AQUA
    100. + shooter.getName() + ChatColor.RED
    101. + " has attemped to " + ChatColor.YELLOW + "shoot"
    102. + ChatColor.RED + " a villager! \n" + ChatColor.GREEN
    103. + "[SDV] " + ChatColor.DARK_RED + "Violation Level: "
    104. + ChatColor.GOLD
    105. + violationLevel.get(shooter.getName()));
    106.  
    107. }
    108. }
    109. }
    110. }
    111.  
     
  2. Offline

    the_merciless

    you have hitter instanceofplayer twice. remove the 1st one, not that that will cause the crash i just dont see the point in having it twice
     
  3. Offline

    ZeusAllMighty11 Retired Staff

    Still crashing when I hit a villager, then hit them again after I join the server again (because it kicks you for hitting them)
     
  4. Offline

    CorrieKay

    wait, something that crashes the client?

    Im totally interested.
     
    KeybordPiano459 likes this.
  5. Offline

    ZeusAllMighty11 Retired Staff

    Ok, take my code and register it it onEnable() then hit a villager to start the violation level, and hit them again to crash the client LOL.

    If I can find out what causes it, I can fix it and maybe make an evil plugin [creeper]

    It'd be nice to see what is wrong here... 0_o I seriously can not find it D;​

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

    Tirelessly

    It'd be nice to have a stacktrace, so someone can find it..
     
  7. Offline

    ZeusAllMighty11 Retired Staff

    There is no stacktrace in the console... And the client literally says "Caused by: NullPointerException" but no line numbers.

    PHP:
    ---- Minecraft Crash Report ----
    // Oops.
    Time9/2/12 8:17 PM
    Description
    Unexpected error
    java
    .lang.NullPointerException
    at dv
    .a(Unknown Source)
    at aga.a(Unknown Source)
    at ahn.if(Unknown Source)
    at dv.byte(Unknown Source)
    at dm.else(Unknown Source)
    at net.minecraft.client.Minecraft.eR(Unknown Source)
    at net.minecraft.client.Minecraft.eT(Unknown Source)
    at net.minecraft.client.Minecraft.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Relevant Details:
    Minecraft Version1.3.1
    Operating SystemWindows 7 (amd64version 6.1
    Java Version1.7.0Oracle Corporation
    Java VM VersionJava HotSpot(TM64-Bit Server VM (mixed mode), Oracle Corporation
    Memory478673368 bytes (456 MB) / 535363584 bytes (510 MBup to 954466304 bytes (910 MB)
    JVM Flags2 total; -Xms512m -Xmx1024m
    LWJGL2.4.2
    OpenGLAMD Radeon HD 6310 Graphics             GL version 4.1.10527 Compatibility Profile ContextATI Technologies Inc.
    Is ModdedProbably not
    TypeClient
    Texture PackSphax PureBDCraft  32x MC13.zip
    Profiler PositionN/(disabled)
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  8. Offline

    Sabersamus


    This is completely off topic, but,

    the server i play on, if you do /give [player] 1000000 10000000 it crashes their client and then throws an NPE (the server owner makes his own plugins, didnt check if(material == null) )
     
  9. Offline

    messageofdeath

    You do check if hitter is an instance of a player twice

    EDIT: Also when there already in the hashmap you add them again :p

    EDIT2: tried it. Its a client issue of being kicked many times...
     
  10. Offline

    ZeusAllMighty11 Retired Staff

    Why would it kick many times? It should only kick once?
     
  11. Offline

    escortkeel

    Both on villager hit and on villager shot are being called, causing the client to be kicked twice.
     
  12. Offline

    Hoolean Retired Staff

    So it is possible to crash the client? I have so got to make a plugin called BetterKicks that crashes the client instead of just kicking :cool::mad:
     
  13. Offline

    escortkeel

    Yeah, just call kick twice. :)
     
  14. Offline

    messageofdeath

    ZeusAllMighty11 escortkeel MrBluebear3

    I just hit the villager and it kicked me saying you violation level will increase. went back on and then it kicked me with violation level 1 then it just kept kicking over and over with a higher violation level
     
  15. Offline

    ZeusAllMighty11 Retired Staff

    I fixed my problem, with the violation. If you have 2 eventhandlers, and same event... nt good
     
Thread Status:
Not open for further replies.

Share This Page