Search in sources :

Example 6 with Art

use of org.bukkit.Art 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)

Aggregations

Art (org.bukkit.Art)6 Painting (org.bukkit.entity.Painting)3 ItemStack (org.bukkit.inventory.ItemStack)3 DyeColor (org.bukkit.DyeColor)2 Location (org.bukkit.Location)2 EntityType (org.bukkit.entity.EntityType)2 Horse (org.bukkit.entity.Horse)2 ItemFrame (org.bukkit.entity.ItemFrame)2 Ocelot (org.bukkit.entity.Ocelot)2 Sheep (org.bukkit.entity.Sheep)2 Villager (org.bukkit.entity.Villager)2 Wolf (org.bukkit.entity.Wolf)2 MapView (org.bukkit.map.MapView)2 MaterialAndData (com.elmakers.mine.bukkit.api.block.MaterialAndData)1 EntityData (com.elmakers.mine.bukkit.api.entity.EntityData)1 Mage (com.elmakers.mine.bukkit.api.magic.Mage)1 HashMap (java.util.HashMap)1 ChangeResultImpl (me.botsko.prism.appliers.ChangeResultImpl)1 Key (net.glowstone.chunk.GlowChunk.Key)1 GlowPainting (net.glowstone.entity.objects.GlowPainting)1