Need help with creating delay

Discussion in 'Plugin Development' started by spyrootjenl, Aug 24, 2016.

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

    spyrootjenl

    Hello, i need to know how i can make a delay in my plugin,
    What i want is:
    When someone perfoms my command it executes a message, wait 10 seconds and then execute another message.
    It would be awesome if you can give me the code for this, thanks
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    spyrootjenl

    ItemStack m = new ItemStack(Material.DIAMOND, 1);
    if(player.getInventory().contains(Material.DIAMOND)){
    player.getInventory().removeItem(m);
    player.updateInventory();
    player.sendMessage(Activate);
    player.setAllowFlight(true);
    player.
    10 seconds wait
    flight disabled
    }

    that is how i want it, how can i do this?
     
  4. Offline

    timtower Administrator Administrator Moderator

    @spyrootjenl BukkitRunnable.runTaskLater(allowFlight(false))
    That won't compile though, not gonna spoonfeed the code for you.
     
  5. Offline

    spyrootjenl

    Someone? Please
     
  6. Offline

    InstanceofDeath

    Why should anyone give you the code? I mean schedulers are such basic stuff in the bukkit.api
    Just search on google "bukkit scheduler tutorial". You cant just start coding plugins without knowing how to create schedulers or dont even know what a Runnable is ...
     
    HeartandSoul and Zombie_Striker like this.
  7. @spyrootjenl You know this forum isn't for people to give you code... No-one will want to help you if that's the case. Anyways like the others said. Use a scheduler and the "runtasklater" method. Have you made an effort to do this on your own? If so, Please create a pastebin with your class: http://pastebin.com don't worry, It's free and you don't need to make an account or anything. After posting your class, Reply to this with the link and we can help you from there. Remember to tahg one of us when doing it so we get a notification.
     
    HeartandSoul and Zombie_Striker like this.
  8. Offline

    nomiht

    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){

    @Override
    public void run() {

    }

    }, Delay in ticks);

    so try this:

    final Player player = e.getPlayer();
    ItemStack m = new ItemStack(Material.DIAMOND, 1);
    if(player.getInventory().contains(Material.DIAMOND)){
    player.getInventory().removeItem(m);
    player.updateInventory();
    player.sendMessage("Activated!");
    player.setAllowFlight(true);

    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){

    @Override
    public void run() {
    player.setAllowFlight(false);
    }

    }, 20 * 10);

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  9. Offline

    Zombie_Striker

    @nomiht
    Don't Spoonfeed. Did you read the posts above you? We are not here to write code for these people. Please, remove your code from your post.

    [edit]Also, you have made a few mistakes in your code. There is no reason for m to be created, and it will require the player to only have one diamond in their inventory. If they have any more diamonds in their inventory, they will not be removed. This means your code will not even work. Again, remove the code.
     
  10. Offline

    spyrootjenl

    @Mindlessmink i have spend 20 hours now searching and following tuts but it never works for me, i know how to code but this is just a hard part for me somehow, tomorrow ill post the pastebin
     
  11. Offline

    HeartandSoul

    No, you don't know how to code if your asking for spoonfeed.

    Create a method with your runnable in it. Cal it when you execute the command
     
    Last edited: Aug 25, 2016
  12. @spyrootjenl i'll link some tutorials I used to learn BukkitRunnables below. All of them work, it's just most of them are using a different method so you have to modify them a bit to suit your needs. However that should be simple enough since we gave you instructions.

    Edit: Sorry I have to go, But I'd look at PogoStick or bcbroz tutorials, on YT
     
  13. Offline

    HeartandSoul

    Don't do BcBroz. Some of what he does is incorrect or deprecated. I'd probably go with PogoStick.

    I apparently suck :(
     
  14. Offline

    Zombie_Striker

  15. Offline

    InstanceofDeath

    Just a small question to you .. Is it okey, when you spoonfeed someone, but explain him each row of the code exactely and then write after it "pls learn this code" ?
     
  16. Offline

    Lordloss

    @InstanceofDeath
    No, simply no. There is a very high chance that this person copypastes it without even reading your comments.
    After about 5 minutes later he comes again with "why do no work pls help" and "give me another code for XY pls"
     
  17. Offline

    InstanceofDeath

    okey ^^
     
Thread Status:
Not open for further replies.

Share This Page