From 483ab3159e2afe4cf2d7e13f44a3ec614df7317f Mon Sep 17 00:00:00 2001 From: sjhub <130253873+sj-hub9796@users.noreply.github.com> Date: Thu, 12 Dec 2024 10:04:43 +0900 Subject: [PATCH] fix mod sign error (#1586) --- .../mixin/bukkit/CraftEventFactoryMixin.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEventFactoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEventFactoryMixin.java index b0170cd06..2dd8957e1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEventFactoryMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEventFactoryMixin.java @@ -2,6 +2,7 @@ import com.google.common.base.Function; import io.izzel.arclight.common.bridge.core.entity.EntityBridge; +import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.core.world.WorldBridge; import io.izzel.arclight.common.mod.util.ArclightCaptures; import io.izzel.arclight.common.mod.util.DistValidate; @@ -12,16 +13,22 @@ import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.entity.SignBlockEntity; import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.Sign; +import org.bukkit.block.sign.Side; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.block.CraftBlockState; import org.bukkit.craftbukkit.v.block.CraftBlockStates; +import org.bukkit.craftbukkit.v.block.CraftSign; import org.bukkit.craftbukkit.v.block.data.CraftBlockData; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.util.CraftMagicNumbers; import org.bukkit.entity.Item; +import org.bukkit.entity.Player; import org.bukkit.event.block.BlockFadeEvent; import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockGrowEvent; @@ -34,6 +41,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.player.PlayerSignOpenEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; @@ -246,4 +254,32 @@ public static NotePlayEvent callNotePlayEvent(Level world, BlockPos pos, NoteBlo cir.setReturnValue(event); } } + + /** + * @author sj-hub9796 + * @reason + */ + @Overwrite + public static boolean callPlayerSignOpenEvent(net.minecraft.world.entity.player.Player player, SignBlockEntity tileEntitySign, boolean front, PlayerSignOpenEvent.Cause cause) { + Block block = CraftBlock.at(tileEntitySign.getLevel(), tileEntitySign.getBlockPos()); + Sign sign; + if (CraftBlockStates.getBlockState(block) instanceof Sign sign1) { + sign = sign1; + } else { + sign = new CraftSign<>(((WorldBridge) tileEntitySign.getLevel()).bridge$getWorld(), tileEntitySign); + } + Side side = front ? Side.FRONT : Side.BACK; + return callPlayerSignOpenEvent(((ServerPlayerEntityBridge) player).bridge$getBukkitEntity(), sign, side, cause); + } + + /** + * @author sj-hub9796 + * @reason + */ + @Overwrite + public static boolean callPlayerSignOpenEvent(Player player, Sign sign, Side side, PlayerSignOpenEvent.Cause cause) { + PlayerSignOpenEvent event = new PlayerSignOpenEvent(player, sign, side, cause); + Bukkit.getPluginManager().callEvent(event); + return !event.isCancelled(); + } }