Skip to content

MaterialTag.sides,snowable,switchable Property Modernization #2661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,80 @@

import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.*;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.RedstoneWire;
import org.bukkit.block.data.type.Wall;

public class MaterialSides implements Property {
public class MaterialSides extends MaterialProperty<ListTag> {

// <--[property]
// @object MaterialTag
// @name sides
// @input ListTag
// @description
// Controls the list of heights for a wall block, or connections for a redstone wire, in order North|East|South|West|Vertical.
// For wall blocks: For n/e/s/w, can be "tall", "low", or "none". For vertical, can be "tall" or "none".
// For redstone wires: For n/e/s/w, can be "none", "side", or "up". No vertical.
// -->

public static boolean describes(MaterialTag material) {
BlockData data = material.getModernData();
return data instanceof Wall || data instanceof RedstoneWire;
}

public static boolean describes(ObjectTag material) {
if (!(material instanceof MaterialTag)) {
return false;
}
MaterialTag mat = (MaterialTag) material;
if (!mat.hasModernData()) {
return false;
}
BlockData data = mat.getModernData();
if (!(data instanceof Wall) && !(data instanceof RedstoneWire)) {
return false;
}
return true;
@Override
public ListTag getPropertyValue() {
return getSidesList();
}

public static MaterialSides getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialSides((MaterialTag) _material);
}
@Override
public String getPropertyId() {
return "sides";
}

public static final String[] handledMechs = new String[] {
"sides", "heights"
};
@Override
public void setPropertyValue(ListTag list, Mechanism mechanism) {

public MaterialSides(MaterialTag _material) {
material = _material;
// <--[mechanism]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this deprecated mech meta is free-floating in a random spot, and the mech isn't registered?

// @object MaterialTag
// @name heights
// @input ElementTag
// @deprecated Use 'sides'
// @description
// Deprecated in favor of <@link property MaterialTag.sides>
// @tags
// <MaterialTag.heights>
// -->
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(CoreUtilities.toLowerCase(list.get(4)).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()));
}
}

MaterialTag material;

public static void register() {
autoRegister("sides", MaterialSides.class, ListTag.class, true, "heights");

// <--[tag]
// @attribute <MaterialTag.heights>
Expand All @@ -57,37 +84,24 @@ public static void register() {
// @group properties
// @deprecated Use 'sides'
// @description
// Deprecated in favor of <@link tag MaterialTag.sides>
// -->
// <--[tag]
// @attribute <MaterialTag.sides>
// @returns ListTag
// @mechanism MaterialTag.sides
// @group properties
// @description
// Returns the list of heights for a wall block, or connections for a redstone wire, in order North|East|South|West|Vertical.
// For wall blocks: For n/e/s/w, can be "tall", "low", or "none". For vertical, can be "tall" or "none".
// For redstone wires: For n/e/s/w, can be "none", "side", or "up". No vertical.
// Deprecated in favor of <@link property MaterialTag.sides>
// -->
PropertyParser.registerStaticTag(MaterialSides.class, ListTag.class, "sides", (attribute, material) -> {
return material.getSidesList();
}, "heights");
}

public boolean isWall() {
return material.getModernData() instanceof Wall;
return getBlockData() instanceof Wall;
}

public Wall getWall() {
return (Wall) material.getModernData();
return (Wall) getBlockData();
}

public boolean isWire() {
return material.getModernData() instanceof RedstoneWire;
return getBlockData() instanceof RedstoneWire;
}

public RedstoneWire getWire() {
return (RedstoneWire) material.getModernData();
return (RedstoneWire) getBlockData();
}

public ListTag getSidesList() {
Expand All @@ -109,66 +123,4 @@ else if (isWire()) {
}
return list;
}

@Override
public String getPropertyString() {
return getSidesList().identify();
}

@Override
public String getPropertyId() {
return "sides";
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name heights
// @input ElementTag
// @deprecated Use 'sides'
// @description
// Deprecated in favor of <@link mechanism MaterialTag.sides>
// @tags
// <MaterialTag.heights>
// -->
// <--[mechanism]
// @object MaterialTag
// @name sides
// @input ElementTag
// @description
// Sets the list of heights for a wall block, or connections for a redstone wire, in order North|East|South|West|Vertical.
// For wall blocks: For n/e/s/w, can be "tall", "low", or "none". For vertical, can be "tall" or "none".
// For redstone wires: For n/e/s/w, can be "none", "side", or "up". No vertical.
// @tags
// <MaterialTag.sides>
// -->
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(CoreUtilities.toLowerCase(list.get(4)).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()));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,28 @@

import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Snowable;

public class MaterialSnowable implements Property {
public class MaterialSnowable extends MaterialProperty<ElementTag> {

public static boolean describes(ObjectTag material) {
return material instanceof MaterialTag
&& ((MaterialTag) material).hasModernData()
&& ((MaterialTag) material).getModernData() instanceof Snowable;
}

public static MaterialSnowable getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialSnowable((MaterialTag) _material);
}
}

public static final String[] handledMechs = new String[] {
"snowy"
};
// <--[tag]
// @object MaterialTag
// @name snowy
// @input ElementTag(Boolean)
// @description
// Controls whether this material is covered in snow.
// -->

public MaterialSnowable(MaterialTag _material) {
material = _material;
}

MaterialTag material;

public static void register() {

// <--[tag]
// @attribute <MaterialTag.snowy>
// @returns ElementTag(Boolean)
// @mechanism MaterialTag.snowy
// @group properties
// @description
// Returns whether this material is covered in snow or not.
// -->
PropertyParser.registerStaticTag(MaterialSnowable.class, ElementTag.class, "snowy", (attribute, material) -> {
return new ElementTag(material.isSnowy());
});
}

public Snowable getSnowable() {
return (Snowable) material.getModernData();
}

public boolean isSnowy() {
return getSnowable().isSnowy();
public static boolean describes(MaterialTag material) {
BlockData data = material.getModernData();
return data instanceof Snowable;
}

@Override
public String getPropertyString() {
return String.valueOf(isSnowy());
public ElementTag getPropertyValue() {
return new ElementTag(getSnowable().isSnowy());
}

@Override
Expand All @@ -69,19 +32,17 @@ public String getPropertyId() {
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name snowy
// @input ElementTag(Boolean)
// @description
// Sets this material to be covered in snow, or not.
// @tags
// <MaterialTag.snowy>
// -->
if (mechanism.matches("snowy") && mechanism.requireBoolean()) {
getSnowable().setSnowy(mechanism.getValue().asBoolean());
public void setPropertyValue(ElementTag value, Mechanism mechanism) {
if (mechanism.requireBoolean()) {
getSnowable().setSnowy(value.asBoolean());
}
}

public static void register() {
autoRegister("snowy", MaterialSnowable.class, ElementTag.class, true);
}

public Snowable getSnowable() {
return (Snowable) getBlockData();
}
}
Loading