HashMap

Discussion in 'Plugin Development' started by Guilherme Sousa de Assis, Apr 6, 2020.

Thread Status:
Not open for further replies.
  1. Hello, my name is guilherme and i am brazilian and i would like to know if anyone could help me create a HashMap to get for example:

    The player gave /test
    will send a message to him and I want to get the player's response in the chat, for example:
    What's your name?
    Player:
    iGuty

    So this is what I would basically like to get the response from the player like an argument, if anyone can help me I will be very grateful.
     
  2. Offline

    CraftCreeper6

    @Guilherme Sousa de Assis
    Firstly, create a hashmap with UUID as the key, and String as the value.

    Then, when they run the command, check if they are in the HashMap, if they are; then maybe block them from doing it, but that's up to you.

    If they aren't, then set the value in the HashMap to the first argument they give in the command.

    If your command was:

    Code:
    /name
    Then you would need to get the first argument they give

    Code:
    /name [first argument]
    If you want to allow spaces in their name then you'll need to use a StringBuilder for that.

    Here are some links that could be useful.
    Commands
    HashMaps
    Using a HashMap
     
  3. Offline

    Strahan

    Well, from what he's saying I think he wants the command to be issued then to capture whatever is said in chat next. If that's correct OP, you don't need a Map. I'd make a List<UUID> then when the player issues the command, add them to the List. Then on the chat event, if they aren't in the list return. Then after that do whatever you need to do with their input then remove them from the List.
     
  4. You could go for CraftCreeper6's answer if these are names you don't need to store anywhere as HashMaps will clear on restart.
    If you do save it to a save file for example, I'd recommend going with Strahan's method. It seems the most efficient and most reasonable way of achieving what you're looking for.
     
Thread Status:
Not open for further replies.

Share This Page