How would I go about doing this?

Discussion in 'Plugin Development' started by Eggspurt, May 4, 2015.

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

    Eggspurt

    I think what I need to do is Hashmaps, but I used Hashmaps before and they annoy me. So I was curious if there is a more simple way to do this..


    I need to be able to store certain strings for players temporarily - So each player has his own list of strings.


    Basically what I am trying to do is make a /thank system so say I do Player1: /thank player2 then if player2 does /checkthanks it'll display "Player1 has thanked you!" but if Player3 did "/checkthanks" it won't display player1 because player1 hasn't thanked him... I hope that makes sense, don't ask why lol its just needed. So is hashmaps the only way around to do this? Let me know

    Thanks :)
     
  2. HashMap is the easiest way to do this
     
  3. Offline

    Eggspurt

    Could you give me a minor example on how I would go about it? Doesn't have to be what I am asking just a Hashmap for a Player in general. Or maybe I should just do strings and use getName()
     
  4. Code:
    public private static protected final Map<UUID, String> xXxThAnKsxXx = new HashMap<>(); //Map with UUID key and String value
    
    You can simply on command check if args.length are over 0, then get a player from args[0], check if players is online if players is only, you can simply store the name of sender like this (Thanks.put(targetUUID, sender.getName()) or store a formated string like sender.getName() + " thanks blablala " + " message, so if a player after /thank <player> <after player> write something it will be saved on the map, you can do it using a StringBuilder. How to get something from the map ? So oncommand check if sender instanceof Player, if it is true get the string from the map using player UUID (String message= thanks.get(playerUUID); check if message is null, if it is null player isn't on the map , else it is on the map, then you just have to send the message and remove the player from the map thanks.remove(playerUUID); . I hope it help.
     
    Last edited: May 5, 2015
  5. Offline

    mythbusterma

    @MaTaMoR_

    What's with that name and why is it public?
     
  6. don't you like Thanks ? its just a random name.
     
  7. Offline

    Konato_K

    @MaTaMoR_ It should be lower case, also not public
     
  8. [​IMG]
     
  9. Offline

    Msrules123

    If you are going to spoonfeed, at least use naming conventions and the correct modifiers...

    @Eggspurt Also, if you want to have more than one "thank" per player, you can change MaTaMoR_'s HashMap layout to have a String list. That's just the way I interpreted what you said.
     
  10. Offline

    RawCode

    @Msrules123

    It should be <UUID\String (player never change it's name at runtime),ArbitraryWrapperClassWithAllFieldsThatMayBeRequiredForUse>
    string list is OK but provide zero scalability.
     
  11. Offline

    Zombie_Striker

    @Eggspurt
    Code:
    Hashmap<UUID,String[]> strings = new Hashmap<>;
    
    Maps are not that bad, and you should use them when you can to get used to them.
     
  12. @Zombie_Striker
    When you answer, do it right . _.
    Code:
    HashMap<UUID, String[]> strings = new HashMap<UUID, String[]>();
    
    //or
    
    Map<UUID, String[]> strings = new HashMap<UUID, String[]>();
     
  13. Offline

    Msrules123

    The string wasn't being used for player names... It was bring used for thank messages, so I said that if he wanted more than one message to be saved to make a string list.
     
Thread Status:
Not open for further replies.

Share This Page