How to prevent the closest player from breaking blocks?

How to prevent the closest player from breaking blocks? - Patient showing stop gesture in light clinic

I just opened a vanilla minecraft server, and I need a command block that when activated, it prevents the closest player (@p) from breaking blocks. Is this thing possible? And how? Thanks.



Best Answer

You can put the closest player into adventure mode:

/gamemode 2 @p

Or give them an extreme level of mining fatigue:

/effect @p mining_fatigue 1000000 100

To undo these (and allow them to break blocks again), you would put them back into survival mode:

/gamemode 0 @p

Or remove the mining fatigue:

/effect @p mining_fatigue 0



Pictures about "How to prevent the closest player from breaking blocks?"

How to prevent the closest player from breaking blocks? - Positive multiethnic friends sitting on skateboards in skate park
How to prevent the closest player from breaking blocks? - Crop smiling friends in casual clothes with gamepads
How to prevent the closest player from breaking blocks? - Young sportsman standing on sports court



How do you stop players from breaking blocks in Minecraft?

The answer is simple: if you do /gamemode adventure @a, than none of the players can place or break blocks. Show activity on this post. Just turn Trust Players off.



BLOCK BREAKING DETECTION!? -- Command Block Tutorial




More answers regarding how to prevent the closest player from breaking blocks?

Answer 2

What I would do is have two command blocks in a chain. The first command block would have:

/gamemode 0 @a 

Then the second in the chain would have:

/gamemode 2 @p

This would allow the nearest player to be unable to break blocks, and also if the nearest player changes, then it would allow the first player to break blocks again and put the new closest player in adventure mode.

If you want the player to still be able to place blocks, then I would put

/effect @p mining_fatigue 1000000 100

instead of

/gamemode 2 @p

as the previous answer suggested.

Answer 3

To add to sirbenet:

/effect @p mining_fatigue 60 255 true

With the command block set to repeating. The true will give the effect without particles so it is more subtle.

You can set a delay of 1-5 ticks if you don’t want a command running every tick. This will restart the effect frequently enough that even after the player drinks milk, they won’t have enough time to mine a block before the effect returns.

If you want to refine how far this command reaches, you can include

/effect @p[r=x] ...

Where x is the radius from the command block. This command will only affect players within the radius.

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: SHVETS production, Budgeron Bach, Gustavo Fring, Harrison Haines