Codec is over 19 for scoreboard.

Discussion in 'Spigot Plugin Development' started by avighnash, May 29, 2016.

  1. Just now, I switched to scoreboard teams (I don't know why I didn't earlier). But when I tested it, it said something about the string codec thingy being 21 > 19. Why is that? Here is my class"

    Code (Text):
    package us.universalpvp.te.scoreboard;

    import 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.plugin.messaging.PluginMessageListener;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.Team;

    import com.google.common.io.ByteArrayDataInput;
    import com.google.common.io.ByteArrayDataOutput;
    import com.google.common.io.ByteStreams;

    import us.universalpvp.te.MainClass;
    import us.universalpvp.te.utils.ColorScroller;
    import us.universalpvp.te.utils.Vault;

    @SuppressWarnings("deprecation")
    public class HubScoreboard implements Listener, PluginMessageListener {

        public HubScoreboard() {
        }

        private Scoreboard sco = MainClass.getInstance().sb;
        private String rankName = " ";
        private String world = " ";

        final Objective obj = sco.registerNewObjective("the hubboard", "dummy");
        final Team playersTeam = sco.registerNewTeam("Players");
        final Team coinsTeam = sco.registerNewTeam("ugh");
        final Team rankTeam = sco.registerNewTeam("Ranks");
        final Team rankDisplayTeam = sco.registerNewTeam("Ranks Display");
        final Team serverTeam = sco.registerNewTeam("Servers");
        final Team ipTeam = sco.registerNewTeam("IP");

        private int players;

        private Scoreboard setHubBoard() {

            new BukkitRunnable() {

                final ColorScroller displayName = new ColorScroller(ChatColor.AQUA, " UniversalPvP", "", "§f", "", true,
                        false, ColorScroller.ScrollType.FORWARD);

                @Override
                public void run() {

                    obj.setDisplayName(displayName.next());
                    obj.setDisplaySlot(DisplaySlot.SIDEBAR);

                    String s = ChatColor.translateAlternateColorCodes('&', "&9&luniversalpvp.us");

                    // SPACER
                    obj.getScore(Bukkit.getOfflinePlayer(ChatColor.RED.toString())).setScore(11);

                    // RANKS
                    rankTeam.setPrefix(ChatColor.WHITE + "Rank:");
                    rankTeam.addEntry("1");

                    obj.getScore("1").setScore(10);

                    rankDisplayTeam.setPrefix(rankName);
                    rankDisplayTeam.addEntry("2");

                    obj.getScore("2").setScore(9);

                    // SPACER
                    obj.getScore(ChatColor.YELLOW.toString()).setScore(8);

                    // COINS
                    coinsTeam.setPrefix(ChatColor.WHITE + "Coins:");
                    coinsTeam.setSuffix(ChatColor.GREEN + " " + 0);
                    coinsTeam.addEntry("3");

                    obj.getScore("3").setScore(7);

                    // PLAYER COUNT
                    playersTeam.setPrefix(ChatColor.WHITE + "Players:");
                    playersTeam.setSuffix(ChatColor.GREEN + " " + players);
                    playersTeam.addEntry("4");

                    obj.getScore("4").setScore(6);

                    // SPACER
                    obj.getScore(ChatColor.GREEN.toString()).setScore(5);

                    // SERVER
                    serverTeam.setPrefix(ChatColor.WHITE + "Server: ");
                    serverTeam.setSuffix(world);
                    serverTeam.addEntry("5");

                    obj.getScore("5").setScore(4);

                    // SPACER
                    obj.getScore(ChatColor.BLUE.toString()).setScore(3);

                    // LINE
                    obj.getScore("---------------").setScore(2);

                    // IP
                    ipTeam.setPrefix(s);
                    ipTeam.addEntry("6");

                }
            }.runTaskTimer(MainClass.getInstance(), 0, 10);

            return sco;

        }

        @EventHandler
        public void onPlayerJoinScoreboard(PlayerJoinEvent e) {

            Player p = e.getPlayer();

            String primaryGroup = Vault.getChat().getPrimaryGroup(p);
            if (primaryGroup.equalsIgnoreCase("default")) {

            } else if (primaryGroup.equalsIgnoreCase("default")) {
                rankName = (ChatColor.translateAlternateColorCodes('&', "&7Default "));

            } else if (primaryGroup.equalsIgnoreCase("Owner")) {
                rankName = (ChatColor.translateAlternateColorCodes('&', "&3[Owner]&3 "));

            } else if (primaryGroup.equalsIgnoreCase("Admin")) {
                rankName = (ChatColor.translateAlternateColorCodes('&', "&c[Admin]&c "));

            } else if (primaryGroup.equalsIgnoreCase("Mod")) {
                rankName = (ChatColor.translateAlternateColorCodes('&', "&2[Mod]&2 "));

            } else if (primaryGroup.equalsIgnoreCase("Helper")) {
                rankName = (ChatColor.translateAlternateColorCodes('&', "&1[Helper]&1 "));

            } else if (primaryGroup.equalsIgnoreCase("Build")) {
                rankName = (ChatColor.translateAlternateColorCodes('&', "&b[Builder]&b "));

            } else if (primaryGroup.equalsIgnoreCase("CoOwner")) {
                rankName = (ChatColor.translateAlternateColorCodes('&', "&e[Co-Owner]&e "));
            }

            world = p.getWorld().getName().replace("Hub", "Lobby");

            for (Player pl : Bukkit.getOnlinePlayers()) {
                pl.setScoreboard(setHubBoard());
            }

        }

        @Override
        public void onPluginMessageReceived(String channel, Player player, byte[] message) {
            if (!channel.equals("BungeeCord")) {
                return;
            }
            ByteArrayDataInput in = ByteStreams.newDataInput(message);
            String subchannel = in.readUTF();

            if (subchannel.equals("BungeeCord")) {
                ByteArrayDataOutput out = ByteStreams.newDataOutput();
                out.writeUTF("PlayerCount");

                players = in.readInt();

                player.sendPluginMessage(MainClass.getInstance(), "BungeeCord", out.toByteArray());
            }
        }

    }
     
     
  2. String s = ChatColor.translateAlternateColorCodes('&', "&9&luniversalpvp.us"); is too long, the scoreboard text parts can be up to 16 characters each. (prefix, score, suffix, team name)
     
  3. Ohh