From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: lexikiq Date: Thu, 13 May 2021 23:52:14 -0400 Subject: [PATCH] Create PlayerUseRespawnAnchorEvent diff --git a/src/main/java/net/minecraft/world/level/block/BlockRespawnAnchor.java b/src/main/java/net/minecraft/world/level/block/BlockRespawnAnchor.java index 028e98decf8b0496b4ebcd1aad3aa474e5c4e7c1..1a3c66464947e16cc085a20ee1172cc51a3fc2f5 100644 --- a/src/main/java/net/minecraft/world/level/block/BlockRespawnAnchor.java +++ b/src/main/java/net/minecraft/world/level/block/BlockRespawnAnchor.java @@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableList.Builder; import com.google.common.collect.UnmodifiableIterator; import java.util.Optional; import java.util.stream.Stream; +import me.lexikiq.event.player.PlayerUseRespawnAnchorEvent; import net.minecraft.core.BaseBlockPosition; import net.minecraft.core.BlockPosition; import net.minecraft.core.EnumDirection; @@ -37,6 +38,8 @@ import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.pathfinder.PathMode; import net.minecraft.world.phys.MovingObjectPositionBlock; import net.minecraft.world.phys.Vec3D; +import org.bukkit.craftbukkit.block.CraftBlock; // Parchment +import org.bukkit.entity.Player; // Parchment public class BlockRespawnAnchor extends Block { @@ -53,6 +56,11 @@ public class BlockRespawnAnchor extends Block { public EnumInteractionResult interact(IBlockData iblockdata, World world, BlockPosition blockposition, EntityHuman entityhuman, EnumHand enumhand, MovingObjectPositionBlock movingobjectpositionblock) { ItemStack itemstack = entityhuman.b(enumhand); + // Parchment start -- PlayerUseRespawnAnchorEvent + Player player = entityhuman.getBukkitEntity() instanceof Player ? (Player) entityhuman.getBukkitEntity() : null; + org.bukkit.block.Block block = CraftBlock.at(world, blockposition); + // Parchment end + if (enumhand == EnumHand.MAIN_HAND && !a(itemstack) && a(entityhuman.b(EnumHand.OFF_HAND))) { return EnumInteractionResult.PASS; } else if (a(itemstack) && h(iblockdata)) { @@ -61,16 +69,31 @@ public class BlockRespawnAnchor extends Block { itemstack.subtract(1); } + // Parchment start + if (player != null && !(new PlayerUseRespawnAnchorEvent(player, block, PlayerUseRespawnAnchorEvent.RespawnAnchorResult.CHARGE).callEvent())) + return EnumInteractionResult.PASS; + // Parchment end + return EnumInteractionResult.a(world.isClientSide); } else if ((Integer) iblockdata.get(BlockRespawnAnchor.a) == 0) { return EnumInteractionResult.PASS; } else if (!a(world)) { + // Parchment start + if (player != null && !(new PlayerUseRespawnAnchorEvent(player, block, PlayerUseRespawnAnchorEvent.RespawnAnchorResult.EXPLODE).callEvent())) + return EnumInteractionResult.PASS; + // Parchment end + if (!world.isClientSide) { this.d(iblockdata, world, blockposition); } return EnumInteractionResult.a(world.isClientSide); } else { + // Parchment start + if (player != null && !(new PlayerUseRespawnAnchorEvent(player, block, PlayerUseRespawnAnchorEvent.RespawnAnchorResult.SET_SPAWN).callEvent())) + return EnumInteractionResult.PASS; + // Parchment end + if (!world.isClientSide) { EntityPlayer entityplayer = (EntityPlayer) entityhuman; @@ -115,7 +138,7 @@ public class BlockRespawnAnchor extends Block { private void d(IBlockData iblockdata, World world, final BlockPosition blockposition) { world.a(blockposition, false); - Stream stream = EnumDirection.EnumDirectionLimit.HORIZONTAL.a(); + Stream stream = EnumDirection.EnumDirectionLimit.HORIZONTAL.a(); // Parchment - Fix deobfuscation error blockposition.getClass(); boolean flag = stream.map(blockposition::shift).anyMatch((blockposition1) -> {