HashMaps not clearing?

Discussion in 'Plugin Development' started by Tommy Raids, Dec 22, 2014.

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

    Tommy Raids

    Title says it all :p
    My HashMaps aren't clearing on player kick/leave events.. Any ideas why?
    Code:
     
     plugin.ffalertcount.put(player.getName(), plugin.i);
                               plugin.i++;
                               Bukkit.broadcastMessage("test, adding 1 to player ;-;");
                               if(plugin.ffalertcount.containsValue(plugin.i) && plugin.i < 3 || plugin.i == 3){
                                  Bukkit.broadcastMessage("sucessfully checked, next step is a go ;3");
                                  plugin.autobanff.add(player.getName());
                                  Bukkit.broadcastMessage("hacker added to autoban list");
                               }
                               event.setCancelled(true);
                           }
                       }
                   
                   }
               }
               @EventHandler
               public void playerleave(PlayerQuitEvent event){
                   Player player = event.getPlayer();
                   this.playerDamageSpeed.remove(player);
                   plugin.autobanff.clear();
                   plugin.ffalertcount.clear();
                   plugin.ffalertcount.clear();
               }
                }
     
    Last edited: Dec 22, 2014
  2. Offline

    dmiller2400

    You will want to check first if your instance is properly returning to you your hash maps. Output to console your hash map. I am guessing your plugin instance is null or something of the like

    Edit: I see you are using your plugin instance above, so if those broadcast statement are working on the server, then it is not an issue of a null instance. I would broadcast on the death event to see if that is working first.

    If this is the first event you have used on the plugin, check that your events are registered like so in your main constructor in the main class
    Code:
    Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
    This is if all your code is contained in one class
     
    Last edited: Dec 22, 2014
  3. Offline

    DeadlyScone

    Your full code would be nice.
    are you sure the players are even getting added to the map in the first place? Any errors?
     
  4. Offline

    dmiller2400

    I second this
     
  5. Offline

    Tommy Raids

    Yes, they're being added. Everything works, it bans the player after 3 warnings, but just doesn't reset.
     
  6. Offline

    DeadlyScone

  7. Offline

    Tommy Raids

  8. Offline

    SuperOriginal

    soooooo.... It got cleared
     
  9. Offline

    DeadlyScone

  10. Offline

    SuperOriginal

    @DeadlyScone If the size is 0, it got cleared, so I don't see an issue.
     
  11. Offline

    DeadlyScone

    @SuperOriginal
    I understand that. Iam just confused on this guys concern.
     
    SuperOriginal likes this.
  12. Offline

    Tommy Raids

    Alright, everytime a Player receives a warning, he will get +1 added to the hashmap, once he gets 3, he will be added to an arraylist. In that arraylist, once you move you're autobanned. (That works)
    What I'm trying to do is when the player is kicked or leaves, it resets everything so when he joins back he'll have a fresh hashmap/arraylist. And then if that player gets 3 more alerts, he will be autobanned, and so on. That is the cycle, but only the first part works. :/
    @SuperOriginal
    @DeadlyScone
     
  13. Offline

    Skionz

    @Tommy Raids This will clear it for everyone. Just use Map#remove()
     
    SuperOriginal likes this.
  14. Offline

    SuperOriginal

    Why are you using an arraylist and move event:eek:? Just check the amount after you add 1.
     
Thread Status:
Not open for further replies.

Share This Page