Forum: gaming.stackexchange.com
Tags: <minecraft-java-edition><minecraft-commands>
Title: How can I use Command Blocks to keep players from placing blocks on a vanilla server?
Question: I want to know how to keep players from  placing  blocks in a certain area on my Minecraft server using  Command Blocks .  I already know how to keep them from breaking anything via [effect player 'mining fatigue'], but that won't stop them from placing lava, TNT, or anything that might obstruct anything important.  Any suggestions?

Answers:
sents: text: 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.
text: This forces your world (or at least any realistic distance from spawn) to have spawn protection.
text: 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).
text: 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.
answer_details: author: gaming.stackexchange.com/users/27903/Gigazelle
score: 7
sents: text: Set their gamemode to adventure mode using /gamemode <plr> adventure .
text: This makes it so that they cannot break or place blocks.
answer_details: author: gaming.stackexchange.com/users/116483/Carcass
score: 6
sents: text: So long as a player has blocks or placeable items, they can place them.
text: Therefore, the only way to prevent placing blocks is to take away a player's inventory with the clear <playername> command.
text: If there are only a few items you need to prevent from being used this way (e.g., you're specifically concerned about TNT and lava buckets, and nothing else), you can get more specific by using the optional [item] and [metadata] arguments of the clear command to remove only a specific type of item per command.
text: But if not, then your only recourse is clearing their whole inventory.
answer_details: author: gaming.stackexchange.com/users/4163/SevenSidedDie
score: 2
sents: text: To the commenter suggesting using @p and the redstone clock he demonstrated, I have two notes.
text: First, you are looking for @a to select all players.
text: The selectors are as follows: @p - selects closest player to the command block@a - selects all players@r - selects a random player@e - selects all entities* *including hostile/friendly mobs, players, items/blocks on the ground, etc.
text: it is *strongly
text: * recommended you use modifiers to reduce the scope when using @e.
text: There are far more efficient and faster ways to build clocks, and having fewer repeaters/redstone torches etc is a bonus.
text: The "Redstone Lag" players often experience is actually the result of block light updates, caused by these devices turning on/off.
text: The blocks around them are lit up and dimmed with each cycle, and these lighting changes are what crush some machines.
text: Pure redstone and redstone blocks tend to have less or no impact on lighting.
text: You can build an incredibly fast clock by simply placing two command blocks against one stone block.
text: In one command block use /setblock to set a redstone block where the stone block currently is.
text: Then, in the other command block, tell it to set the redstone block (using the setblock command) to air (minecraft:air).
text: Lastly, replace the stone block that is adjacent to both command blocks with a redstone block manually.
text: They will instantly start fighting each other for control of the block and an insanely fast, relatively low impact clock is produced.
text: I would also suggest running /gamerule
text: commandBlockOutput
text: Falseotherwise
text: your chat will be filled with line after line of "Block Placed".
text: For clarity's sake, C is a command block, S is the stone block Command: /setblock
text: x y z minecraft:redstone_blockvC S C
text: ^Command
text: : /setblock
text: x y z minecraft:air both sets of x y z should be replaced with the coordinates for the S block.
text: Use full integers, no decimal places.
text: Alternatively, you can use relative coordinates.
text: These are done as ~ ~ ~ instead of numbers.
text: The three tildes (~) will run the command directly on the command blocks own coordinates.
text: You can modify relative coordinates using positive or negative values.
text: In the drawn example above I could use the following integers.
text: (be sure to know which axis you're adjusting, in this case I've simply used the X axis as an example).
text: First: /setblock
text: ~1
text: ~ ~ minecraft:redstoneblockSecond:
text: /setblock
text: ~-1 ~ ~ minecraft:air
text: This causes the command block to the left to select in the positive direction on the left axis (while maintaining the command blocs y and z).
text: The block to the right does the exact opposite.
text: In this example the only axis that changes is X.
text: The advantage is we can copy this system using a command like clone, or by copying just the code, and not need to adjust the coordinates each time.
text: It saves a lot of work.
text: Getting the hang of command blocks is a -big- undertaking, an
answer_details: author: gaming.stackexchange.com/users/73678/MisterBuilder
score: 2
sents: text: I made a system using command blocks and scoreboard objectives that I call GriefDenial 2.0 .
text: It's available in schematic file format that you can import into your world using MCedit or other tools that understand schematic files.
text: This system allows any and all players to create a protected 30×30 area in which only they can build or place blocks, with the ability to add one other trusted user who can also build in their claim.
text: Since it is built out of command blocks and scoreboard objectives, this is useful for any vanilla server.
answer_details: author: gaming.stackexchange.com/users/103891/Guest
score: 2
sents: text: You could, Have a command block and make a redstone loop where it goes around and around.
text: Example: R= Redstone J= Redstone Repeaters.
text: (Repeaters face oppisite directions)Then, light the redstone with a redstone torch, break torch, and with redstone, as quick as you can break and replace the lit redstone.
text: RR JJ RR After you have made this, or something like this you need a command block.
text: In the command block type /clear @p
text: I think @p is it, there's some code that is everyone.
text: So this will clear their inventories.
text: Rapidly, so you don't have to manually do it.
answer_details: author: gaming.stackexchange.com/users/63997/Deadly124
score: 0
sents: text: use setblock and clone to place air blocks all around the area.
text: Hook the command blocks up to a fill clock, and that should do the trick.
text: Note:this will take a LOT of work.
answer_details: author: gaming.stackexchange.com/users/137879/Kylun11
score: 0
sents: text: Maybe set all players not within an "OP team" and within a certain radius to Adventure mode.
text: This would mean that you could still edit the spawn, and allow for "survival zones" outside the spawn.
answer_details: author: gaming.stackexchange.com/users/158727/Chemical Comrade
score: 0

Summary of the answers:
Try modifying the following variable in the server or clear the player's inventory.
The community suggested some ways to tackle the problem.