delay between messages

Discussion in 'Plugin Development' started by bobthefish, Jul 15, 2014.

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

    bobthefish

    Hi

    I am trying to make it so that when a player joins, it sends them a series of messages. the only thing is, between each message, I need a delay (a small one, maybe .25 seconds or so) Im not sure how to do this, and if the answer is Threads, could you point me in the direction of a good tutorial on this? I dont know how to use threads
     
  2. Offline

    Gater12

  3. Offline

    bobthefish

    I feel like that would be really helpful, But I dont understand what its trying to tell me D:

    Bump? I really need this, and idk what that link is trying to tell me

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

    mythbusterma

    bobthefish

    Bump once every 24 hours.

    It's telling you to create a delayed task that is run after a certain number of ticks to accomplish what you need.
     
  5. Offline

    bobthefish

    mythbusterma

    OK, Sorry about bumping it again, I understood that, but I dont understand what its telling me to do to get to that point
     
  6. Offline

    mythbusterma

    bobthefish

    Read the entire article, it explains that you must create a Runnable (for all intents and purposes, a section of code) to be run at a later time, and then to schedule it run delayed on the main thread. The article explains how to do all of that.
     
  7. Offline

    bobthefish

    mythbusterma
    OK, Thank you for telling me to read it, I only read parts of it *facepalm*

    I believe this is the code I need:

    Code:java
    1. @EventHandler
    2. public void onJoin(PlayerJoinEvent event) {
    3. // Create the task anonymously and schedule to run it once, after 20 ticks
    4. new BukkitRunnable() {
    5.  
    6. @Override
    7. public void run() {
    8. // What you want to schedule goes here
    9. plugin.getServer().broadcastMessage(
    10. "Welcome to Bukkit! Remember to read the documentation!");
    11. }
    12.  
    13. }.runTaskLater(this.plugin, 20);
    14. }



    but could I make (in this case I need 7 different sets of messages sent) 7 of those? or put in a for loop that runs 7 times?
     
  8. Offline

    mythbusterma

    bobthefish

    That depends, if the messages are sent one after the other, you could just send them all in the delayed task, however if they need to be sent at different times, you would need separate runnables for each. Although you could just schedule a repeating one that iterates over a list of messages if the delay between them is the same, and then just cancel it when it is finished.
     
  9. Offline

    bobthefish

    mythbusterma

    I have 3 messages that are sent at the same time, and then those 3 are each sent 7 times in their groups of 3, so I should make 7 runnables?

    I cant really repeat it, because they arent the same 3 messages each time

    one other thing, how many ticks are in a second, ive heard 2, 4, 20 and even 50. Do you know the number?

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

    mythbusterma

    bobthefish

    But you could repeat it, if you iterate over a list.

    Code:java
    1. ArrayList <String> list = getConfig().getStringList("joinmessages");
    2.  
    3. Iterator iter = list.iterator();
    4. new BukkitRunnable () {
    5. @Override
    6. public void run() {
    7. for(int i = 0; i <3; i++ ) {
    8. if(iter.hasNext()) {
    9. player.sendMessage(iter.next());
    10. }
    11. else {
    12. cancel();
    13. break;
    14. }
    15. }
    16. }
    17. }.runTaskTimer(pluigin,0,delay);


    A server running at full speed runs at 20 ticks per second, it may run slower if the server is overloaded, however.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
    bobthefish likes this.
  11. Offline

    Necrodoom

    Normally, 20. Can be fewer if the server is slow, due to longer time to calculate a tick. I'm interested where you heard 2, 4 and 50, though.

    Edit: ninja'd *shakes fist at above post*
     
  12. Offline

    bobthefish

    Necrodoom a while back I looked around a little bit for a redstone gadget, but got mixed answers, thanks for helping me mythbusterma, Ill try to repeat it!
     
  13. Offline

    mythbusterma

    That's because redstone ticks only happen at 10 ticks a second, rather than 20.
     
  14. Offline

    bobthefish

    mythbusterma so I tried to repeat it, but couldnt quite get it, although I may have just thought of something, the other thing is though, I didnt repeat it, and put it all in a big line down my code but when logged on, it sent them all out of order :/

    mythbusterma I got it to repeat, but in your repeating example, where it says "plugin,0,delay" down at the bottom what is the "o" for?

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

    hankered

    Show us the updated code OP
     
  16. Offline

    bobthefish

    I figured it out! thanks you everyone for helping (mostly mythbusterma)
     
Thread Status:
Not open for further replies.

Share This Page