Search in sources :

Example 16 with Hanging

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);
    }
}
Also used : Hanging(org.bukkit.entity.Hanging) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Example 17 with Hanging

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));
            }
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Hanging(org.bukkit.entity.Hanging) Block(org.bukkit.block.Block) ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock) HangingPreBreakEvent(org.cubeengine.module.log.action.hanging.HangingPreBreakEvent) Location(org.spongepowered.api.world.Location)

Example 18 with Hanging

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);
}
Also used : Art(org.bukkit.Art) Hanging(org.bukkit.entity.Hanging) BlockFace(org.bukkit.block.BlockFace) ChangeResultImpl(me.botsko.prism.appliers.ChangeResultImpl) Location(org.bukkit.Location) Painting(org.bukkit.entity.Painting)

Example 19 with Hanging

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));
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Hanging(org.bukkit.entity.Hanging) ItemFrame(org.bukkit.entity.ItemFrame) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Hanging (org.bukkit.entity.Hanging)19 EventHandler (org.bukkit.event.EventHandler)11 Entity (org.bukkit.entity.Entity)9 Location (org.bukkit.Location)8 Player (org.bukkit.entity.Player)8 LivingEntity (org.bukkit.entity.LivingEntity)7 Projectile (org.bukkit.entity.Projectile)7 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)5 Painting (org.bukkit.entity.Painting)4 BlockFace (org.bukkit.block.BlockFace)3 Animals (org.bukkit.entity.Animals)3 Minecart (org.bukkit.entity.Minecart)3 Monster (org.bukkit.entity.Monster)3 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)2 Block (org.bukkit.block.Block)2 ArmorStand (org.bukkit.entity.ArmorStand)2 Boat (org.bukkit.entity.Boat)2 EnderCrystal (org.bukkit.entity.EnderCrystal)2 Golem (org.bukkit.entity.Golem)2 ItemFrame (org.bukkit.entity.ItemFrame)2