Solved name greater than sixteen chars error when using prefix and suffix

Discussion in 'Spigot Plugin Development' started by Z3tr0nix, Jun 12, 2017.

Thread Status:
Not open for further replies.
  1. when using the bukkit scoreboard API I am gettiing an error when logging on to my server, I am changing the prefix of a line on scoreboard (§1§r), to stop jitter and support 32 chars per line, but this is what i get:
    2017-06-12_17.47.34.png
    I can give code when requested, nothing shows up in console...
     
  2. Code please.
     
  3. Code (Java):
                                    Team team;
                                    if(objective.getScoreboard().getTeam(getName(currentScore)) != null){
                                        team = objective.getScoreboard().registerNewTeam(getName(currentScore));
                                        team.addEntry(getName(currentScore));
                                    }else{
                                        team = objective.getScoreboard().getTeam(getName(currentScore));
                                        if(!team.hasEntry(getName(currentScore)))
                                            team.addEntry(getName(currentScore));
                                    }
                                    char color = 'f';
                                    for(int i = 0; i < animations.get(currentLine).get(currentAnimation).length()/2; ++i){
                                        if(animations.get(currentLine).get(currentAnimation).charAt(i) == '§'){
                                            color = animations.get(currentLine).get(currentAnimation).charAt(i + 1);
                                        }
                                    }
                                    team.setPrefix(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.
                                            setPlaceholders(player, animations.get(currentLine).
                                                    get(currentAnimation).substring(animations.get(currentLine)
                                                            .get(currentAnimation).length()/2))));
                                    team.setSuffix(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.
                                            setPlaceholders(player, "§"+ color + animations.get(currentLine)
                                            .get(currentAnimation).substring(0, animations.get(currentLine)
                                                    .get(currentAnimation).length()/2))));                              
                                    currentScore = currentScore + 1; //move on to the next line
    its a bit messy, but I think the problem happens in team.setPrefix, that is when i think the player gets kicked
     
  4. When you setPrefix, addEntry, or setSuffix, one of those is greater than 16, add some debug to check.
     
  5. I have made sure that all of them are below 16 chars.... and if they are above then it errors out in console....
     
  6. Debug all of them, and double check.

    Make them log into the console.

    Send us the debug.
     
  7. A single chat color is 2 characters, if you have two chat colors in your prefix then it has a maximum length of 12.
     
    • Informative Informative x 1
  8. I know, now i cant login at all, the method that caused this isnt even getting invoked...
     
  9. *bump*, how can i log back in, can someone take a look at my problem?
     
  10. remove the scoreboard with commands. Then you can join back.
     
  11. You mean team, and i did Bukkit.getNewScoreboard()... how would i remove that?
     
  12. Simply remove the player from the team. Open up your console and remove the player with the command.

    See here
     
  13. Make a check to see if the total length of the name is above 16 characters.

    If it is, simplify the name, like taking as many characters of the name as you can to equal 16
     
  14. you mean substring it, but why would i substring the name, its 2 chars :|
    basically everything total (prefix + name + suffix) > 16 chars, that is going 19 chars..... can someone look into my problem? I can give you the class which is causing this...
     
  15. Well either use a second line or drop the prefix
     
  16. :\ i need to use the prefix, as I know WITH the bukkit scoreboard api (which needs alot of improv) allows me to do lines with up to 48 chars with prefix + entry + suffix, but rn i can not get it above 16 chars....
     
  17. Code (Text):
    if (!prefix.length > 12) {

       scoreboard.addEntry(player.getName);
       team.setPrefix(prefix);
       team.addPlayer(player);

    }
     
  18. im not adding the player, im adding a scoreboard line
    EDIT: HERE is the scoreboard method (not the whole thing ofc i dont want someone copying) =
    Code (Java):
                           
                            int currentScore = 0; //the current line to edit
                           
                            for(String currentLine : lines){ //get all the lines and set them
                                if(firstTime){
                                    objective.getScore(getName(currentScore)).setScore(currentScore);
                                }
                                try{
                                    Team team;
                                    if(objective.getScoreboard().getTeam(getName(currentScore)) != null){
                                        team = objective.getScoreboard().registerNewTeam(getName(currentScore));
                                        team.addEntry(getName(currentScore));
                                    }else{
                                        team = objective.getScoreboard().getTeam(getName(currentScore));
                                        if(!team.hasEntry(getName(currentScore)))
                                            team.addEntry(getName(currentScore));
                                    }
                                    char color = 'f';
                                    for(int i = 0; i < animations.get(currentLine).get(currentAnimation).length()/2; ++i){
                                        if(animations.get(currentLine).get(currentAnimation).charAt(i) == '§'){
                                            color = animations.get(currentLine).get(currentAnimation).charAt(i + 1);
                                        }
                                    }
                                    team.setPrefix(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.
                                            setPlaceholders(player, animations.get(currentLine).
                                                    get(currentAnimation).substring(animations.get(currentLine)
                                                            .get(currentAnimation).length()/2))));
                                    team.setSuffix(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.
                                            setPlaceholders(player, "§"+ color + animations.get(currentLine)
                                            .get(currentAnimation).substring(0, animations.get(currentLine)
                                                    .get(currentAnimation).length()/2))));                      
                                    currentScore = currentScore + 1; //move on to the next line
                                   
                                }catch(Exception e){ //incase the animation does not exist
                                   
                                    currentAnimation = 0; //go back to the first frame
                                    Team team;
                                    if(objective.getScoreboard().getTeam(getName(currentScore)) == null){
                                        team = objective.getScoreboard().registerNewTeam(getName(currentScore));
                                        team.addEntry(getName(currentScore));
                                    }else{
                                        team = objective.getScoreboard().getTeam(getName(currentScore));
                                        if(!team.hasEntry(getName(currentScore)))
                                            team.addEntry(getName(currentScore));
                                    }
                                    char color = 'f';
                                    for(int i = 0; i < animations.get(currentLine).get(currentAnimation).length()/2; ++i){
                                        if(animations.get(currentLine).get(currentAnimation).charAt(i) == '§'){
                                            color = animations.get(currentLine).get(currentAnimation).charAt(i + 1);
                                        }
                                    }
                                    System.out.print(getName(currentScore).length());
                                    System.out.print(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.
                                            setPlaceholders(player, animations.get(currentLine).
                                                    get(currentAnimation).substring(animations.get(currentLine)
                                                            .get(currentAnimation).length()/2))).length());
                                    System.out.print(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.
                                            setPlaceholders(player, "§"+ color + animations.get(currentLine)
                                            .get(currentAnimation).substring(0, animations.get(currentLine)
                                                    .get(currentAnimation).length()/2))).length());
                                    team.setPrefix(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.
                                            setPlaceholders(player, animations.get(currentLine).
                                                    get(currentAnimation).substring(animations.get(currentLine)
                                                            .get(currentAnimation).length()/2))));
                                    team.setSuffix(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.
                                            setPlaceholders(player, "§"+ color + animations.get(currentLine)
                                            .get(currentAnimation).substring(0, animations.get(currentLine)
                                                    .get(currentAnimation).length()/2))));

                                }
     
    #18 Z3tr0nix, Jun 13, 2017
    Last edited: Jun 13, 2017
  19. Every time you go to setPrefix or setSuffix check to see if the message you are putting in there is less than 12 characters.
     
  20. mate i am...
     
Thread Status:
Not open for further replies.