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 13, 2024
1 parent f3717a6 commit 995aab6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 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.7"
version = "1.5.7.1"
description = "Serverside component for Axiom on Paper"

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,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 @@ -93,6 +95,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 @@ -105,6 +109,27 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk

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

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

BlockPlaceContext blockPlaceContext = new BlockPlaceContext(player, hand, player.getItemInHand(hand), blockHit);

// Call interact event
if (new PlayerInteractEvent(bukkitPlayer, interactAction, heldItem, blockClicked, blockFace).callEvent()) {
updateBlocks(player, bukkitPlayer, hand, world, blockPlaceContext, breaking, 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();
}

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

// Call interact event
PlayerInteractEvent playerInteractEvent = new PlayerInteractEvent(bukkitPlayer,
breaking ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK, heldItem, blockClicked, blockFace);
Expand All @@ -115,10 +140,14 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
return;
}

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

BlockPlaceContext blockPlaceContext = new BlockPlaceContext(player, hand, player.getItemInHand(hand), blockHit);

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

private void updateBlocks(ServerPlayer player, Player bukkitPlayer, InteractionHand hand, CraftWorld world, BlockPlaceContext blockPlaceContext, boolean breaking, boolean updateNeighbors, Map<BlockPos, BlockState> blocks) {
// Update blocks
if (updateNeighbors) {
int count = 0;
Expand Down Expand Up @@ -259,10 +288,6 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk
if (!breaking) {
BlockItem.updateCustomBlockEntityTag(player.level(), player, blockPlaceContext.getClickedPos(), player.getItemInHand(hand));
}

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

}

0 comments on commit 995aab6

Please sign in to comment.