3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-16 21:10:17 +01:00
Dieser Commit ist enthalten in:
Erik Broes 2011-03-21 00:25:26 +01:00
Ursprung 0d2dc3902c
Commit 324efa8224
11 geänderte Dateien mit 355 neuen und 202 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,66 @@
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.block.BlockPlaceEvent;
// CraftBukkit end
public class ItemBed extends Item {
public ItemBed(int i) {
super(i);
}
public boolean a(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) {
if (l != 1) {
return false;
} else {
int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit;
++j;
BlockBed blockbed = (BlockBed) Block.BED;
int i1 = MathHelper.b((double) (entityhuman.yaw * 4.0F / 360.0F) + 0.5D) & 3;
byte b0 = 0;
byte b1 = 0;
if (i1 == 0) {
b1 = 1;
}
if (i1 == 1) {
b0 = -1;
}
if (i1 == 2) {
b1 = -1;
}
if (i1 == 3) {
b0 = 1;
}
if (world.isEmpty(i, j, k) && world.isEmpty(i + b0, j, k + b1) && world.d(i, j - 1, k) && world.d(i + b0, j - 1, k + b1)) {
BlockState blockState = CraftBlockState.getBlockState(world, i, j, k); // CraftBukkit
world.b(i, j, k, blockbed.id, i1);
// CraftBukkit start - bed
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, blockbed);
if (event.isCancelled() || !event.canBuild()) {
event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false);
return false;
}
// CraftBukkit end
world.b(i + b0, j, k + b1, blockbed.id, i1 + 8);
--itemstack.count;
return true;
} else {
return false;
}
}
}
}

Datei anzeigen

@ -1,13 +1,11 @@
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.block.BlockPlaceEvent;
// CraftBukkit end
@ -22,14 +20,7 @@ public class ItemBlock extends Item {
}
public boolean a(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) {
// CraftBukkit start -- Bail if we have nothing of the item in hand
if (itemstack.count == 0) {
return false;
}
CraftBlock blockClicked = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k);
BlockFace faceClicked = CraftBlock.notchToBlockFace(l);
// CraftBukkit end
int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit;
if (world.getTypeId(i, j, k) == Block.SNOW.id) {
l = 0;
@ -62,23 +53,16 @@ public class ItemBlock extends Item {
if (itemstack.count == 0) {
return false;
} else {
// CraftBukkit start
/* We store the old data so we can undo it. Snow(78) and half-steps(44) are special in that they replace the block itself,
* rather than the block touching the face we clicked on.
*/
int typeId = blockClicked.getTypeId();
org.bukkit.block.Block placedBlock = blockClicked.getFace(faceClicked);
if (typeId == Block.SNOW.id || (typeId == Block.STEP.id && itemstack.id == Block.STEP.id && faceClicked == BlockFace.UP))
placedBlock = blockClicked;
final BlockState replacedBlockState = new CraftBlockState(placedBlock);
// CraftBukkit end
if (world.a(this.a, i, j, k, false)) {
Block block = Block.byId[this.a];
// CraftBukkit start - This executes the placement of the block
BlockState replacedBlockState = CraftBlockState.getBlockState(world, i, j, k);
// Special case the silly stepstone :'(
if (l == 1 && world.getTypeId(i, j - 1, k) == Block.STEP.id && itemstack.id == Block.STEP.id) {
replacedBlockState = CraftBlockState.getBlockState(world, i, j - 1, k);
}
/**
* @see net.minecraft.server.World#b(int i, int j, int k, int l, int i1)
*
@ -90,22 +74,7 @@ public class ItemBlock extends Item {
* replace this with.
*/
if (world.setTypeIdAndData(i, j, k, a, a(itemstack.h()))) { // <-- world.b does this to place the block
org.bukkit.Server server = ((WorldServer) world).getServer();
Type eventType = Type.BLOCK_PLACE;
org.bukkit.inventory.ItemStack itemInHand = new CraftItemStack(itemstack);
Player thePlayer = (entityhuman == null) ? null : (Player) entityhuman.getBukkitEntity();
ChunkCoordinates chunkcoordinates = world.l();
int spawnX = chunkcoordinates.a;
int spawnZ = chunkcoordinates.c;
int distanceFromSpawn = (int) Math.max(Math.abs(i - spawnX), Math.abs(k - spawnZ));
// CraftBukkit Configurable spawn protection start
boolean canBuild = distanceFromSpawn > ((WorldServer) world).x.spawnProtection || thePlayer.isOp();
BlockPlaceEvent event = new BlockPlaceEvent(eventType, placedBlock, replacedBlockState, blockClicked, itemInHand, thePlayer, canBuild);
server.getPluginManager().callEvent(event);
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, replacedBlockState, clickedX, clickedY, clickedZ, block);
if (event.isCancelled() || !event.canBuild()) {
// CraftBukkit Undo!
@ -116,7 +85,7 @@ public class ItemBlock extends Item {
} else {
if (this.a == block.ICE.id) {
if (this.a == Block.ICE.id) {
// Ice will explode if we set straight to 0
world.setTypeId(i, j, k, 20);
}

Datei anzeigen

@ -0,0 +1,97 @@
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.block.BlockPlaceEvent;
// CraftBukkit end
public class ItemDoor extends Item {
private Material a;
public ItemDoor(int i, Material material) {
super(i);
this.a = material;
this.durability = 64;
this.maxStackSize = 1;
}
public boolean a(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) {
if (l != 1) {
return false;
} else {
int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit;
++j;
Block block;
if (this.a == Material.WOOD) {
block = Block.WOODEN_DOOR;
} else {
block = Block.IRON_DOOR_BLOCK;
}
if (!block.a(world, i, j, k)) {
return false;
} else {
int i1 = MathHelper.b((double) ((entityhuman.yaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
byte b0 = 0;
byte b1 = 0;
if (i1 == 0) {
b1 = 1;
}
if (i1 == 1) {
b0 = -1;
}
if (i1 == 2) {
b1 = -1;
}
if (i1 == 3) {
b0 = 1;
}
int j1 = (world.d(i - b0, j, k - b1) ? 1 : 0) + (world.d(i - b0, j + 1, k - b1) ? 1 : 0);
int k1 = (world.d(i + b0, j, k + b1) ? 1 : 0) + (world.d(i + b0, j + 1, k + b1) ? 1 : 0);
boolean flag = world.getTypeId(i - b0, j, k - b1) == block.id || world.getTypeId(i - b0, j + 1, k - b1) == block.id;
boolean flag1 = world.getTypeId(i + b0, j, k + b1) == block.id || world.getTypeId(i + b0, j + 1, k + b1) == block.id;
boolean flag2 = false;
if (flag && !flag1) {
flag2 = true;
} else if (k1 > j1) {
flag2 = true;
}
if (flag2) {
i1 = i1 - 1 & 3;
i1 += 4;
}
BlockState blockState = CraftBlockState.getBlockState(world, i, j, k); // CraftBukkit
world.e(i, j, k, block.id);
world.c(i, j, k, i1);
// CraftBukkit start - bed
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, block);
if (event.isCancelled() || !event.canBuild()) {
event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false);
return false;
}
// CraftBukkit end
world.e(i, j + 1, k, block.id);
world.c(i, j + 1, k, i1 + 8);
--itemstack.count;
return true;
}
}
}
}

Datei anzeigen

@ -1,15 +1,14 @@
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerItemEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
// CraftBukkit end
@ -22,11 +21,7 @@ public class ItemFlintAndSteel extends Item {
}
public boolean a(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) {
// CraftBukkit start - store the clicked block
CraftWorld craftWorld = ((WorldServer) world).getWorld();
CraftServer craftServer = ((WorldServer) world).getServer();
org.bukkit.block.Block blockClicked = craftWorld.getBlockAt(i, j, k);
// CraftBukkit end
int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit;
if (l == 0) {
--j;
@ -55,34 +50,37 @@ public class ItemFlintAndSteel extends Item {
int i1 = world.getTypeId(i, j, k);
if (i1 == 0) {
// CraftBukkit start - Flint and steel
Type eventType = Type.PLAYER_ITEM;
// CraftBukkit start - store the clicked block
CraftWorld craftWorld = ((WorldServer) world).getWorld();
CraftServer craftServer = ((WorldServer) world).getServer();
org.bukkit.block.Block blockClicked = craftWorld.getBlockAt(i, j, k);
Player thePlayer = (Player) entityhuman.getBukkitEntity();
CraftItemStack itemInHand = new CraftItemStack(itemstack);
BlockFace blockFace = CraftBlock.notchToBlockFace(l);
PlayerItemEvent event = new PlayerItemEvent(eventType, thePlayer, itemInHand, blockClicked, blockFace);
craftServer.getPluginManager().callEvent(event);
boolean preventLighter = event.isCancelled();
IgniteCause igniteCause = BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL;
BlockIgniteEvent eventIgnite = new BlockIgniteEvent(blockClicked, igniteCause, thePlayer);
craftServer.getPluginManager().callEvent(eventIgnite);
boolean preventFire = eventIgnite.isCancelled();
if (preventLighter) {
return false;
}
if (preventFire) {
itemstack.b(1);
return false;
}
// CraftBukkit end
BlockState blockState = CraftBlockState.getBlockState(world, i, j, k); // CraftBukkit
world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "fire.ignite", 1.0F, b.nextFloat() * 0.4F + 0.8F);
world.e(i, j, k, Block.FIRE.id);
// CraftBukkit start
BlockPlaceEvent placeEvent = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, Block.FIRE.id);
if (placeEvent.isCancelled() || !placeEvent.canBuild()) {
placeEvent.getBlockPlaced().setTypeIdAndData(0, (byte)0, false);
return false;
}
// CraftBukkit end
}
itemstack.b(1);

Datei anzeigen

@ -1,14 +1,10 @@
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerItemEvent;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.block.BlockPlaceEvent;
// CraftBukkit end
public class ItemHoe extends Item {
@ -32,25 +28,18 @@ public class ItemHoe extends Item {
if (world.isStatic) {
return true;
} else {
// CraftBukkit start - Hoes
CraftWorld craftWorld = ((WorldServer) world).getWorld();
CraftServer craftServer = ((WorldServer) world).getServer();
BlockState blockState = CraftBlockState.getBlockState(world, i, j, k); // CraftBukkit
Type eventType = Type.PLAYER_ITEM;
Player who = (entityhuman == null) ? null : (Player) entityhuman.getBukkitEntity();
org.bukkit.inventory.ItemStack itemInHand = new CraftItemStack(itemstack);
org.bukkit.block.Block blockClicked = craftWorld.getBlockAt(i, j, k);
BlockFace blockFace = CraftBlock.notchToBlockFace(l);
world.e(i, j, k, block.id);
PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockFace);
craftServer.getPluginManager().callEvent(event);
if (event.isCancelled()) {
// CraftBukkit start - Hoes - blockface -1 for 'SELF'
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k, block);
if (event.isCancelled() || !event.canBuild()) {
event.getBlockPlaced().setTypeId(blockState.getTypeId());
return false;
}
// CraftBukkit end
world.e(i, j, k, block.id);
itemstack.b(1);
if (world.k.nextInt(8) == 0 && i1 == Block.GRASS.id) {
byte b0 = 1;

Datei anzeigen

@ -1,14 +1,10 @@
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerItemEvent;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.block.BlockPlaceEvent;
// CraftBukkit end
public class ItemRedstone extends Item {
@ -18,11 +14,7 @@ public class ItemRedstone extends Item {
}
public boolean a(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) {
// CraftBukkit start - store the clicked block
CraftWorld craftWorld = ((WorldServer) world).getWorld();
CraftServer craftServer = ((WorldServer) world).getServer();
org.bukkit.block.Block blockClicked = craftWorld.getBlockAt(i, j, k);
// CraftBukkit end
int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit;
if (l == 0) {
--j;
@ -52,22 +44,20 @@ public class ItemRedstone extends Item {
return false;
} else {
if (Block.REDSTONE_WIRE.a(world, i, j, k)) {
// CraftBukkit start - Redstone
Type eventType = Type.PLAYER_ITEM;
Player who = (entityhuman == null) ? null : (Player) entityhuman.getBukkitEntity();
org.bukkit.inventory.ItemStack itemInHand = new CraftItemStack(itemstack);
BlockFace blockface = CraftBlock.notchToBlockFace(l);
BlockState blockState = CraftBlockState.getBlockState(world, i, j, k); // CraftBukkit
PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockface);
craftServer.getPluginManager().callEvent(event);
world.e(i, j, k, Block.REDSTONE_WIRE.id);
if (event.isCancelled()) {
// CraftBukkit start - redstone
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, Block.REDSTONE_WIRE);
if (event.isCancelled() || !event.canBuild()) {
event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false);
return false;
}
// CraftBukkit end
--itemstack.count;
world.e(i, j, k, Block.REDSTONE_WIRE.id);
--itemstack.count; // CraftBukkit -- ORDER MATTERS
}
return true;

Datei anzeigen

@ -1,16 +1,10 @@
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.Material;
import org.bukkit.event.player.PlayerVegetationPlantEvent;
// CraftBukkit end
public class ItemReed extends Item {
@ -23,14 +17,7 @@ public class ItemReed extends Item {
}
public boolean a(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) {
// CraftBukkit start -- Bail if we have nothing of the item in hand
if (itemstack.count == 0) {
return false;
}
CraftBlock blockClicked = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k);
BlockFace faceClicked = CraftBlock.notchToBlockFace(l);
// CraftBukkit end
int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit;
if (world.getTypeId(i, j, k) == Block.SNOW.id) {
l = 0;
@ -63,23 +50,11 @@ public class ItemReed extends Item {
if (itemstack.count == 0) {
return false;
} else {
// CraftBukkit start
/* We store the old data so we can undo it. Snow(78) and half-steps(44) are special in that they replace the block itself,
* rather than the block touching the face we clicked on.
*/
int typeId = blockClicked.getTypeId();
org.bukkit.block.Block placedBlock = blockClicked.getFace(faceClicked);
if (typeId == Block.SNOW.id || (typeId == Block.STEP.id && itemstack.id == Block.STEP.id && faceClicked == BlockFace.UP))
placedBlock = blockClicked;
final BlockState replacedBlockState = new CraftBlockState(placedBlock);
// CraftBukkit end
if (world.a(this.a, i, j, k, false)) {
Block block = Block.byId[this.a];
// CraftBukkit start - This executes the placement of the block
BlockState replacedBlockState = CraftBlockState.getBlockState(world, i, j, k); // CraftBukkit
/**
* @see net.minecraft.server.World#e(int i, int j, int k, int l)
*
@ -91,22 +66,7 @@ public class ItemReed extends Item {
* replace this with.
*/
if (world.setTypeId(i, j, k, this.a)) { // <-- world.e does this to place the block
org.bukkit.Server server = ((WorldServer) world).getServer();
Type eventType = Type.BLOCK_PLACE;
org.bukkit.inventory.ItemStack itemInHand = new CraftItemStack(itemstack);
Player thePlayer = (entityhuman == null) ? null : (Player) entityhuman.getBukkitEntity();
ChunkCoordinates chunkcoordinates = world.l();
int spawnX = chunkcoordinates.a;
int spawnZ = chunkcoordinates.c;
int distanceFromSpawn = (int) Math.max(Math.abs(i - spawnX), Math.abs(k - spawnZ));
// CraftBukkit Configurable spawn protection start
boolean canBuild = distanceFromSpawn > ((WorldServer) world).x.spawnProtection || thePlayer.isOp();
BlockPlaceEvent event = new BlockPlaceEvent(eventType, placedBlock, replacedBlockState, blockClicked, itemInHand, thePlayer, canBuild);
server.getPluginManager().callEvent(event);
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, replacedBlockState, clickedX, clickedY, clickedZ, block);
if (event.isCancelled() || !event.canBuild()) {
// CraftBukkit Undo -- this only has reed, repeater and pie blocks

Datei anzeigen

@ -1,14 +1,10 @@
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerItemEvent;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.block.BlockPlaceEvent;
// CraftBukkit end
public class ItemSeeds extends Item {
@ -27,25 +23,17 @@ public class ItemSeeds extends Item {
int i1 = world.getTypeId(i, j, k);
if (i1 == Block.SOIL.id && world.isEmpty(i, j + 1, k)) {
// CraftBukkit start - Seeds
CraftWorld craftWorld = ((WorldServer) world).getWorld();
CraftServer craftServer = ((WorldServer) world).getServer();
BlockState blockState = CraftBlockState.getBlockState( world, i, j + 1, k); // CraftBukkit
Type eventType = Type.PLAYER_ITEM;
Player who = (entityhuman == null) ? null : (Player) entityhuman.getBukkitEntity();
org.bukkit.inventory.ItemStack itemInHand = new CraftItemStack(itemstack);
org.bukkit.block.Block blockClicked = craftWorld.getBlockAt(i, j, k);
BlockFace blockface = CraftBlock.notchToBlockFace(l);
world.e(i, j + 1, k, this.a);
PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockface);
craftServer.getPluginManager().callEvent(event);
if (event.isCancelled()) {
// CraftBukkit start - seeds
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k, this.a);
if (event.isCancelled() || !event.canBuild()) {
event.getBlockPlaced().setTypeId(0);
return false;
}
// CraftBukkit end
world.e(i, j + 1, k, this.a);
--itemstack.count;
return true;
} else {

Datei anzeigen

@ -1,14 +1,10 @@
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerItemEvent;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.block.BlockPlaceEvent;
// CraftBukkit end
public class ItemSign extends Item {
@ -25,11 +21,7 @@ public class ItemSign extends Item {
} else if (!world.getMaterial(i, j, k).isBuildable()) {
return false;
} else {
// CraftBukkit start - store the clicked block
CraftWorld craftWorld = ((WorldServer) world).getWorld();
CraftServer craftServer = ((WorldServer) world).getServer();
org.bukkit.block.Block blockClicked = craftWorld.getBlockAt(i, j, k);
// CraftBukkit end
int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit;
if (l == 1) {
++j;
@ -54,20 +46,7 @@ public class ItemSign extends Item {
if (!Block.SIGN_POST.a(world, i, j, k)) {
return false;
} else {
// CraftBukkit start
// Signs
Type eventType = Type.PLAYER_ITEM;
Player who = (entityhuman == null) ? null : (Player) entityhuman.getBukkitEntity();
org.bukkit.inventory.ItemStack itemInHand = new CraftItemStack(itemstack);
BlockFace blockface = CraftBlock.notchToBlockFace(l);
PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockface);
craftServer.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return false;
}
// CraftBukkit end
BlockState blockState = CraftBlockState.getBlockState(world, i, j, k); // CraftBukkit
if (l == 1) {
world.b(i, j, k, Block.SIGN_POST.id, MathHelper.b((double) ((entityhuman.yaw + 180.0F) * 16.0F / 360.0F) + 0.5D) & 15);
@ -75,6 +54,15 @@ public class ItemSign extends Item {
world.b(i, j, k, Block.WALL_SIGN.id, l);
}
// CraftBukkit start - sign
BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, l == 1 ? Block.SIGN_POST : Block.WALL_SIGN);
if (event.isCancelled() || !event.canBuild()) {
event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false);
return false;
}
// CraftBukkit end
--itemstack.count;
TileEntitySign tileentitysign = (TileEntitySign) world.getTileEntity(i, j, k);

Datei anzeigen

@ -10,6 +10,7 @@ import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.CraftChunk;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.material.MaterialData;
import net.minecraft.server.WorldServer;
public class CraftBlockState implements BlockState {
private final CraftWorld world;
@ -33,6 +34,10 @@ public class CraftBlockState implements BlockState {
createData(block.getData());
}
public static BlockState getBlockState( net.minecraft.server.World world, int x, int y, int z) {
return new CraftBlockState( ((WorldServer) world).getWorld().getBlockAt(x, y, z) );
}
/**
* Gets the world which contains this Block
*

Datei anzeigen

@ -0,0 +1,103 @@
package org.bukkit.craftbukkit.event;
import net.minecraft.server.ChunkCoordinates;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.Item;
import net.minecraft.server.ItemStack;
import net.minecraft.server.World;
import net.minecraft.server.WorldServer;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerEvent;
public class CraftEventFactory {
private static boolean canBuild(CraftWorld world, Player player, int x, int z) {
WorldServer worldServer = world.getHandle();
int spawnSize = worldServer.x.spawnProtection;
if (spawnSize <= 0) return true;
if (player.isOp()) return true;
ChunkCoordinates chunkcoordinates = worldServer.l();
int distanceFromSpawn = (int) Math.max(Math.abs(x - chunkcoordinates.a), Math.abs(z - chunkcoordinates.c));
return distanceFromSpawn > spawnSize;
}
/**
* Block place methods
*/
public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ, int type) {
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();
CraftServer craftServer = ((WorldServer) world).getServer();
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
CraftItemStack itemInHand = new CraftItemStack(itemstack);
Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
Block placedBlock = replacedBlockState.getBlock();
boolean canBuild = canBuild(craftWorld, player, placedBlock.getX(), placedBlock.getZ());
BlockPlaceEvent event = new BlockPlaceEvent(Type.BLOCK_PLACE, placedBlock, replacedBlockState, blockClicked, itemInHand, player, canBuild);
craftServer.getPluginManager().callEvent(event);
return event;
}
/**
* Bucket methods
*/
public static PlayerBucketEmptyEvent callPlayerBucketEmptyEvent(EntityHuman who, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemInHand) {
return (PlayerBucketEmptyEvent) getPlayerBucketEvent(Type.PLAYER_BUCKET_EMPTY, who, clickedX, clickedY, clickedZ, clickedFace, itemInHand, Item.BUCKET);
}
public static PlayerBucketFillEvent callPlayerBucketFillEvent(EntityHuman who, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemInHand, net.minecraft.server.Item bucket) {
return (PlayerBucketFillEvent) getPlayerBucketEvent(Type.PLAYER_BUCKET_FILL, who, clickedX, clickedY, clickedZ, clickedFace, itemInHand, bucket);
}
private static PlayerEvent getPlayerBucketEvent(Type type, EntityHuman who, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemstack, net.minecraft.server.Item item) {
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
CraftItemStack itemInHand = new CraftItemStack(new ItemStack(item));
Material bucket = Material.getMaterial(itemstack.id);
CraftWorld craftWorld = (CraftWorld) player.getWorld();
CraftServer craftServer = (CraftServer) player.getServer();
Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);
PlayerEvent event = null;
if (type == Type.PLAYER_BUCKET_EMPTY) {
event = new PlayerBucketEmptyEvent(player, blockClicked, blockFace, bucket, itemInHand);
((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
} else if(type == Type.PLAYER_BUCKET_FILL) {
event = new PlayerBucketFillEvent(player, blockClicked, blockFace, bucket, itemInHand);
((PlayerBucketFillEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
}
craftServer.getPluginManager().callEvent(event);
return event;
}
}