Solved Spleep

Discussion in 'Plugin Development' started by danichef, Dec 11, 2016.

Thread Status:
Not open for further replies.
  1. Hi, im working with a Thread.Sleep but i cant solution that when its in sleep all server stops until the time passes heres part of the code its a command:
    Thread.sleep(1000 * Integer.parseInt(args[3]));
    World w = Bukkit.getServer().getWorld(settings.getData().getString("office." + args[0] + ".world"));
    double x = settings.getData().getDouble("office." + args[0] + ".x");
    double y = settings.getData().getDouble("office." + args[0] + ".y");
    double z = settings.getData().getDouble("office." + args[0] + ".z");
    target.teleport(new Location(w, x, y, z));
    } catch (Exception e) { System.out.println(e);
    }


    how can i solucion it so only sends to sleep this code and not all serv?
    Thx
     
  2. Offline

    timtower Administrator Administrator Moderator

    @danichef Never sleep on the main thread, use runTaskLater instead
     
  3. Offline

    Zombie_Striker

  4. Offline

    mythbusterma

  5. I dont really understand the schedul thing
     
  6. Offline

    Zombie_Striker

    @danichef
    What do you not understand? What you need to do is call bukkit's "scheduler", create a new sync delayed task, provide a "runnable" (which is just an object that stores what you want to happen), and then set the delay.

    Have you tried creating a delayed task? If not, try. If you run into any errors/problems, post the code here.
     
  7. Ive been trying but i cult add args into it
     
  8. Offline

    mythbusterma

    @danichef

    What are you even talking about.
     
  9. Offline

    Zombie_Striker

    @danichef
     
  10. Well as i posted i was working with args.
    But anyway, Thank you @Zombie_Striker , @timtower and @mythbusterma ur the best!
     
    Last edited: Dec 18, 2016
  11. Offline

    DoggyCode™

    Someone has watched TheBCBroz on YouTube ;) "and to add a timer, we use Thread.sleep, then milliseconds). "

    Just a tip, don't watch him. The server runs on the main thread. if you call Thread.sleep, then it is only logical that your entire server will sleep unless you handle this operation on a separate thread. BukkitSchedulers were made for this


    Sent from my iPhone using Tapatalk
     
  12. @DoggyCode™ I was helped by one of my uncles but he dosent know bukkit coding.
     
  13. Offline

    DoggyCode™

    One of your uncles told you to sleep on the main thread? I'm guessing it might work in some cases


    Sent from my iPhone using Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page