Plugin Help Removing a key from a hashmap.. and viewing the hashmap.

Discussion in 'Plugin Help/Development/Requests' started by Ricecutter0, Apr 19, 2015.

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

    Ricecutter0

    So I'm making this plugin.. when they do /helpme, and it puts them in a hashmap, with an integer, and their name. Then this is the part where I need help. So I made a command where they can do /dismiss <id> which removes the number and the player in the hashmap. Then they can do /view, to see who did /helpme, and is still looking for help. So when there is two people in the list for /view, and I do /dismiss 1, it removes it sucessfully, but when I do /view, it shows 1. null..

    [​IMG]

    Code:

    Code:java
    1. if(cmd.getName().equalsIgnoreCase("dismiss")){
    2.  
    3. if(args.length < 1){
    4. send(sender, prefix + "Oops!");
    5. send(sender, "&c/dismiss <id>");
    6. return true;
    7. }
    8. Integer id = null;
    9. try{
    10. id = Integer.parseInt(args[0]);
    11. }catch (NumberFormatException ex){
    12. send(sender, prefix + "&4That's not a vaild id number!");
    13. return true;
    14. }
    15. if(!requests.containsKey(id)){
    16. send(sender, prefix + "&4That's not a vaild id number!");
    17. return true;
    18. }
    19. String targetid = lastRe.get(p.getName());
    20. requests.remove(id);
    21. lastRe.remove(p.getName());
    22. lastRe.remove(targetid);
    23. send(sender, prefix + "&6Dismissed request &4#" + id);
    24. send(sender, requests.toString());
    25. return true;
    26. }



    Code:java
    1. if(cmd.getName().equalsIgnoreCase("view")){
    2. if(requests.isEmpty()){
    3. send(sender, prefix + "&6There are no current requests!");
    4. return true;
    5. }
    6. send(sender, "&8---===---== &cRequests&8 ==---===---");
    7. for(int i = 1; i<=requests.size();i++){
    8. send(sender, "&4" + i + ".&6 " + requests.get(i));
    9. }
    10. send(sender, "&8-------------------------------");
    11. return true;
    12. }


    Thank you for reading!

    EDIT:

    Nevermind! I figured it out. For anyone that is wondering you would put it in a for loop, for every keyset...

    Code:java
    1. for(Integer e : <HASHMAP>.keySet()){
    2. <PLAYER>.sendMessage("&6" + <HASHMAP>.get(e) + " &7ID: &a" + e);
    3. }
     
    Last edited: Apr 19, 2015
Thread Status:
Not open for further replies.

Share This Page