Search in sources :

Example 6 with Painting

use of org.bukkit.entity.Painting in project RedProtect by FabioZumbi12.

the class RPBlockListener method onFrameBrake.

@EventHandler
public void onFrameBrake(HangingBreakEvent e) {
    RedProtect.get().logger.debug("Is BlockListener - HangingBreakEvent event");
    if (e.isCancelled()) {
        return;
    }
    Entity ent = e.getEntity();
    Location l = e.getEntity().getLocation();
    if ((ent instanceof ItemFrame || ent instanceof Painting) && (e.getCause().toString().equals("EXPLOSION"))) {
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canFire()) {
            e.setCancelled(true);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) ItemFrame(org.bukkit.entity.ItemFrame) Location(org.bukkit.Location) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Example 7 with Painting

use of org.bukkit.entity.Painting in project modules-extra by CubeEngine.

the class ListenerHanging method onHangingBreak.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
    if (event.getCause() == HangingBreakEvent.RemoveCause.PHYSICS) {
        Hanging hanging = event.getEntity();
        Location location = hanging.getLocation();
        BaseAction cause = this.plannedHangingBreak.get(location);
        if (cause != null) {
            if (cause instanceof ActionPlayerBlock) {
                HangingBreak action;
                if (hanging instanceof ItemFrame) {
                    action = this.newAction(ItemframeBreak.class, location.getWorld());
                    ItemStack item = ((ItemFrame) hanging).getItem();
                    if (action != null && item != null) {
                        ((ItemframeBreak) action).item = item;
                    }
                } else if (hanging instanceof Painting) {
                    action = this.newAction(PaintingBreak.class, location.getWorld());
                    ((PaintingBreak) action).art = ((Painting) hanging).getArt();
                } else {
                    action = this.newAction(HangingBreak.class, location.getWorld());
                }
                if (action != null) {
                    action.setLocation(location);
                    action.setHanging(hanging);
                    action.player = ((ActionPlayerBlock) cause).player;
                    action.setCause(cause);
                    this.logAction(action);
                }
            }
        // else // TODO
        }
    // else TODO this.module.getLog().info("Unexpected HangingBreakEvent");
    }
}
Also used : ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock) Hanging(org.bukkit.entity.Hanging) BaseAction(org.cubeengine.module.log.action.BaseAction) ItemFrame(org.bukkit.entity.ItemFrame) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Location(org.spongepowered.api.world.Location) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Example 8 with Painting

use of org.bukkit.entity.Painting in project modules-extra by CubeEngine.

the class ListenerHanging method onHangingBreakByEntity.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {
    Entity causer;
    if (event.getRemover() instanceof Projectile) {
        ProjectileSource shooter = ((Projectile) event.getRemover()).getShooter();
        if (shooter instanceof Entity) {
            causer = (Entity) shooter;
        } else {
            // TODO other ProjectileSources
            return;
        }
    } else {
        causer = event.getRemover();
    }
    Hanging hanging = event.getEntity();
    Location location = hanging.getLocation();
    if (causer instanceof Player) {
        HangingBreak action;
        if (hanging instanceof ItemFrame) {
            action = this.newAction(ItemframeBreak.class, location.getWorld());
            ItemStack item = ((ItemFrame) hanging).getItem();
            if (action != null && item != null) {
                ((ItemframeBreak) action).item = item;
            }
        } else if (hanging instanceof Painting) {
            action = this.newAction(PaintingBreak.class, location.getWorld());
            if (action != null) {
                ((PaintingBreak) action).art = ((Painting) hanging).getArt();
            }
        } else {
            action = this.newAction(HangingBreak.class, location.getWorld());
        }
        if (action != null) {
            action.setLocation(location);
            action.setHanging(hanging);
            action.setPlayer((Player) causer);
            this.logAction(action);
        }
    } else {
    // TODO
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.player.Player) Hanging(org.bukkit.entity.Hanging) ProjectileSource(org.bukkit.projectiles.ProjectileSource) ItemFrame(org.bukkit.entity.ItemFrame) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Projectile(org.bukkit.entity.Projectile) Location(org.spongepowered.api.world.Location) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Example 9 with Painting

use of org.bukkit.entity.Painting in project MagicPlugin by elBukkit.

the class EntityData method modifyPreSpawn.

private boolean modifyPreSpawn(MageController controller, Entity entity) {
    if (entity == null || entity.getType() != type)
        return false;
    boolean isPlayer = (entity instanceof Player);
    if (extraData != null) {
        extraData.apply(entity);
    }
    CompatibilityUtils.setSilent(entity, isSilent);
    entity.setFireTicks(fireTicks);
    if (entity instanceof Ageable) {
        Ageable ageable = (Ageable) entity;
        if (isBaby) {
            ageable.setBaby();
        } else {
            ageable.setAdult();
        }
    }
    if (entity instanceof Tameable) {
        ((Tameable) entity).setTamed(isTamed);
    }
    if (entity instanceof Colorable && dyeColor != null) {
        Colorable colorable = (Colorable) entity;
        colorable.setColor(dyeColor);
    }
    if (tags != null && !tags.isEmpty()) {
        Set<String> entityTags = CompatibilityUtils.getTags(entity);
        entityTags.addAll(tags);
    }
    if (entity instanceof Creature) {
        Creature creature = (Creature) entity;
        creature.setCanPickupItems(canPickupItems);
    }
    if (entity instanceof Painting) {
        Painting painting = (Painting) entity;
        if (art != null) {
            painting.setArt(art, true);
        }
        if (facing != null) {
            painting.setFacingDirection(facing, true);
        }
    } else if (entity instanceof ItemFrame) {
        ItemFrame itemFrame = (ItemFrame) entity;
        itemFrame.setItem(item);
        if (facing != null) {
            itemFrame.setFacingDirection(facing, true);
        }
    } else if (entity instanceof Item) {
        Item droppedItem = (Item) entity;
        droppedItem.setItemStack(item);
    } else if (entity instanceof Wolf && dyeColor != null) {
        Wolf wolf = (Wolf) entity;
        wolf.setCollarColor(dyeColor);
    } else if (entity instanceof Ocelot && ocelotType != null) {
        Ocelot ocelot = (Ocelot) entity;
        ocelot.setCatType(ocelotType);
    } else if (entity instanceof Rabbit && rabbitType != null) {
        Rabbit rabbit = (Rabbit) entity;
        rabbit.setRabbitType(rabbitType);
    } else if (entity instanceof ExperienceOrb && xp != null) {
        ((ExperienceOrb) entity).setExperience(xp);
    }
    if (entity instanceof LivingEntity) {
        LivingEntity li = (LivingEntity) entity;
        if (hasPotionEffects) {
            Collection<PotionEffect> currentEffects = li.getActivePotionEffects();
            for (PotionEffect effect : currentEffects) {
                li.removePotionEffect(effect.getType());
            }
            if (potionEffects != null) {
                for (PotionEffect effect : potionEffects) {
                    li.addPotionEffect(effect);
                }
            }
        }
        try {
            if (!isPlayer) {
                applyAttributes(li);
                copyEquipmentTo(li);
                if (maxHealth != null) {
                    li.setMaxHealth(maxHealth);
                }
            }
            if (health != null) {
                li.setHealth(Math.min(health, li.getMaxHealth()));
            }
            if (airLevel != null) {
                li.setRemainingAir(Math.min(airLevel, li.getRemainingAir()));
            }
            if (!hasAI) {
                li.setAI(hasAI);
            }
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
    }
    if (!isPlayer && name != null && name.length() > 0) {
        entity.setCustomName(name);
    }
    boolean needsMage = controller != null && mageData != null;
    if (needsMage) {
        Mage apiMage = controller.getMage(entity);
        if (apiMage instanceof com.elmakers.mine.bukkit.magic.Mage) {
            ((com.elmakers.mine.bukkit.magic.Mage) apiMage).setEntityData(this);
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) Tameable(org.bukkit.entity.Tameable) Creature(org.bukkit.entity.Creature) PotionEffect(org.bukkit.potion.PotionEffect) Rabbit(org.bukkit.entity.Rabbit) ExperienceOrb(org.bukkit.entity.ExperienceOrb) ItemFrame(org.bukkit.entity.ItemFrame) Ageable(org.bukkit.entity.Ageable) Painting(org.bukkit.entity.Painting) LivingEntity(org.bukkit.entity.LivingEntity) Item(org.bukkit.entity.Item) Ocelot(org.bukkit.entity.Ocelot) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Colorable(org.bukkit.material.Colorable) Wolf(org.bukkit.entity.Wolf)

Example 10 with Painting

use of org.bukkit.entity.Painting in project MagicPlugin by elBukkit.

the class AlterSpell method alterEntity.

protected SpellResult alterEntity(Entity entity) {
    EntityType entityType = entity.getType();
    switch(entityType) {
        case PAINTING:
            registerModified(entity);
            Painting painting = (Painting) entity;
            Art[] artValues = Art.values();
            Art oldArt = painting.getArt();
            Art newArt = oldArt;
            int ordinal = (oldArt.ordinal() + 1);
            for (int i = 0; i < artValues.length; i++) {
                newArt = artValues[ordinal++ % artValues.length];
                painting.setArt(newArt);
                newArt = painting.getArt();
                if (oldArt != newArt) {
                    break;
                }
            }
            if (oldArt == newArt) {
                return SpellResult.FAIL;
            }
            mage.sendDebugMessage("Altering art from " + oldArt + " to " + newArt);
            break;
        case ITEM_FRAME:
            ItemFrame itemFrame = (ItemFrame) entity;
            ItemStack frameItem = itemFrame.getItem();
            if (frameItem == null || frameItem.getType() != Material.MAP) {
                return SpellResult.NO_TARGET;
            }
            short data = frameItem.getDurability();
            data++;
            MapView mapView = DeprecatedUtils.getMap(data);
            if (mapView == null) {
                data = 0;
                mapView = DeprecatedUtils.getMap(data);
                if (mapView == null) {
                    return SpellResult.NO_TARGET;
                }
            }
            registerModified(entity);
            frameItem.setDurability(data);
            itemFrame.setItem(frameItem);
            break;
        case HORSE:
            registerModified(entity);
            Horse horse = (Horse) entity;
            Color color = horse.getColor();
            Color[] colorValues = Color.values();
            color = colorValues[(color.ordinal() + 1) % colorValues.length];
            Style horseStyle = horse.getStyle();
            Style[] styleValues = Style.values();
            horseStyle = styleValues[(horseStyle.ordinal() + 1) % styleValues.length];
            horse.setStyle(horseStyle);
            horse.setColor(color);
            break;
        case OCELOT:
            registerModified(entity);
            Ocelot ocelot = (Ocelot) entity;
            Type catType = ocelot.getCatType();
            Type[] typeValues = Type.values();
            catType = typeValues[(catType.ordinal() + 1) % typeValues.length];
            ocelot.setCatType(catType);
            break;
        case VILLAGER:
            registerModified(entity);
            Villager villager = (Villager) entity;
            Profession profession = villager.getProfession();
            Profession[] professionValues = Profession.values();
            profession = professionValues[(profession.ordinal() + 1) % professionValues.length];
            villager.setProfession(profession);
            break;
        case WOLF:
            registerModified(entity);
            Wolf wolf = (Wolf) entity;
            DyeColor wolfColor = wolf.getCollarColor();
            DyeColor[] wolfColorValues = DyeColor.values();
            wolfColor = wolfColorValues[(wolfColor.ordinal() + 1) % wolfColorValues.length];
            wolf.setCollarColor(wolfColor);
            break;
        case SHEEP:
            registerModified(entity);
            Sheep sheep = (Sheep) entity;
            DyeColor dyeColor = sheep.getColor();
            DyeColor[] dyeColorValues = DyeColor.values();
            dyeColor = dyeColorValues[(dyeColor.ordinal() + 1) % dyeColorValues.length];
            sheep.setColor(dyeColor);
            break;
        case SKELETON:
            registerModified(entity);
            Skeleton skeleton = (Skeleton) entity;
            SkeletonType skeletonType = skeleton.getSkeletonType();
            SkeletonType[] skeletonTypeValues = SkeletonType.values();
            skeletonType = skeletonTypeValues[(skeletonType.ordinal() + 1) % skeletonTypeValues.length];
            skeleton.setSkeletonType(skeletonType);
            break;
        default:
            return SpellResult.NO_TARGET;
    }
    ;
    registerForUndo();
    return SpellResult.CAST;
}
Also used : Art(org.bukkit.Art) ItemFrame(org.bukkit.entity.ItemFrame) SkeletonType(org.bukkit.entity.Skeleton.SkeletonType) Horse(org.bukkit.entity.Horse) Villager(org.bukkit.entity.Villager) MapView(org.bukkit.map.MapView) Style(org.bukkit.entity.Horse.Style) Skeleton(org.bukkit.entity.Skeleton) Wolf(org.bukkit.entity.Wolf) Color(org.bukkit.entity.Horse.Color) DyeColor(org.bukkit.DyeColor) DyeColor(org.bukkit.DyeColor) Painting(org.bukkit.entity.Painting) EntityType(org.bukkit.entity.EntityType) Ocelot(org.bukkit.entity.Ocelot) SkeletonType(org.bukkit.entity.Skeleton.SkeletonType) Type(org.bukkit.entity.Ocelot.Type) EntityType(org.bukkit.entity.EntityType) Profession(org.bukkit.entity.Villager.Profession) Sheep(org.bukkit.entity.Sheep) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

Painting (org.bukkit.entity.Painting)14 ItemFrame (org.bukkit.entity.ItemFrame)11 Entity (org.bukkit.entity.Entity)8 Location (org.bukkit.Location)7 LivingEntity (org.bukkit.entity.LivingEntity)7 EventHandler (org.bukkit.event.EventHandler)6 Ocelot (org.bukkit.entity.Ocelot)5 Wolf (org.bukkit.entity.Wolf)5 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)4 DyeColor (org.bukkit.DyeColor)4 EntityType (org.bukkit.entity.EntityType)4 Hanging (org.bukkit.entity.Hanging)4 Horse (org.bukkit.entity.Horse)4 Sheep (org.bukkit.entity.Sheep)4 Villager (org.bukkit.entity.Villager)4 ItemStack (org.bukkit.inventory.ItemStack)4 Art (org.bukkit.Art)3 Rabbit (org.bukkit.entity.Rabbit)3 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 Material (org.bukkit.Material)2