Skip to content
Open
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 @@ -50,6 +50,7 @@
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockFertilizeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockIgniteEvent;
Expand Down Expand Up @@ -821,6 +822,38 @@ public void onBlockIgnite(BlockIgniteEvent igniteEvent)
}
}

private Claim lastBlockFertilizeClaim = null;
@EventHandler(priority = EventPriority.LOWEST)
private void onBlockFertilize(@NotNull BlockFertilizeEvent event)
{

// Don't track in worlds where claims are not enabled.
if (!GriefPrevention.instance.claimsEnabledForWorld(event.getBlock().getWorld())) return;

// Trees are handled by the StructureGrowEvent handler.
if (Tag.SAPLINGS.isTagged(event.getBlock().getType())) return;

Player player = event.getPlayer();
Claim sourceClaim = null;
if (player == null) {
sourceClaim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, false, lastBlockFertilizeClaim);
if (sourceClaim != null) lastBlockFertilizeClaim = sourceClaim;
}

BoundingBox box = BoundingBox.ofStates(event.getBlocks());
BiPredicate<@NotNull Claim, @NotNull BoundingBox> conflictCheck;
if (player != null) {
conflictCheck = (claim, boundingBox) -> claim.checkPermission(player, ClaimPermission.Build, event) != null;
} else {
conflictCheck = denyOtherOwnerIntersection(sourceClaim);
}

if (boxConflictsWithClaims(event.getBlock().getWorld(), box, sourceClaim, conflictCheck))
{
event.setCancelled(true);
}
}

private Claim lastBlockSpreadClaim = null;
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockSpread(@NotNull BlockSpreadEvent spreadEvent)
Expand Down