How can I pause this

Discussion in 'Plugin Development' started by Lightcaster5, Jan 3, 2019.

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

    Lightcaster5

    I'm trying to make a login loading bar using ActionBarAPI
    my code:
    @EventHandler
    public void onJoin(PlayerJoinEvent e){
    Player p = e.getPlayer();
    ActionBarAPI.sendActionBar(p,"Logging you in §b|§7|||||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §b||§7||||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §b|||§7|||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|§b|||§7||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||§b|||§7|||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|||§b|||§7||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||||§b|||§7|||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|||||§b|||§7||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||||||§b|||§7|", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|||||||§b|||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||||||||§b||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|||||||||§b|", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||||||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §b|§7|||||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §b||§7||||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §b|||§7|||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|§b|||§7||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||§b|||§7|||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|||§b|||§7||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||||§b|||§7|||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|||||§b|||§7||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||||||§b|||§7|", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|||||||§b|||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||||||||§b||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|||||||||§b|", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||||||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §b|§7|||||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §b||§7||||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §b|||§7|||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|§b|||§7||||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||§b|||§7|||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|||§b|||§7||||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||||§b|||§7|||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|||||§b|||§7||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||||||§b|||§7|", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|||||||§b|||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||||||||§b||", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7|||||||||§b|", 4);
    ActionBarAPI.sendActionBar(p,"Logging you in §7||||||||||", 4);
    ActionBarAPI.sendActionBar(p,"§bLogged in!", 20);

    How can I delay each thing by 1/4th a second? I just did this and it happened so fast you couldn't even see it
     
  2. Online

    timtower Ninja on the waves Moderator

  3. Offline

    Lightcaster5

    Im new to this, I have heard this term used before but I have no Idea how to set that up...
     
  4. Online

    timtower Ninja on the waves Moderator

  5. Offline

    Lightcaster5

    I Dont want to delay the entire thing, I just want to add a delay in between each of the ActionBar messages.
     
  6. Online

    timtower Ninja on the waves Moderator

    In this case I would use a single runnable that has its own internal counter that it increments after a run.
    In a run it checks the counter and sends the right message based on it.
    When the counter is big enough you cancel the task.
    This is based on runTaskTimer btw
     
  7. Offline

    Lightcaster5

    ...

    How do you do that? Again, im new at this.

    Could I use Thread.sleep() somehow?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 3, 2019
  8. Online

    timtower Ninja on the waves Moderator

  9. Offline

    Lightcaster5

  10. Offline

    Zombie_Striker

    @Lightcaster5
    1. First, the messages are pretty much the same, exception the chatcolor moves over one character each time. Instead of having all the lines copy and pasted, make a separate method for generating the string. With that, it will be easier to modify it if you ever need, and will be a lot easier to clean/use that way.
    2. After doing that, I'd recommend creating a for-int loop that loops from 0 up to the number of messages that should be sent. Doing this will mean we don't need to copy and paste code for each of the bukkit runnables, since they will do essentially the same thing.
    3. Then, inside the for loop, use the method from #1 to get the message that should be displayed at that point. Do this by using the for loop as the "index" of the message.
    4. Then, create a new bukkit runnable. In it, send that message from #3. Set the delay equal to 5* (int-from-for-loop) , which will mean that each message will appear 1/4 second after the previous one.
     
  11. Offline

    Lightcaster5

    If you haven't noticed, I'm a noob at this stuff, how do you do all of that?
     
  12. Online

    timtower Ninja on the waves Moderator

    @Lightcaster5 What part? How long have you been programming? How much Java do you know?
     
  13. Offline

    Lightcaster5

    All of it, less than a month, I can make a plugin that will send a player a message when they type a command and thats about it
     
  14. Online

    timtower Ninja on the waves Moderator

    Then I suggest a simpler start.
    Send a single message after 100 ticks using a BukkitRunnable
     
  15. Offline

    Lightcaster5

    I did

    Sorry for the trouble, I don't want to be spoon fed but I do need some assistance.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 3, 2019
Thread Status:
Not open for further replies.

Share This Page