Search in sources :

Example 1 with Art

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

use of org.bukkit.Art in project MagicPlugin by elBukkit.

the class Schematic method load.

@SuppressWarnings("deprecation")
public void load(short width, short height, short length, short[] blockTypes, byte[] data, Collection<Object> tileEntityData, Collection<Object> entityData, Vector origin, Vector offset) {
    size = new Vector(width, height, length);
    center = new Vector(Math.floor(size.getBlockX() / 2), 0, Math.floor(size.getBlockZ() / 2));
    blocks = new MaterialAndData[width][height][length];
    entities = new ArrayList<>();
    // Load entities
    for (Object entity : entityData) {
        String type = NMSUtils.getMetaString(entity, "id");
        Vector position = NMSUtils.getPosition(entity, "Pos");
        if (position == null)
            continue;
        position = position.subtract(origin).subtract(center);
        if (type == null)
            continue;
        // Only doing paintings and item frames for now.
        if (type.equals("Painting")) {
            String motive = NMSUtils.getMetaString(entity, "Motive");
            motive = motive.toLowerCase();
            Art art = Art.ALBAN;
            for (Art test : Art.values()) {
                if (test.name().toLowerCase().replace("_", "").equals(motive)) {
                    art = test;
                    break;
                }
            }
            byte facing = NMSUtils.getMetaByte(entity, "Facing");
            EntityData painting = com.elmakers.mine.bukkit.entity.EntityData.loadPainting(position, art, getFacing(facing));
            entities.add(painting);
        } else if (type.equals("ItemFrame")) {
            byte facing = NMSUtils.getMetaByte(entity, "Facing");
            byte rotation = NMSUtils.getMetaByte(entity, "ItemRotation");
            Rotation rot = Rotation.NONE;
            if (rotation < Rotation.values().length) {
                rot = Rotation.values()[rotation];
            }
            ItemStack item = NMSUtils.getItem(NMSUtils.getNode(entity, "Item"));
            EntityData itemFrame = com.elmakers.mine.bukkit.entity.EntityData.loadItemFrame(position, item, getFacing(facing), rot);
            entities.add(itemFrame);
        }
    }
    // Map tile entity data
    Map<BlockVector, Object> tileEntityMap = new HashMap<>();
    for (Object tileEntity : tileEntityData) {
        try {
            Integer x = NMSUtils.getMetaInt(tileEntity, "x");
            Integer y = NMSUtils.getMetaInt(tileEntity, "y");
            Integer z = NMSUtils.getMetaInt(tileEntity, "z");
            if (x == null || y == null || z == null)
                continue;
            BlockVector location = new BlockVector(x, y, z);
            tileEntityMap.put(location, tileEntity);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    for (int y = 0; y < height; y++) {
        for (int z = 0; z < length; z++) {
            for (int x = 0; x < width; x++) {
                int index = x + (y * length + z) * width;
                Material material = null;
                try {
                    material = Material.getMaterial(blockTypes[index]);
                } catch (Exception ex) {
                    material = null;
                    ex.printStackTrace();
                }
                if (material != null) {
                    MaterialAndData block = new com.elmakers.mine.bukkit.block.MaterialAndData(material, data[index]);
                    // Check for tile entity data
                    BlockVector blockLocation = new BlockVector(x, y, z);
                    Object tileEntity = tileEntityMap.get(blockLocation);
                    if (tileEntity != null) {
                        try {
                            if (material == Material.COMMAND) {
                                String customName = NMSUtils.getMetaString(tileEntity, "CustomName");
                                if (!customName.isEmpty()) {
                                    block.setCustomName(customName);
                                }
                                block.setCommandLine(NMSUtils.getMetaString(tileEntity, "Command"));
                            } else {
                                block.setRawData(tileEntity);
                            }
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                    blocks[x][y][z] = block;
                }
            }
        }
    }
    loaded = true;
}
Also used : Art(org.bukkit.Art) HashMap(java.util.HashMap) EntityData(com.elmakers.mine.bukkit.api.entity.EntityData) Material(org.bukkit.Material) Rotation(org.bukkit.Rotation) MaterialAndData(com.elmakers.mine.bukkit.api.block.MaterialAndData) BlockVector(org.bukkit.util.BlockVector) ItemStack(org.bukkit.inventory.ItemStack) BlockVector(org.bukkit.util.BlockVector) Vector(org.bukkit.util.Vector)

Example 3 with Art

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

Example 4 with Art

use of org.bukkit.Art in project Glowstone by GlowstoneMC.

the class ItemPainting method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc, EquipmentSlot hand) {
    Location center = target.getRelative(face).getLocation();
    GlowPainting painting = new GlowPainting(center, face);
    for (Key key : ART_BY_SIZE.keySet()) {
        List<Art> arts = ART_BY_SIZE.get(key);
        painting.setArtInternal(arts.get(0));
        if (!painting.isObstructed()) {
            int i = ThreadLocalRandom.current().nextInt(0, arts.size());
            painting.setArtInternal(arts.get(i));
            return;
        }
    }
    player.playSound(center, Sound.ENTITY_PAINTING_PLACE, SoundCategory.NEUTRAL, 1.0f, 1.0f);
}
Also used : GlowPainting(net.glowstone.entity.objects.GlowPainting) Art(org.bukkit.Art) Key(net.glowstone.chunk.GlowChunk.Key) Location(org.bukkit.Location)

Example 5 with Art

use of org.bukkit.Art in project Glowstone by GlowstoneMC.

the class GlowPainting method setArt.

@Override
public boolean setArt(@NotNull Art art, boolean force) {
    Art oldArt = this.art;
    setArtInternal(art);
    if (!force && isObstructed()) {
        setArtInternal(oldArt);
        return false;
    }
    EntityUtils.refresh(this);
    return true;
}
Also used : Art(org.bukkit.Art)

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