Scoreboards keep flashing

Discussion in 'Plugin Development' started by Aussie_Jhawking, Jun 24, 2014.

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

    Aussie_Jhawking

    Hey I am trying to created a scoreboard for my lobby server but it flashes randomly every 2-3 seconds here is my code hope you guys can help me.


    Code:java
    1. package com.network.xex;
    2.  
    3.  
    4.  
    5. import com.xexnetwork.pointsapi.ps;
    6. import net.milkbowl.vault.permission.Permission;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.player.PlayerJoinEvent;
    14. import org.bukkit.plugin.RegisteredServiceProvider;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16. import org.bukkit.scoreboard.DisplaySlot;
    17. import org.bukkit.scoreboard.Objective;
    18. import org.bukkit.scoreboard.Scoreboard;
    19.  
    20.  
    21.  
    22. public class Core extends JavaPlugin implements Listener {
    23.  
    24.  
    25. public static Permission permission = null;
    26.  
    27.  
    28. public void onEnable()
    29. {
    30. getServer().getPluginManager().registerEvents(this, this);
    31.  
    32.  
    33.  
    34. setupTimer();
    35. setupPermissions();
    36.  
    37.  
    38.  
    39.  
    40.  
    41.  
    42.  
    43.  
    44.  
    45.  
    46.  
    47.  
    48.  
    49.  
    50.  
    51.  
    52.  
    53.  
    54.  
    55. }
    56.  
    57.  
    58.  
    59.  
    60.  
    61.  
    62.  
    63.  
    64.  
    65.  
    66.  
    67. @Override
    68. public void onDisable() {
    69. getLogger().info("Disabling Plugin...");
    70. }
    71.  
    72.  
    73.  
    74.  
    75.  
    76. private boolean setupPermissions() {
    77. RegisteredServiceProvider<Permission> permissionProvider = getServer()
    78. .getServicesManager().getRegistration(
    79. net.milkbowl.vault.permission.Permission.class);
    80. if (permissionProvider != null) {
    81. permission = permissionProvider.getProvider();
    82. }
    83. return (permission != null);
    84. }
    85.  
    86.  
    87.  
    88.  
    89.  
    90.  
    91.  
    92.  
    93. @SuppressWarnings("deprecation")
    94. public void updateScoreboard(Player player) {
    95. Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
    96.  
    97. String group = permission.getPrimaryGroup(player);
    98.  
    99.  
    100.  
    101. String pl = player.getName();
    102.  
    103. Objective obj = board.registerNewObjective("scoreboard", "dummy");
    104. obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    105. obj.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "XeX Network");
    106. obj.getScore(Bukkit.getOfflinePlayer(ChatColor.GOLD + "" + ChatColor.BOLD + "Points")).setScore(16);
    107. obj.getScore(Bukkit.getOfflinePlayer("" + ChatColor.BLUE + ChatColor.BOLD + ps.getBalance(pl))).setScore(15);
    108. obj.getScore(Bukkit.getOfflinePlayer(" ")).setScore(14);
    109. obj.getScore(Bukkit.getOfflinePlayer(ChatColor.GOLD + "" + ChatColor.BOLD + "Rank")).setScore(13);
    110. obj.getScore(Bukkit.getOfflinePlayer("" + ChatColor.BLUE + ChatColor.BOLD + group)).setScore(12);
    111. obj.getScore(Bukkit.getOfflinePlayer(" ")).setScore(11);
    112. obj.getScore(Bukkit.getOfflinePlayer(ChatColor.GOLD + "" + ChatColor.BOLD + "Website")).setScore(10);
    113. obj.getScore(Bukkit.getOfflinePlayer("" + ChatColor.BLUE + ChatColor.BOLD + "xex-mc.info")).setScore(9);
    114. obj.getScore(Bukkit.getOfflinePlayer(ChatColor.BLACK + "-------------")).setScore(8);
    115.  
    116. player.setScoreboard(board);
    117.  
    118. }
    119.  
    120.  
    121.  
    122. public void setupTimer()
    123. {
    124. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    125. {
    126. public void run() {
    127. for (Player p : Bukkit.getOnlinePlayers())
    128. {
    129. updateScoreboard(p);
    130. }
    131. }
    132. }, 0L, 1L);
    133. }
    134.  
    135.  
    136.  
    137.  
    138. @EventHandler
    139. public void onjoin(PlayerJoinEvent e){
    140. updateScoreboard(e.getPlayer());
    141. }
    142.  
    143.  
    144.  
    145. }


    Sorry about this but I need to bump this.

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

    Konato_K

    It will flash because you're creating a new scoreboard every time you call updateScoreboard(), the only way you can prevent this is, instead of creating a new scoreboard, you need to modify the current one, just change the value of the scores and that.
     
  3. Offline

    Aussie_Jhawking

  4. Offline

    GeorgeeeHD

    Aussie_Jhawking try declaring the scoreboard variable outside of the method and reference it within the method and it might fix it
     
  5. Offline

    Pik0

    Aussie_Jhawking Declare the scoreboard outside the method, so it will only define when the server enables. You should declare the Objective too so you can access scores with objective.getScore... and then its just change the score
     
  6. Offline

    CakePvP

    ...alternatively you can set the scoreboard once then get the scoreboard using player.getScoreboard() and then edit the values.
     
Thread Status:
Not open for further replies.

Share This Page