From 3e532b24a89d5aea5f4aa5db540cc61a424a2e92 Mon Sep 17 00:00:00 2001 From: themode Date: Fri, 18 Dec 2020 00:28:06 +0100 Subject: [PATCH] Prevent placing block in adventure mode --- .../listener/BlockPlacementListener.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/minestom/server/listener/BlockPlacementListener.java b/src/main/java/net/minestom/server/listener/BlockPlacementListener.java index 33f1a4329..d4e5716a2 100644 --- a/src/main/java/net/minestom/server/listener/BlockPlacementListener.java +++ b/src/main/java/net/minestom/server/listener/BlockPlacementListener.java @@ -60,10 +60,17 @@ public class BlockPlacementListener { return; } - // Check if item at hand is a block - final Material material = usedItem.getMaterial(); - if (material == Material.AIR) { - return; + final Material useMaterial = usedItem.getMaterial(); + + // Verify if the player can place the block + { + if (useMaterial == Material.AIR) { // Can't place air + return; + } + if (player.getGameMode().equals(GameMode.ADVENTURE)) { // Can't place in adventure mode + return; + } + } // Get the newly placed block position @@ -79,9 +86,9 @@ public class BlockPlacementListener { // This will ensure that the player has the correct version of the chunk boolean refreshChunk = false; - if (material.isBlock()) { + if (useMaterial.isBlock()) { if (!chunk.isReadOnly()) { - final Block block = material.getBlock(); + final Block block = useMaterial.getBlock(); final Set entities = instance.getChunkEntities(chunk); // Check if the player is trying to place a block in an entity boolean intersect = false;