How to just wait 5 seconds, then continue

Discussion in 'Plugin Development' started by JjPwN1, Aug 9, 2012.

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

    JjPwN1

    How do I make it so my code waits 5 seconds, and then continues the rest of the code after that.

    Code I want to add it to:
    Code:
                    }if (args.length == 1) {
                        player.setFallDistance(-100.0F);
                        Player targetPlayer = player.getServer().getPlayer(args [0]);
                        Vector dir = targetPlayer.getLocation().getDirection();
                        Vector vec = new Vector(dir.getZ() * .5D, .5D, dir.getX() * .5D);
                        targetPlayer.setVelocity(vec);
                        targetPlayer.sendMessage(ChatColor.GOLD + "[BbySlap]" + ChatColor.DARK_RED + " Slapped by " + player.getDisplayName() + ChatColor.DARK_RED + "!");
                        player.sendMessage(ChatColor.GOLD + "[BbySlap]" + ChatColor.DARK_RED + " You have slapped " + args [0]);
                        targetPlayer.damage(1);
                        //wait 5 seconds here
                          player.setFallDistance(0F);
     
  2. Offline

    petteyg359

    Quick and dirty:

    Code:
    Calendar c = new Calendar();
    int s = c.get(SECOND) % 5 + 5;
    while (s > c.get(SECOND) % 5) {}
    
     
  3. Offline

    JjPwN1

    Errors:

    [​IMG]
     
  4. Offline

    evilmidget38

    That would freeze the server for 5 seconds. Not exactly a good idea.

    Instead, check out the scheduler.
     
  5. Offline

    petteyg359

    Since the OP expended the effort to not do a basic search (see the first result from https://www.google.com/search?q=bukkit+wait), I felt it necessary to expend the effort to provide a bad answer.
     
    desht likes this.
  6. Offline

    evilmidget38

    Fair enough.
     
  7. nonono! ._.

    Use the Bukkit Scheduler

    You would want:
    Code:java
    1.  
    2. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { player.setFallDamage(0F); } }, 20 * 5); // 20 (one second in ticks) * 5 (seconds to wait)
    3.  

    Make sure player is final or it will give errors
     
  8. Offline

    JjPwN1

    Errors

    [​IMG]

    I, in fact, did expend the effort to perform a basic search. Everything I found, I didn't understand, because it was all vague. I came here hoping to get some detail and lessons on how to make it and why it works. Apparently you feel it necessary to provide me with fake and nasty code.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  9. Offline

    WarmakerT

    Replace "plugin" with "this".
    Edit.: Also, it looks like you have no idea of what you're doing. Please watch thenewboston's Java series at youtube.com/thenewboston
     
    Phinary and CorrieKay like this.
  10. Offline

    JjPwN1

    WarmakerT
    I know things when I learn them. I have learned quite a bit of stuff so far, and I have only started last week. I've heard of thenewboston many times and I will watch his videos sometime, as soon as I get free time to do that.
     
  11. Offline

    CorrieKay

    No offense but its gonna be really dificult for you to just jump into plugin dev that quickly. to each his own, however.

    But heres a protip: Never copypaste code someone gives you. 99% of the time its psuedocode, and doesnt work at all. Its just supposed to convey you an idea.

    Whenever you copypaste psuedocode, you always get stuff like in those two pictures. See how both of them are like "Uh... i dont know what this is. What do i do with it?" Its because youre trying to use variables that are undefined. You might as well just roll your face across the keyboard and get the same result. :p
     
    WarmakerT likes this.
  12. Offline

    JjPwN1

    CorrieKay
    Well, it won't be that hard to jump into plugin dev in 2 weeks. As all I am coding and learning to code are simple plugins. I will watch TheNewBoston when I get to it and learn a lot of more stuff so I can code more... eh... useful plugins. And see, I suppose when I watch videos, I will learn more about variables and stuff like that, as I am dumb as a man can be with that right now. Thanks for all of your guy's help. Sorry for being such a noob. XD
     
  13. Offline

    CorrieKay

    Hey, dont sweat it! we were all there once! I was back there in november!
     
    desht likes this.
  14. Offline

    dart2112

    OK so i put the scheduler into my code here:
    Code:java
    1. } else if (commandLabel.equalsIgnoreCase("update")) {
    2. if (player.hasPermission("cyber.admin")) {
    3. // if they type /update and have the "cyber.admin" perm
    4. player.sendMessage(ChatColor.BLUE + "Checking for updates");
    5. player.sendMessage(ChatColor.BLUE + "...........");
    6. if (!getConfig().getBoolean("update")) {
    7. // checks if updating is disabled in the config
    8. player.sendMessage(ChatColor.DARK_RED
    9. + "Plugin updating is disabled in the config!");
    10. return true;
    11. } else {
    12. Updater updater = new Updater(this, 85403, this.getFile(),
    13. Updater.UpdateType.DEFAULT, true);
    14. }
    15. // updates the plugin from bukkit dev
    16. plugin.getServer().getScheduler()
    17. .scheduleSyncDelayedTask(this, new Runnable() {
    18. public void run() {
    19. if (updater.getResult() == Updater.UpdateResult.SUCCESS) {
    20. player.sendMessage(ChatColor.BLUE
    21. + "Plugin Updated!");
    22. } else {
    23. player.sendMessage(ChatColor.BLUE
    24. + "The plugin eather failed to update or there is no update available");
    25. }
    26. }
    27. }, 20 * 20); // 20 (one second in ticks) * 5 (seconds to
    28. // wait)
    29.  
    30. } else {
    31. player.sendMessage(ChatColor.DARK_RED
    32. + "You are not allowed to use that command");
    33. // if they dont have the perm, then send them a message in dark
    34. // red
    35. }
    36. }

    Now its throwing null pointer exceptions
     
  15. Offline

    Skionz

    show us the stack trace or point us to the line.
     
  16. Offline

    teej107

    dart2112 Get your own thread and stop necro-posting.
     
  17. Offline

    Monkey_Swag

    JjPwN1 I'm very confused right now.
     
  18. Offline

    macboinc

    Necro-thread much
     
  19. Offline

    Monkey_Swag

    dart2112 why not just create a thread? It's simple.
    ^^^^^
     
  20. Offline

    Skionz

    Monkey_Swag Oh shit didn't realize how old this thread was lol
     
    Hawktasard likes this.
  21. Offline

    Monkey_Swag

    Holy crap this thread is 3 years old wtf
     
  22. Offline

    dart2112

    Monkey_Swag I didn't make a new thread because i used the code and stuff that are already in this thread
    And eclipse isnt showing any errors but there is a um-handled null pointer between line 6 and 28
     
  23. Offline

    mythbusterma

    dart2112

    Forgive me, but doesn't it unload your plugin when it updates?
     
  24. Offline

    coasterman10

    that moment when you start liking posts then realize a thread is 2 years old
     
    Konkz likes this.
  25. Offline

    dart2112

    mythbusterma
    no it only downloads the update then moves it into the plugins folder when the server restarts/reloads
     
  26. Offline

    JjPwN1

    u stupid
     
    Monkey_Swag likes this.
Thread Status:
Not open for further replies.

Share This Page