[Bleeding] Implement new Hanging events. Adds BUKKIT-2754

Dieser Commit ist enthalten in:
h31ix 2012-10-30 23:21:53 -04:00 committet von EvilSeph
Ursprung 4efd06a6b5
Commit 54cce5bf92
2 geänderte Dateien mit 66 neuen und 42 gelöschten Zeilen

Datei anzeigen

@ -4,8 +4,10 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
// CraftBukkit start // CraftBukkit start
import org.bukkit.entity.Hanging;
import org.bukkit.entity.Painting; import org.bukkit.entity.Painting;
import org.bukkit.event.painting.PaintingBreakEvent.RemoveCause; import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.painting.PaintingBreakEvent; import org.bukkit.event.painting.PaintingBreakEvent;
// CraftBukkit end // CraftBukkit end
@ -104,25 +106,29 @@ public abstract class EntityHanging extends Entity {
this.e = 0; this.e = 0;
if (!this.dead && !this.survives()) { if (!this.dead && !this.survives()) {
// CraftBukkit start // CraftBukkit start
Material material = this.world.getMaterial((int) this.locX, (int) this.locY, (int) this.locZ);
HangingBreakEvent.RemoveCause cause;
if (!material.equals(Material.AIR)) {
// TODO: This feels insufficient to catch 100% of suffocation cases
cause = HangingBreakEvent.RemoveCause.OBSTRUCTION;
} else {
cause = HangingBreakEvent.RemoveCause.PHYSICS;
}
HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), cause);
this.world.getServer().getPluginManager().callEvent(event);
PaintingBreakEvent paintingEvent = null;
if (this instanceof EntityPainting) { if (this instanceof EntityPainting) {
Material material = this.world.getMaterial((int) this.locX, (int) this.locY, (int) this.locZ); // Fire old painting event until it can be removed
RemoveCause cause; paintingEvent = new PaintingBreakEvent((Painting) this.getBukkitEntity(), PaintingBreakEvent.RemoveCause.valueOf(cause.name()));
paintingEvent.setCancelled(event.isCancelled());
this.world.getServer().getPluginManager().callEvent(paintingEvent);
}
if (material.equals(Material.WATER)) { if (dead || event.isCancelled() || (paintingEvent != null && paintingEvent.isCancelled())) {
cause = RemoveCause.WATER; return;
} else if (!material.equals(Material.AIR)) {
// TODO: This feels insufficient to catch 100% of suffocation cases
cause = RemoveCause.OBSTRUCTION;
} else {
cause = RemoveCause.PHYSICS;
}
PaintingBreakEvent event = new PaintingBreakEvent((Painting) this.getBukkitEntity(), cause);
this.world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || dead) {
return;
}
} }
// CraftBukkit end // CraftBukkit end
@ -200,28 +206,39 @@ public abstract class EntityHanging extends Entity {
public boolean damageEntity(DamageSource damagesource, int i) { public boolean damageEntity(DamageSource damagesource, int i) {
if (!this.dead && !this.world.isStatic) { if (!this.dead && !this.world.isStatic) {
// CraftBukkit start // CraftBukkit start
HangingBreakEvent event = null;
PaintingBreakEvent paintingEvent = null;
if (damagesource.getEntity() != null) {
event = new HangingBreakByEntityEvent((Hanging) this.getBukkitEntity(), damagesource.getEntity() == null ? null : damagesource.getEntity().getBukkitEntity());
} else {
if (damagesource == DamageSource.FIRE) {
event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.FIRE);
}
// TODO: Could put other stuff here?
}
if (this instanceof EntityPainting) { if (this instanceof EntityPainting) {
PaintingBreakEvent event = null; // Fire old painting event until it can be removed
if (damagesource.getEntity() != null) { if (damagesource.getEntity() != null) {
event = new org.bukkit.event.painting.PaintingBreakByEntityEvent((Painting) this.getBukkitEntity(), damagesource.getEntity() == null ? null : damagesource.getEntity().getBukkitEntity()); paintingEvent = new org.bukkit.event.painting.PaintingBreakByEntityEvent((Painting) this.getBukkitEntity(), damagesource.getEntity() == null ? null : damagesource.getEntity().getBukkitEntity());
} else { } else {
if (damagesource == DamageSource.FIRE) { if (damagesource == DamageSource.FIRE) {
event = new PaintingBreakEvent((Painting) this.getBukkitEntity(), RemoveCause.FIRE); paintingEvent = new PaintingBreakEvent((Painting) this.getBukkitEntity(), PaintingBreakEvent.RemoveCause.valueOf(HangingBreakEvent.RemoveCause.FIRE.name()));
}
// TODO: Could put other stuff here?
}
if (event != null) {
this.world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
} }
} }
}
if (this.dead) { if (event != null) {
return true; this.world.getServer().getPluginManager().callEvent(event);
} }
if (paintingEvent != null) {
paintingEvent.setCancelled(event != null && event.isCancelled());
this.world.getServer().getPluginManager().callEvent(paintingEvent);
}
if (dead || event.isCancelled() || (paintingEvent != null && paintingEvent.isCancelled())) {
return true;
} }
// CraftBukkit end // CraftBukkit end

Datei anzeigen

@ -2,6 +2,7 @@ package net.minecraft.server;
// CraftBukkit start // CraftBukkit start
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.painting.PaintingPlaceEvent; import org.bukkit.event.painting.PaintingPlaceEvent;
// CraftBukkit end // CraftBukkit end
@ -30,17 +31,23 @@ public class ItemHanging extends Item {
if (entityhanging != null && entityhanging.survives()) { if (entityhanging != null && entityhanging.survives()) {
if (!world.isStatic) { if (!world.isStatic) {
// CraftBukkit start // CraftBukkit start
if (entityhanging instanceof EntityPainting) { Player who = (entityhuman == null) ? null : (Player) entityhuman.getBukkitEntity();
Player who = (entityhuman == null) ? null : (Player) entityhuman.getBukkitEntity(); org.bukkit.block.Block blockClicked = world.getWorld().getBlockAt(i, j, k);
org.bukkit.block.Block blockClicked = world.getWorld().getBlockAt(i, j, k); org.bukkit.block.BlockFace blockFace = org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(l);
org.bukkit.block.BlockFace blockFace = org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(l);
PaintingPlaceEvent event = new PaintingPlaceEvent((org.bukkit.entity.Painting) entityhanging.getBukkitEntity(), who, blockClicked, blockFace); HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) entityhanging.getBukkitEntity(), who, blockClicked, blockFace);
world.getServer().getPluginManager().callEvent(event); world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { PaintingPlaceEvent paintingEvent = null;
return false; if(entityhanging instanceof EntityPainting) {
} // Fire old painting event until it can be removed
paintingEvent = new PaintingPlaceEvent((org.bukkit.entity.Painting) entityhanging.getBukkitEntity(), who, blockClicked, blockFace);
paintingEvent.setCancelled(event.isCancelled());
world.getServer().getPluginManager().callEvent(paintingEvent);
}
if (event.isCancelled() || (paintingEvent != null && paintingEvent.isCancelled())) {
return false;
} }
// CraftBukkit end // CraftBukkit end