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());
}
}
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());
});
}
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);
}
}
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()));
}
}
}
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;
}
Aggregations