Solved Scoreboard and tabprefix

Discussion in 'Plugin Development' started by MrGG4ming, Mar 28, 2017.

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

    MrGG4ming

    - Hello everyone, I'm working with a plugin where you will have the scoreboard informing you of some information such as coins and clan group, but I'm having a hard time keeping both scoreboard and tabprefix running at the same time. I can work with each one individually quietly, however when I try to use both of them always one of them buga, The following code is only bugging the tab in which it does not add the tag of the players that are already online in the server to which it enters and does not adress to Who is online the tag of who enters ..

    Code:
    public void add(final Player p) {
            final ScoreboardManager manager1 = Bukkit.getScoreboardManager();
            final Scoreboard board1 = manager1.getNewScoreboard();
            final Objective objective1 = board1.registerNewObjective("Scoreboard", "dummy");
          
            objective1.setDisplaySlot(DisplaySlot.SIDEBAR);
    
    // Here I create the groups and soon after they go to when they enter
            Team MASTER = board1.registerNewTeam("00000master");
            Team ADMIN = board1.registerNewTeam("00001admin");
            MASTER.setPrefix("§6[MASTER] ");
            ADMIN.setPrefix("§c[ADMIN] ");
          
            if (GroupAPI.getGroup(p.getName()).equals("MASTER")) {
                MASTER.addPlayer(p);
            } else {
                if (GroupAPI.getGroup(p.getName()).equals("ADMIN")) {
                    ADMIN.addPlayer(p);
                }
            }
            //Finish here (Tabprefix)
    
            Score spacer2 = objective1.getScore("§d ");
            spacer2.setScore(7);
    
            if (GroupAPI.getGroup(p.getName()).equals("MASTER")) {
                Score score = objective1.getScore("Grupo: §6[MASTER]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("ADMIN")) {
                Score score = objective1.getScore("Grupo: §c[ADMIN]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("SUPORTE")) {
                Score score = objective1.getScore("Grupo: §a[SUPORTE]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("MODERADOR")) {
                Score score = objective1.getScore("Grupo: §2[MODERADOR]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("BUILDER")) {
                Score score = objective1.getScore("Grupo: §9[BUILDER]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("YT")) {
                Score score = objective1.getScore("Grupo: §c[YT]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("DEFAULT")) {
                Score score = objective1.getScore("Grupo: §8[MEMBRO]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("VIP")) {
                Score score = objective1.getScore("Grupo: §4[GLADIADOR]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("VIP+")) {
                Score score = objective1.getScore("Grupo: §b[LORD]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("VIP++")) {
                Score score = objective1.getScore("Grupo: §5[TITAN]");
                score.setScore(6);
            }
    
            Score Score4 = objective1.getScore("Gangue: §7[BREVE]");
            Score4.setScore(5);
    
            double saldo = CoinAPI.getCoins(p.getName());
            DecimalFormat formatter = new DecimalFormat("#,###.00");
    
            if (CoinAPI.getCoins(p.getName()) == 0.0D) {
                String saldo0 = "0.0";
    
                Score score3 = objective1.getScore("Moedas: " + ChatColor.GREEN + saldo0);
                score3.setScore(4);
            } else {
                Score score3 = objective1.getScore("Moedas: " + ChatColor.GREEN + formatter.format(saldo));
                score3.setScore(4);
            }
            Score score2 = objective1.getScore("Online: " + ChatColor.GREEN + Bukkit.getOnlinePlayers().size());
            score2.setScore(3);
    
            Score spacer1 = objective1.getScore(" ");
            spacer1.setScore(2);
            Score score1 = objective1.getScore("§ewww.finalelite.com.br");
            score1.setScore(1);
    
            A.clear();
            A.add("1");
    
            BukkitScheduler Scheduler1 = Bukkit.getServer().getScheduler();
            Scheduler1.scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    Integer i = Integer.valueOf(Main.A.size());
    
                    if (i.intValue() == 1) {
                        objective1.setDisplayName(Main.Format("&c&lFinalElite"));
                        Main.A.add("A");
                    }
                    if (i.intValue() == 2) {
                        objective1.setDisplayName(Main.Format("&6&lFinalElite"));
                        Main.A.add("B");
                    }
                    if (i.intValue() == 3) {
                        objective1.setDisplayName(Main.Format("&f&lFinalElite"));
                        Main.A.add("C");
                    }
                    if (i.intValue() == 4) {
                        objective1.setDisplayName(Main.Format("&e&lFinalElite"));
                        Main.A.add("D");
                    }
                    if (i.intValue() == 4) {
                        Main.A.clear();
                        Main.A.add("1");
                    }
                }
            }, 0L, 5L);
            p.setScoreboard(board1);
        }
    
    //
    Here I get the player giving join and hedge in add ..
        @EventHandler
        public void onJoinScore(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            this.add(p);
        }
    The problem in this case is not in the scoreboard, but in the tabprefix itself.
    Sorry, my english because I'm Brazilian.
     
    Last edited: Mar 28, 2017
  2. Offline

    Zombie_Striker

    @MrGG4ming
    Your issue is that you are creating a new scoreboard for each player, which overrides tabprefix's scoreboard. Instead of creating a new scoreboard, get the player's scoreboard and create a new objective for that scoreboard.
     
  3. Offline

    MrGG4ming

    @Zombie_Striker
    So I had done in a way in which the tab loaded properly, but the one who gave error was the scoreboard ..
    I will send the second code I had made ...

    @Zombie_Striker
    Already this error code the scoreboard ..

    Code:
    public class Main extends JavaPlugin implements Listener {
    
        static ArrayList<String> A = new ArrayList<String>();
    
        ScoreboardManager manager1;
        Scoreboard board1;
        Objective objective1;
        Team MASTER;
        Team ADMIN;
    
        public void onEnable() {
            MySql.connect();
            manager1 = Bukkit.getScoreboardManager();
            board1 = manager1.getNewScoreboard();
            objective1 = board1.registerNewObjective("board", "dummy");
            MASTER = board1.registerNewTeam("00000master");
            ADMIN = board1.registerNewTeam("00001admin");
    
            setPrefix();
        }
    
        public void onDisable() {
            MySql.disconnect();
            ConsoleCommandSender b = Bukkit.getConsoleSender();
            b.sendMessage("§c§lPlugin basics desativado!");
        }
    
        @SuppressWarnings("deprecation")
        @EventHandler
        public void PlayerJoinEvent(PlayerJoinEvent e) {
            Player player = e.getPlayer();
            if (GroupAPI.getGroup(player.getName()).equals("MASTER")) {
                MASTER.addPlayer(player);
            } else {
                if (GroupAPI.getGroup(player.getName()).equals("ADMIN")) {
                    ADMIN.addPlayer(player);
                }
            }
        }
    
        public void setPrefix() {
            MASTER.setPrefix("§6[MASTER] ");
            ADMIN.setPrefix("§c[ADMIN] ");
        }
    
        public void add(final Player p) {
         
            objective1.setDisplaySlot(DisplaySlot.SIDEBAR);
    
            Score spacer2 = objective1.getScore("§d ");
            spacer2.setScore(7);
    
            if (GroupAPI.getGroup(p.getName()).equals("MASTER")) {
                Score score = objective1.getScore("Grupo: §6[MASTER]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("ADMIN")) {
                Score score = objective1.getScore("Grupo: §c[ADMIN]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("SUPORTE")) {
                Score score = objective1.getScore("Grupo: §a[SUPORTE]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("MODERADOR")) {
                Score score = objective1.getScore("Grupo: §2[MODERADOR]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("BUILDER")) {
                Score score = objective1.getScore("Grupo: §9[BUILDER]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("YT")) {
                Score score = objective1.getScore("Grupo: §c[YT]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("DEFAULT")) {
                Score score = objective1.getScore("Grupo: §8[MEMBRO]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("VIP")) {
                Score score = objective1.getScore("Grupo: §4[GLADIADOR]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("VIP+")) {
                Score score = objective1.getScore("Grupo: §b[LORD]");
                score.setScore(6);
            }
            if (GroupAPI.getGroup(p.getName()).equals("VIP++")) {
                Score score = objective1.getScore("Grupo: §5[TITAN]");
                score.setScore(6);
            }
    
            Score Score4 = objective1.getScore("Gangue: §7[BREVE]");
            Score4.setScore(5);
    
            double saldo = CoinAPI.getCoins(p.getName());
            DecimalFormat formatter = new DecimalFormat("#,###.00");
    
            if (CoinAPI.getCoins(p.getName()) == 0.0D) {
                String saldo0 = "0.0";
    
                Score score3 = objective1.getScore("Moedas: " + ChatColor.GREEN + saldo0);
                score3.setScore(4);
            } else {
                Score score3 = objective1.getScore("Moedas: " + ChatColor.GREEN + formatter.format(saldo));
                score3.setScore(4);
            }
            Score score2 = objective1.getScore("Online: " + ChatColor.GREEN + Bukkit.getOnlinePlayers().size());
            score2.setScore(3);
    
            Score spacer1 = objective1.getScore(" ");
            spacer1.setScore(2);
            Score score1 = objective1.getScore("§ewww.finalelite.com.br");
            score1.setScore(1);
    
            A.clear();
            A.add("1");
    
            BukkitScheduler Scheduler1 = Bukkit.getServer().getScheduler();
            Scheduler1.scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    Integer i = Integer.valueOf(Main.A.size());
    
                    if (i.intValue() == 1) {
                        objective1.setDisplayName(Main.Format("&c&lFinalElite"));
                        Main.A.add("A");
                    }
                    if (i.intValue() == 2) {
                        objective1.setDisplayName(Main.Format("&6&lFinalElite"));
                        Main.A.add("B");
                    }
                    if (i.intValue() == 3) {
                        objective1.setDisplayName(Main.Format("&f&lFinalElite"));
                        Main.A.add("C");
                    }
                    if (i.intValue() == 4) {
                        objective1.setDisplayName(Main.Format("&e&lFinalElite"));
                        Main.A.add("D");
                    }
                    if (i.intValue() == 4) {
                        Main.A.clear();
                        Main.A.add("1");
                    }
                }
            }, 0L, 5L);
            p.setScoreboard(board1);
        }
    
        @EventHandler
        public void onJoinScore(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            this.add(p);
        }
    
        public static String Format(String text) {
            return text.replaceAll("&", "§");
        }
    }
    
    First error in tab: https://imgur.com/QIXSpLi
    Second error in scoreboard: http://prntscr.com/epkruu

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Mar 28, 2017
  4. Offline

    Drkmaster83

    For your tab problem: Either your players need to have the same scoreboard, or if you have personalized objectives in the sidebar, they need to have duplicate teams with duplicate prefixes across all existing/online player scoreboards.

    For your scoreboard problem: You have multiple entries that have the same score. You probably need to build a system that associates one entry per score (Only one value can have a red 6 on the right). Aside from that, the problem gets complicated from you attempting to have the same scoreboard for all players.

    In summation, you will need a scoreboard for every player on the server.
     
Thread Status:
Not open for further replies.

Share This Page