Solved Scoreboard line skipped

Discussion in 'Spigot Plugin Development' started by Christophe6, May 22, 2016.

  1. Hello, this line is skipped:
    Code (Java):
    Score kingdomname = objective.getScore(ChatColor.RED + "" + ChatColor.BOLD + ">>> " + ChatColor.RESET + "None");
                kingdomname.setScore(7);
    Why? The rest is working. When a player has a kingdom it works but when he hasn't the line will be skipped.
    Full code:
    Code (Java):
    package me.christophe6.kingdom;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class ScoreBoardHandler {
       
        static ScoreBoardHandler instance = new ScoreBoardHandler();
       
        public static ScoreBoardHandler getInstance() {
                return instance;
        }
       
        public void setScoreBoard(Player player) {
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
            Objective objective = board.registerNewObjective("test", "dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName(ChatColor.AQUA + "" + ChatColor.BOLD + "Kingdom");
           
            //Kingdom:
            Score kingdom = objective.getScore(ChatColor.GREEN + "Kingdom:");
            kingdom.setScore(8);
           
            //KINGDOMNAME
            if(KingdomHandler.getInstance().hasKingdom(player)) {
                Score kingdomname = objective.getScore(ChatColor.RED + "" + ChatColor.BOLD + ">>> " + ChatColor.RESET + KingdomHandler.getInstance().getColor(KingdomHandler.getInstance().getKingdom(player)) + KingdomHandler.getInstance().getKingdom(player));
                kingdomname.setScore(7);
            } else {
                Score kingdomname = objective.getScore(ChatColor.RED + "" + ChatColor.BOLD + ">>> " + ChatColor.RESET + "None");
                kingdomname.setScore(7);
            }
           
            //SPACE
            Score space = objective.getScore("                     ");
            space.setScore(6);
           
            //Prefix:
            Score prefix = objective.getScore(ChatColor.GREEN + "Prefix:");
            prefix.setScore(5);
           
            //PREFIX
            Score prefixname = objective.getScore(ChatColor.RED + "" + ChatColor.BOLD + ">>> " + ChatColor.RESET + ChatColor.translateAlternateColorCodes('&', KingdomHandler.getInstance().getPrefix(player)));
            prefixname.setScore(4);
           
            //SPACE2
               Score space2 = objective.getScore(" ");
               space2.setScore(3);
               
               //Owner:
            Score owner = objective.getScore(ChatColor.GREEN + "Owner:");
            owner.setScore(2);
               
            //OWNER
            if(KingdomHandler.getInstance().hasKingdom(player)) {
                Score ownername = objective.getScore(ChatColor.RED + "" + ChatColor.BOLD + ">>> " + ChatColor.RESET + ChatColor.translateAlternateColorCodes('&', KingdomHandler.getInstance().getOwner(KingdomHandler.getInstance().getKingdom(player))));
                ownername.setScore(1);
            } else {
                Score ownername = objective.getScore(ChatColor.RED + "" + ChatColor.BOLD + ">>> " + ChatColor.RESET + "None");
                ownername.setScore(1);
            }
           
            player.setScoreboard(board);
        }
    }
     
     
  2. Well ehh I don't think you got a kingdom then
     
  3. @Pr0totype2
    But if I do not have a kingdom, I would see one line with ">>> None".
    Code (Text):
            //KINGDOMNAME
            if(KingdomHandler.getInstance().hasKingdom(player)) {
                Score kingdomname = objective.getScore(ChatColor.RED + "" + ChatColor.BOLD + ">>> " + ChatColor.RESET + KingdomHandler.getInstance().getColor(KingdomHandler.getInstance().getKingdom(player)) + KingdomHandler.getInstance().getKingdom(player));
                kingdomname.setScore(7);
            } else {
                Score kingdomname = objective.getScore(ChatColor.RED + "" + ChatColor.BOLD + ">>> " + ChatColor.RESET + "None");
                kingdomname.setScore(7);
            }
     
  4. put debug prints
    or compute the message in an if statement and take the applying to the scoreboard out of the if/else

    Gesendet von meinem Nexus 5 mit Tapatalk
     
  5. Are you sure KingdomHandler.getInstance().hasKingdom(player) doesn't return an error?
     
  6. Doesn't really help us. Where are you returning the boolean? Use debug messages to check if it always returns true/false, and work from there.
     
  7. What do you mean by that?
     
  8. Where is he instantiating the boolean? For all we know, it could be a simple mistake, such as:

    Code (Text):
    private boolean ownsKingdom = true;

    public boolean hasKingdom() {
    return ownsKingdom;
    }
    In which case it would always return true.
     
  9. View this vídeo:
     
  10. check the config
     
  11. oh ew, his naming conventions
     
    • Agree Agree x 1
  12. Have you even watched that video? There are so many things wrong with it, I can't even begin to explain.

    • Why have a static ArrayList when you can simply use a getter/setter?
    • Why send a message when the plugin is enabled/disabled? Bukkit does this for you.
    • He obviously doesn't understand Java conventions by any means, and doesn't follow them.
    • Why replace characters when you can use translateAlternateColorCodes(char c, String s) already with Bukkit?
     
  13. mhm, I didn't watch 2 minutes in and I found 3 errors
    so...
     
  14. It's so weird, when I put the code out of the if-statement, it will only show when the player has a kingdom! I don't know why the debug message gets in the else? It's printing my debug messages but not executing this:
    Code (Java):
    Score kingdomnone = objective.getScore(ChatColor.RED + "" + ChatColor.BOLD + ">>> " + ChatColor.RESET + "None");
                kingdomnone.setScore(7);
     
  15. Does anyone knows the solution?
     
  16. Dont bump within 24 hours. As far as I know score can't have empty lines. add a ChatColor into it. And I suggest to use teams for your scoreboard.
     
  17. I found the problem! The problem was that I had two scores called the same "CHATCOLORTAGS + "None";
    It was taking over the first "none" and replaced it with the second "none".