Hashmap help

Discussion in 'Plugin Development' started by Gopaintman, Oct 5, 2013.

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

    Gopaintman

    Alright so I have this
    Code:java
    1. private HashMap<Player, Player> tag = new HashMap<Player, Player>();
    2.  
    3. @EventHandler
    4. public void onEntityDamage(EntityDamageByEntityEvent e){
    5. if(e.getEntity() instanceof Player && e.getDamager() instanceof Player){
    6. Player hit = (Player) e.getEntity();
    7. Player damager = (Player) e.getDamager();
    8. if(tag.get(hit) != null){
    9.  
    10. if(tag.get(hit).equals(damager)){
    11.  
    12. e.setCancelled(true);
    13. return;
    14.  
    15. }
    16. if(tag.get(hit).equals(hit)){
    17. tag.clear();
    18. return;
    19. }
    20.  
    21.  
    22. }
    23.  
    24. }
    25. }
    26.  
    27. @EventHandler
    28. public void onPlayerDeath(PlayerDeathEvent e) {
    29. if (e.getEntity().getKiller() instanceof Player) {
    30. tag.put(e.getEntity(), e.getEntity().getKiller());
    31. }
    32. }


    Basically if a player is killed by another one then they cannot be hit by their killer until they hit the killer. I got the killer cannot hit victim part down however the second part just isn't working. I've tried every combination with hit and damager and still isn't working. Any ideas?
     
  2. Offline

    adam753

    Shouldn't this be
    Code:
    if(tag.get(damager).equals(hit)){
    
    ? I can't imagine a player having hit themself.
     
  3. Offline

    Gopaintman

    Well I'm passing in hit to get the killer. As the .get method returns the value, and the passed in argument is the key for it.
     
  4. Offline

    adam753

    Oh you're right, my mistake.
     
Thread Status:
Not open for further replies.

Share This Page