Weird Error! Please help! Generates through a task that runs each second.

Discussion in 'Plugin Development' started by TheWolfBadger, Jun 10, 2014.

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

    TheWolfBadger

    Error:
    Code:java
    1. 10.06 15:49:31 [Server] INFO java.lang.NullPointerException
    2. 10.06 15:49:31 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    3. 10.06 15:49:30 [Server] INFO java.lang.NullPointerException
    4. 10.06 15:49:30 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    5. 10.06 15:49:29 [Server] INFO java.lang.NullPointerException
    6. 10.06 15:49:29 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    7. 10.06 15:49:28 [Server] INFO java.lang.NullPointerException
    8. 10.06 15:49:28 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    9. 10.06 15:49:27 [Server] INFO java.lang.NullPointerException
    10. 10.06 15:49:27 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    11. 10.06 15:49:26 [Server] INFO java.lang.NullPointerException
    12. 10.06 15:49:26 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    13. 10.06 15:49:25 [Server] INFO java.lang.NullPointerException
    14. 10.06 15:49:25 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    15. 10.06 15:49:24 [Server] INFO java.lang.NullPointerException
    16. 10.06 15:49:24 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    17. 10.06 15:49:23 [Server] INFO java.lang.NullPointerException
    18. 10.06 15:49:23 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    19. 10.06 15:49:22 [Server] INFO java.lang.NullPointerException
    20. 10.06 15:49:22 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    21. 10.06 15:49:21 [Server] INFO java.lang.NullPointerException
    22. 10.06 15:49:21 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    23. 10.06 15:49:20 [Server] INFO java.lang.NullPointerException
    24. 10.06 15:49:20 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    25. 10.06 15:49:19 [Server] INFO java.lang.NullPointerException
    26. 10.06 15:49:19 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    27. 10.06 15:49:18 [Server] INFO java.lang.NullPointerException
    28. 10.06 15:49:18 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    29. 10.06 15:49:17 [Server] INFO java.lang.NullPointerException
    30. 10.06 15:49:17 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    31. 10.06 15:49:16 [Server] INFO java.lang.NullPointerException
    32. 10.06 15:49:16 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    33. 10.06 15:49:15 [Server] INFO java.lang.NullPointerException
    34. 10.06 15:49:15 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception
    35. 10.06 15:49:14 [Server] INFO java.lang.NullPointerException
    36. 10.06 15:49:14 [Server] WARN Task #269797 for Anti-Teaming v1.0 generated an exception

    This error stops the plugin from working properly and it does not label what is causing it. Please help me to solve it. Thank you. - Jack
    Main:
    Code:java
    1. package com.core.wolfbadger.antiTeaming;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.configuration.file.FileConfiguration;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.entity.Entity;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    10. import org.bukkit.event.entity.PlayerDeathEvent;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12. import org.bukkit.scheduler.BukkitRunnable;
    13.  
    14. import java.util.HashMap;
    15. import java.util.UUID;
    16.  
    17. /**
    18. * Created with IntelliJ IDEA.
    19. * User: MayoDwarf
    20. * Date: 6/8/14
    21. * Time: 8:40 AM
    22. * To change this template use File | Settings | File Templates.
    23. */
    24. public class Main extends JavaPlugin implements Listener {
    25. API api;
    26. private FileConfiguration config;
    27. public HashMap<UUID, UUID> versing = new HashMap<UUID, UUID>();
    28. public void onEnable() {
    29. api = new API(this);
    30. getConfig().options().copyDefaults(true);
    31. saveDefaultConfig();
    32. this.getServer().getPluginManager().registerEvents(this, this);
    33. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new BukkitRunnable() {
    34. @Override
    35. public void run() {
    36. if(api.inMatch.size() >= 2 && versing.size() >= 2) {
    37. for(UUID ids : api.inMatch) {
    38. for(Player players : Bukkit.getOnlinePlayers()) {
    39. Player p = Bukkit.getPlayer(ids);
    40. if(api.inMatch.contains(p.getUniqueId())) {
    41. if(!p.getUniqueId().equals(players.getUniqueId()) && !versing.get(p.getUniqueId()).equals(players.getUniqueId())) {
    42. p.hidePlayer(players);
    43. UUID id = versing.get(p.getUniqueId());
    44. Player p2 = Bukkit.getPlayer(id);
    45. p2.hidePlayer(players);
    46. players.hidePlayer(p2);
    47. players.hidePlayer(p);
    48. }
    49. }
    50. }
    51. }
    52. }
    53. }
    54. }, 0, 20);
    55. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new BukkitRunnable() {
    56. @Override
    57. public void run() {
    58. if(api.count.size() >= 1) {
    59. for(Player p : Bukkit.getOnlinePlayers()) {
    60. if(api.count.containsKey(p.getUniqueId())) {
    61. api.count.put(p.getUniqueId(), api.count.get(p.getUniqueId())-1);
    62. if(api.count.get(p.getUniqueId()) <= 0) {
    63. for(Player players : Bukkit.getOnlinePlayers()) {
    64. p.showPlayer(players);
    65. players.showPlayer(p);
    66. api.count.remove(p.getUniqueId());
    67. versing.remove(p.getUniqueId());
    68. api.inMatch.remove(p.getUniqueId());
    69. }
    70. }
    71. }
    72. }
    73. }
    74. }
    75. }, 0, 20);
    76. }
    77. public void onDisable() {}
    78. @EventHandler
    79. public void onFight(EntityDamageByEntityEvent evt) {
    80. Entity e = evt.getEntity();
    81. Entity damager = evt.getDamager();
    82. if(damager instanceof Player && e instanceof Player) {
    83. Player p1 = (Player) e;
    84. Player p2 = (Player) damager;
    85. api.setVersing(p1, p2);
    86. }
    87. }
    88. @EventHandler
    89. public void onDeath(PlayerDeathEvent evt) {
    90. Player p = evt.getEntity();
    91. if(versing.containsKey(p.getUniqueId())) {
    92. UUID s = versing.get(p.getUniqueId());
    93. Player p2 = Bukkit.getPlayer(s);
    94. versing.remove(p.getUniqueId());
    95. versing.remove(p2.getUniqueId());
    96. api.inMatch.remove(p.getUniqueId());
    97. api.inMatch.remove(p2.getUniqueId());
    98. api.count.remove(p.getUniqueId());
    99. api.count.remove(p2.getUniqueId());
    100. for(Player players : Bukkit.getOnlinePlayers()) {
    101. p.showPlayer(players);
    102. p2.showPlayer(players);
    103. players.showPlayer(p);
    104. players.showPlayer(p2);
    105. }
    106. }
    107. }
    108. }

    API:
    Code:java
    1. package com.core.wolfbadger.antiTeaming;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Player;
    5.  
    6. import java.util.HashMap;
    7. import java.util.HashSet;
    8. import java.util.UUID;
    9.  
    10. /**
    11. * Created with IntelliJ IDEA.
    12. * User: MayoDwarf
    13. * Date: 6/6/14
    14. * Time: 7:45 PM
    15. * To change this template use File | Settings | File Templates.
    16. */
    17. public class API {
    18. Main m;
    19. public API(Main m) {
    20. this.m = m;
    21. }
    22. public HashSet<UUID> inMatch = new HashSet<UUID>();
    23. public HashMap<UUID, Integer> count = new HashMap<UUID, Integer>();
    24. public void setVersing(Player starter, Player p) {
    25. m.versing.put(starter.getUniqueId(), p.getUniqueId());
    26. m.versing.put(p.getUniqueId(), starter.getUniqueId());
    27. inMatch.add(starter.getUniqueId());
    28. inMatch.add(p.getUniqueId());
    29. count.put(p.getUniqueId(), m.getConfig().getInt("Time"));
    30. count.put(starter.getUniqueId(), m.getConfig().getInt("Time"));
    31. if(!m.versing.containsKey(starter.getUniqueId())) {
    32. for(Player players : Bukkit.getOnlinePlayers()) {
    33. if(!players.getUniqueId().equals(starter.getUniqueId()) && !players.getUniqueId().equals(p.getUniqueId())) {
    34. starter.hidePlayer(players);
    35. players.hidePlayer(starter);
    36. players.hidePlayer(p);
    37. p.hidePlayer(players);
    38. }
    39. }
    40. }
    41. }
    42. }
    43.  
     
  2. Offline

    AmShaegar

    Although I'd like to help you with your problem a lot of other problems in your code make it really hard to understand whyt you are trying to do with it. The problem is obviously in one of the two run() methods. Try to disable one of them to check which one is it. Then print out everything in the erroneous run() method before you use it. Something like this:

    Code:
    System.out.println(api);
    System.out.println(api.count);
    if(api.count.size() >= 1) {
      for(Player p : Bukkit.getOnlinePlayers()) {
        System.out.println(p);
        if(api.count.containsKey(p.getUniqueId())) {
    Something will print "null". This is what causes your error.
     
Thread Status:
Not open for further replies.

Share This Page