From 1811737e6ad5896d9f2e8ee93d0404977cf7845a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=81=AA=E8=81=AA?= <178666380@qq.com> Date: Fri, 30 Jun 2017 14:14:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B9=E5=9D=97=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E9=83=A8=E5=88=86=E5=8F=82=E6=95=B0=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/world/BlockEvent.java.patch | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/patches/net/minecraftforge/event/world/BlockEvent.java.patch b/patches/net/minecraftforge/event/world/BlockEvent.java.patch index a71df42..8d61880 100644 --- a/patches/net/minecraftforge/event/world/BlockEvent.java.patch +++ b/patches/net/minecraftforge/event/world/BlockEvent.java.patch @@ -1,18 +1,23 @@ --- ../src-base/minecraft/net/minecraftforge/event/world/BlockEvent.java +++ ../src-work/minecraft/net/minecraftforge/event/world/BlockEvent.java -@@ -16,6 +16,11 @@ +@@ -16,6 +16,16 @@ import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.util.BlockSnapshot; ++import org.bukkit.block.BlockState; ++import org.bukkit.craftbukkit.block.CraftBlockState; +// Cauldron start +import org.bukkit.craftbukkit.event.CraftEventFactory; ++import org.bukkit.event.block.BlockBreakEvent; ++import org.bukkit.event.block.BlockMultiPlaceEvent; ++ +import net.minecraft.entity.player.EntityPlayerMP; +// Cauldron end + public class BlockEvent extends Event { private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugBlockEvent", "false")); -@@ -80,17 +85,18 @@ +@@ -80,17 +90,18 @@ super(x, y, z, world, block, blockMetadata); this.player = player; @@ -37,20 +42,38 @@ } public EntityPlayer getPlayer() -@@ -140,6 +146,16 @@ +@@ -140,6 +151,16 @@ this.blockSnapshot = blockSnapshot; this.placedBlock = blockSnapshot.getCurrentBlock(); this.placedAgainst = placedAgainst; + // Cauldron start - handle event on bukkit side -+ org.bukkit.craftbukkit.block.CraftBlockState blockstate = org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(super.world, super.x, super.y, -+ super.z); -+ org.bukkit.event.block.BlockPlaceEvent bukkitEvent = CraftEventFactory.callBlockPlaceEvent(super.world, player, blockstate, super.x, super.y, -+ super.z); -+ if (bukkitEvent.isCancelled() || !bukkitEvent.canBuild()) -+ { -+ this.setCanceled(true); ++ if(!(this instanceof MultiPlaceEvent)){ ++ org.bukkit.craftbukkit.block.CraftBlockState blockstate=new org.bukkit.craftbukkit.block.CraftBlockState(blockSnapshot); ++ org.bukkit.event.block.BlockPlaceEvent bukkitEvent=CraftEventFactory.callBlockPlaceEvent(super.world,player,blockstate,super.x,super.y, ++ super.z); ++ if(bukkitEvent.isCancelled()||!bukkitEvent.canBuild()){ ++ this.setCanceled(true); ++ } + } + // Cauldron end if (DEBUG) { System.out.printf("Created PlaceEvent - [PlacedBlock: %s ][PlacedAgainst: %s ][ItemStack: %s ][Player: %s ]\n", placedBlock, placedAgainst, player.getCurrentEquippedItem(), player); +@@ -160,7 +181,17 @@ + + public MultiPlaceEvent(List blockSnapshots, Block placedAgainst, EntityPlayer player) { + super(blockSnapshots.get(0), placedAgainst, player); ++ + this.blockSnapshots = ImmutableList.copyOf(blockSnapshots); ++ ++ //bukkit start ++ ArrayList tStates=new ArrayList(blockSnapshots.size()); ++ for(BlockSnapshot sSnapshot : this.blockSnapshots){ ++ tStates.add(new CraftBlockState(sSnapshot)); ++ } ++ BlockMultiPlaceEvent tEvent=CraftEventFactory.callBlockMultiPlaceEvent(super.world,player,tStates,super.x,super.y,super.z); ++ this.setCanceled(tEvent.isCancelled()||!tEvent.canBuild()); ++ + if (DEBUG) + { + System.out.printf("Created MultiPlaceEvent - [PlacedAgainst: %s ][ItemInHand: %s ][Player: %s ]\n", placedAgainst, this.itemInHand, player);