[SPIGOT-1428] Scoreboard crashes server Created: 17/Jan/16  Updated: 22/Jan/16  Resolved: 22/Jan/16

Status: Closed
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: - Pr0totype2 Assignee: Unassigned
Resolution: Invalid Votes: 0
Labels: 1.8, 1.8.8, Spigot, bug, crash, error, event, spigot
Environment:

//Details provided below.


Attachments: GIF File scoreboardCrash.gif    
Plugin: RazerRealm (Custom)

 Description   

While using Spigot (1.8.8 Snapshot), I've created a scoreboard and it seems to act weird after a while (Flashes more and more till it just simply doesn't look like a scoreboard anymore and crashes). This is what I mean;

After this, my server just simply crashed and it returned an IOException

This is my code;

package com.pr0totype2.razerrealm.holograms;

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

import com.pr0totype2.razerrealm.RazerRealm;

public class ScoreboardManagement implements Listener {

    private RazerRealm plugin;
    
    Scoreboard mainBoard;
    Objective objective;
    Score score;
    
    String splitLine = ChatColor.RED + "" + ChatColor.BOLD + ChatColor.STRIKETHROUGH + "-------------";
    
    public ScoreboardManagement(RazerRealm plugin) {
	this.plugin = plugin;
    }

    public Scoreboard mainScoreboard(Player player) {
	mainBoard = Bukkit.getScoreboardManager().getNewScoreboard();
	objective = mainBoard.registerNewObjective("rekt", "dummy");
	objective.setDisplayName(ChatColor.DARK_GREEN + "R" + ChatColor.GREEN + "azer" + ChatColor.DARK_GREEN + "R" + ChatColor.GREEN + "ealm");
	objective.setDisplaySlot(DisplaySlot.SIDEBAR);
	
	score = objective.getScore(splitLine + ChatColor.RED);
	score.setScore(99);
	score = objective.getScore(plugin.rankshandler.getPrefix(player) + " " + player.getDisplayName());
	score.setScore(98);
	score = objective.getScore(splitLine + ChatColor.BLUE);
	score.setScore(97);
	score = objective.getScore(ChatColor.YELLOW + "    " + ChatColor.BOLD + "WEB");
	score.setScore(96);
	score = objective.getScore(ChatColor.AQUA + "websitedotcom");
	score.setScore(95);
	score = objective.getScore(ChatColor.YELLOW + "" + ChatColor.BOLD + "TAG: " + ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + plugin.townhandler.getTownTag(player) + ChatColor.DARK_GRAY + "]");
	score.setScore(94);
	score = objective.getScore(splitLine + ChatColor.AQUA);
	score.setScore(93);
	
	Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
	    @Override
	    public void run() {
		for (Player aOnline : Bukkit.getOnlinePlayers()) {
		    aOnline.setScoreboard(mainScoreboard(aOnline));
		}
	    }
	}, 600L, 600L);
	return mainBoard;
    }
}

This method is being triggered upon PlayerJoinEvent, PlayerQuitEvent and ofc via this runnable to update the scoreboard every x ticks.
Nobody's able to currently join my server as it'll simply crash after a few minutes after the first player joined the server.

What do I do? What's wrong?

Thanks in advance,
Pr0totype2



 Comments   
Comment by Pangea [ 17/Jan/16 ]

The problem isn't within spigot, it's in your code.

in your mainScoreboard method, you are scheduling a new task to run every 30 seconds but the task contains mainScoreboard (for each player online!!) so you are infinitely scheduling more tasks along with running the rest of the method. Your code is sssso broken..

Comment by - Pr0totype2 [ 17/Jan/16 ]

@Phoenix616
Tbh I thought this wasn't something that was wrong on my side really, but I started to notice it actually is. My excuses!

Comment by Phoenix616 [ 17/Jan/16 ]

That still starts the task everytime you run mainScoreboard(Player player). Start the task outside of the method.

Also the ticket system is not there for plugin help, you should use the forums or the irc

Comment by - Pr0totype2 [ 17/Jan/16 ]

@Phoenix616
Method now looks like this;

    public void mainScoreboard(Player player) {
	mainBoard = Bukkit.getScoreboardManager().getNewScoreboard();
	objective = mainBoard.registerNewObjective("rekt", "dummy");
	objective.setDisplayName(ChatColor.DARK_GREEN + "R" + ChatColor.GREEN + "azer" + ChatColor.DARK_GREEN + "R" + ChatColor.GREEN + "ealm");
	objective.setDisplaySlot(DisplaySlot.SIDEBAR);
	
	score = objective.getScore(splitLine + ChatColor.RED);
	score.setScore(99);
	score = objective.getScore(plugin.rankshandler.getPrefix(player) + " " + player.getDisplayName());
	score.setScore(98);
	score = objective.getScore(splitLine + ChatColor.BLUE);
	score.setScore(97);
	score = objective.getScore(ChatColor.YELLOW + "    " + ChatColor.BOLD + "WEB");
	score.setScore(96);
	score = objective.getScore(ChatColor.AQUA + "websitedotcom");
	score.setScore(95);
	score = objective.getScore(ChatColor.YELLOW + "" + ChatColor.BOLD + "TAG: " + ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + plugin.townhandler.getTownTag(player) + ChatColor.DARK_GRAY + "]");
	score.setScore(94);
	score = objective.getScore(splitLine + ChatColor.AQUA);
	score.setScore(93);
	
	for (Player aOnline : Bukkit.getOnlinePlayers()) {
	    aOnline.setScoreboard(mainBoard);
	}
	
	Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
	    @Override
	    public void run() {
		for (Player aOnline : Bukkit.getOnlinePlayers()) {
		    mainScoreboard(aOnline);
		}
	    }
	}, 600L, 600L);
    }

Upon player join and quit, mainScoreboard for all players is being ran.

Comment by Phoenix616 [ 17/Jan/16 ]

Looks like "normal" behavior to me when you use recursion to set more and more scoreboards at the same time until infinity.

With other words: Fix your code and don't spawn new repeating tasks every time you get your custom scoreboard.

Comment by SpigotMC [ 17/Jan/16 ]

Your build is not the latest and therefore may be the reason you are having this issue. Spigot is 0 version(s) behind. CraftBukkit is 3 version(s) behind. This message was automatically generated and is not guaranteed to be a solution to your issue.

Generated at Tue Apr 22 03:43:28 UTC 2025 using Jira 10.3.5#10030005-sha1:190c783f2bd6c69cd5accdb70f97e48812a78d14.