ActionBar

Discussion in 'Plugin Development' started by CombedHoney, Jan 3, 2024.

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

    CombedHoney

    Hi! i need a help for a action bar plugin
    Code:
    package coding.with.combed.ghostmcapocalis.ui;
    
    import coding.with.combed.ghostmcapocalis.Main;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    
    public class ActionBarManager {
    
        public static void sendActionBar(Player player, String message) {
            player.spigot().sendMessage(net.md_5.bungee.api.ChatMessageType.ACTION_BAR, net.md_5.bungee.api.chat.TextComponent.fromLegacyText(message));
        }
    
        public static void startActionBarTask() {
            Bukkit.getScheduler().runTaskTimer(Main.getInstance(), () -> {
                for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
                    sendActionBar(onlinePlayer, ChatColor.GREEN + "Il tuo messaggio qui!");
                }
            }, 0L, 20L); // 0L indica il ritardo iniziale, 20L รจ l'intervallo (in ticks, 20 ticks = 1 secondo)
        }
    }
    
    Code:
    package coding.with.combed.ghostmcapocalis;
    
    import coding.with.combed.ghostmcapocalis.ui.ActionBarManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public final class Main extends JavaPlugin {
    
        private static Main plugin;
    
        @Override
        public void onEnable() {
            // Plugin startup logic
            plugin = this;
            ActionBarManager.startActionBarTask();
        }
    
        @Override
        public void onDisable() {
            // Plugin shutdown logic
        }
    
        public static Main getInstance(){
            return plugin;
        }
    }
     
  2. Offline

    timtower Administrator Administrator Moderator

    @CombedHoney Don't put an onDisable down if you don't need it.
    You never need that static Main instance.
    What kind of help do you need?
     
  3. Offline

    CombedHoney

    ok, but the code in Right? this can work?
    Sorry for the bad English but i'm italian .-.
     
  4. Offline

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page