Block List Instances

Discussion in 'Plugin Development' started by Ironraptor3, Mar 16, 2014.

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

    Ironraptor3

    Hey all! I'm on the last bug of my first plugin (WOOT). Quick question. My moves were all working fine, until i discovered a major bug that happened if two ppl used the move at once. I fixed it, but now something weird happens with all the moves (its a pvp based plugin) that alter blocks. Usually i make a list of changed blocks, then set them back to what they were at the end of the move. This worked until i used instances of moves.

    This spams a null pointer exception until I restart the server:
    Code:java
    1. public static ConcurrentHashMap<String, ArrayList<Block>> changed = new ConcurrentHashMap<String, Block>();
    2.  
    3. //Stuff to add a players name to the actual move
    4.  
    5. ArrayList<Block> changeadd = changed.get(s); //s is the players name
    6. //more stuff
    7. changed.put(s, change add) //no problems here (yet)
    8.  
    9. //cancel logic
    10. for (Block b : changed.get(s)) { //andd here it is NullPointerExecepton's galore
    11. b.setType(Material.AIR);
    12. }
     
  2. Offline

    mrkirby153

  3. Offline

    Ironraptor3

    mrkirby153
    kk, its just, its in a lot of classes, that just everything that relates to the block list

    FullClass (one of them):
    Code:java
    1. public class ironpillar {
    2.  
    3. static int length = Main.plugin.getConfig().getInt("moveSettings.IronDragon.Basic.Length");
    4. static int damage = Main.plugin.getConfig().getInt("moveSettings.IronDragon.Basic.Damage");
    5. static double dragonforcemultiplier = Main.plugin.getConfig().getDouble("moveSettings.IronDragon.DragonForceMultiplier");
    6. static double knockback = Main.plugin.getConfig().getDouble("moveSettings.IronDragon.Basic.Knockback");
    7.  
    8. int MagicRequirement = Main.plugin.getConfig().getInt("MagicSettings.BasisUsage");
    9. HashMap<String, Float> magiclevel = Main.magiclevel;
    10.  
    11. public static ConcurrentHashMap<String, Integer> instances = new ConcurrentHashMap<String, Integer>();
    12. public static ConcurrentHashMap<String, BlockIterator> iterators = new ConcurrentHashMap<String, BlockIterator>();
    13. public static ConcurrentHashMap<String, ArrayList<Block>> changed = new ConcurrentHashMap<String, ArrayList<Block>>();
    14.  
    15. public static HashMap<String, Long> dragonforce = DragonForce.indragonforce;
    16.  
    17. public ironpillar(final Player player) {
    18. if (magiclevel.containsKey(player.getName()) && magiclevel.get(player.getName()) >= MagicRequirement && !instances.containsKey(player.getName())) {
    19. magiclevel.put(player.getName(), magiclevel.get(player.getName()) - MagicRequirement);
    20. BarAPI.displayBar(player, ChatColor.LIGHT_PURPLE + "Magic Level", magiclevel.get(player.getName()), 1220, true);
    21.  
    22. instances.put(player.getName(), 0);
    23. iterators.put(player.getName(), new BlockIterator(player.getWorld(), player.getEyeLocation().toVector(), player.getEyeLocation().getDirection(), 0, length));
    24. }
    25. }
    26.  
    27. public static void advance() {
    28.  
    29. for (String s : instances.keySet()) {
    30.  
    31. Player player = Bukkit.getServer().getPlayer(s);
    32. if (player == null || !player.isOnline()) {
    33. for (Block b : changed.get(s)) {
    34. b.setType(Material.AIR);
    35. b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.IRON_BLOCK);
    36. }
    37. changed.remove(s);
    38. iterators.remove(s);
    39. instances.remove(s);
    40. continue;
    41. }
    42.  
    43. int count = instances.get(s);
    44. ArrayList<Block> blocks = changed.get(s);
    45. instances.put(s, instances.get(s) + 1);
    46.  
    47. if (count >= length) {
    48. for (Block b : changed.get(s)) {
    49. b.setType(Material.AIR);
    50. player.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.IRON_BLOCK);
    51. }
    52. changed.remove(s);
    53. iterators.remove(s);
    54. instances.remove(s);
    55. continue;
    56. }
    57.  
    58. if (iterators.get(s).hasNext() && count < length) {
    59. Block change = iterators.get(s).next();
    60. if (change.getType() == Material.AIR) {
    61. if (count == 1) {
    62. player.getWorld().playEffect(change.getLocation(), Effect.STEP_SOUND, Material.IRON_BLOCK);
    63. blocks.add(change);
    64. changed.put(s, blocks);
    65. }
    66. if (count > 1) {
    67. change.setType(Material.IRON_BLOCK);
    68. }
    69. for (Entity e : player.getWorld().getEntities()) {
    70. if (e instanceof LivingEntity && e.getLocation().distanceSquared(change.getLocation()) <= 2 && e != player) {
    71. if (dragonforce.containsKey(s) && dragonforce.get(s) <= (System.currentTimeMillis() - (30*1000))) {
    72. ((LivingEntity) e).damage(damage * dragonforcemultiplier);
    73. e.setVelocity(e.getVelocity().add(e.getLocation().toVector().subtract(player.getLocation().toVector()).normalize().multiply(knockback * dragonforcemultiplier)));
    74. }
    75. else {
    76. ((LivingEntity) e).damage(damage);
    77. e.setVelocity(e.getVelocity().add(e.getLocation().toVector().subtract(player.getLocation().toVector()).normalize().multiply(knockback)));
    78. }
    79. }
    80. }
    81. }
    82.  
    83. }
    84. }
    85. }
    86. }


    StackTrace:

    Code:
    [15:31:39 WARN]: [Fairy_Tail] Task #9 for Fairy_Tail v1.0 generated an exception
    java.lang.NullPointerException
        at IronMoves.ironpillar.advance(ironpillar.java:68) ~[?:?]
        at me.Ironraptor3.FairyTail.Main$2.run(Main.java:344) ~[?:?]
        at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftTask.run(CraftTask.java:53) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:587) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Thanks :3
     
  4. Offline

    mrkirby153

    Ironraptor3

    Either your stack trace is not the latest or your provided code is not. The stack trace is saying Line 68 but on line 68, there is a "}" which cannot throw an error
     
Thread Status:
Not open for further replies.

Share This Page