mojira.dev
MC-79255

Using /trigger first time on player gives score of 0 but not displayed on scoreboard

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

  1. Add scoreboard objective

    /scoreboard objectives add test trigger
  2. Set sidebar display

    /scoreboard objectives setdisplay sidebar test
  3. Enable trigger

    /scoreboard players enable @a test
  4. Notice score does not display on side bar but player has score of 0

    /say @a[score_test_min=0]
  5. Remove scoreboard display

    /scoreboard objectives setdisplay sidebar
  6. Put back display

    /scoreboard objectives setdisplay sidebar test
  7. 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.

Linked issues

Comments 2

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.

Is this still an issue in the latest snapshot 16w44a? If so please update the affected versions.

This is an automated comment on any open or reopened issue with out-of-date affected versions.

onnowhere

Nathan Adams

Confirmed

score, scoreboard, trigger

Minecraft 1.8.3, Minecraft 1.8.4, Minecraft 1.8.5, Minecraft 1.8.6, Minecraft 15w45a, ..., Minecraft 17w16a, Minecraft 1.12 Pre-Release 2, Minecraft 1.12, Minecraft 1.12.2, Minecraft 17w46a

Minecraft 17w47a

Retrieved