Skip to content

Commit

Permalink
Made the temporary fix for the latest changes from Moulberry.
Browse files Browse the repository at this point in the history
  • Loading branch information
Timongcraft committed Jan 1, 2024
1 parent 8106e24 commit cbabb05
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.moulberry.axiom"
version = "1.5.6"
version = "1.5.6.1"
description = "Serverside component for Axiom on Paper"

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlock;
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -91,6 +93,8 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk

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

Action interactAction = breaking ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK;

org.bukkit.inventory.ItemStack heldItem;
if (hand == InteractionHand.MAIN_HAND) {
heldItem = bukkitPlayer.getInventory().getItemInMainHand();
Expand All @@ -103,19 +107,31 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk

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

CraftWorld world = player.level().getWorld();

// Call interact event
PlayerInteractEvent playerInteractEvent = new PlayerInteractEvent(bukkitPlayer,
breaking ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK, heldItem, blockClicked, blockFace);
if (!playerInteractEvent.callEvent()) {
if (sequenceId >= 0) {
player.connection.ackBlockChangesUpTo(sequenceId);
if (new PlayerInteractEvent(bukkitPlayer, interactAction, heldItem, blockClicked, blockFace).callEvent()) {
updateBlocks(player, bukkitPlayer, world, updateNeighbors, blocks);

org.bukkit.block.Block bukkitBlock = bukkitPlayer.getWorld().getBlockAt(blockClicked.getX(), blockClicked.getY(), blockClicked.getZ());

boolean cancelled;
if (interactAction.isLeftClick()) {
cancelled = !new BlockBreakEvent(bukkitBlock, bukkitPlayer).callEvent();
} else {
cancelled = CraftEventFactory.callBlockPlaceEvent(player.serverLevel(), player, player.getUsedItemHand(), bukkitBlock.getState(), blockClicked.getX(), blockClicked.getY(), blockClicked.getZ()).isCancelled();
}
return;

if (cancelled)
updateBlocks(player, bukkitPlayer, world, updateNeighbors, blocks);
}

CraftWorld world = player.level().getWorld();
if (sequenceId >= 0) {
player.connection.ackBlockChangesUpTo(sequenceId);
}
}

// Update blocks
private void updateBlocks(ServerPlayer player, Player bukkitPlayer, CraftWorld world, boolean updateNeighbors, Map<BlockPos, BlockState> blocks) {
if (updateNeighbors) {
int count = 0;
for (Map.Entry<BlockPos, BlockState> entry : blocks.entrySet()) {
Expand Down Expand Up @@ -251,10 +267,6 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
}
}
}

if (sequenceId >= 0) {
player.connection.ackBlockChangesUpTo(sequenceId);
}
}

}

0 comments on commit cbabb05

Please sign in to comment.