This solution is based on defining the person closest to a wolf when it first sits down as it's tamer.
The reason for this workaround is twofold:
- Players don't have a "wolves tamed" statistic
- Wolves don't have a "tamed" entry in their NBT, and it's not possible to look for an empty "ownerUUID"
Start with the following commands.
/scoreboard objective add isTamed dummy
/scoreboard objective add wolvesTamed dummy Wolves Tamed
This will add an objective that is used to check for tamed wolves, and another for the players.
Now run the following commands on a clock
/scoreboard players add @e[type=Wolf] isTamed 1 {Sitting:1}
/scoreboard players add @e[type=Wolf,score_isTamed_min=3] isTamed -1
/execute @e[type=Wolf,score_isTamed=1,score_isTamed_min=1] scoreboard players add @p[r=3] wolvesTamed 1
This will continuously increase the isTamed
objective by 1 as long as the wolf sits. This is followed by decreasing it by one if it is greater than 2 (this is not technically necessary, but keeps the scores low)
In addition, the player closest to a wolf (and within 3m) with an isTamed
score of exactly 1 (which can only happen when it first sits down) will have their wolvesTamed
score increased by 1.
There might be an issue with the last command, because wolves might not be able to use "cheats". In this case, you would need to find a way to use the /trigger
command instead.
First of all, let's talk about the mistake you are making:
Your testfor
command output will be permanently on, as long as there is at least one player with 30 to 49 levels, meaning the scoreboard command will only be run if there was no player in that range and then there is.
Secondly, @p[something]
will always target the player nearest to the execution position that qualifies for "something". You'll need to use @a
in the team join command.
That said, lucky for you the testfor
is completely unnecessary*. scoreboard
can do the job perfectly fine on it's own.
/scoreboard teams join (team) @a[lm=30,l=49,team=!(team)]
The latter part of the command prevents people from being added to the same team multiple times. If there is no-one in that level range (or all of them are assigned a team already), the command will simply not add anyone to the team.
* In most cases, execute
is strictly better than testfor
Best Answer
Vanilla Minecraft does not support this. However, it looks like most if not all permissions plugins do. You will need to use a modded server to accomplish this.
If you are currently running a fully vanilla server, then the decision to mod is a big one. Mainly because once you mod your server, you'll have an increased maintenance load managing it around Minecraft updates, or increased complexity for your users as they have to learn how to log into an out of date server. (This is easy, but some still stumble.)
If you are already modding, then it's an easy decision... For Bukkit or Paper servers, LuckPerms is great. (I have no affiliation with them.) You can create groups or assign permissions to individual users. and to apply permissions, you just need to use commands like:
Further info: https://github.com/lucko/LuckPerms/wiki
There are other permissions mods for other systems, and they all work relatively the same. Some have more or less features, but all allow granular permissions control.
Good luck!