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;
|
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
|
||||||
if (this instanceof EntityPainting) {
|
|
||||||
Material material = this.world.getMaterial((int) this.locX, (int) this.locY, (int) this.locZ);
|
Material material = this.world.getMaterial((int) this.locX, (int) this.locY, (int) this.locZ);
|
||||||
RemoveCause cause;
|
HangingBreakEvent.RemoveCause cause;
|
||||||
|
|
||||||
if (material.equals(Material.WATER)) {
|
if (!material.equals(Material.AIR)) {
|
||||||
cause = RemoveCause.WATER;
|
|
||||||
} else if (!material.equals(Material.AIR)) {
|
|
||||||
// TODO: This feels insufficient to catch 100% of suffocation cases
|
// TODO: This feels insufficient to catch 100% of suffocation cases
|
||||||
cause = RemoveCause.OBSTRUCTION;
|
cause = HangingBreakEvent.RemoveCause.OBSTRUCTION;
|
||||||
} else {
|
} 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);
|
this.world.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (event.isCancelled() || dead) {
|
PaintingBreakEvent paintingEvent = null;
|
||||||
return;
|
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
|
// 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
|
||||||
if (this instanceof EntityPainting) {
|
HangingBreakEvent event = null;
|
||||||
PaintingBreakEvent event = null;
|
PaintingBreakEvent paintingEvent = null;
|
||||||
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());
|
event = new HangingBreakByEntityEvent((Hanging) 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);
|
event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.FIRE);
|
||||||
}
|
}
|
||||||
// TODO: Could put other stuff here?
|
// 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) {
|
if (event != null) {
|
||||||
this.world.getServer().getPluginManager().callEvent(event);
|
this.world.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.dead) {
|
if (paintingEvent != null) {
|
||||||
return true;
|
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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren