Solved Arena Question | Countdown

Discussion in 'Plugin Development' started by ThatOneDev123, May 21, 2014.

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

    ThatOneDev123

    Hello I am making a mini game, and am following the basic arena format, where you have an arena class and a singleton Arena Manager.

    I had a specific question, let's say in my Arena Manager, I am about to start an Arena, I have a method for this. I want to do a 5 second count down before starting the arena, I plan to use a scheduler to do this, but my question is, will the countdown stall execution of my ArenaManager?

    For example, if I have a countdown happening, and then another user tries to join an area, it is the Arena Mangers job to place that user in there, but will that countdown cause problems when another class tries to access the singleton and call addPlayer?
     
  2. Offline

    ChazSchmidt

    I can't say for certain but I would think no, it wouldn't affect it. If you use an Async task then it creates a separate thread which will not interfere with the main thread.
     
  3. Offline

    Garris0n

    The countdown will be run on an interval. It won't stall anything, it just waits a certain amount of time before doing something.

    ChazSchmidt Who said anything about async tasks?

    Edit: Just saw this. There is no need to make more threads for any of this and you're going to set yourself up for some very unpleasant debugging if you do, only to come to the conclusion that you shouldn't be doing any of it asynchronously.
     
  4. Offline

    ThatOneDev123

    Should I use Async or Sync? (repeating Task?) The countdown just displays the timer 3..2..1 and changes an instance field of that arena (to set the state to in game).
     
  5. Offline

    Garris0n

    Do not use async unless you need it for something that you don't want run on the main thread, like downloading a file or sending a query to a database. Most of the Bukkit API is not thread safe, and, by trying to run Bukkit methods in other threads, you are going to end up with some weird concurrency issues that won't show up all at once. Everything could be going fine until you and the server try to access some method at the same time, it breaks, and some block gets corrupted and crashes everybody.
     
  6. Offline

    ThatOneDev123

    Got it thanks. So Just use a synchronousReatingTask?
     
  7. Offline

    ChazSchmidt

    Garris0n is right. I wasn't thinking straight when I said that. It's generally advised to avoid Async
     
  8. Offline

    Garris0n

    ThatOneDev123 likes this.
  9. Offline

    ThatOneDev123

  10. Offline

    mrkirby153

    ThatOneDev123

    By the laws of OOP, yes, each countdown will have their own counter vars
     
    ThatOneDev123 likes this.
Thread Status:
Not open for further replies.

Share This Page