Solved Delaying Code

Discussion in 'Plugin Development' started by CommonSenze, Mar 12, 2018.

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

    CommonSenze

    Hello everyone,

    I'm glad you made the time to read my thread. I am currently at a dilemma right now. I am currently trying to make a delay system so I won't have to rely on BukkitRunnables. I was told from a Bukkit coding tutorial on cooldowns that they aren't the most efficient and to use System.currentTimeMillis() instead.

    My question is as follows, is this code that I printed below an efficient cooldown method? I haven't got the time to test it in minecraft due to personal issues, however I've tested it in my IDE console and it works fine. Although it works fine, however, I want to make sure I am using the most efficient and optimized solution for cooldowns so I can have a smooth server experience.

    Thank you for your time.

    Code:java
    1.  
    2. for (int i = 5; i > 0;){
    3. if (!getInstance().inSamePlace(player, x, y, z))return false; // ignore this.
    4. while (time - System.currentTimeMillis() < 0) {
    5. time = System.currentTimeMillis() + 1000;
    6. i--;
    7. }
    8. }
    9.  
     
  2. Offline

    timtower Administrator Administrator Moderator

    @CommonSenze Yeah, that method will freeze the server.
    BukkitRunnables exist with a reason.
     
  3. Offline

    CommonSenze

    @timtower Alright I'll stick with what I'm good at. Thanks for the advice.
     
Thread Status:
Not open for further replies.

Share This Page