Solved Scoreboards... Mindblown.

Discussion in 'Plugin Development' started by ztowne13, May 1, 2014.

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

    ztowne13

    Alright guys, I've used scoreboards before but I've just run into an error and i have no clue why.
    My code:

    Code:
    public static HashMap<Player, NZScoreboard> boards = new HashMap<Player, NZScoreboard>();
     
    Player p;
    Scoreboard board;
    Objective SB;
    //Objective bnty;
     
    public NZScoreboard(Player p)
    {
    this.board = Bukkit.getScoreboardManager().getNewScoreboard();
    this.p = p;
    boards.put(this.p, this);
    this.SB = this.board.registerNewObjective("sidebar", "dummy");
    //this.bnty = this.board.registerNewObjective("bnty", "dummy");
    this.SB.setDisplaySlot(DisplaySlot.SIDEBAR);
    //this.bnty.setDisplaySlot(DisplaySlot.BELOW_NAME);
    this.SB.setDisplayName(ChatColor.AQUA + "" + ChatColor.BOLD + "NoZen Prison");
    //this.bnty.setDisplayName(ChatColor.RED + "" + ChatColor.BOLD + "Bounty");
    }
     
    public void destroyAndSend()
    {
    board = Bukkit.getScoreboardManager().getNewScoreboard();
    display();
    }
     
    public Integer getBounty()
    {
    return new Bounty(p).currentBounty;
    }
     
    public Integer getDeaths()
    {
    return NZPrison.plugin.getConfig().getInt(p.getUniqueId() + ".deaths");
    }
     
    public Integer getOnline()
    {
    return Bukkit.getOnlinePlayers().length;
    }
     
    public Integer getKills()
    {
    return NZPrison.plugin.getConfig().getInt(p.getUniqueId() + ".kills");
    }
     
    public void setDeaths(int amount)
    {
    NZPrison.plugin.getConfig().set(p.getUniqueId() + ".deaths", amount);
    }
     
    public void setKills(int amount)
    {
    NZPrison.plugin.getConfig().set(p.getUniqueId() + ".kills", amount);
    }
     
    public void display()
    {
    Bukkit.broadcastMessage("online: " + getOnline());
    Bukkit.broadcastMessage("bounty: " + getBounty());
    Bukkit.broadcastMessage("deaths: " + getDeaths());
    Bukkit.broadcastMessage("kills: " + getKills());
     
    Score online = SB.getScore(op(ChatColor.GREEN + "" + ChatColor.BOLD + "Online"));
    online.setScore(15);
    Score onlinescore = SB.getScore(op(getOnline() + ""));
    onlinescore.setScore(14);
     
    Score bounty = SB.getScore(op(ChatColor.RED + "" + ChatColor.BOLD + "Bounty"));
    bounty.setScore(13);
    Score bountyscore = SB.getScore(op("$" + getBounty()));
    bountyscore.setScore(12);
     
    Score kills = SB.getScore(op(ChatColor.BLUE + "" + ChatColor.BOLD + "Kills"));
    kills.setScore(11);
    Score killsscore = SB.getScore(op(ChatColor.WHITE + "" + getKills()));
    killsscore.setScore(10);
     
    Score deaths = SB.getScore(op(ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Deaths"));
    deaths.setScore(9);
    Score deathsscore = SB.getScore(op(ChatColor.WHITE + "" + ChatColor.WHITE + "" + getDeaths()));
    deathsscore.setScore(8);
     
    Score website = SB.getScore(op(ChatColor.YELLOW + "" + ChatColor.BOLD + "Website"));
    website.setScore(7);
    Score websitescore = SB.getScore(op("NoZenPvP.org"));
    websitescore.setScore(6);
    Bukkit.broadcastMessage("Board: " + this.board);
    p.setScoreboard(this.board);
    }
     
    @SuppressWarnings("deprecation")
    public static OfflinePlayer op(String name)
    {
    return Bukkit.getOfflinePlayer(name);
     
    }
    
    The code below is used when a player joins.
    Code:
    if(!(NZScoreboard.boards.containsKey(e.getPlayer().getName())))
    {
    new NZScoreboard(e.getPlayer()).display();
    }
    else
    {
    NZScoreboard.boards.get(e.getPlayer()).display();
     
    }
    
    Whenever I join, I get kicked and I don't know why. The "error":
    Code:
    [19:04:58 INFO]: ztowne13 lost connection: Internal Exception: net.minecraft.util.io.netty.handler.codec.EncoderException: java.lang.NullPointerException
     
    [19:04:58 INFO]: ztowne13 left the game.
    
    I have no idea why it doesn't work.
    I've tested, all the values in the scoreboard are not null and I'm just completely mindblown.. And help would be fantastic.
     
  2. Offline

    kennethbgoodin

    Is there a stacktrace of the error in the server console?
     
  3. Offline

    ztowne13

    No, none at all. Otherwise i would figure it out :). I don't use any try-catch statements and that's why I'm confused.
     
  4. Offline

    JOPHESTUS

    Make sure no labels for scoreboards are longer than 16 chars. (a colour code is worth 2)
     
  5. Offline

    ztowne13

    They aren't :/ that's why I'm confused.

    So I just found out that it isn't working because when I get an offlineplayer that doesn't exist it returns a null value... any answers to how I can do this?

    Figured it out guys, thanks.

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

    Etsijä

    It would be polite to include your solution, to help others who might be struggling with the same problem.
     
Thread Status:
Not open for further replies.

Share This Page