From 104e8ba71593f70a8d01d16b4ffbe71f0a24e88a Mon Sep 17 00:00:00 2001 From: MCSamuel Date: Sun, 18 Jan 2026 12:54:34 -0800 Subject: [PATCH 1/3] Added MossyCarpet to MaterialSides, modernized property. --- .../properties/material/MaterialSides.java | 225 +++++++----------- 1 file changed, 88 insertions(+), 137 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialSides.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialSides.java index 7da3aeb2a3..7f69ae2ec1 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialSides.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialSides.java @@ -1,118 +1,96 @@ package com.denizenscript.denizen.objects.properties.material; +import com.denizenscript.denizen.nms.NMSHandler; +import com.denizenscript.denizen.nms.NMSVersion; 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.MossyCarpet; import org.bukkit.block.data.type.RedstoneWire; import org.bukkit.block.data.type.Wall; -public class MaterialSides implements Property { - - 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; - } - - public static MaterialSides getFrom(ObjectTag _material) { - if (!describes(_material)) { - return null; - } - else { - return new MaterialSides((MaterialTag) _material); - } +public class MaterialSides extends MaterialProperty { + + // <--[property] + // @object MaterialTag + // @name sides + // @input ListTag + // @description + // Controls the heights for a wall block or mossy carpet, 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. + // For mossy carpets: For n/e/s/w, can be "tall", "low", or "none". Vertical controls the bottom, and can either be "true" or "false". + // --> + + public static boolean describes(MaterialTag material) { + BlockData data = material.getModernData(); + return (data instanceof Wall + || data instanceof RedstoneWire + || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && data instanceof MossyCarpet)); } - public static final String[] handledMechs = new String[] { - "sides", "heights" - }; - - public MaterialSides(MaterialTag _material) { - material = _material; - } - - MaterialTag material; - - public static void register() { - - // <--[tag] - // @attribute - // @returns ListTag - // @mechanism MaterialTag.heights - // @group properties - // @deprecated Use 'sides' - // @description - // Deprecated in favor of <@link tag MaterialTag.sides> - // --> - // <--[tag] - // @attribute - // @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. - // --> - PropertyParser.registerStaticTag(MaterialSides.class, ListTag.class, "sides", (attribute, material) -> { - return material.getSidesList(); - }, "heights"); - } - - public boolean isWall() { - return material.getModernData() instanceof Wall; - } - - public Wall getWall() { - return (Wall) material.getModernData(); - } - - public boolean isWire() { - return material.getModernData() instanceof RedstoneWire; - } - - public RedstoneWire getWire() { - return (RedstoneWire) material.getModernData(); - } - - public ListTag getSidesList() { + @Override + public ListTag getPropertyValue() { ListTag list = new ListTag(5); - if (isWall()) { - Wall wall = getWall(); + if (getBlockData() instanceof Wall wall) { 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(); + else if (getBlockData() instanceof RedstoneWire wire) { 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()); } + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof MossyCarpet carpet) { + list.add(carpet.getHeight(BlockFace.NORTH).name()); + list.add(carpet.getHeight(BlockFace.EAST).name()); + list.add(carpet.getHeight(BlockFace.SOUTH).name()); + list.add(carpet.getHeight(BlockFace.WEST).name()); + list.add(carpet.isBottom() ? "TRUE" : "FALSE"); + } return list; } @Override - public String getPropertyString() { - return getSidesList().identify(); + public void setPropertyValue(ListTag list, Mechanism mechanism) { + if (getBlockData() instanceof Wall wall) { + if (list.size() != 5) { + mechanism.echoError("Invalid sides list, size must be 5."); + return; + } + 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).equalsIgnoreCase("tall")); + } + else if (getBlockData() instanceof RedstoneWire wire) { + if (list.size() != 4) { + mechanism.echoError("Invalid sides list, size must be 4."); + return; + } + 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())); + } + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof MossyCarpet carpet) { + if (list.size() != 5) { + mechanism.echoError("Invalid sides list, size must be 5."); + return; + } + carpet.setHeight(BlockFace.NORTH, MossyCarpet.Height.valueOf(list.get(0).toUpperCase())); + carpet.setHeight(BlockFace.EAST, MossyCarpet.Height.valueOf(list.get(1).toUpperCase())); + carpet.setHeight(BlockFace.SOUTH, MossyCarpet.Height.valueOf(list.get(2).toUpperCase())); + carpet.setHeight(BlockFace.WEST, MossyCarpet.Height.valueOf(list.get(3).toUpperCase())); + carpet.setBottom(list.get(4).equalsIgnoreCase("true")); + } } @Override @@ -120,55 +98,28 @@ public String getPropertyId() { return "sides"; } - @Override - public void adjust(Mechanism mechanism) { + // <--[tag] + // @attribute + // @returns ListTag + // @mechanism MaterialTag.heights + // @group properties + // @deprecated Use 'sides' + // @description + // Deprecated in favor of <@link property MaterialTag.sides> + // --> + + // <--[mechanism] + // @object MaterialTag + // @name heights + // @input ElementTag + // @deprecated Use 'sides' + // @description + // Deprecated in favor of <@link property MaterialTag.sides> + // @tags + // + // --> - // <--[mechanism] - // @object MaterialTag - // @name heights - // @input ElementTag - // @deprecated Use 'sides' - // @description - // Deprecated in favor of <@link mechanism MaterialTag.sides> - // @tags - // - // --> - // <--[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 - // - // --> - 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())); - } - } + public static void register() { + autoRegister("sides", MaterialSides.class, ListTag.class, false, "heights"); } } From 8d980d9da2c2645d42901505af275fc015be269a Mon Sep 17 00:00:00 2001 From: MCSamuel Date: Mon, 2 Mar 2026 07:54:34 -0800 Subject: [PATCH 2/3] minor changes --- .../objects/properties/material/MaterialSides.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialSides.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialSides.java index 7f69ae2ec1..4022353452 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialSides.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialSides.java @@ -21,14 +21,14 @@ public class MaterialSides extends MaterialProperty { // Controls the heights for a wall block or mossy carpet, 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. - // For mossy carpets: For n/e/s/w, can be "tall", "low", or "none". Vertical controls the bottom, and can either be "true" or "false". + // For mossy carpets: For n/e/s/w, can be "tall", "low", or "none". Vertical controls the bottom, and can either be "bottom" or "none". // --> public static boolean describes(MaterialTag material) { BlockData data = material.getModernData(); - return (data instanceof Wall + return data instanceof Wall || data instanceof RedstoneWire - || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && data instanceof MossyCarpet)); + || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && data instanceof MossyCarpet); } @Override @@ -52,7 +52,7 @@ else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() i list.add(carpet.getHeight(BlockFace.EAST).name()); list.add(carpet.getHeight(BlockFace.SOUTH).name()); list.add(carpet.getHeight(BlockFace.WEST).name()); - list.add(carpet.isBottom() ? "TRUE" : "FALSE"); + list.add(carpet.isBottom() ? "BOTTOM" : "NONE"); } return list; } From 4ecd5121bd34054fb7a89e645eaf82106ad6f46d Mon Sep 17 00:00:00 2001 From: MCSamuel Date: Sat, 7 Mar 2026 15:23:37 -0800 Subject: [PATCH 3/3] slight changes in error handling --- .../properties/material/MaterialSides.java | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialSides.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialSides.java index 4022353452..093f9d70bf 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialSides.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialSides.java @@ -3,14 +3,19 @@ import com.denizenscript.denizen.nms.NMSHandler; import com.denizenscript.denizen.nms.NMSVersion; import com.denizenscript.denizen.objects.MaterialTag; +import com.denizenscript.denizen.utilities.Utilities; import com.denizenscript.denizencore.objects.Mechanism; +import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.core.ListTag; +import com.denizenscript.denizencore.utilities.debugging.DebugInternals; import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.MossyCarpet; import org.bukkit.block.data.type.RedstoneWire; import org.bukkit.block.data.type.Wall; +import java.util.function.BiConsumer; + public class MaterialSides extends MaterialProperty { // <--[property] @@ -64,10 +69,10 @@ public void setPropertyValue(ListTag list, Mechanism mechanism) { mechanism.echoError("Invalid sides list, size must be 5."); return; } - 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())); + setSide(wall::setHeight, Wall.Height.class, BlockFace.NORTH, list, 0, mechanism); + setSide(wall::setHeight, Wall.Height.class, BlockFace.EAST, list, 1, mechanism); + setSide(wall::setHeight, Wall.Height.class, BlockFace.SOUTH, list, 2, mechanism); + setSide(wall::setHeight, Wall.Height.class, BlockFace.WEST, list, 3, mechanism); wall.setUp(list.get(4).equalsIgnoreCase("tall")); } else if (getBlockData() instanceof RedstoneWire wire) { @@ -75,22 +80,31 @@ else if (getBlockData() instanceof RedstoneWire wire) { mechanism.echoError("Invalid sides list, size must be 4."); return; } - 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())); + setSide(wire::setFace, RedstoneWire.Connection.class, BlockFace.NORTH, list, 0, mechanism); + setSide(wire::setFace, RedstoneWire.Connection.class, BlockFace.EAST, list, 1, mechanism); + setSide(wire::setFace, RedstoneWire.Connection.class, BlockFace.SOUTH, list, 2, mechanism); + setSide(wire::setFace, RedstoneWire.Connection.class, BlockFace.WEST, list, 3, mechanism); } else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof MossyCarpet carpet) { if (list.size() != 5) { mechanism.echoError("Invalid sides list, size must be 5."); return; } - carpet.setHeight(BlockFace.NORTH, MossyCarpet.Height.valueOf(list.get(0).toUpperCase())); - carpet.setHeight(BlockFace.EAST, MossyCarpet.Height.valueOf(list.get(1).toUpperCase())); - carpet.setHeight(BlockFace.SOUTH, MossyCarpet.Height.valueOf(list.get(2).toUpperCase())); - carpet.setHeight(BlockFace.WEST, MossyCarpet.Height.valueOf(list.get(3).toUpperCase())); - carpet.setBottom(list.get(4).equalsIgnoreCase("true")); + setSide(carpet::setHeight, MossyCarpet.Height.class, BlockFace.NORTH, list, 0, mechanism); + setSide(carpet::setHeight, MossyCarpet.Height.class, BlockFace.EAST, list, 1, mechanism); + setSide(carpet::setHeight, MossyCarpet.Height.class, BlockFace.SOUTH, list, 2, mechanism); + setSide(carpet::setHeight, MossyCarpet.Height.class, BlockFace.WEST, list, 3, mechanism); + carpet.setBottom(list.get(4).equalsIgnoreCase("bottom")); + } + } + + public static void setSide(BiConsumer consumer, Class type, BlockFace face, ListTag list, int index, Mechanism mechanism) { + T value = Utilities.elementToEnumlike(new ElementTag(list.get(index)), type); + if (value == null) { + mechanism.echoError("'"+ list.get(index) + "' is not a valid " + DebugInternals.getClassNameOpti(type) + "."); + return; } + consumer.accept(face, value); } @Override