HashMap Help!

Discussion in 'Plugin Development' started by mrgreen33gamer, Apr 24, 2014.

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

    mrgreen33gamer

    Hello dear Bukkit Coders and Bukkit Code Seekers. I really need some help right now! I am trying to save my credits to the default configuration file, but I only have the HashMap. I am trying to load and save a HashMap. For instance, if i was to kill a player, then in the config it sets an amount for killing the player (I set the amount) and I already have the scoreboard setup on my server, so i need to figure out how to load the players credits through a scoreboard.

    So let's recap.

    What i want is: How to set a hashmap or add numbers to the config when a player kills another player they get credits, which i will have in the code at the bottom.

    Second. I want to load the players credits on my scoreboard, now for this i just need to know how to load the players credits from the config file.

    Here is my code:

    Code:java
    1.  
    2. public static HashMap<String, Integer> credits= new HashMap<String, Integer>(); @EventHandler
    3. public void getCredits(PlayerDeathEvent event){
    4. Player player = event.getEntity().getPlayer();
    5. Player killer = event.getEntity().getKiller();
    6.  
    7. if (event.getEntity().getKiller() instanceof Player) {
    8.  
    9. //Set a number of credits here.
    10. killer.getServer().broadcastMessage(player.getName() + "was whooped to death by " + killer.getName());
    11.  
    12. }
    13.  
    14. }
    15.  
    16.  


    That's about all the code that I have started out with, i have searched on the forums and never got any luck. I would like any help involving this. Thank you!

    Anyone?!

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

    RawCode

    java wont magically add or remove values from hashmap, there are methods that must be invoked in order to alter object state.
     
  3. Offline

    mrgreen33gamer

    Ok i get were you are going, but this isn't any help to what i am trying to get to.
     
  4. Offline

    RawCode

    your code have nothing with config or hashmap or scoreboard.

    i just can't understand what wrong with it and what you want.
     
  5. Offline

    Wizehh

  6. Offline

    mrgreen33gamer

    Read the topic please, it has what you are looking for.....
     
  7. Offline

    RawCode

  8. Offline

    mrgreen33gamer

  9. Offline

    Zethariel

    mrgreen33gamer That you need to implement yourself. Usually you want to iterate through the keys and save the values under a specific path in your file. Same goes for loading.
     
Thread Status:
Not open for further replies.

Share This Page