Scoreboad Update

Discussion in 'Plugin Development' started by SatchelMC, Nov 30, 2020.

  1. Offline

    SatchelMC

    Hey, I am new to java and have been learning scoreboards. But I just don't know how to make the scoreboard update for the player because when I give someone a new rank, it does not update until they re-log into the server. Can anyone help, Please? Here is my code.

    Code:
    mport org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.scoreboard.*;
    import zach.hubcore.how.Files.CustomScoreboard;
    import zach.hubcore.how.Util.ColourTranslate;
    import zach.hubcore.how.Util.Var;
    
    
    public class ScoreboardEvent implements Listener {
    
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
    
    
            Player player = event.getPlayer();
    
           
            ScoreboardManager m = Bukkit.getScoreboardManager();
            Scoreboard b = m.getNewScoreboard();
    
            Objective o = b.registerNewObjective("Gold", "");
            o.setDisplaySlot(DisplaySlot.SIDEBAR);
            o.setDisplayName(ChatColor.translateAlternateColorCodes('&', CustomScoreboard.get().getString("Title")));
            Score blank = o.getScore("   ");
            blank.setScore(12);
    
            Score date = o.getScore(PlaceholderAPI.setPlaceholders(event.getPlayer(), ColourTranslate.colour("&7%server_time_d/M/y%")));
            date.setScore(11);
    
            Score blank1 = o.getScore(PlaceholderAPI.setPlaceholders(event.getPlayer(), "  "));
            blank1.setScore(10);
    
            Score gold = o.getScore(PlaceholderAPI.setPlaceholders(event.getPlayer(),
                    ChatColor.translateAlternateColorCodes('&', "Rank: ") + ChatColor.translateAlternateColorCodes('&', "%luckperms_suffix%")));
            gold.setScore(9);
    
            Score blank2 = o.getScore(" ");
            blank2.setScore(8);
    
            Score name = o.getScore(PlaceholderAPI.setPlaceholders(event.getPlayer(),
                    "Lobby: " + ColourTranslate.colour(CustomScoreboard.get().getString("lobbynumber"))));
            name.setScore(7);
    
            Score blank3 = o.getScore("       ");
            blank3.setScore(6);
    
            Score pnamerank = o.getScore(PlaceholderAPI.setPlaceholders(event.getPlayer(), ColourTranslate.colour("%vault_prefix% %player_name%")));
            pnamerank.setScore(5);
    
            Score blank4 = o.getScore("    ");
            blank4.setScore(4);
    
            Score mdust = o.getScore(PlaceholderAPI.setPlaceholders(event.getPlayer(),
                    ColourTranslate.colour(CustomScoreboard.get().getString("mystery") + "" + " %gadgetsmenu_mystery_dust%")));
            mdust.setScore(3);
    
            Score blank5 = o.getScore("      ");
            blank5.setScore(2);
    
            Score domain = o.getScore(ColourTranslate.colour(Var.Domain));
            domain.setScore(1);
    
            //REMOVE THE IF WHEN RELEASE
            if (player.hasPermission("SHC.scoreboard.not.default")) {
                player.setScoreboard(b);
            } else {
            }
        }
        }
     
  2. Offline

    timtower Administrator Moderator

    @SatchelMC Scoreboard does not auto update, you might want to use a BukkitRunnable for that.
     
  3. Offline

    SatchelMC

    How can i do that?
     
  4. Offline

    timtower Administrator Moderator

    Make a BukkitRunnable in the onEnable, loop over the players, set their scoreboard?
     
  5. Offline

    SatchelMC

    Thanks, I'll give it a try
     

Share This Page