Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,17 @@ public Entity getFirstNonPlayerEntity() {
return null;
}

/**
* Get the first causing block if it is accessible from the current thread.
* On Folia, the block may belong to a different region or world.
*
* @return the block, or null if there is no block or its region is not owned by the current thread
*/
@Nullable
public Block getFirstBlock() {
for (Object object : causes) {
if (object instanceof Block b) {
return b;
return WorldGuardPlugin.inst().isFolia() && !Bukkit.isOwnedByCurrentRegion(b.getLocation()) ? null : b;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void onBlockPlace(BlockPlaceEvent event) {
BlockState previousState = event.getBlockReplacedState();

// Some blocks, like tall grass and fire, get replaced
if (previousState.getType() != Material.AIR && previousState.getType() != event.getBlockReplacedState().getType()) {
if (previousState.getType() != Material.AIR && previousState.getType() != event.getBlockPlaced().getType()) {
Events.fireToCancel(event, new BreakBlockEvent(event, create(event.getPlayer()), previousState.getLocation(), previousState.getType()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ public void onPlaceBlock(final PlaceBlockEvent event) {

RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();

Block block;
if ((block = event.getCause().getFirstBlock()) != null) {
if (Materials.isPistonBlock(block.getType())) {
event.filter(testState(query, Flags.PISTONS), false);
}
Block causeBlock = event.getCause().getFirstBlock();
if (causeBlock != null && Materials.isPistonBlock(causeBlock.getType())) {
event.filter(testState(query, Flags.PISTONS), false);
}

if (event.getCause().find(EntityType.SNOW_GOLEM) != null) {
Expand All @@ -85,11 +83,9 @@ public void onBreakBlock(final BreakBlockEvent event) {
WorldConfiguration config = getWorldConfig(event.getWorld());
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();

Block block;
if ((block = event.getCause().getFirstBlock()) != null) {
if (Materials.isPistonBlock(block.getType())) {
event.filter(testState(query, Flags.PISTONS), false);
}
Block causeBlock = event.getCause().getFirstBlock();
if (causeBlock != null && Materials.isPistonBlock(causeBlock.getType())) {
event.filter(testState(query, Flags.PISTONS), false);
}

if (event.getCause().find(EntityType.CREEPER) != null) { // Creeper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ public void onPlaceBlock(final PlaceBlockEvent event) {

/* Flint and steel, fire charge, etc. */
if (Materials.isFire(type)) {
Block block = event.getCause().getFirstBlock();
boolean fire = block != null && Materials.isFire(block.getType());
boolean lava = block != null && Materials.isLava(block.getType());
Block causeBlock = event.getCause().getFirstBlock();
Material causeType = causeBlock != null ? causeBlock.getType() : null;
boolean fire = causeType != null && Materials.isFire(causeType);
boolean lava = causeType != null && Materials.isLava(causeType);
List<StateFlag> flags = new ArrayList<>();
flags.add(Flags.BLOCK_PLACE);
flags.add(Flags.LIGHTER);
Expand Down