Waiting for an event after a command

Discussion in 'Plugin Development' started by Lazoh, Jan 31, 2019.

Thread Status:
Not open for further replies.
  1. I've been busy trying to make a plugin that can sort the contents of a chest. To accomplish this, the player uses a command then has a few second to punch the chest he wants to sort.
    There's some async going on here.
    First of all, the player needs to be marked so the chest will sort when the player punches it.
    Second, there has to be a timeout after those seconds.

    (My knowledge of threads is quite limited so the problem might be quite simple, but I'm trying to figure it all out)
    My idea was to make a new thread in the commandexecutor and let it sleep for those seconds.
    An event handler checks if the circumstances are right (including if the player is marked via a set containing that player). If they are right, it then runs the code to sort the chest and interrupts the thread which removes the player from the set.

    So far, I have done this with a Set in my JavaPlugin class, having that class as a field in the executor/listener (same class). In this executor class, I make and run the Runnable in the onCommand, and have the event logic in an EventHandler.

    The command works and the threads runs, but the eventhandler isn't called

    How should I tackle this problem? Should I be multithreading it at all? The planned use is for a small server (never more than 15 players) so memory problems aren't an issue.
     
  2. Offline

    MightyOne

    Without seeimg your code it will be hardly possible to help you. Of course the Runnable is a good idea but if your plugin doesn't react on the fired event maybe something completely else is wrong
     
Thread Status:
Not open for further replies.

Share This Page