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 @@ -27,6 +27,7 @@
import com.sk89q.worldguard.bukkit.util.Entities;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.entity.AnimalTamer;
Expand Down Expand Up @@ -187,6 +188,22 @@ public Block getFirstBlock() {
return null;
}

/**
* Get the first causing block's current material when its region is owned
* by the current thread. A cause may refer to a block in another region
* or world, for example the origin of a falling block.
*
* @return the material, or null if the block cannot be read here
*/
@Nullable
public Material getFirstBlockType() {
Block block = getFirstBlock();
if (block == null || (WorldGuardPlugin.inst().isFolia() && !Bukkit.isOwnedByCurrentRegion(block.getLocation()))) {
return null;
}
return block.getType();
}

/**
* Find the first type matching one in the given array.
*
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 @@ -33,8 +33,8 @@
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
Expand Down 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);
}
Material causeType = event.getCause().getFirstBlockType();
if (causeType != null && Materials.isPistonBlock(causeType)) {
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);
}
Material causeType = event.getCause().getFirstBlockType();
if (causeType != null && Materials.isPistonBlock(causeType)) {
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,9 @@ 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());
Material causeType = event.getCause().getFirstBlockType();
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