Tutorials/Command stats

This tutorial provides examples of how to use command stats (values returned after executing a command). This tutorial assumes the reader is already familiar with the Commands/stats.

Sidebar
These examples demonstrate how to display command stats in the sidebar. This can be useful when testing commands, monitoring command block creations, etc.

Player sidebar
We'll use five "fake players" to hold the five command stats. Let's call them "Blocks", "Entities", "Items", "Query", and "Success".

First, create the scoreboard objective that will be used to store the command stats.



Second, set the sidebar to display the CommandStats objective.



Third, add the fake players to the sidebar by setting their CommandStats objective to 0. These five commands can be executed in any order, and a new fake player should appear in the sidebar after each one.



Finally, use the command to specify which player should be used to update the sidebar with the command stats of the commands they execute. These five commands can be executed in any order. Replace player in the commands below with the name of the player (the player does not need to be online when the commands are run). If the player runs the commands themself, the Entities and Success entries in the sidebar will start updating after each command after they each are set up (because each command below should return a command stat of 1 for AffectedEntities and SuccessCount).



Command block sidebar
To have the sidebar show the command stats of a specific command block instead of a player, run the first three steps described above in Player sidebar to set up the sidebar, but use these commands for the final step (replace x y z with the position of the command block in absolute coordinates or in tilde notation).



Multiple sidebars
The sidebar can be set up to show different objectives to different teams. By setting up multiple objectives to be updated by different blocks or entities, players can switch which command stats they're looking at by switching which team they're on. Let's try setting up two teams, one for monitoring the command stats of a player, the other for monitoring the command stats of a command block.

First, create the scoreboard objectives that will be used to store the command stats.



Second, create the teams.



Third, set the colors for the teams so the sidebar will know which objective to display for that team. Let's use "blue" for "Block", and "red" for "Player".



Fourth, set the sidebar to display the BlockStats and PlayerStats objectives for the correct team.



Fifth, add the fake players to both sidebars by setting their BlockStats and PlayerStats objectives to 0. If you're running these commands from the chat, it might be useful to put yourself on one team or the other now to see the fake players getting added.





Finally, use the command to specify which block and player should be used to update the sidebars with the command stats of the commands they execute.





Now players can switch which stats they see in the sidebar by changing their team. Players who can execute commands can use the following commands:



教程/命令统计值