Prevent placing block in adventure mode

This commit is contained in:
themode 2020-12-18 00:28:06 +01:00
parent 8b515e8686
commit 3e532b24a8

View File

@ -60,11 +60,18 @@ public class BlockPlacementListener {
return;
}
// Check if item at hand is a block
final Material material = usedItem.getMaterial();
if (material == Material.AIR) {
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
final int offsetX = blockFace == BlockFace.WEST ? -1 : blockFace == BlockFace.EAST ? 1 : 0;
@ -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<Entity> entities = instance.getChunkEntities(chunk);
// Check if the player is trying to place a block in an entity
boolean intersect = false;