mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-27 21:19:00 +01:00
[Bleeding] Use player.getItemInHand(), instead of a new ItemStack. Addresses BUKKIT-767
This commit is contained in:
parent
70c5f06425
commit
d7f6d2d929
@ -47,7 +47,7 @@ public class ItemBed extends Item {
|
|||||||
world.setTypeIdAndData(i, j, k, blockbed.id, i1);
|
world.setTypeIdAndData(i, j, k, blockbed.id, i1);
|
||||||
|
|
||||||
// CraftBukkit start - bed
|
// CraftBukkit start - bed
|
||||||
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, blockbed);
|
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ);
|
||||||
|
|
||||||
if (event.isCancelled() || !event.canBuild()) {
|
if (event.isCancelled() || !event.canBuild()) {
|
||||||
event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false);
|
event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false);
|
||||||
|
@ -68,7 +68,7 @@ public class ItemBlock extends Item {
|
|||||||
|
|
||||||
world.suppressPhysics = true;
|
world.suppressPhysics = true;
|
||||||
world.setTypeIdAndData(i, j, k, id, this.filterData(itemstack.getData()));
|
world.setTypeIdAndData(i, j, k, id, this.filterData(itemstack.getData()));
|
||||||
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, replacedBlockState, clickedX, clickedY, clickedZ, block);
|
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, replacedBlockState, clickedX, clickedY, clickedZ);
|
||||||
id = world.getTypeId(i, j, k);
|
id = world.getTypeId(i, j, k);
|
||||||
int data = world.getData(i, j, k);
|
int data = world.getData(i, j, k);
|
||||||
replacedBlockState.update(true);
|
replacedBlockState.update(true);
|
||||||
|
@ -97,7 +97,7 @@ public class ItemDoor extends Item {
|
|||||||
world.setTypeIdAndData(i, j, k, block.id, l);
|
world.setTypeIdAndData(i, j, k, block.id, l);
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
if (entityhuman != null) {
|
if (entityhuman != null) {
|
||||||
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k, block);
|
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k);
|
||||||
|
|
||||||
if (event.isCancelled() || !event.canBuild()) {
|
if (event.isCancelled() || !event.canBuild()) {
|
||||||
event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false);
|
event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false);
|
||||||
|
@ -68,7 +68,7 @@ public class ItemFlintAndSteel extends Item {
|
|||||||
world.setTypeId(i, j, k, Block.FIRE.id);
|
world.setTypeId(i, j, k, Block.FIRE.id);
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
BlockPlaceEvent placeEvent = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, Block.FIRE.id);
|
BlockPlaceEvent placeEvent = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ);
|
||||||
|
|
||||||
if (placeEvent.isCancelled() || !placeEvent.canBuild()) {
|
if (placeEvent.isCancelled() || !placeEvent.canBuild()) {
|
||||||
placeEvent.getBlockPlaced().setTypeIdAndData(0, (byte) 0, false);
|
placeEvent.getBlockPlaced().setTypeIdAndData(0, (byte) 0, false);
|
||||||
|
@ -35,7 +35,7 @@ public class ItemHoe extends Item {
|
|||||||
world.setTypeId(i, j, k, block.id);
|
world.setTypeId(i, j, k, block.id);
|
||||||
|
|
||||||
// CraftBukkit start - Hoes - blockface -1 for 'SELF'
|
// CraftBukkit start - Hoes - blockface -1 for 'SELF'
|
||||||
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k, block);
|
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k);
|
||||||
|
|
||||||
if (event.isCancelled() || !event.canBuild()) {
|
if (event.isCancelled() || !event.canBuild()) {
|
||||||
event.getBlockPlaced().setTypeId(blockState.getTypeId());
|
event.getBlockPlaced().setTypeId(blockState.getTypeId());
|
||||||
|
@ -55,7 +55,7 @@ public class ItemRedstone extends Item {
|
|||||||
world.suppressPhysics = true;
|
world.suppressPhysics = true;
|
||||||
world.setRawTypeId(i, j, k, Block.REDSTONE_WIRE.id); // We update after the event
|
world.setRawTypeId(i, j, k, Block.REDSTONE_WIRE.id); // We update after the event
|
||||||
|
|
||||||
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, Block.REDSTONE_WIRE);
|
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ);
|
||||||
blockState.update(true);
|
blockState.update(true);
|
||||||
|
|
||||||
if (event.isCancelled() || !event.canBuild()) {
|
if (event.isCancelled() || !event.canBuild()) {
|
||||||
|
@ -68,7 +68,7 @@ public class ItemReed extends Item {
|
|||||||
* replace this with.
|
* replace this with.
|
||||||
*/
|
*/
|
||||||
if (world.setRawTypeId(i, j, k, this.id)) { // <-- world.e does this to place the block
|
if (world.setRawTypeId(i, j, k, this.id)) { // <-- world.e does this to place the block
|
||||||
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, replacedBlockState, clickedX, clickedY, clickedZ, block);
|
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, replacedBlockState, clickedX, clickedY, clickedZ);
|
||||||
|
|
||||||
if (event.isCancelled() || !event.canBuild()) {
|
if (event.isCancelled() || !event.canBuild()) {
|
||||||
// CraftBukkit - undo; this only has reed, repeater and pie blocks
|
// CraftBukkit - undo; this only has reed, repeater and pie blocks
|
||||||
|
@ -29,7 +29,7 @@ public class ItemSeeds extends Item {
|
|||||||
world.setTypeId(i, j + 1, k, this.id);
|
world.setTypeId(i, j + 1, k, this.id);
|
||||||
|
|
||||||
// CraftBukkit start - seeds
|
// CraftBukkit start - seeds
|
||||||
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k, this.id);
|
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k);
|
||||||
|
|
||||||
if (event.isCancelled() || !event.canBuild()) {
|
if (event.isCancelled() || !event.canBuild()) {
|
||||||
event.getBlockPlaced().setTypeId(0);
|
event.getBlockPlaced().setTypeId(0);
|
||||||
|
@ -57,7 +57,7 @@ public class ItemSign extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CraftBukkit start - sign
|
// CraftBukkit start - sign
|
||||||
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, l == 1 ? Block.SIGN_POST : Block.WALL_SIGN);
|
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ);
|
||||||
|
|
||||||
if (event.isCancelled() || !event.canBuild()) {
|
if (event.isCancelled() || !event.canBuild()) {
|
||||||
event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false);
|
event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false);
|
||||||
|
@ -37,7 +37,7 @@ public class ItemWaterLily extends ItemColoredBlock {
|
|||||||
world.setTypeId(i, j + 1, k, Block.WATER_LILY.id);
|
world.setTypeId(i, j + 1, k, Block.WATER_LILY.id);
|
||||||
|
|
||||||
// CraftBukkit start - waterlily
|
// CraftBukkit start - waterlily
|
||||||
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k, Block.WATER_LILY.id);
|
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k);
|
||||||
|
|
||||||
if (event.isCancelled() || !event.canBuild()) {
|
if (event.isCancelled() || !event.canBuild()) {
|
||||||
event.getBlockPlaced().setTypeId(0);
|
event.getBlockPlaced().setTypeId(0);
|
||||||
|
@ -64,27 +64,18 @@ public class CraftEventFactory {
|
|||||||
/**
|
/**
|
||||||
* Block place methods
|
* Block place methods
|
||||||
*/
|
*/
|
||||||
public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ, int type) {
|
public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) {
|
||||||
return callBlockPlaceEvent(world, who, replacedBlockState, clickedX, clickedY, clickedZ, net.minecraft.server.Block.byId[type]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ, net.minecraft.server.Block block) {
|
|
||||||
return callBlockPlaceEvent(world, who, replacedBlockState, clickedX, clickedY, clickedZ, new ItemStack(block));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ, ItemStack itemstack) {
|
|
||||||
CraftWorld craftWorld = ((WorldServer) world).getWorld();
|
CraftWorld craftWorld = ((WorldServer) world).getWorld();
|
||||||
CraftServer craftServer = ((WorldServer) world).getServer();
|
CraftServer craftServer = ((WorldServer) world).getServer();
|
||||||
|
|
||||||
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
|
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
|
||||||
CraftItemStack itemInHand = new CraftItemStack(itemstack);
|
|
||||||
|
|
||||||
Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
|
Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
|
||||||
Block placedBlock = replacedBlockState.getBlock();
|
Block placedBlock = replacedBlockState.getBlock();
|
||||||
|
|
||||||
boolean canBuild = canBuild(craftWorld, player, placedBlock.getX(), placedBlock.getZ());
|
boolean canBuild = canBuild(craftWorld, player, placedBlock.getX(), placedBlock.getZ());
|
||||||
|
|
||||||
BlockPlaceEvent event = new BlockPlaceEvent(placedBlock, replacedBlockState, blockClicked, itemInHand, player, canBuild);
|
BlockPlaceEvent event = new BlockPlaceEvent(placedBlock, replacedBlockState, blockClicked, player.getItemInHand(), player, canBuild);
|
||||||
craftServer.getPluginManager().callEvent(event);
|
craftServer.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
return event;
|
return event;
|
||||||
|
Loading…
Reference in New Issue
Block a user