Minecraft – How to display players XP levels on Scoreboard
minecraft-commandsminecraft-java-edition
I've tried using command blocks only.
I googled but couldn't find anything.
Best Answer
I see two main ways to do this, neither of which are that great. If it's not necessary, I'd recommend not doing this.
First way would be to set the score individually for each level, like this:
/scoreboard players set @a[l=0,lm=0] XPScore 0
/scoreboard players set @a[l=1,lm=1] XPScore 1
/scoreboard players set @a[l=2,lm=2] XPScore 2
...
The main problem with this method is that you'll need a ton of command blocks. I'd probably go with supporting 127 levels if this is just vanilla/survival.
Next method is a bit more complicated, but would cut down the command blocks needed from 127 to around 30 whilst still supporting the same max level.
This should set everyone's XPScore to their XP. Problem is that it also sets their XP to 0, so afterwards you need to clone their XPScore to another objective, I'll call mine "XPTemp":
My suggestion would be to modify the following variable in the server.properties file:
spawn-protection=999999
Then OP yourself and anyone else you trust to place and destroy blocks. This forces your world (or at least any realistic distance from spawn) to have spawn protection. Blocks cannot be placed or destroyed in this area, unless you're an OP (and at least one OP must be listed in order for it to work).
Note that it is currently not possible to fully prevent the griefing you described above in vanilla without tampering with the user's inventory or use of modding tools.
To do this, you will need 10 command blocks in series, connected to this daylight sensor setup:
Attach the daylight sensor output to A- a not gate, and B- a 14-block long line of redstone dust. The outputs of both of these should activate the 10 command blocks all containing:
execute @a ~ ~ ~ summon Zombie
P.S. the execute command CAN be used in command blocks.
Best Answer
I see two main ways to do this, neither of which are that great. If it's not necessary, I'd recommend not doing this.
First way would be to set the score individually for each level, like this:
The main problem with this method is that you'll need a ton of command blocks. I'd probably go with supporting 127 levels if this is just vanilla/survival.
Next method is a bit more complicated, but would cut down the command blocks needed from 127 to around 30 whilst still supporting the same max level.
First, you'd set everyone's XP score to 0:
Then, in this exact order, run these commands:
This should set everyone's XPScore to their XP. Problem is that it also sets their XP to 0, so afterwards you need to clone their XPScore to another objective, I'll call mine "XPTemp":
Then you need to set their XP level back to what it was before using pretty much the reverse of what was above.