[Bleeding] Added getting and setting drops to all appropriate events. Fixes BUKKIT-397 and fixes BUKKIT-1252

- Allows drops in creative mode by adding items to the getDrops() list
- Contents of containers are not reported
- Contents of storage minecarts are not reported
This commit is contained in:
Celtic Minstrel
2012-03-05 14:21:43 -05:00
committed by EvilSeph
parent 8d62de7055
commit 5ba8928041
20 changed files with 344 additions and 60 deletions

View File

@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
// CraftBukkit start
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Painting;
import org.bukkit.event.painting.PaintingBreakByEntityEvent;
import org.bukkit.event.painting.PaintingBreakEvent.RemoveCause;
@@ -125,6 +126,8 @@ public class EntityPainting extends Entity {
this.f = 0;
if (!this.survives()) {
// CraftBukkit start
List<org.bukkit.inventory.ItemStack> drops = new ArrayList<org.bukkit.inventory.ItemStack>();
drops.add(new CraftItemStack(Item.PAINTING.id, 1));
Material material = this.world.getMaterial((int) this.locX, (int) this.locY, (int) this.locZ);
RemoveCause cause;
if (material.equals(Material.WATER)) {
@@ -135,7 +138,7 @@ public class EntityPainting extends Entity {
} else {
cause = RemoveCause.PHYSICS;
}
PaintingBreakEvent event = new PaintingBreakEvent((Painting) this.getBukkitEntity(), cause);
PaintingBreakEvent event = new PaintingBreakEvent((Painting) this.getBukkitEntity(), cause, drops);
this.world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || dead) {
@@ -144,7 +147,12 @@ public class EntityPainting extends Entity {
// CraftBukkit end
this.die();
this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, new ItemStack(Item.PAINTING)));
// CraftBukkit start - replace following line with the loop
//this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, new ItemStack(Item.PAINTING)));
for (org.bukkit.inventory.ItemStack stack : drops) {
this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, CraftItemStack.createNMSItemStack(stack)));
}
// CraftBukkit end
}
}
}
@@ -214,12 +222,14 @@ public class EntityPainting extends Entity {
public boolean damageEntity(DamageSource damagesource, int i) {
if (!this.dead && !this.world.isStatic) {
// CraftBukkit start
List<org.bukkit.inventory.ItemStack> drops = new ArrayList<org.bukkit.inventory.ItemStack>();
drops.add(new CraftItemStack(Item.PAINTING.id, 1));
PaintingBreakEvent event = null;
if (damagesource.getEntity() != null) {
event = new PaintingBreakByEntityEvent((Painting) this.getBukkitEntity(), damagesource.getEntity() == null ? null : damagesource.getEntity().getBukkitEntity());
event = new PaintingBreakByEntityEvent((Painting) this.getBukkitEntity(), damagesource.getEntity().getBukkitEntity(), drops);
} else {
if (damagesource == DamageSource.FIRE) {
event = new PaintingBreakEvent((Painting) this.getBukkitEntity(), RemoveCause.FIRE);
event = new PaintingBreakEvent((Painting) this.getBukkitEntity(), RemoveCause.FIRE, drops);
}
// TODO: Could put other stuff here?
}
@@ -236,7 +246,12 @@ public class EntityPainting extends Entity {
this.die();
this.aV();
this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, new ItemStack(Item.PAINTING)));
// CraftBukkit start - replace following line with the loop
//this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, new ItemStack(Item.PAINTING)));
for (org.bukkit.inventory.ItemStack stack : drops) {
this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, CraftItemStack.createNMSItemStack(stack)));
}
// CraftBukkit end
}
return true;