Solved Controlling thread with EventListener

Discussion in 'Plugin Development' started by Gorbit99, Dec 15, 2015.

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

    Gorbit99

    What are the way of controlling an alredy running BukkitRunnable from the EventListener? I have a slotmachine kinda thing, and I want that when the player closes the inventory (Inventory based of course), he'll gets the items immediatly. I can solve the second part of the problem, but for that, I need to have a boolean, that can be set to true by the eventlistener, and if it's true, then it will proceed. I already have a way to store the task/taskId.
     
  2. Offline

    WolfMage1

    use an inventory event?
     
  3. Offline

    Gorbit99

    [​IMG]
    I'm talking about the communication between the thread and the eventlistener
     
  4. Offline

    teej107

    What kind of thread are we talking about? Synchronous runnables run on the same thread as the rest of the events do. Could you go into more detail? Perhaps I can get a better idea if you show us what you have tried.
     
  5. Offline

    Gorbit99

    @teej107 Ok, the "Thread" word was not the best for this one. It's a synchronous bukkittask, and I run it with runTaskTimer. I linked the task to the player using a Class that contains both of them. Is there a way to run a function inside a task, because I have the skeleton of the whole thing: if I could run that function, the boolean would be set to true, and the rest is set too
     
  6. Offline

    teej107

    Yes.
     
    Gorbit99 likes this.
  7. Offline

    Gorbit99

    So there is one. Could you actually post the command? I mean, it's fine that there is one, but that doesn't help :D
     
  8. Offline

    teej107

    @Gorbit99 calling a method inside a task is the same way as you do everywhere else.
     
  9. Offline

    Gorbit99

    @teej107 Should I create the task using BukkitTask task = new ...; or ClassName task = new...;? If I do it with the first one, then I can't access the functions

    EDIT: I solved it in a different way. Since I stored the inventory and the Player in different variables, I just checked if p.getOpenInventory().getTopInventory was equal to the stored inventory, and if it's not, I set the closedInventory variable to true

    Sorry, I derped a bit, I didn't think of inserting an event listener function inside the class :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 15, 2015
Thread Status:
Not open for further replies.

Share This Page