Search in sources :

Example 76 with ListTag

use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemRawNBT method jnbtTagToObject.

public static ObjectTag jnbtTagToObject(Tag tag) {
    if (tag instanceof CompoundTag) {
        MapTag result = new MapTag();
        for (Map.Entry<String, Tag> entry : ((CompoundTag) tag).getValue().entrySet()) {
            result.putObject(entry.getKey(), jnbtTagToObject(entry.getValue()));
        }
        return result;
    } else if (tag instanceof JNBTListTag) {
        ListTag result = new ListTag();
        for (Tag entry : ((JNBTListTag) tag).getValue()) {
            result.addObject(jnbtTagToObject(entry));
        }
        return new ElementTag("list:" + NBTUtils.getTypeCode(((JNBTListTag) tag).getType()) + ":" + result.identify());
    } else if (tag instanceof ByteArrayTag) {
        byte[] data = ((ByteArrayTag) tag).getValue();
        StringBuilder output = new StringBuilder(data.length * 4);
        for (int i = 0; i < data.length; i++) {
            output.append(data[i]).append("|");
        }
        return new ElementTag("byte_array:" + output.toString());
    } else if (tag instanceof IntArrayTag) {
        int[] data = ((IntArrayTag) tag).getValue();
        StringBuilder output = new StringBuilder(data.length * 4);
        for (int i = 0; i < data.length; i++) {
            output.append(data[i]).append("|");
        }
        return new ElementTag("int_array:" + output.toString());
    } else if (tag instanceof ByteTag) {
        return new ElementTag("byte:" + ((ByteTag) tag).getValue());
    } else if (tag instanceof ShortTag) {
        return new ElementTag("short:" + ((ShortTag) tag).getValue());
    } else if (tag instanceof IntTag) {
        return new ElementTag("int:" + ((IntTag) tag).getValue());
    } else if (tag instanceof LongTag) {
        return new ElementTag("long:" + ((LongTag) tag).getValue());
    } else if (tag instanceof FloatTag) {
        return new ElementTag("float:" + ((FloatTag) tag).getValue());
    } else if (tag instanceof DoubleTag) {
        return new ElementTag("double:" + ((DoubleTag) tag).getValue());
    } else if (tag instanceof StringTag) {
        return new ElementTag("string:" + ((StringTag) tag).getValue());
    } else if (tag instanceof EndTag) {
        return new ElementTag("end");
    } else {
        return new ElementTag("unknown:" + tag.getValue());
    }
}
Also used : ListTag(com.denizenscript.denizencore.objects.core.ListTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 77 with ListTag

use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.

the class MaterialDirectional method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <MaterialTag.valid_directions>
    // @returns ListTag
    // @mechanism MaterialTag.direction
    // @group properties
    // @description
    // Returns a list of directions that are valid for a directional material.
    // See also <@link tag MaterialTag.direction>
    // -->
    PropertyParser.<MaterialDirectional, ListTag>registerStaticTag(ListTag.class, "valid_directions", (attribute, material) -> {
        ListTag toReturn = new ListTag();
        if (material.isOrientable()) {
            for (Axis axis : material.getOrientable().getAxes()) {
                toReturn.add(axis.name());
            }
        } else if (material.isRail()) {
            for (Rail.Shape shape : material.getRail().getShapes()) {
                toReturn.add(shape.name());
            }
        } else if (material.isDirectional()) {
            for (BlockFace face : material.getDirectional().getFaces()) {
                toReturn.add(face.name());
            }
        } else if (material.isRotatable()) {
            for (BlockFace face : rotatableValidFaces) {
                toReturn.add(face.name());
            }
        } else if (material.isDripstone()) {
            for (BlockFace face : ((PointedDripstone) material.material.getModernData()).getVerticalDirections()) {
                // TODO: 1.17
                toReturn.add(face.name());
            }
        } else if (material.isJigsaw()) {
            for (Jigsaw.Orientation orientation : Jigsaw.Orientation.values()) {
                toReturn.add(orientation.name());
            }
        } else {
            // Unreachable
            return null;
        }
        return toReturn;
    });
    // <--[tag]
    // @attribute <MaterialTag.direction>
    // @returns ElementTag
    // @mechanism MaterialTag.direction
    // @group properties
    // @description
    // Returns the current facing direction for a directional material (like a door or a bed).
    // This includes materials that Spigot classifies as "directional", "orientable", or "rotatable", as well as rails, dripstone, and jigsaw blocks.
    // Output is a direction name like "NORTH", or an axis like "X", or a rail direction like "ASCENDING_NORTH".
    // -->
    PropertyParser.<MaterialDirectional, ElementTag>registerStaticTag(ElementTag.class, "direction", (attribute, material) -> {
        return new ElementTag(material.getDirectionName());
    });
}
Also used : PointedDripstone(org.bukkit.block.data.type.PointedDripstone) BlockFace(org.bukkit.block.BlockFace) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) Axis(org.bukkit.Axis)

Example 78 with ListTag

use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemSpawnerDelay method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("spawner_delay_data")) {
        ListTag list = mechanism.valueAsType(ListTag.class);
        if (list.size() < 3) {
            return;
        }
        BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
        CreatureSpawner state = (CreatureSpawner) meta.getBlockState();
        state.setDelay(Integer.parseInt(list.get(0)));
        int minDelay = Integer.parseInt(list.get(1));
        int maxDelay = Integer.parseInt(list.get(2));
        // or new min would be higher than the current max
        if (minDelay > state.getMaxSpawnDelay()) {
            state.setMaxSpawnDelay(maxDelay);
            state.setMinSpawnDelay(minDelay);
        } else {
            state.setMinSpawnDelay(minDelay);
            state.setMaxSpawnDelay(maxDelay);
        }
        meta.setBlockState(state);
        item.setItemMeta(meta);
    }
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) ListTag(com.denizenscript.denizencore.objects.core.ListTag) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Example 79 with ListTag

use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.

the class MaterialSides method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if ((mechanism.matches("sides") || mechanism.matches("heights")) && mechanism.requireObject(ListTag.class)) {
        ListTag list = mechanism.valueAsType(ListTag.class);
        if (isWall()) {
            if (list.size() != 5) {
                mechanism.echoError("Invalid sides list, size must be 5.");
                return;
            }
            Wall wall = getWall();
            wall.setHeight(BlockFace.NORTH, Wall.Height.valueOf(list.get(0).toUpperCase()));
            wall.setHeight(BlockFace.EAST, Wall.Height.valueOf(list.get(1).toUpperCase()));
            wall.setHeight(BlockFace.SOUTH, Wall.Height.valueOf(list.get(2).toUpperCase()));
            wall.setHeight(BlockFace.WEST, Wall.Height.valueOf(list.get(3).toUpperCase()));
            wall.setUp(list.get(4).toUpperCase().equals("TALL"));
        } else if (isWire()) {
            if (list.size() != 4) {
                mechanism.echoError("Invalid sides list, size must be 4.");
                return;
            }
            RedstoneWire wire = getWire();
            wire.setFace(BlockFace.NORTH, RedstoneWire.Connection.valueOf(list.get(0).toUpperCase()));
            wire.setFace(BlockFace.EAST, RedstoneWire.Connection.valueOf(list.get(1).toUpperCase()));
            wire.setFace(BlockFace.SOUTH, RedstoneWire.Connection.valueOf(list.get(2).toUpperCase()));
            wire.setFace(BlockFace.WEST, RedstoneWire.Connection.valueOf(list.get(3).toUpperCase()));
        }
    }
}
Also used : RedstoneWire(org.bukkit.block.data.type.RedstoneWire) Wall(org.bukkit.block.data.type.Wall) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 80 with ListTag

use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.

the class MaterialSides method getSidesList.

public ListTag getSidesList() {
    ListTag list = new ListTag(5);
    if (isWall()) {
        Wall wall = getWall();
        list.add(wall.getHeight(BlockFace.NORTH).name());
        list.add(wall.getHeight(BlockFace.EAST).name());
        list.add(wall.getHeight(BlockFace.SOUTH).name());
        list.add(wall.getHeight(BlockFace.WEST).name());
        list.add(wall.isUp() ? "TALL" : "NONE");
    } else if (isWire()) {
        RedstoneWire wire = getWire();
        list.add(wire.getFace(BlockFace.NORTH).name());
        list.add(wire.getFace(BlockFace.EAST).name());
        list.add(wire.getFace(BlockFace.SOUTH).name());
        list.add(wire.getFace(BlockFace.WEST).name());
    }
    return list;
}
Also used : RedstoneWire(org.bukkit.block.data.type.RedstoneWire) Wall(org.bukkit.block.data.type.Wall) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Aggregations

ListTag (com.denizenscript.denizencore.objects.core.ListTag)122 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)71 MapTag (com.denizenscript.denizencore.objects.core.MapTag)21 ItemStack (org.bukkit.inventory.ItemStack)18 EntityTag (com.denizenscript.denizen.objects.EntityTag)16 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)14 List (java.util.List)14 ItemTag (com.denizenscript.denizen.objects.ItemTag)13 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)13 Player (org.bukkit.entity.Player)13 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)12 LocationTag (com.denizenscript.denizen.objects.LocationTag)11 NPCTag (com.denizenscript.denizen.objects.NPCTag)9 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)9 ArrayList (java.util.ArrayList)9 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)8 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)7 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)7 NPC (net.citizensnpcs.api.npc.NPC)7 Entity (org.bukkit.entity.Entity)7