The bug
Enabling a /trigger for a player who has not yet been enabled before will set their score for the objective to 0, but does not display this on the sidebar scoreboard if the scoreboard is displaying when their trigger is enabled.
How to reproduce
Add scoreboard objective
/scoreboard objectives add test trigger
Set sidebar display
/scoreboard objectives setdisplay sidebar test
Enable trigger
/scoreboard players enable @a test
Notice score does not display on side bar but player has score of 0
/say @a[score_test_min=0]
Remove scoreboard display
/scoreboard objectives setdisplay sidebar
Put back display
/scoreboard objectives setdisplay sidebar test
Notice score is now displaying as 0 for player
Code analysis
The problem is that the game creates a Score
object when enabling a trigger for a player who has no score. As the score value inside the Score
object is stored as an int
, its default value is 0 (see MC-107049). Creating a Score
object does not send a packet to the player. Changing this would cause the server to send a packet twice is you set a value for a player who had no Score
object before, which could cause problems. A solution might be to store the score as an Integer
. Then the default value would be null
. Some methods would need to be changed then to test if the player has a Score
object and the score value is not null
instead of testing if the Score
object is null
.
A problem which should appear already is that using /scoreboard players reset
also disables the trigger as it removes the Score
object. With the suggested change a parameter like resetScore
could be added which only sets the score of the Score
object to null
and by that remains the trigger state.
The problem is that the game creates a
Score
object when enabling a trigger for a player who has no score. As the score value inside theScore
object is stored as anint
, its default value is 0 (see MC-107049). Creating aScore
object does not send a packet to the player. Changing this would cause the server to send a packet twice is you set a value for a player who had noScore
object before, which could cause problems. A solution might be to store the score as anInteger
. Then the default value would benull
. Some methods would need to be changed then to test if the player has aScore
object and the score value is notnull
instead of testing if theScore
object isnull
.A problem which should appear already is that using
/scoreboard players reset
also disables the trigger as it removes theScore
object. With the suggested change a parameter likeresetScore
could be added which only sets the score of theScore
object tonull
and by that remains the trigger state.