Search in sources :

Example 1 with Painting

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

the class CycleEntityAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity entity = context.getTargetEntity();
    EntityType entityType = entity.getType();
    Mage mage = context.getMage();
    switch(entityType) {
        case PAINTING:
            context.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;
                }
            }
            context.registerModified(entity);
            frameItem.setDurability(data);
            itemFrame.setItem(frameItem);
            break;
        case HORSE:
            context.registerModified(entity);
            Horse horse = (Horse) entity;
            Horse.Color color = horse.getColor();
            Horse.Color[] colorValues = Horse.Color.values();
            color = colorValues[(color.ordinal() + 1) % colorValues.length];
            Horse.Style horseStyle = horse.getStyle();
            Horse.Style[] styleValues = Horse.Style.values();
            horseStyle = styleValues[(horseStyle.ordinal() + 1) % styleValues.length];
            horse.setStyle(horseStyle);
            horse.setColor(color);
            break;
        case OCELOT:
            context.registerModified(entity);
            Ocelot ocelot = (Ocelot) entity;
            Ocelot.Type catType = ocelot.getCatType();
            Ocelot.Type[] typeValues = Ocelot.Type.values();
            catType = typeValues[(catType.ordinal() + 1) % typeValues.length];
            ocelot.setCatType(catType);
            break;
        case VILLAGER:
            context.registerModified(entity);
            Villager villager = (Villager) entity;
            Villager.Profession profession = villager.getProfession();
            Villager.Profession[] professionValues = Villager.Profession.values();
            int villagerOrdinal = (profession.ordinal() + 1) % professionValues.length;
            // Special-cases for zombie-reserved professions
            if (villagerOrdinal == 0 || villagerOrdinal == 7) {
                villagerOrdinal = 1;
            }
            profession = professionValues[villagerOrdinal];
            villager.setProfession(profession);
            break;
        case WOLF:
            context.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:
            context.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;
        default:
            return SpellResult.NO_TARGET;
    }
    ;
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) Art(org.bukkit.Art) ItemFrame(org.bukkit.entity.ItemFrame) Horse(org.bukkit.entity.Horse) Villager(org.bukkit.entity.Villager) MapView(org.bukkit.map.MapView) Wolf(org.bukkit.entity.Wolf) DyeColor(org.bukkit.DyeColor) DyeColor(org.bukkit.DyeColor) Painting(org.bukkit.entity.Painting) EntityType(org.bukkit.entity.EntityType) Ocelot(org.bukkit.entity.Ocelot) EntityType(org.bukkit.entity.EntityType) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Sheep(org.bukkit.entity.Sheep) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with Painting

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

the class CompatibilityUtils method createPainting.

public static Painting createPainting(Location location, BlockFace facing, Art art) {
    Painting newPainting = null;
    try {
        location = getPaintingOffset(location, facing, art);
        Object worldHandle = getHandle(location.getWorld());
        Object newEntity = null;
        @SuppressWarnings("unchecked") Enum<?> directionEnum = Enum.valueOf(class_EnumDirection, facing.name());
        Object blockLocation = class_BlockPosition_Constructor.newInstance(location.getX(), location.getY(), location.getZ());
        newEntity = class_EntityPaintingConstructor.newInstance(worldHandle, blockLocation, directionEnum);
        if (newEntity != null) {
            Entity bukkitEntity = getBukkitEntity(newEntity);
            if (bukkitEntity == null || !(bukkitEntity instanceof Painting))
                return null;
            newPainting = (Painting) bukkitEntity;
            newPainting.setFacingDirection(facing, true);
            newPainting.setArt(art, true);
        }
    } catch (Throwable ex) {
        ex.printStackTrace();
        newPainting = null;
    }
    return newPainting;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) Painting(org.bukkit.entity.Painting)

Example 3 with Painting

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

the class RPGlobalListener method onPlayerInteract.

@EventHandler
public void onPlayerInteract(PlayerInteractEntityEvent e) {
    if (e.isCancelled()) {
        return;
    }
    Player p = e.getPlayer();
    Entity ent = e.getRightClicked();
    Location l = ent.getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r != null) {
        return;
    }
    if (ent instanceof ItemFrame || ent instanceof Painting) {
        if (!bypassBuild(p, null, 0)) {
            e.setCancelled(true);
            return;
        }
    }
    if (ent instanceof Minecart || ent instanceof Boat) {
        if (!RPConfig.getGlobalFlagBool(l.getWorld().getName() + ".use-minecart") && !p.hasPermission("redprotect.bypass.world")) {
            e.setCancelled(true);
            return;
        }
    }
    if (!RPConfig.getGlobalFlagBool(l.getWorld().getName() + ".interact") && !p.hasPermission("redprotect.bypass.world") && (!(ent instanceof Player))) {
        if (RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-interact-false.allow-entities").contains(ent.getType().name())) {
            return;
        }
        e.setCancelled(true);
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Minecart(org.bukkit.entity.Minecart) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) ItemFrame(org.bukkit.entity.ItemFrame) Location(org.bukkit.Location) Painting(org.bukkit.entity.Painting) Boat(org.bukkit.entity.Boat) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Painting

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

the class RPPlayerListener method onPlayerInteract.

@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEntityEvent event) {
    Entity e = event.getRightClicked();
    Player p = event.getPlayer();
    if (e == null) {
        return;
    }
    RedProtect.get().logger.debug("RPPlayerListener - Is PlayerInteractEntityEvent event: " + e.getType().name());
    Location l = e.getLocation();
    if (e instanceof ItemFrame || e instanceof Painting) {
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canBuild(p)) {
            RPLang.sendMessage(p, "playerlistener.region.cantedit");
            event.setCancelled(true);
        }
    } else if ((e instanceof Minecart || e instanceof Boat)) {
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canMinecart(p)) {
            RPLang.sendMessage(p, "blocklistener.region.cantenter");
            event.setCancelled(true);
        }
    } else if (RedProtect.get().MyPet && e instanceof MyPetBukkitEntity) {
        if (((MyPetBukkitEntity) e).getOwner().getPlayer().equals(p)) {
        }
    } else if (!RPUtil.isBukkitEntity(e) && (!(event.getRightClicked() instanceof Player))) {
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.allowMod(p)) {
            RedProtect.get().logger.debug("PlayerInteractEntityEvent - Block is " + event.getRightClicked().getType().name());
            RPLang.sendMessage(p, "playerlistener.region.cantinteract");
            event.setCancelled(true);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) MyPetBukkitEntity(de.Keyle.MyPet.api.entity.MyPetBukkitEntity) Player(org.bukkit.entity.Player) PvPlayer(me.NoChance.PvPManager.PvPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) Minecart(org.bukkit.entity.Minecart) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) ItemFrame(org.bukkit.entity.ItemFrame) MyPetBukkitEntity(de.Keyle.MyPet.api.entity.MyPetBukkitEntity) Location(org.bukkit.Location) Painting(org.bukkit.entity.Painting) Boat(org.bukkit.entity.Boat) EventHandler(org.bukkit.event.EventHandler)

Example 5 with Painting

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

the class RPBlockListener method onFrameBrake.

@EventHandler
public void onFrameBrake(HangingBreakByEntityEvent e) {
    RedProtect.get().logger.debug("Is BlockListener - HangingBreakByEntityEvent event");
    if (e.isCancelled()) {
        return;
    }
    Entity remover = e.getRemover();
    Entity ent = e.getEntity();
    Location l = e.getEntity().getLocation();
    if ((ent instanceof ItemFrame || ent instanceof Painting) && remover instanceof Monster) {
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canMobLoot()) {
            e.setCancelled(true);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Monster(org.bukkit.entity.Monster) 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)

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