Implement Bucket events

Dieser Commit ist enthalten in:
Erik Broes 2011-03-16 16:13:42 +01:00
Ursprung 324efa8224
Commit bb9558adec
2 geänderte Dateien mit 124 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,72 @@
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.Location;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerBucketFillEvent;
// CraftBukkit end
public class EntityCow extends EntityAnimal {
public EntityCow(World world) {
super(world);
this.texture = "/mob/cow.png";
this.a(0.9F, 1.3F);
}
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
}
public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
}
protected String e() {
return "mob.cow";
}
protected String f() {
return "mob.cowhurt";
}
protected String g() {
return "mob.cowhurt";
}
protected float i() {
return 0.4F;
}
protected int h() {
return Item.LEATHER.id;
}
public boolean a(EntityHuman entityhuman) {
ItemStack itemstack = entityhuman.inventory.b();
if (itemstack != null && itemstack.id == Item.BUCKET.id) {
// CraftBukkit start - got milk?
Location loc = this.getBukkitEntity().getLocation();
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), -1, itemstack, Item.MILK_BUCKET);
if (event.isCancelled()) {
return false;
}
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
itemstack = new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data );
entityhuman.inventory.a(entityhuman.inventory.c, itemstack);
// CraftBukkit end
return true;
} else {
return false;
}
}
}

Datei anzeigen

@ -1,13 +1,17 @@
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerItemEvent;
// CraftBukkit end
@ -52,50 +56,54 @@ public class ItemBucket extends Item {
return itemstack;
}
// CraftBukkit start - Click == placed when handling an empty bucket!
CraftWorld craftWorld = ((WorldServer) world).getWorld();
CraftServer craftServer = ((WorldServer) world).getServer();
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(movingobjectposition.e);
// CraftBukkit end
if (this.a == 0) {
if (world.getMaterial(i, j, k) == Material.WATER && world.getData(i, j, k) == 0) {
// CraftBukkit start
PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockFace);
craftServer.getPluginManager().callEvent(event);
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, i, j, k, -1, itemstack, Item.WATER_BUCKET);
if (event.isCancelled()) {
return itemstack;
}
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
// CraftBukkit end
world.e(i, j, k, 0);
return new ItemStack(Item.WATER_BUCKET);
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data); // CraftBukkit
}
if (world.getMaterial(i, j, k) == Material.LAVA && world.getData(i, j, k) == 0) {
// CraftBukkit start
PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockFace);
craftServer.getPluginManager().callEvent(event);
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, i, j, k, -1, itemstack, Item.LAVA_BUCKET);
if (event.isCancelled()) {
return itemstack;
}
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
// CraftBukkit end
world.e(i, j, k, 0);
return new ItemStack(Item.LAVA_BUCKET);
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data ); // CraftBukkit
}
} else {
if (this.a < 0) {
return new ItemStack(Item.BUCKET);
// CraftBukkit start
PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, i, j, k, movingobjectposition.e, itemstack);
if (event.isCancelled()) {
return itemstack;
}
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data );
// CraftBukkit end
}
int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit
if (movingobjectposition.e == 0) {
--j;
}
@ -121,6 +129,14 @@ public class ItemBucket extends Item {
}
if (world.isEmpty(i, j, k) || !world.getMaterial(i, j, k).isBuildable()) {
// CraftBukkit start
PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, clickedX, clickedY, clickedZ, movingobjectposition.e, itemstack);
if (event.isCancelled()) {
return itemstack;
}
// CraftBukkit end
if (world.m.d && this.a == Block.WATER.id) {
world.a(d0 + 0.5D, d1 + 0.5D, d2 + 0.5D, "random.fizz", 0.5F, 2.6F + (world.k.nextFloat() - world.k.nextFloat()) * 0.8F);
@ -128,23 +144,29 @@ public class ItemBucket extends Item {
world.a("largesmoke", (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D);
}
} else {
// CraftBukkit start - bucket empty.
PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockFace);
craftServer.getPluginManager().callEvent(event);
world.b(i, j, k, this.a, 0);
}
// CraftBukkit start
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data );
// CraftBukkit end
}
}
} else if (this.a == 0 && movingobjectposition.g instanceof EntityCow) {
// CraftBukkit start -- This codepath seems to be *NEVER* called
Location loc = movingobjectposition.g.getBukkitEntity().getLocation();
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), -1, itemstack, Item.MILK_BUCKET);
if (event.isCancelled()) {
return itemstack;
}
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data );
// CraftBukkit end
world.b(i, j, k, this.a, 0);
}
return new ItemStack(Item.BUCKET);
}
}
} else if (this.a == 0 && movingobjectposition.g instanceof EntityCow) {
return new ItemStack(Item.MILK_BUCKET);
}
return itemstack;