From a110aff6451e098ff63cd0f41ebbeeed1d5f76ca Mon Sep 17 00:00:00 2001 From: hyper Date: Thu, 31 Oct 2024 18:09:40 -0400 Subject: [PATCH 1/4] Modernized half property --- .../properties/material/MaterialHalf.java | 160 +++++++----------- 1 file changed, 57 insertions(+), 103 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialHalf.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialHalf.java index 413b2f94e9..e7c9344715 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialHalf.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialHalf.java @@ -2,73 +2,66 @@ import com.denizenscript.denizen.objects.LocationTag; import com.denizenscript.denizen.objects.MaterialTag; -import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.Mechanism; -import com.denizenscript.denizencore.objects.ObjectTag; -import com.denizenscript.denizencore.objects.properties.Property; +import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.properties.PropertyParser; import org.bukkit.block.BlockFace; import org.bukkit.block.data.Bisected; import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.Directional; import org.bukkit.block.data.type.Bed; import org.bukkit.block.data.type.Chest; import org.bukkit.util.Vector; -public class MaterialHalf implements Property { +public class MaterialHalf extends MaterialProperty { + + // <--[property] + // @object MaterialTag + // @name half + // @input ElementTag + // @description + // Controls the current half for a bisected material (like a door, double-plant, chest, or a bed). + // For "Bisected" blocks (doors/double plants/...), values are either "BOTTOM" or "TOP". + // For beds, values are either "HEAD" or "FOOT". + // For chests, values are either "LEFT" or "RIGHT". + // For the half name, see <@link tag MaterialTag.half>. + // For the relative vector, see <@link tag MaterialTag.relative_vector>. + // --> + + public static boolean describes(MaterialTag material) { + BlockData data = material.getModernData(); + return data instanceof Bisected + || data instanceof Bed + || data instanceof Chest; + } + + MaterialTag material; - public static boolean describes(ObjectTag material) { - return material instanceof MaterialTag - && ((MaterialTag) material).hasModernData() - && isHalfData(((MaterialTag) material).getModernData()); + @Override + public String getPropertyId() { + return "half"; } - public static boolean isHalfData(BlockData data) { - if (data instanceof Bisected || data instanceof Bed || data instanceof Chest) { - return true; - } - return false; + @Override + public ElementTag getPropertyValue() { + return new ElementTag(getHalfName()); } - public static MaterialHalf getFrom(ObjectTag _material) { - if (!describes(_material)) { - return null; + @Override + public void setPropertyValue(ElementTag value, Mechanism mechanism) { + BlockData data = material.getModernData(); + if (data instanceof Bisected bisected) { + bisected.setHalf(value.asEnum(Bisected.Half.class)); } - else { - return new MaterialHalf((MaterialTag) _material); + else if (data instanceof Bed bed) { + bed.setPart(value.asEnum(Bed.Part.class)); + } + else if (data instanceof Chest chest) { + chest.setType(value.asEnum(Chest.Type.class)); } } - public static final String[] handledMechs = new String[] { - "half" - }; - - public MaterialHalf(MaterialTag _material) { - material = _material; - } - - MaterialTag material; - public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag - // @mechanism MaterialTag.half - // @group properties - // @description - // Returns the current half for a bisected material (like a door, double-plant, chest, or a bed). - // Output for "Bisected" blocks (doors/double plants/...) is "BOTTOM" or "TOP". - // Output for beds is "HEAD" or "FOOT". - // Output for chests is "LEFT" or "RIGHT". - // --> - PropertyParser.registerStaticTag(MaterialHalf.class, ElementTag.class, "half", (attribute, material) -> { - String halfName = material.getHalfName(); - if (halfName == null) { - return null; - } - return new ElementTag(halfName); - }); + autoRegister("half", MaterialHalf.class, ElementTag.class, true); // <--[tag] // @attribute @@ -88,17 +81,17 @@ public static void register() { } public static String getHalfName(BlockData data) { - if (data instanceof Bisected) { - return ((Bisected) data).getHalf().name(); + if (data instanceof Bisected bisected) { + return bisected.getHalf().name(); } - else if (data instanceof Bed) { - return ((Bed) data).getPart().name(); + else if (data instanceof Bed bed) { + return bed.getPart().name(); } - else if (data instanceof Chest) { - if (((Chest) data).getType() == Chest.Type.SINGLE) { + else if (data instanceof Chest chest) { + if (chest.getType() == Chest.Type.SINGLE) { return null; } - return ((Chest) data).getType().name(); + return chest.getType().name(); } return null; } @@ -107,40 +100,28 @@ public String getHalfName() { return getHalfName(material.getModernData()); } - public static void setHalfByName(BlockData data, String name) { - if (data instanceof Bisected) { - ((Bisected) data).setHalf(Bisected.Half.valueOf(name)); - } - else if (data instanceof Bed) { - ((Bed) data).setPart(Bed.Part.valueOf(name)); - } - else if (data instanceof Chest) { - ((Chest) data).setType(Chest.Type.valueOf(name)); - } - } - public static Vector getRelativeBlockVector(BlockData data) { - if (data instanceof Bisected) { - if (((Bisected) data).getHalf() == Bisected.Half.TOP) { + if (data instanceof Bisected bisected) { + if (bisected.getHalf() == Bisected.Half.TOP) { return new Vector(0, -1, 0); } else { return new Vector(0, 1, 0); } } - else if (data instanceof Bed) { - BlockFace face = ((Directional) data).getFacing(); - if (((Bed) data).getPart() == Bed.Part.HEAD) { + else if (data instanceof Bed bed) { + BlockFace face = bed.getFacing(); + if (bed.getPart() == Bed.Part.HEAD) { face = face.getOppositeFace(); } return face.getDirection(); } - else if (data instanceof Chest) { - if (((Chest) data).getType() == Chest.Type.SINGLE) { + else if (data instanceof Chest chest) { + if (chest.getType() == Chest.Type.SINGLE) { return null; } - Vector direction = ((Directional) data).getFacing().getDirection(); - if (((Chest) data).getType() == Chest.Type.LEFT) { + Vector direction = chest.getFacing().getDirection(); + if (chest.getType() == Chest.Type.LEFT) { return new Vector(-direction.getZ(), 0, direction.getX()); } return new Vector(direction.getZ(), 0, -direction.getX()); @@ -151,31 +132,4 @@ else if (data instanceof Chest) { public Vector getRelativeBlockVector() { return getRelativeBlockVector(material.getModernData()); } - - @Override - public String getPropertyString() { - return getHalfName(); - } - - @Override - public String getPropertyId() { - return "half"; - } - - @Override - public void adjust(Mechanism mechanism) { - - // <--[mechanism] - // @object MaterialTag - // @name half - // @input ElementTag - // @description - // Sets the current half for a bisected material (like a door, double-plant, chest, or a bed). - // @tags - // - // --> - if (mechanism.matches("half")) { - setHalfByName(material.getModernData(), mechanism.getValue().asString().toUpperCase()); - } - } } From b4c1b7e24a9118003a0e22e67c74c164f2656085 Mon Sep 17 00:00:00 2001 From: hyper Date: Thu, 31 Oct 2024 18:09:46 -0400 Subject: [PATCH 2/4] Modernized faces property --- .../properties/material/MaterialFaces.java | 103 ++++++------------ 1 file changed, 34 insertions(+), 69 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialFaces.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialFaces.java index 38ec5ae3c2..b83128eaf9 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialFaces.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialFaces.java @@ -2,41 +2,53 @@ 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 org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; import org.bukkit.block.data.MultipleFacing; -public class MaterialFaces implements Property { +public class MaterialFaces extends MaterialProperty { - public static boolean describes(ObjectTag material) { - return material instanceof MaterialTag - && ((MaterialTag) material).hasModernData() - && ((MaterialTag) material).getModernData() instanceof MultipleFacing; - } + // <--[property] + // @object MaterialTag + // @name valid_faces + // @input ListTag + // @description + // Controls a list of the current faces for a material that has multiple faces (like a mushroom block). + // For valid faces, see <@link tag MaterialTag.valid_faces>. + // --> - public static MaterialFaces getFrom(ObjectTag _material) { - if (!describes(_material)) { - return null; - } - else { - return new MaterialFaces((MaterialTag) _material); - } + public static boolean describes(MaterialTag material) { + BlockData data = material.getModernData(); + return data instanceof MultipleFacing; } - public static final String[] handledMechs = new String[] { - "faces" - }; + MaterialTag material; - public MaterialFaces(MaterialTag _material) { - material = _material; + @Override + public String getPropertyId() { + return "faces"; } - MaterialTag material; + @Override + public ListTag getPropertyValue() { + return getFaceList(); + } + + @Override + public void setPropertyValue(ListTag list, Mechanism mechanism) { + MultipleFacing facing = getFaces(); + for (BlockFace face : facing.getAllowedFaces()) { + facing.setFace(face, false); + } + for (String faceName : list) { + facing.setFace(BlockFace.valueOf(faceName.toUpperCase()), true); + } + } public static void register() { + autoRegister("faces", MaterialFaces.class, ListTag.class, true); // <--[tag] // @attribute @@ -45,7 +57,7 @@ public static void register() { // @group properties // @description // Returns a list of faces that are valid for a material that has multiple faces. - // See also <@link tag MaterialTag.faces> + // See also <@link property MaterialTag.faces> // --> PropertyParser.registerStaticTag(MaterialFaces.class, ListTag.class, "valid_faces", (attribute, material) -> { ListTag toReturn = new ListTag(); @@ -54,19 +66,6 @@ public static void register() { } return toReturn; }); - - // <--[tag] - // @attribute - // @returns ListTag - // @mechanism MaterialTag.faces - // @group properties - // @description - // Returns a list of the current faces for a material that has multiple faces (like a mushroom block). - // Output is a direction name like "NORTH". - // --> - PropertyParser.registerStaticTag(MaterialFaces.class, ListTag.class, "faces", (attribute, material) -> { - return material.getFaceList(); - }); } public ListTag getFaceList() { @@ -80,38 +79,4 @@ public ListTag getFaceList() { public MultipleFacing getFaces() { return (MultipleFacing) material.getModernData(); } - - @Override - public String getPropertyString() { - return getFaceList().identify(); - } - - @Override - public String getPropertyId() { - return "faces"; - } - - @Override - public void adjust(Mechanism mechanism) { - - // <--[mechanism] - // @object MaterialTag - // @name faces - // @input ListTag - // @description - // Sets the current faces for a material that has multiple faces (like a mushroom block). - // @tags - // - // - // --> - if (mechanism.matches("faces")) { - MultipleFacing facing = getFaces(); - for (BlockFace face : facing.getAllowedFaces()) { - facing.setFace(face, false); - } - for (String faceName : mechanism.valueAsType(ListTag.class)) { - facing.setFace(BlockFace.valueOf(faceName.toUpperCase()), true); - } - } - } } From 7ffc2e3cb191babda336421056fe4ab4aa72f662 Mon Sep 17 00:00:00 2001 From: hyper Date: Thu, 31 Oct 2024 18:09:53 -0400 Subject: [PATCH 3/4] Modernized distance property --- .../properties/material/MaterialDistance.java | 118 +++++++----------- 1 file changed, 43 insertions(+), 75 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialDistance.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialDistance.java index f348ec09a3..cf869f3274 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialDistance.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialDistance.java @@ -2,55 +2,61 @@ 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.type.Leaves; import org.bukkit.block.data.type.Scaffolding; -public class MaterialDistance implements Property { - - public static boolean describes(Object material) { - return material instanceof MaterialTag - && ((MaterialTag) material).hasModernData() - && (((MaterialTag) material).getModernData() instanceof Scaffolding - || ((MaterialTag) material).getModernData() instanceof Leaves); +public class MaterialDistance extends MaterialProperty { + + // <--[property] + // @object MaterialTag + // @name distance + // @input ElementTag(Number) + // @description + // Controls the horizontal distance between a scaffolding block and the nearest scaffolding block placed above a 'bottom' scaffold, + // or between a leaves block and the nearest log (a distance of 7 will cause a leaf to decay if 'persistent' is also false, less than 7 will prevent decay). + // --> + + public static boolean describes(MaterialTag material) { + BlockData data = material.getModernData(); + return data instanceof Scaffolding + || data instanceof Leaves; } - public static MaterialDistance getFrom(ObjectTag _material) { - if (!describes(_material)) { - return null; - } - else { - return new MaterialDistance((MaterialTag) _material); - } - } + MaterialTag material; - public static final String[] handledMechs = new String[] { - "distance" - }; + @Override + public String getPropertyId() { + return "distance"; + } - public MaterialDistance(MaterialTag _material) { - material = _material; + @Override + public ElementTag getPropertyValue() { + return new ElementTag(getDistance()); } - MaterialTag material; + @Override + public void setPropertyValue(ElementTag value, Mechanism mechanism) { + if (!mechanism.requireInteger()) { + return; + } + int distance = value.asInt(); + if (isScaffolding()) { + if (distance >= 0 && distance <= getScaffolding().getMaximumDistance()) { + getScaffolding().setDistance(distance); + } + else { + mechanism.echoError("Distance must be between 0 and " + getScaffolding().getMaximumDistance()); + } + } + else if (isLeaves()) { + getLeaves().setDistance(distance); + } + } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Number) - // @mechanism MaterialTag.distance - // @group properties - // @description - // Returns the horizontal distance between a scaffolding block and the nearest scaffolding block placed above a 'bottom' scaffold, - // or between a leaves block and the nearest log (a distance of 7 will cause a leaf to decay if 'persistent' is also false, less than 7 will prevent decay). - // --> - PropertyParser.registerStaticTag(MaterialDistance.class, ElementTag.class, "distance", (attribute, material) -> { - return new ElementTag(material.getDistance()); - }); + autoRegister("distance", MaterialDistance.class, ElementTag.class, true); } public int getDistance() { @@ -78,42 +84,4 @@ public boolean isScaffolding() { public boolean isLeaves() { return material.getModernData() instanceof Leaves; } - - @Override - public String getPropertyString() { - return String.valueOf(getDistance()); - } - - @Override - public String getPropertyId() { - return "distance"; - } - - @Override - public void adjust(Mechanism mechanism) { - - // <--[mechanism] - // @object MaterialTag - // @name distance - // @input ElementTag(Number) - // @description - // Sets the horizontal distance between a scaffolding block and the nearest scaffolding block placed above a 'bottom' scaffold, or between a leaves block and the nearest log. - // @tags - // - // --> - if (mechanism.matches("distance") && mechanism.requireInteger()) { - int distance = mechanism.getValue().asInt(); - if (isScaffolding()) { - if (distance >= 0 && distance <= getScaffolding().getMaximumDistance()) { - getScaffolding().setDistance(distance); - } - else { - mechanism.echoError("Distance must be between 0 and " + getScaffolding().getMaximumDistance()); - } - } - else if (isLeaves()) { - getLeaves().setDistance(distance); - } - } - } } From 9f2c1512dc05b5391929decbb9eca05666dbf878 Mon Sep 17 00:00:00 2001 From: hyper Date: Thu, 31 Oct 2024 19:58:27 -0400 Subject: [PATCH 4/4] Updated distance and half property files --- .../properties/material/MaterialDistance.java | 13 +++++++++++++ .../objects/properties/material/MaterialHalf.java | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialDistance.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialDistance.java index cf869f3274..72db854991 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialDistance.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialDistance.java @@ -84,4 +84,17 @@ public boolean isScaffolding() { public boolean isLeaves() { return material.getModernData() instanceof Leaves; } + + public static MaterialDistance getFrom(MaterialTag _material) { + if (!describes(_material)) { + return null; + } + else { + return new MaterialDistance(_material); + } + } + + public MaterialDistance(MaterialTag _material) { + material = _material; + } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialHalf.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialHalf.java index e7c9344715..e3d2357c13 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialHalf.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialHalf.java @@ -132,4 +132,17 @@ else if (data instanceof Chest chest) { public Vector getRelativeBlockVector() { return getRelativeBlockVector(material.getModernData()); } + + public static MaterialHalf getFrom(MaterialTag _material) { + if (!describes(_material)) { + return null; + } + else { + return new MaterialHalf(_material); + } + } + + public MaterialHalf(MaterialTag _material) { + material = _material; + } }