Waiting For Input

Discussion in 'Plugin Development' started by zirbinator, Apr 1, 2011.

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

    zirbinator

    Hello,

    I've been trying to create a plugin that will wait for user input (in this case, just a simple y/n). I am able to get chat messages that the player sends. First, is there a simple way to get input with the bukkit api? If so, that would be excellent, however, I doubt it's as easy as that.

    This is my current approach:
    I've made a simple listener class that will listen for a player's chat messages. This class can determine whether or not the response was positive or negative.
    I have another class that sent the informative message (something like: "do you want to do this (y/n)") and I would like to have that class wait until the listener determines a response.

    Preferably, I would use a the methods wait() and notify() but I'm uncomfortable with these methods and I don't know how they would mess with the server.

    So far, I have tried putting a boolean in the listener class that will be set to true as soon as there is a response and then used Thread.sleep() in the other class to wait for this response. This doesn't seem to agree with my server and screws everything up.

    Any ideas as to how to do this?

    Thanks.
     
  2. Offline

    ssell

    I would do the following:
    1. Print out the statement that has the y/n in it.
    2. Alert the PlayerListener to listen for that particular player.
    3. The next time the player chats, intercept the message and read if it is the y/n.
    4. If it was the y/n, cancel the event so the rest of the players don't see it. Otherwise let it go through.
    5. Either way, at this point tell the PlayerListener to stop paying attention to that player. If the message was not y/n perhaps alert the user that what they typed was not accepted.
    6. Execute whatever code the player was confirming.
    It is essentially what you were doing. But does not mess around with waiting and stuff. Not sure if it helps at all.
     
  3. Offline

    zirbinator

    Well that's exactly what I'm doing except for the last step. The problem is that I'm doing this in a method that has to return a value so that the proper acceptance/rejection message can be printed, along with any error messages.

    Anyway, I rewrote my code a little to incorporate your design so thanks it works now!

    However, if anyone has any ideas about how to do this within one method so that I can return a value, that would still be appreciated.
     
Thread Status:
Not open for further replies.

Share This Page