Skip to content

Commit 98093e0

Browse files
committed
Made the temporary fix for the latest changes from Moulberry.
1 parent 488bbd5 commit 98093e0

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group = "com.moulberry.axiom"
11-
version = "1.5.2"
11+
version = "1.5.2.1"
1212
description = "Serverside component for Axiom on Paper"
1313

1414
java {

src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
import org.bukkit.block.BlockFace;
2727
import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlock;
2828
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
29+
import org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory;
2930
import org.bukkit.entity.Player;
3031
import org.bukkit.event.block.Action;
32+
import org.bukkit.event.block.BlockBreakEvent;
3133
import org.bukkit.event.player.PlayerInteractEvent;
3234
import org.bukkit.plugin.messaging.PluginMessageListener;
3335
import org.jetbrains.annotations.NotNull;
@@ -83,6 +85,8 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
8385

8486
ServerPlayer player = ((CraftPlayer)bukkitPlayer).getHandle();
8587

88+
Action interactAction = breaking ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK;
89+
8690
org.bukkit.inventory.ItemStack heldItem;
8791
if (hand == InteractionHand.MAIN_HAND) {
8892
heldItem = bukkitPlayer.getInventory().getItemInMainHand();
@@ -91,21 +95,33 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
9195
}
9296

9397
org.bukkit.block.Block blockClicked = bukkitPlayer.getWorld().getBlockAt(blockHit.getBlockPos().getX(),
94-
blockHit.getBlockPos().getY(), blockHit.getBlockPos().getZ());
98+
blockHit.getBlockPos().getY(), blockHit.getBlockPos().getZ());
9599

96100
BlockFace blockFace = CraftBlock.notchToBlockFace(blockHit.getDirection());
97101

98102
// Call interact event
99-
PlayerInteractEvent playerInteractEvent = new PlayerInteractEvent(bukkitPlayer,
100-
breaking ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK, heldItem, blockClicked, blockFace);
101-
if (!playerInteractEvent.callEvent()) {
102-
if (sequenceId >= 0) {
103-
player.connection.ackBlockChangesUpTo(sequenceId);
103+
if (new PlayerInteractEvent(bukkitPlayer, interactAction, heldItem, blockClicked, blockFace).callEvent()) {
104+
updateBlocks(player, updateNeighbors, blocks);
105+
106+
org.bukkit.block.Block bukkitBlock = bukkitPlayer.getWorld().getBlockAt(blockClicked.getX(), blockClicked.getY(), blockClicked.getZ());
107+
108+
boolean cancelled;
109+
if (interactAction.isLeftClick()) {
110+
cancelled = !new BlockBreakEvent(bukkitBlock, bukkitPlayer).callEvent();
111+
} else {
112+
cancelled = CraftEventFactory.callBlockPlaceEvent(player.serverLevel(), player, player.getUsedItemHand(), bukkitBlock.getState(), blockClicked.getX(), blockClicked.getY(), blockClicked.getZ()).isCancelled();
104113
}
105-
return;
114+
115+
if (cancelled)
116+
updateBlocks(player, updateNeighbors, blocks);
117+
}
118+
119+
if (sequenceId >= 0) {
120+
player.connection.ackBlockChangesUpTo(sequenceId);
106121
}
122+
}
107123

108-
// Update blocks
124+
private void updateBlocks(ServerPlayer player, boolean updateNeighbors, Map<BlockPos, BlockState> blocks) {
109125
if (updateNeighbors) {
110126
for (Map.Entry<BlockPos, BlockState> entry : blocks.entrySet()) {
111127
player.level().setBlock(entry.getKey(), entry.getValue(), 3);
@@ -210,10 +226,6 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
210226
}
211227
}
212228
}
213-
214-
if (sequenceId >= 0) {
215-
player.connection.ackBlockChangesUpTo(sequenceId);
216-
}
217229
}
218230

219231
}

0 commit comments

Comments
 (0)