Solved Stopwatch on actionbar

Discussion in 'Plugin Development' started by MiBB3L, Jun 1, 2020.

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

    MiBB3L

    I want to create a stopwatch on the actionbar. It should goes from 00:00:00 up, like 00:00:01, 00:00:02 ... . I´ve never worked with schedulers and don´t know how to do that. Could someone help me?
     
  2. Offline

    KarimAKL

    @MiBB3L You can create a new BukkitRunnable using this:
    Code:Java
    1. new BukkitRunnable() {
    2. @Override
    3. public void run() {
    4. // Increment the time and resend the actionbar here
    5. }
    6. }.runTaskTimer(plugin /*main class*/, delay /*delay before the runnable starts*/, period /*time in between runs*/);

    The delay and period are in ticks, meaning that you'll set it to 20 for it to run every second.
     
  3. Offline

    MiBB3L

    Everything is working perfectly, except I can´t get the Timer on the actionbar, because this isnt working:
    Code:
    player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
    How can I send a actionbar message?
     
  4. Offline

    KarimAKL

    @MiBB3L That should work, are you getting any errors?
     
  5. Offline

    MiBB3L

    "The method fromLegacyText(String) is undefined for the type TextComponent"
     
  6. Offline

    KarimAKL

    @MiBB3L Did you accidentally import "java.awt.TextComponent" instead of "net.md_5.bungee.api.chat.TextComponent"?
     
  7. Offline

    MiBB3L

    When I import "net.md_5.bungee.api.chat.TextComponent", than I get the error: "The method sendMessage(BaseComponent...) in the type Player.Spigot is not applicable for the arguments (ChatMessageType, BaseComponent[])"
     
    Last edited: Jun 1, 2020
  8. Offline

    KarimAKL

    @MiBB3L You're using an old version. (1.9 or below) The Player.Spigot#sendMessage(ChatMessageType, BaseComponent) method was added in 1.9.2.

    You'll have to use NMS for older versions.
     
  9. Offline

    MiBB3L

    Last edited: Jun 2, 2020
Thread Status:
Not open for further replies.

Share This Page