Solved Get input from another user

Discussion in 'Plugin Development' started by martian3333, Apr 22, 2013.

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

    martian3333

    Inside one of my commands, I need to get an input from another user.

    Code:
    //command
     
    if (args[0].toString() == "sellto" && args[1].toString() == somePlayer.getName()){
      //
      // ask somePlayer for a reaponse and wait for it
      //
      if (response == "yes"){
        sender.sendMessage("That guy bought your stuff");
      }
    }
     
  2. Use .equals() to compare objects.

    For the response system you can use the Conversations API which is useful just for that, look in resources for tutorials about it.
     
  3. Offline

    martian3333

    Sadly I've read and read and read all the posts and tutorials about he conversation api... and I just don't get it. All that code there is just fluff, I'm only concerned with how to send a prompt to another player and get a response which I'll use to decide what happens next. I really wish I could have just read those tutorials and got it right already, but I just can't do this one without help.
     
  4. Well, you need to register the AsyncPlayerChatEvent and create a field with a HashMap or HashSet (if you don't need values) to store player's name and their action (if you have multiple prompts) then in the event just check if the sender is in the map/set (and get its prompt type) then process what he said and block what he said from printing (cancel the event I guess) and remove him from the map/set and you're done.

    The command code ends after you send the request signal to the other player and add them to that map or set.

    Also, if you want a timeout just start a task and remove them from the map or set if they're there... I also suggest tracking the task and canceling it when they say something valid because it might overlap later and cancel stuff prematurely.

    Note that the AsyncPlayerChatEvent is async (diferent thread), therefore you should NOT interact with the game or the API, if you want to break out of the thread just create a new sync task inside there.
     
  5. Offline

    martian3333

    Do I understand the Conversation API 100% now? ...no! Do I understand it a lot better than I did.... yes.

    I just had to watch like 3 times very carefully.
     
Thread Status:
Not open for further replies.

Share This Page