Skip to content

Commit dadb0b0

Browse files
committed
Made the temporary fix for the protocol v7 AxiomPaper.
1 parent 5c63a3a commit dadb0b0

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
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.0"
11+
version = "1.5.1"
1212
description = "Serverside component for Axiom on Paper"
1313

1414
java {

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

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import net.minecraft.world.InteractionHand;
1313
import net.minecraft.world.entity.ai.village.poi.PoiType;
1414
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
15-
import net.minecraft.world.item.ItemStack;
1615
import net.minecraft.world.level.block.Block;
1716
import net.minecraft.world.level.block.EntityBlock;
1817
import net.minecraft.world.level.block.entity.BlockEntity;
@@ -26,8 +25,10 @@
2625
import org.bukkit.block.BlockFace;
2726
import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlock;
2827
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
28+
import org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory;
2929
import org.bukkit.entity.Player;
3030
import org.bukkit.event.block.Action;
31+
import org.bukkit.event.block.BlockBreakEvent;
3132
import org.bukkit.event.player.PlayerInteractEvent;
3233
import org.bukkit.plugin.messaging.PluginMessageListener;
3334
import org.jetbrains.annotations.NotNull;
@@ -38,7 +39,6 @@
3839
import java.util.Map;
3940
import java.util.Objects;
4041
import java.util.Optional;
41-
import java.util.logging.Level;
4242

4343
public class SetBlockPacketListener implements PluginMessageListener {
4444

@@ -62,9 +62,8 @@ public SetBlockPacketListener(AxiomPaper plugin) {
6262

6363
@Override
6464
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player bukkitPlayer, @NotNull byte[] message) {
65-
if (!bukkitPlayer.hasPermission("axiom.*")) {
65+
if (!bukkitPlayer.hasPermission("axiom.*"))
6666
return;
67-
}
6867

6968
// Check if player is allowed to modify this world
7069
AxiomModifyWorldEvent modifyWorldEvent = new AxiomModifyWorldEvent(bukkitPlayer, bukkitPlayer.getWorld());
@@ -82,7 +81,9 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
8281
InteractionHand hand = friendlyByteBuf.readEnum(InteractionHand.class);
8382
int sequenceId = friendlyByteBuf.readVarInt();
8483

85-
ServerPlayer player = ((CraftPlayer)bukkitPlayer).getHandle();
84+
ServerPlayer player = ((CraftPlayer) bukkitPlayer).getHandle();
85+
86+
Action interactAction = breaking ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK;
8687

8788
org.bukkit.inventory.ItemStack heldItem;
8889
if (hand == InteractionHand.MAIN_HAND) {
@@ -92,21 +93,33 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
9293
}
9394

9495
org.bukkit.block.Block blockClicked = bukkitPlayer.getWorld().getBlockAt(blockHit.getBlockPos().getX(),
95-
blockHit.getBlockPos().getY(), blockHit.getBlockPos().getZ());
96+
blockHit.getBlockPos().getY(), blockHit.getBlockPos().getZ());
9697

9798
BlockFace blockFace = CraftBlock.notchToBlockFace(blockHit.getDirection());
9899

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

109-
// Update blocks
122+
private void updateBlocks(ServerPlayer player, boolean updateNeighbors, Map<BlockPos, BlockState> blocks) {
110123
if (updateNeighbors) {
111124
for (Map.Entry<BlockPos, BlockState> entry : blocks.entrySet()) {
112125
player.level().setBlock(entry.getKey(), entry.getValue(), 3);
@@ -143,7 +156,8 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
143156
case OCEAN_FLOOR -> oceanFloor = heightmap.getValue();
144157
case MOTION_BLOCKING -> motionBlocking = heightmap.getValue();
145158
case MOTION_BLOCKING_NO_LEAVES -> motionBlockingNoLeaves = heightmap.getValue();
146-
default -> {}
159+
default -> {
160+
}
147161
}
148162
}
149163

@@ -160,7 +174,7 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
160174

161175
if (blockEntity == null) {
162176
// There isn't a block entity here, create it!
163-
blockEntity = ((EntityBlock)block).newBlockEntity(blockPos, blockState);
177+
blockEntity = ((EntityBlock) block).newBlockEntity(blockPos, blockState);
164178
if (blockEntity != null) {
165179
chunk.addAndRegisterBlockEntity(blockEntity);
166180
}
@@ -178,7 +192,7 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
178192
// Block entity type isn't correct, we need to recreate it
179193
chunk.removeBlockEntity(blockPos);
180194

181-
blockEntity = ((EntityBlock)block).newBlockEntity(blockPos, blockState);
195+
blockEntity = ((EntityBlock) block).newBlockEntity(blockPos, blockState);
182196
if (blockEntity != null) {
183197
chunk.addAndRegisterBlockEntity(blockEntity);
184198
}
@@ -201,7 +215,7 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
201215
Optional<Holder<PoiType>> oldPoi = PoiTypes.forState(old);
202216
if (!Objects.equals(oldPoi, newPoi)) {
203217
if (oldPoi.isPresent()) level.getPoiManager().remove(blockPos);
204-
if (newPoi.isPresent()) level.getPoiManager().add(blockPos, newPoi.get());
218+
newPoi.ifPresent(poiTypeHolder -> level.getPoiManager().add(blockPos, newPoi.get()));
205219
}
206220
}
207221

@@ -211,10 +225,6 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
211225
}
212226
}
213227
}
214-
215-
if (sequenceId >= 0) {
216-
player.connection.ackBlockChangesUpTo(sequenceId);
217-
}
218228
}
219229

220230
}

0 commit comments

Comments
 (0)