use of org.bukkit.entity.Hanging in project modules-extra by CubeEngine.
the class ListenerHanging method onHangingPlace.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingPlace(HangingPlaceEvent event) {
Hanging hanging = event.getEntity();
HangingPlace action;
if (hanging instanceof Painting) {
action = this.newAction(PaintingPlace.class, hanging.getWorld());
if (action != null) {
((PaintingPlace) action).art = ((Painting) hanging).getArt();
}
} else {
action = this.newAction(HangingPlace.class, hanging.getWorld());
}
if (action != null) {
action.setLocation(hanging.getLocation());
action.setHanging(hanging);
action.setPlayer(event.getPlayer());
this.logAction(action);
}
}
use of org.bukkit.entity.Hanging in project modules-extra by CubeEngine.
the class ListenerBlock method logAttachedBlocks.
public static void logAttachedBlocks(LogListener ll, EventManager em, Block block, ActionBlock action) {
if (!block.getType().isSolid() && !(block.getType() == SUGAR_CANE_BLOCK)) {
// cannot have attached
return;
}
for (Block aBlock : BlockUtil.getAttachedBlocks(block)) {
em.fireEvent(new BlockPreBreakEvent(aBlock.getLocation(), action));
}
for (Block dBlock : BlockUtil.getDetachableBlocksOnTop(block)) {
if (// ignore upper door halfs
isNotUpperDoorHalf(dBlock)) {
em.fireEvent(new BlockPreBreakEvent(dBlock.getLocation(), action));
}
}
if (ll.isActive(HangingBreak.class, block.getWorld())) {
Location location = block.getLocation();
Location entityLocation = block.getLocation();
for (Entity entity : block.getChunk().getEntities()) {
if (entity instanceof Hanging && location.distanceSquared(entity.getLocation(entityLocation)) < 4) {
em.fireEvent(new HangingPreBreakEvent(entityLocation, action));
}
}
}
}
use of org.bukkit.entity.Hanging in project Prism-Bukkit by prism.
the class HangingItemAction method hangItem.
/**
* Get A change result.
* @param player Player
* @param parameters Query params
* @param isPreview is preview.
* @return ChangeResult
* @todo I am not sure this actual is used during preview?? also no rollback info is saved to undo this.
*/
private ChangeResult hangItem(Player player, PrismParameters parameters, boolean isPreview) {
if (actionData == null) {
Prism.debug(parameters.getProcessType() + "Skipped - Hanging action data was null");
return new ChangeResultImpl(ChangeResultType.SKIPPED, null);
}
final BlockFace attachedFace = getDirection();
final Location loc = getLoc().getBlock().getRelative(getDirection()).getLocation();
// Ensure there's a block at this location that accepts an attachment
if (Utilities.materialMeansBlockDetachment(loc.getBlock().getType())) {
Prism.debug(parameters.getProcessType() + "Hanging Skipped - block would detach: " + loc.getBlock().getType());
return new ChangeResultImpl(ChangeResultType.SKIPPED, null);
}
try {
if (getHangingType().equals("item_frame")) {
final Hanging hangingItem = getWorld().spawn(loc, ItemFrame.class);
hangingItem.setFacingDirection(attachedFace, true);
// no change recorded
return new ChangeResultImpl(ChangeResultType.APPLIED, null);
} else if (getHangingType().equals("painting")) {
final Painting hangingItem = getWorld().spawn(loc, Painting.class);
hangingItem.setFacingDirection(getDirection(), true);
Art art = Art.getByName(getArt());
if (art != null) {
hangingItem.setArt(art);
}
// no change recorded
return new ChangeResultImpl(ChangeResultType.APPLIED, null);
}
} catch (final IllegalArgumentException e) {
// Something interfered with being able to place the painting
}
return new ChangeResultImpl(ChangeResultType.SKIPPED, null);
}
use of org.bukkit.entity.Hanging in project Prism-Bukkit by prism.
the class PrismEntityEvents method onHangingBreakEvent.
/**
* Hanging items broken by a player fall under the HangingBreakByEntityEvent
* events. This is merely here to capture cause = physics for when they detach
* from a block.
*
* @param event HangingBreakEvent
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreakEvent(final HangingBreakEvent event) {
// Ignore other causes. Entity cause already handled.
if (!event.getCause().equals(RemoveCause.PHYSICS)) {
return;
}
if (!Prism.getIgnore().event("hangingitem-break", event.getEntity().getWorld())) {
return;
}
final Hanging e = event.getEntity();
// Check for planned hanging item breaks
final String coord_key = e.getLocation().getBlockX() + ":" + e.getLocation().getBlockY() + ":" + e.getLocation().getBlockZ();
String value = plugin.preplannedBlockFalls.remove(coord_key);
if (value == null) {
value = "unknown";
}
Player player = null;
try {
player = Bukkit.getPlayer(UUID.fromString(value));
} catch (Exception ignored) {
// ignored.
}
// Track the hanging item break
if (player != null) {
RecordingQueue.addToQueue(ActionFactory.createHangingItem("hangingitem-break", e, player));
} else {
RecordingQueue.addToQueue(ActionFactory.createHangingItem("hangingitem-break", e, value));
}
plugin.preplannedBlockFalls.remove(coord_key);
if (!Prism.getIgnore().event("item-remove", event.getEntity().getWorld())) {
return;
}
// If an item frame, track it's contents
if (e instanceof ItemFrame) {
final ItemFrame frame = (ItemFrame) e;
if (!checkNotNullorAir(frame.getItem())) {
if (player != null) {
RecordingQueue.addToQueue(ActionFactory.createItemStack("item-remove", frame.getItem(), frame.getItem().getAmount(), -1, null, e.getLocation(), player));
} else {
RecordingQueue.addToQueue(ActionFactory.createItemStack("item-remove", frame.getItem(), frame.getItem().getAmount(), -1, null, e.getLocation(), value));
}
}
}
}
Aggregations