geforkt von Mirrors/Paper
[Bleeding] Implement new Hanging events. Adds BUKKIT-2754
Dieser Commit ist enthalten in:
Ursprung
4efd06a6b5
Commit
54cce5bf92
@ -4,8 +4,10 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.entity.Hanging;
|
||||
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;
|
||||
// CraftBukkit end
|
||||
|
||||
@ -104,25 +106,29 @@ public abstract class EntityHanging extends Entity {
|
||||
this.e = 0;
|
||||
if (!this.dead && !this.survives()) {
|
||||
// CraftBukkit start
|
||||
if (this instanceof EntityPainting) {
|
||||
Material material = this.world.getMaterial((int) this.locX, (int) this.locY, (int) this.locZ);
|
||||
RemoveCause cause;
|
||||
HangingBreakEvent.RemoveCause cause;
|
||||
|
||||
if (material.equals(Material.WATER)) {
|
||||
cause = RemoveCause.WATER;
|
||||
} else if (!material.equals(Material.AIR)) {
|
||||
if (!material.equals(Material.AIR)) {
|
||||
// TODO: This feels insufficient to catch 100% of suffocation cases
|
||||
cause = RemoveCause.OBSTRUCTION;
|
||||
cause = HangingBreakEvent.RemoveCause.OBSTRUCTION;
|
||||
} else {
|
||||
cause = RemoveCause.PHYSICS;
|
||||
cause = HangingBreakEvent.RemoveCause.PHYSICS;
|
||||
}
|
||||
|
||||
PaintingBreakEvent event = new PaintingBreakEvent((Painting) this.getBukkitEntity(), cause);
|
||||
HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), cause);
|
||||
this.world.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled() || dead) {
|
||||
return;
|
||||
PaintingBreakEvent paintingEvent = null;
|
||||
if (this instanceof EntityPainting) {
|
||||
// Fire old painting event until it can be removed
|
||||
paintingEvent = new PaintingBreakEvent((Painting) this.getBukkitEntity(), PaintingBreakEvent.RemoveCause.valueOf(cause.name()));
|
||||
paintingEvent.setCancelled(event.isCancelled());
|
||||
this.world.getServer().getPluginManager().callEvent(paintingEvent);
|
||||
}
|
||||
|
||||
if (dead || event.isCancelled() || (paintingEvent != null && paintingEvent.isCancelled())) {
|
||||
return;
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
@ -200,28 +206,39 @@ public abstract class EntityHanging extends Entity {
|
||||
public boolean damageEntity(DamageSource damagesource, int i) {
|
||||
if (!this.dead && !this.world.isStatic) {
|
||||
// CraftBukkit start
|
||||
if (this instanceof EntityPainting) {
|
||||
PaintingBreakEvent event = null;
|
||||
HangingBreakEvent event = null;
|
||||
PaintingBreakEvent paintingEvent = null;
|
||||
if (damagesource.getEntity() != null) {
|
||||
event = new org.bukkit.event.painting.PaintingBreakByEntityEvent((Painting) this.getBukkitEntity(), damagesource.getEntity() == null ? null : damagesource.getEntity().getBukkitEntity());
|
||||
event = new HangingBreakByEntityEvent((Hanging) this.getBukkitEntity(), damagesource.getEntity() == null ? null : damagesource.getEntity().getBukkitEntity());
|
||||
} else {
|
||||
if (damagesource == DamageSource.FIRE) {
|
||||
event = new PaintingBreakEvent((Painting) this.getBukkitEntity(), RemoveCause.FIRE);
|
||||
event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.FIRE);
|
||||
}
|
||||
// TODO: Could put other stuff here?
|
||||
}
|
||||
|
||||
if (this instanceof EntityPainting) {
|
||||
// Fire old painting event until it can be removed
|
||||
if (damagesource.getEntity() != null) {
|
||||
paintingEvent = new org.bukkit.event.painting.PaintingBreakByEntityEvent((Painting) this.getBukkitEntity(), damagesource.getEntity() == null ? null : damagesource.getEntity().getBukkitEntity());
|
||||
} else {
|
||||
if (damagesource == DamageSource.FIRE) {
|
||||
paintingEvent = new PaintingBreakEvent((Painting) this.getBukkitEntity(), PaintingBreakEvent.RemoveCause.valueOf(HangingBreakEvent.RemoveCause.FIRE.name()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event != null) {
|
||||
this.world.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.dead) {
|
||||
return true;
|
||||
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
|
||||
|
||||
|
@ -2,6 +2,7 @@ package net.minecraft.server;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
import org.bukkit.event.painting.PaintingPlaceEvent;
|
||||
// CraftBukkit end
|
||||
|
||||
@ -30,17 +31,23 @@ public class ItemHanging extends Item {
|
||||
if (entityhanging != null && entityhanging.survives()) {
|
||||
if (!world.isStatic) {
|
||||
// CraftBukkit start
|
||||
if (entityhanging instanceof EntityPainting) {
|
||||
Player who = (entityhuman == null) ? null : (Player) entityhuman.getBukkitEntity();
|
||||
org.bukkit.block.Block blockClicked = world.getWorld().getBlockAt(i, j, k);
|
||||
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);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return false;
|
||||
PaintingPlaceEvent paintingEvent = null;
|
||||
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
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren