2012-10-25 05:53:23 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.entity.Player;
|
2012-10-31 04:21:53 +01:00
|
|
|
import org.bukkit.event.hanging.HangingPlaceEvent;
|
2012-10-25 05:53:23 +02:00
|
|
|
import org.bukkit.event.painting.PaintingPlaceEvent;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
public class ItemHanging extends Item {
|
|
|
|
|
|
|
|
private final Class a;
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public ItemHanging(Class oclass) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.a = oclass;
|
|
|
|
this.a(CreativeModeTab.c);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean interactWith(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l, float f, float f1, float f2) {
|
|
|
|
if (l == 0) {
|
|
|
|
return false;
|
|
|
|
} else if (l == 1) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
int i1 = Direction.e[l];
|
|
|
|
EntityHanging entityhanging = this.a(world, i, j, k, i1);
|
|
|
|
|
|
|
|
if (!entityhuman.a(i, j, k, l, itemstack)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (entityhanging != null && entityhanging.survives()) {
|
|
|
|
if (!world.isStatic) {
|
2014-03-21 05:26:30 +01:00
|
|
|
// CraftBukkit start - fire HangingPlaceEvent
|
2012-10-31 04:21:53 +01:00
|
|
|
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);
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2012-10-31 04:21:53 +01:00
|
|
|
HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) entityhanging.getBukkitEntity(), who, blockClicked, blockFace);
|
|
|
|
world.getServer().getPluginManager().callEvent(event);
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2012-10-31 04:21:53 +01:00
|
|
|
PaintingPlaceEvent paintingEvent = null;
|
2013-07-01 13:03:00 +02:00
|
|
|
if (entityhanging instanceof EntityPainting) {
|
2012-10-31 04:21:53 +01:00
|
|
|
// 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;
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
world.addEntity(entityhanging);
|
|
|
|
}
|
|
|
|
|
|
|
|
--itemstack.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private EntityHanging a(World world, int i, int j, int k, int l) {
|
|
|
|
return (EntityHanging) (this.a == EntityPainting.class ? new EntityPainting(world, i, j, k, l) : (this.a == EntityItemFrame.class ? new EntityItemFrame(world, i, j, k, l) : null));
|
|
|
|
}
|
|
|
|
}
|