Skip to content

Commit

Permalink
Don't fire block place event for non-replaceable blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Moulberry committed Nov 16, 2024
1 parent 8fee0bd commit 8255423
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,26 @@ public void onReceive(Player bukkitPlayer, FriendlyByteBuf friendlyByteBuf) {
List<org.bukkit.block.BlockState> blockStates = new ArrayList<>();
World world = player.serverLevel().getWorld();
for (Map.Entry<BlockPos, BlockState> entry : blocks.entrySet()) {
blockStates.add(new AxiomPlacingCraftBlockState(world, entry.getKey(), entry.getValue()));
BlockState existing = player.serverLevel().getBlockState(entry.getKey());
if (existing.canBeReplaced()) {
blockStates.add(new AxiomPlacingCraftBlockState(world, entry.getKey(), entry.getValue()));
}
}

Cancellable event = null;
if (blockStates.size() > 1) {
event = CraftEventFactory.callBlockMultiPlaceEvent(player.serverLevel(),
player, hand, blockStates, blockHit.getBlockPos().getX(),
blockHit.getBlockPos().getY(), blockHit.getBlockPos().getZ());
} else if (blockStates.size() == 1) {
event = CraftEventFactory.callBlockPlaceEvent(player.serverLevel(),
player, hand, blockStates.get(0), blockHit.getBlockPos().getX(),
blockHit.getBlockPos().getY(), blockHit.getBlockPos().getZ());
}
if (event != null && event.isCancelled()) {
return;
if (!blockStates.isEmpty()) {
Cancellable event;
if (blockStates.size() > 1) {
event = CraftEventFactory.callBlockMultiPlaceEvent(player.serverLevel(),
player, hand, blockStates, blockHit.getBlockPos().getX(),
blockHit.getBlockPos().getY(), blockHit.getBlockPos().getZ());
} else {
event = CraftEventFactory.callBlockPlaceEvent(player.serverLevel(),
player, hand, blockStates.get(0), blockHit.getBlockPos().getX(),
blockHit.getBlockPos().getY(), blockHit.getBlockPos().getZ());
}
if (event.isCancelled()) {
return;
}
}
}

Expand Down

0 comments on commit 8255423

Please sign in to comment.