2

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.

3

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
2
  • 1
    With a bucket of milk "mining_fatigue" would be useless and with patience you could still break the blocks.
    – Martin H.
    Jul 12 '16 at 15:22
  • 1.13 syntax: /gamemode <adventure|survival> @p, /effect give @p mining_fatigue 1000000 100, /effect clear @p mining_fatigue
    – pppery
    Aug 27 '19 at 23:42
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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.