Creating Kill Steaks

Discussion in 'Plugin Development' started by edm wasrevilosmith1999, Apr 28, 2014.

Thread Status:
Not open for further replies.
  1. I am trying to add killstreaks into my FFA plugin.
    I have an arraylist to store in game players called "players"
    and a Hashmap which stores a String and Integer (Player name and kills)
    Here is my code what am i doing wrong?
    Code:java
    1. @EventHandler
    2. public void onDeath(PlayerDeathEvent event){
    3.  
    4. Player player = event.getEntity();
    5.  
    6. if(players.contains(player.getName())){
    7.  
    8. event.getDrops().clear();
    9. event.setDeathMessage("");
    10.  
    11. Location death = player.getLocation();
    12. ItemStack goldenApple = new ItemStack(Material.GOLDEN_APPLE, 1);
    13.  
    14. death.getWorld().dropItemNaturally(death, goldenApple);
    15.  
    16. // Kill Streaks
    17.  
    18. if(kills.containsKey(player.getName())){
    19.  
    20. kills.remove(player.getName());
    21.  
    22. Player killer = player.getKiller();
    23.  
    24. kills.put(killer.getName(), kills.get(player.getName() + 1));
    25.  
    26. if(kills.get(killer.getName()) == 3){
    27.  
    28. ItemStack FlintAndSteel = new ItemStack(Material.FLINT_AND_STEEL, 1);
    29.  
    30. killer.getInventory().addItem(FlintAndSteel);
    31.  
    32. for(Player inGame : Bukkit.getOnlinePlayers()){
    33.  
    34. if(players.contains(inGame.getName())){
    35.  
    36. inGame.sendMessage(prefix + ChatColor.DARK_AQUA + killer.getName() + " is on a 3 kill streak!");
    37. }
    38. }
    39. }
    40.  
    41. }
    42. }
    43. }
     
  2. Offline

    adam753

    Took me a moment but:
    Code:
    kills.put(killer.getName(), kills.get(player.getName() + 1));
    Should be
    Code:
    kills.put(killer.getName(), kills.get(player.getName()) + 1);
     
    AoH_Ruthless likes this.
  3. Ah xD such a small mistake let me test!

    I did that but it still doesnt work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    clmcd42

    It would be great if you could tell us what was happening that was wrong, or give us an error message or something to work with.
     
  5. Offline

    DxDy

    Code:java
    1. kills.put(killer.getName(), kills.get(player.getName() + 1));
    2.  

    Are you sure that isn't supposed to be kills.get(killer.getName ... ) ?
     
  6. Ahhhh thats it thanks must be ill test it out

    This is the code im using and it still doesnt work:
    Code:
        @EventHandler
        public void onDeath(PlayerDeathEvent event){
           
            Player player = event.getEntity();
           
            if(players.contains(player.getName())){
               
                event.getDrops().clear();
                event.setDeathMessage("");
               
                Location death = player.getLocation();
                ItemStack goldenApple = new ItemStack(Material.GOLDEN_APPLE, 1);
               
                death.getWorld().dropItemNaturally(death, goldenApple);
               
                // Kill Streaks
               
                if(kills.containsKey(player.getName())){
                   
                    kills.remove(player.getName());
                   
                    Player killer = player.getKiller();
                   
                    kills.put(killer.getName(), kills.get(killer.getName()) + 1);
                   
                    if(kills.get(killer.getName()) == 3){
                       
                        ItemStack FlintAndSteel = new ItemStack(Material.FLINT_AND_STEEL, 1);
                       
                        killer.getInventory().addItem(FlintAndSteel);
                       
                        for(Player inGame : Bukkit.getOnlinePlayers()){
                           
                            if(players.contains(inGame.getName())){
                               
                                inGame.sendMessage(prefix + ChatColor.DARK_AQUA + killer.getName() + " is on a 3 kill streak!");
                            }
                        }
                    }
                   
                }
            }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  7. Offline

    GaaTavares

    You are removing the player from kills HashMap even without getting the value, so it will always return null.
     
  8. Im new to hash maps how would I go about doing this (Also the player is the player who died killer is the players killer)

    Sorry to bump before 24hours but can anyone else spot any errors here

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  9. Offline

    AoH_Ruthless

  10. Offline

    xTigerRebornx

    GaaTavares He is removing the Player's kills, not the Player's killer's kills.
    edm wasrevilosmith1999 Add some debug, print out what the values are, see where it gets stuck, and try to figure out why.
     
  11. Offline

    mrgreen33gamer

    Make sure you add a killer, and then make sure the killers is set to null whenever the killer doesn't exist:

    Killer:
    Code:
    Player killer = event.getEntity().getKiller();
    Then set the killer to null

    Code:java
    1.  
    2.  
    3. if(killer == null){
    4. return;
    5. }
    6.  
    7.  
     
  12. Tried this with no look, can anyone tell me if theres an error in the code or if theres a reason that it wont work? or how would I implement this ^^ into my code
     
  13. Offline

    mrgreen33gamer

    I used this code to create my own code, Lol.
     
  14. Did it work
     
  15. Offline

    itzrobotix

    Before you get a value from a hashmap you need to check it isn't null.
    Add above this;
    Code:java
    1. kills.put(killer.getName(), kills.get(killer.getName()) + 1);
    2.  
    3. if(kills.get(killer.getName()) == 3){

    This;
    Code:java
    1. if(kills.get(killer.getName()) == null){
    2. return;
    3. }
     
Thread Status:
Not open for further replies.

Share This Page