Scoreboard Team Prefix

Discussion in 'Plugin Development' started by FlipSide_Mike, Dec 14, 2014.

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

    FlipSide_Mike

    I am using teams to make the tab list organized, and for some other ideas I have ;) but I can't get the prefixes to work... They used to work for me, now when I join I crash and get the client side error:
    Code:
    Internal Exception: io.netty.handler.codec.DecoderException: java.io.IOException: The received string length is longer than the maximum allowed (20>16)
    Now my issue is that A) Team Prefixes have a maximum length of 16 characters, as well as when in use, allow the tab list strings to increase by 16, same with suffixes, hypothetically making names up to 48 characters, and B) My full IGN is 11 Characters, plus 6 for the Prefix is 17, not 20...
    My Code:
    Code:
    package com.Petro.TabDeco;
    
    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.java.JavaPlugin;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    import org.bukkit.scoreboard.Team;
    
    /**
    * * **************************************************************************************
    * Copyright TheFlipSide (c) 2014.  All Rights Reserved.
    * Any code contained within TabDeco (this document), and any associated APIs with similar branding
    * are the sole property of Michael Petramalo.  Distribution, reproduction, taking sections, or
    * claiming any contents as your own will break the terms of the license, and void any
    * agreements with the third-party, you.
    * Thanks.
    * Created on 12/14/2014 at 3:32 PM.
    * ******************************************************************************************
    */
    public class Core extends JavaPlugin implements Listener {
    
        ScoreboardManager man;
        Scoreboard sb;
    
        Team OP;
        Team ADMIN;
        Team SRMOD;
        Team MOD;
        Team HELPER;
        Team BUILDER;
        Team YOUTUBER;
        Team COMMANDER;
        Team ENGINEER;
        Team SPECIALIST;
        Team PILOT;
        Team MEMBER;
    
        @Override
        public void onEnable() {
            getLogger().info("Enabled");
            getServer().getPluginManager().registerEvents(this, this);
    
            man = Bukkit.getScoreboardManager();
            sb =  man.getMainScoreboard();
    
            OP = sb.registerNewTeam("OP");
            ADMIN = sb.registerNewTeam("ADMIN");
            SRMOD = sb.registerNewTeam("SRMOD");
            MOD = sb.registerNewTeam("MOD");
            HELPER = sb.registerNewTeam("HELPER");
            BUILDER = sb.registerNewTeam("BUILDER");
            YOUTUBER = sb.registerNewTeam("YOUTUBER");
            COMMANDER = sb.registerNewTeam("COMMANDER");
            ENGINEER = sb.registerNewTeam("ENGINEER");
            SPECIALIST = sb.registerNewTeam("SPECIALIST");
            PILOT = sb.registerNewTeam("PILOT");
            MEMBER = sb.registerNewTeam("MEMBER");
    
            setPrefix();
        }
    
        public void setPrefix(){
            OP.setPrefix("§4§lOWNER §r");
            ADMIN.setPrefix("§1§lADMIN §r");
            SRMOD.setPrefix("§2§lSR. MOD §r");
            MOD.setPrefix("§a§lMOD §");
            HELPER.setPrefix("§d§lHELPER §");
            BUILDER.setPrefix("§d§lBUILDER §");
            YOUTUBER.setPrefix("§c§lYOUTUBER §");
            COMMANDER.setPrefix("§6§lCOMMANDER §");
            ENGINEER.setPrefix("§5§lENGINEER §");
            SPECIALIST.setPrefix("§b§lSPECIALIST §");
            PILOT.setPrefix("§e§lPILOT §");
        }
    
        @Override
        public void onDisable() {
            getLogger().info("Disabled");
        }
    
        @EventHandler
             public void onPlayerJoin(PlayerJoinEvent event){
            Player player = event.getPlayer();
            player.setScoreboard(sb);
            if (player.hasPermission("prefix.owner")) {
                OP.addPlayer(player);
            } else if (player.hasPermission("prefix.admin")) {
                ADMIN.addPlayer(player);
            } else if (player.hasPermission("prefix.srmod")) {
                SRMOD.addPlayer(player);
            } else if (player.hasPermission("prefix.mod")) {
                MOD.addPlayer(player);
            } else if (player.hasPermission("prefix.helper")) {
                HELPER.addPlayer(player);
            } else if (player.hasPermission("prefix.builder")) {
                BUILDER.addPlayer(player);
            } else if (player.hasPermission("prefix.youtuber")) {
                YOUTUBER.addPlayer(player);
            } else if (player.hasPermission("prefix.commander")) {
                COMMANDER.addPlayer(player);
            } else if (player.hasPermission("prefix.engineer")) {
                ENGINEER.addPlayer(player);
            } else if (player.hasPermission("prefix.specialist")) {
                SPECIALIST.addPlayer(player);
            } else if (player.hasPermission("prefix.pilot")) {
                PILOT.addPlayer(player);
            } else {
                MEMBER.addPlayer(player);
            }
        }
    }
    
    To be clear, for prefixes I have tried
    Translating Alternate Color Codes w/ &
    Translating Alternate Color Codes w/ & using Pre-Defined Strings
    Using ChatColors
    Not Using Any Special Characters
    Using the Formatting Char §
    Having No Prefix!!!
    Using No ColorChars!

    None of these worked!
     
    Last edited: Dec 15, 2014
  2. Offline

    pookeythekid

    @FlipSide_Mike Hm. I've encountered a similar thing with a plugin that uses signs. I could only squeeze 15 characters into the sign's prefix when the tag was converted from normal black to color codes (and apparently ChatColors count as color code characters). I found no way around this, so I simply warned users in the config not to exceed 15 characters including color codes. Unless someone responds and knows how to fix this, which I would love to try for myself, I would suggest finding a way to shorten the usernames of players to fit 16 characters with the prefix.
     
  3. Offline

    FlipSide_Mike

    @pookeythekid
    Okay, I just tried simply "OWNER" even tho it would make the tab look really bad, and it gave me the same error (23>16) even though without the extension it 16 characters! This is legitimately annoying me to no end!

    BUMP - The only way I have gotten it to allow access to the server is use predefined string but the issue arises that "Smiley Faces" are also in the prefix
    [​IMG] http://gyazo.com/d414927d813afc6e67729a884820fc78
    Predefined Strings
    Code:
        public String red = "§4";
        public String purple = "§5";
        public String green = "§2";
        public String lime = "§a";
        public String orange = "§6";
        public String pink = "§d";
        public String lightred = "§c";
        public String yellow = "§e";
        public String blue = "§9";
        public String aqua = "§b";
        public String bold = "§l";
        public String reset = "§r";
        public String space = " ";
    Prefixes
    Code:
         
            OP.setPrefix(this.red + this.bold + "OWNER" + this.reset + this.space);
            ADMIN.setPrefix(this.orange + this.bold + "ADMIN" + this.reset + this.space);
            SRMOD.setPrefix(this.green + this.bold + "SR. MOD" + this.reset + this.space);
            MOD.setPrefix(this.lime + this.bold + "MOD" + this.reset + this.space);
            HELPER.setPrefix(this.pink + this.bold + "HELPER" + this.reset + this.space);
            BUILDER.setPrefix(this.pink + this.bold + "BUILDER" + this.reset + this.space);
            YOUTUBER.setPrefix(this.lightred + this.bold + "YOUTUBER" + this.reset + this.space);
            COMMANDER.setPrefix(this.blue + this.bold + "COMMANDER" + this.reset + this.space);
            ENGINEER.setPrefix(this.purple + this.bold + "ENGINEER" + this.reset + this.space);
            SPECIALIST.setPrefix(this.aqua + this.bold + "SPECIALIST" + this.reset + this.space);
            PILOT.setPrefix(this.yellow + this.bold + "PILOT" + this.reset + this.space);
    Why is the Smiley Face there when I use the § symbol? Or how do I fix the original issue?!

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

    joeygallegos

    @FlipSide_Mike You might have a problem with a custom resource pack no "understanding" what the § character is and translating it. In this way I would stick with the usual ChatColor.COLOR. I wouldn't also use a bunch of if and else statements. I would use a switch statement. If I understand correctly using ChatColor isn't used as character like §.
     
  5. Offline

    FlipSide_Mike

    @joeygallegos For a Switch statement using permissions how would that work? Something like this?
    Code:
    public static Team getTeam(String perm){
         for(Player player : Bukkit.getOnlinePlayers){
         if(perm == null){
              MEMBER.addPlayer(player);
         }
         switch(perm){
               case "prefix.owner":
                       OP.addPlayer(player);
               case "prefix.admin":
                       ADMIN.addPlayer(player);
     
  6. Offline

    pookeythekid

    As I said in an earlier post, I'm pretty sure it still ends up being one character of ChatColor, as a ChatColor apparently counts as a character in a string, although it's invisible.

    @FlipSide_Mike Yep.
     
  7. Offline

    FlipSide_Mike

    @pookeythekid The ChatColor didn't work anyways, even when I have a one character prefix, its still 'too long' :/
     
  8. Offline

    pookeythekid

  9. Offline

    FlipSide_Mike

    @pookeythekid It works without me setting a prefix, but as for no characters in the string I am yet to try that!
     
  10. Offline

    FlipSide_Mike

    Anybody have a working solution?
     
Thread Status:
Not open for further replies.

Share This Page