diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java index 9cdd68fd02..e723c790db 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java @@ -16,7 +16,6 @@ import com.denizenscript.denizencore.objects.core.ListTag; import com.denizenscript.denizencore.objects.core.QueueTag; import com.denizenscript.denizencore.objects.core.ScriptTag; -import com.denizenscript.denizencore.objects.properties.Property; import com.denizenscript.denizencore.objects.properties.PropertyParser; import dev.unizen.denizen.objects.properties.entity.*; import dev.unizen.denizen.objects.properties.material.*; @@ -162,21 +161,29 @@ public static void registermainProperties() { PropertyParser.registerProperty(MaterialAge.class, MaterialTag.class); PropertyParser.registerProperty(MaterialAttached.class, MaterialTag.class); PropertyParser.registerProperty(MaterialDirectional.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialFarmlandMoisture.class, MaterialTag.class); PropertyParser.registerProperty(MaterialHalf.class, MaterialTag.class); - PropertyParser.registerProperty(MaterialSlab.class, MaterialTag.class); - PropertyParser.registerProperty(MaterialLeaves.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialGateInStoneWall.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialHopperEnabled.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialJukeboxRecord.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialLeavesDistance.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialLeavesPersistence.class, MaterialTag.class); PropertyParser.registerProperty(MaterialLevel.class, MaterialTag.class); PropertyParser.registerProperty(MaterialLightable.class, MaterialTag.class); - PropertyParser.registerProperty(MaterialMultipleFacing.class, MaterialTag.class); - PropertyParser.registerProperty(MaterialOpen.class, MaterialTag.class); - PropertyParser.registerProperty(MaterialOrientation.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialNoteblockInstrument.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialNoteblockNote.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialPistonExtended.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialPistonHeadRetracting.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialPistonType.class, MaterialTag.class); PropertyParser.registerProperty(MaterialRailShape.class, MaterialTag.class); - PropertyParser.registerProperty(MaterialRedstonePower.class, MaterialTag.class); - PropertyParser.registerProperty(MaterialRotation.class, MaterialTag.class); - PropertyParser.registerProperty(MaterialSnowy.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialRedstoneConnection.class, MaterialTag.class); PropertyParser.registerProperty(MaterialSwitchFace.class, MaterialTag.class); PropertyParser.registerProperty(MaterialWaterlogged.class, MaterialTag.class); } + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_14)) { + PropertyParser.registerProperty(MaterialLanternHanging.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialLecternBook.class, MaterialTag.class); + } // register core TradeTag properties PropertyParser.registerProperty(TradeHasXp.class, TradeTag.class); diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialFarmlandMoisture.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialFarmlandMoisture.java new file mode 100644 index 0000000000..e0d13df41e --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialFarmlandMoisture.java @@ -0,0 +1,131 @@ +package dev.unizen.denizen.objects.properties.material; + +import com.denizenscript.denizen.objects.MaterialTag; +import com.denizenscript.denizen.utilities.debugging.Debug; +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.tags.Attribute; +import org.bukkit.block.data.type.Farmland; + +public class MaterialFarmlandMoisture implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Farmland; + } + + public static MaterialFarmlandMoisture getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialFarmlandMoisture((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "moisture", "max_moisture" + }; + + public static final String[] handledMechs = new String[] { + "moisture" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialFarmlandMoisture(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Farmland getFarmland() { + return (Farmland) material.getModernData().data; + } + + private int getMoisture() { + return getFarmland().getMoisture(); + } + + private int getMaxMoisture() { + return getFarmland().getMoisture(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return getMoisture() != 0 ? String.valueOf(getMoisture()) : null; + } + + @Override + public String getPropertyId() { + return "moisture"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @group properties + // @description + // Returns the maximum moisture level of the farmland material. + // --> + if (attribute.startsWith("max_moisture")) { + return new ElementTag(getMaxMoisture()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @mechanism MaterialTag.moisture + // @group properties + // @description + // Returns the moisture level of the farmland material. + // --> + if (attribute.startsWith("moisture")) { + return new ElementTag(getMoisture()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name moisture + // @input ElementTag(Number) + // @description + // Sets the moisture level of the farmland material. + // Cannot be higher than the max moisture level. + // @tags + // + // + // --> + if (mechanism.matches("moisture") && mechanism.requireInteger()) { + int moisture = mechanism.getValue().asInt(); + if (moisture < 0 || moisture > getMaxMoisture()) { + Debug.echoError("The moisture level must be between '0' and '" + getMaxMoisture() + "'!"); + return; + } + getFarmland().setMoisture(moisture); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialGateInStoneWall.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialGateInStoneWall.java new file mode 100644 index 0000000000..c44ce0c356 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialGateInStoneWall.java @@ -0,0 +1,109 @@ +package dev.unizen.denizen.objects.properties.material; + +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.tags.Attribute; +import org.bukkit.block.data.type.Gate; + +public class MaterialGateInStoneWall implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Gate; + } + + public static MaterialGateInStoneWall getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialGateInStoneWall((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "in_stone_wall" + }; + + public static final String[] handledMechs = new String[] { + "in_stone_wall" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialGateInStoneWall(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Gate getGate() { + return (Gate) material.getModernData().data; + } + + private boolean isInWall() { + return getGate().isInWall(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return isInWall() ? "true" : null; + } + + @Override + public String getPropertyId() { + return "in_stone_wall"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @mechanism MaterialTag.in_stone_wall + // @group properties + // @description + // Returns whether this fence gate material is attached to a stone wall. + // --> + if (attribute.startsWith("in_stone_wall")) { + return new ElementTag(isInWall()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name in_stone_wall + // @input ElementTag(Boolean) + // @description + // Sets whether this fence gate material is attached to a stone wall. + // If true, then the material's texture is lowered. + // @tags + // + // --> + if (mechanism.matches("in_stone_wall") && mechanism.requireBoolean()) { + getGate().setInWall(mechanism.getValue().asBoolean()); + } + } +} diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialHalf.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialHalf.java similarity index 94% rename from plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialHalf.java rename to plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialHalf.java index ef6bac1aed..3cfdb5c469 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialHalf.java +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialHalf.java @@ -1,4 +1,4 @@ -package com.denizenscript.denizen.objects.properties.material; +package dev.unizen.denizen.objects.properties.material; import com.denizenscript.denizen.objects.MaterialTag; import com.denizenscript.denizencore.objects.core.ElementTag; diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialHopperEnabled.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialHopperEnabled.java new file mode 100644 index 0000000000..aa1e39a481 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialHopperEnabled.java @@ -0,0 +1,111 @@ +package dev.unizen.denizen.objects.properties.material; + +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.tags.Attribute; +import org.bukkit.block.data.type.Hopper; + +public class MaterialHopperEnabled implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Hopper; + } + + public static MaterialHopperEnabled getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialHopperEnabled((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "enabled" + }; + + public static final String[] handledMechs = new String[] { + "enabled" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialHopperEnabled(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Hopper getHopper() { + return (Hopper) material.getModernData().data; + } + + private boolean isEnabled() { + return getHopper().isEnabled(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + // The default state of a hopper is being enabled. + return !isEnabled() ? "false" : null; + } + + @Override + public String getPropertyId() { + return "enabled"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @mechanism MaterialTag.enabled + // @group properties + // @description + // Returns whether this hopper material is enabled. + // NOTE: A hopper is enabled when it is not receiving power! + // --> + if (attribute.startsWith("enabled")) { + return new ElementTag(isEnabled()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name enabled + // @input ElementTag(Boolean) + // @description + // Sets whether this hopper material is enabled. + // NOTE: A hopper is enabled when it is not receiving power! + // @tags + // + // --> + if (mechanism.matches("enabled") && mechanism.requireBoolean()) { + getHopper().setEnabled(mechanism.getValue().asBoolean()); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialJukeboxRecord.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialJukeboxRecord.java new file mode 100644 index 0000000000..d4ddbb711b --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialJukeboxRecord.java @@ -0,0 +1,91 @@ +package dev.unizen.denizen.objects.properties.material; + +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.tags.Attribute; +import org.bukkit.block.data.type.Jukebox; + +public class MaterialJukeboxRecord implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Jukebox; + } + + public static MaterialJukeboxRecord getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialJukeboxRecord((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "has_record" + }; + + public static final String[] handledMechs = new String[] { + // None + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialJukeboxRecord(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private boolean hasRecord() { + return ((Jukebox) material.getModernData().data).hasRecord(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return hasRecord() ? "true" : null; + } + + @Override + public String getPropertyId() { + return "has_record"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @group properties + // @description + // Returns whether the jukebox material has a record inside of it. + // --> + if (attribute.startsWith("has_record")) { + return new ElementTag(hasRecord()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + // None + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialLanternHanging.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialLanternHanging.java new file mode 100644 index 0000000000..d5119aff70 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialLanternHanging.java @@ -0,0 +1,108 @@ +package dev.unizen.denizen.objects.properties.material; + +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.tags.Attribute; +import org.bukkit.block.data.type.Lantern; + +public class MaterialLanternHanging implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Lantern; + } + + public static MaterialLanternHanging getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialLanternHanging((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "is_hanging" + }; + + public static final String[] handledMechs = new String[] { + "is_hanging" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialLanternHanging(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Lantern getLantern() { + return (Lantern) material.getModernData().data; + } + + private boolean isHanging() { + return getLantern().isHanging(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return isHanging() ? "true" : null; + } + + @Override + public String getPropertyId() { + return "is_hanging"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @mechanism MaterialTag.is_hanging + // @group properties + // @description + // Returns whether the lantern material is hanging from a block. + // --> + if (attribute.startsWith("is_hanging")) { + return new ElementTag(isHanging()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name is_hanging + // @input ElementTag(Boolean) + // @description + // Sets whether the lantern material is hanging from a block. + // @tags + // + // --> + if (mechanism.matches("is_hanging") && mechanism.requireBoolean()) { + getLantern().setHanging(mechanism.getValue().asBoolean()); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialLeavesDistance.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialLeavesDistance.java new file mode 100644 index 0000000000..af8109af02 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialLeavesDistance.java @@ -0,0 +1,110 @@ +package dev.unizen.denizen.objects.properties.material; + +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.tags.Attribute; +import org.bukkit.block.data.type.Leaves; + +public class MaterialLeavesDistance implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Leaves; + } + + public static MaterialLeavesDistance getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialLeavesDistance((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "distance" + }; + + public static final String[] handledMechs = new String[] { + "distance" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialLeavesDistance(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Leaves getLeaves() { + return (Leaves) material.getModernData().data; + } + + private int getDistance() { + return getLeaves().getDistance(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return getDistance() != 0 ? String.valueOf(getDistance()) : null; + } + + @Override + public String getPropertyId() { + return "distance"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @mechanism MaterialTag.distance + // @group properties + // @description + // Returns how far the leaves material is from a tree. + // Used together with <@link tag MaterialTag.persistent> to determine if the leaves will decay. + // --> + if (attribute.startsWith("distance")) { + return new ElementTag(getDistance()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name distance + // @input ElementTag(Number) + // @description + // Sets how far the leaves material is from a tree. + // Used together with <@link mechanism MaterialTag.persistent> to determine if the leaves will decay. + // @tags + // + // --> + if (mechanism.matches("distance") && mechanism.requireInteger()) { + getLeaves().setDistance(mechanism.getValue().asInt()); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialLeavesPersistence.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialLeavesPersistence.java new file mode 100644 index 0000000000..013053ad66 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialLeavesPersistence.java @@ -0,0 +1,108 @@ +package dev.unizen.denizen.objects.properties.material; + +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.tags.Attribute; +import org.bukkit.block.data.type.Leaves; + +public class MaterialLeavesPersistence implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Leaves; + } + + public static MaterialLeavesPersistence getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialLeavesPersistence((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "persistent" + }; + + public static final String[] handledMechs = new String[] { + "persistent" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialLeavesPersistence(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Leaves getLeaves() { + return (Leaves) material.getModernData().data; + } + + private boolean isPersistent() { + return getLeaves().isPersistent(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return isPersistent() ? "true" : null; + } + + @Override + public String getPropertyId() { + return "persistent"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @mechanism MaterialTag.persistent + // @group properties + // @description + // Returns whether the leaves material is persistent or not. + // --> + if (attribute.startsWith("persistent")) { + return new ElementTag(isPersistent()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name persistent + // @input ElementTag(Boolean) + // @description + // Sets whether the leaves material is persistent or not. + // @tags + // + // --> + if (mechanism.matches("persistent") && mechanism.requireBoolean()) { + getLeaves().setPersistent(mechanism.getValue().asBoolean()); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialLecternBook.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialLecternBook.java new file mode 100644 index 0000000000..11ab7b75c5 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialLecternBook.java @@ -0,0 +1,91 @@ +package dev.unizen.denizen.objects.properties.material; + +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.tags.Attribute; +import org.bukkit.block.data.type.Lectern; + +public class MaterialLecternBook implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Lectern; + } + + public static MaterialLecternBook getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialLecternBook((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "has_book" + }; + + public static final String[] handledMechs = new String[] { + // None + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialLecternBook(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private boolean hasBook() { + return ((Lectern) material.getModernData().data).hasBook(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return hasBook() ? "true" : null; + } + + @Override + public String getPropertyId() { + return "has_book"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @group properties + // @description + // Returns whether the lectern material has a book. + // --> + if (attribute.startsWith("has_book")) { + return new ElementTag(hasBook()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + // None + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialNoteblockInstrument.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialNoteblockInstrument.java new file mode 100644 index 0000000000..e6253d7cd4 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialNoteblockInstrument.java @@ -0,0 +1,111 @@ +package dev.unizen.denizen.objects.properties.material; + +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.tags.Attribute; +import org.bukkit.Instrument; +import org.bukkit.block.data.type.NoteBlock; + +public class MaterialNoteblockInstrument implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof NoteBlock; + } + + public static MaterialNoteblockInstrument getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialNoteblockInstrument((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "instrument" + }; + + public static final String[] handledMechs = new String[] { + "instrument" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialNoteblockInstrument(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private NoteBlock getNoteBlock() { + return (NoteBlock) material.getModernData().data; + } + + private String getInstrument() { + return getNoteBlock().getInstrument().name(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return getNoteBlock().getInstrument() != Instrument.PIANO ? getInstrument() : null; + } + + @Override + public String getPropertyId() { + return "instrument"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @mechanism MaterialTag.instrument + // @group properties + // @description + // Returns the instrument the noteblock material is using. + // The instrument can be any of: <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Instrument.html> + // --> + if (attribute.startsWith("instrument")) { + return new ElementTag(getInstrument()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name instrument + // @input ElementTag + // @description + // Sets the instrument the noteblock material is using. + // The instrument can be any of: <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Instrument.html> + // @tags + // + // --> + if (mechanism.matches("instrument") && mechanism.requireEnum(false, Instrument.values())) { + getNoteBlock().setInstrument(Instrument.valueOf(mechanism.getValue().asString().toUpperCase())); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialNoteblockNote.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialNoteblockNote.java new file mode 100644 index 0000000000..376a335865 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialNoteblockNote.java @@ -0,0 +1,199 @@ +package dev.unizen.denizen.objects.properties.material; + +import com.denizenscript.denizen.objects.MaterialTag; +import com.denizenscript.denizen.utilities.debugging.Debug; +import com.denizenscript.denizencore.objects.Mechanism; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.objects.core.ListTag; +import com.denizenscript.denizencore.objects.properties.Property; +import com.denizenscript.denizencore.tags.Attribute; +import org.bukkit.Note; +import org.bukkit.block.data.type.NoteBlock; + +public class MaterialNoteblockNote implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof NoteBlock; + } + + public static MaterialNoteblockNote getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialNoteblockNote((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "note" + }; + + public static final String[] handledMechs = new String[] { + "note" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialNoteblockNote(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private NoteBlock getNoteBlock() { + return (NoteBlock) material.getModernData().data; + } + + private int getNoteOctave() { + return getNoteBlock().getNote().getOctave(); + } + + private String getNoteTone() { + return getNoteBlock().getNote().getTone().name(); + } + + private boolean isNoteSharped() { + return getNoteBlock().getNote().isSharped(); + } + + private String getNoteInfo() { + return getNoteOctave() + "|" + getNoteTone() + "|" + isNoteSharped(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return getNoteInfo(); + } + + @Override + public String getPropertyId() { + return "note"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number)|ElementTag|ElementTag(Boolean) + // @mechanism MaterialTag.note + // @group properties + // @description + // Returns the note information of the noteblock material. + // Formatted as: OCTAVE|TONE|SHARP + // --> + if (attribute.startsWith("note")) { + attribute.fulfill(1); + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @mechanism MaterialTag.note + // @group properties + // @description + // Returns the note octave of the noteblock material. + // --> + if (attribute.startsWith("octave")) { + return new ElementTag(getNoteOctave()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @mechanism MaterialTag.note + // @group properties + // @description + // Returns the note tone of the noteblock material. + // --> + if (attribute.startsWith("tone")) { + return new ElementTag(getNoteTone()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @mechanism MaterialTag.note + // @group properties + // @description + // Returns whether the note tone of the noteblock material is sharp. + // --> + if (attribute.startsWith("is_sharp")) { + return new ElementTag(isNoteSharped()).getAttribute(attribute.fulfill(1)); + } + + return new ElementTag(getNoteInfo()).getAttribute(attribute); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name note + // @input ElementTag(Number)|ElementTag(|ElementTag(Boolean)) + // @description + // Sets the note information of the noteblock material. + // The first ElementTag is a number noting the octave. + // The second ElementTag is the note tone, which can be any of: <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Note.Tone.html> + // Optionally, use the third ElementTag to specify if the note should be sharp. + // Omitting the third ElementTag or setting it to "false" makes the note's tone natural. + // @tags + // + // + // + // + // --> + if (mechanism.matches("note") && mechanism.requireObject(ListTag.class)) { + ListTag noteInfo = mechanism.valueAsType(ListTag.class); + if (noteInfo.size() < 2 || noteInfo.size() > 3) { + Debug.echoError("Invalid input! Valid input must be at least OCTAVE|NOTE, and at most OCTAVE|NOTE|SHARP!"); + return; + } + + ElementTag elOctave = new ElementTag(noteInfo.get(0)); + int octave = 0; + if (elOctave.isInt()) { + octave = elOctave.asInt(); + } + + String elTone = noteInfo.get(1); + Note.Tone tone; + try { + tone = Note.Tone.valueOf(elTone.toUpperCase()); + } + catch (IllegalArgumentException e) { + Debug.echoError(e); + return; + } + + boolean sharp = false; + if (noteInfo.size() == 3) { + ElementTag elSharp = new ElementTag(noteInfo.get(2)); + if (elSharp.isBoolean()) { + sharp = elSharp.asBoolean(); + } + } + + getNoteBlock().setNote(new Note(octave, tone, sharp)); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialPistonExtended.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialPistonExtended.java new file mode 100644 index 0000000000..82e369608f --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialPistonExtended.java @@ -0,0 +1,108 @@ +package dev.unizen.denizen.objects.properties.material; + +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.tags.Attribute; +import org.bukkit.block.data.type.Piston; + +public class MaterialPistonExtended implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Piston; + } + + public static MaterialPistonExtended getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialPistonExtended((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "extended" + }; + + public static final String[] handledMechs = new String[] { + "extended" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialPistonExtended(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Piston getPiston() { + return (Piston) material.getModernData().data; + } + + private boolean isExtended() { + return getPiston().isExtended(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return isExtended() ? "true" : null; + } + + @Override + public String getPropertyId() { + return "extended"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @mechanism MaterialTag.extended + // @group properties + // @description + // Returns whether the piston material's head is extended. + // --> + if (attribute.startsWith("extended")) { + return new ElementTag(isExtended()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name extended + // @input ElementTag(Boolean) + // @description + // Sets whether the piston material's head is extended. + // @tags + // + // --> + if (mechanism.matches("extended") && mechanism.requireBoolean()) { + getPiston().setExtended(mechanism.getValue().asBoolean()); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialPistonHeadRetracting.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialPistonHeadRetracting.java new file mode 100644 index 0000000000..db9ec365e8 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialPistonHeadRetracting.java @@ -0,0 +1,108 @@ +package dev.unizen.denizen.objects.properties.material; + +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.tags.Attribute; +import org.bukkit.block.data.type.PistonHead; + +public class MaterialPistonHeadRetracting implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof PistonHead; + } + + public static MaterialPistonHeadRetracting getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialPistonHeadRetracting((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "retracting" + }; + + public static final String[] handledMechs = new String[] { + "retracting" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialPistonHeadRetracting(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private PistonHead getPistonHead() { + return (PistonHead) material.getModernData().data; + } + + private boolean isShort() { + return getPistonHead().isShort(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return isShort() ? "true" : null; + } + + @Override + public String getPropertyId() { + return "retracting"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @mechanism MaterialTag.retracting + // @group properties + // @description + // Returns whether this piston head is currently retracting. + // --> + if (attribute.startsWith("retracting")) { + return new ElementTag(isShort()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name retracting + // @input ElementTag(Boolean) + // @description + // Sets whether this piston head is currently retracting. + // @tags + // + // --> + if (mechanism.matches("retracting") && mechanism.requireBoolean()) { + getPistonHead().setShort(mechanism.getValue().asBoolean()); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialPistonType.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialPistonType.java new file mode 100644 index 0000000000..ba533c00d2 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialPistonType.java @@ -0,0 +1,110 @@ +package dev.unizen.denizen.objects.properties.material; + +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.tags.Attribute; +import org.bukkit.block.data.type.TechnicalPiston; + +public class MaterialPistonType implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof TechnicalPiston; + } + + public static MaterialPistonType getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialPistonType((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "piston_type" + }; + + public static final String[] handledMechs = new String[] { + "piston_type" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialPistonType(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private TechnicalPiston getPiston() { + return (TechnicalPiston) material.getModernData().data; + } + + private String getType() { + return getPiston().getType().name(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return getPiston().getType() != TechnicalPiston.Type.NORMAL ? getType() : null; + } + + @Override + public String getPropertyId() { + return "piston_type"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @mechanism MaterialTag.piston_type + // @group properties + // @description + // Returns the kind of piston this piston block is. + // Can be either NORMAL or STICKY. + // --> + if (attribute.startsWith("piston_type")) { + return new ElementTag(getType()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name piston_type + // @input ElementTag + // @description + // Sets the kind of piston this piston block is. + // Can be either NORMAL or STICKY. + // @tags + // + // --> + if (mechanism.matches("piston_type") && mechanism.requireEnum(false, TechnicalPiston.Type.values())) { + getPiston().setType(TechnicalPiston.Type.valueOf(mechanism.getValue().asString().toUpperCase())); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialRedstoneConnection.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialRedstoneConnection.java new file mode 100644 index 0000000000..1353496054 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialRedstoneConnection.java @@ -0,0 +1,186 @@ +package dev.unizen.denizen.objects.properties.material; + +import com.denizenscript.denizen.objects.MaterialTag; +import com.denizenscript.denizen.utilities.debugging.Debug; +import com.denizenscript.denizencore.objects.Mechanism; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.objects.core.ListTag; +import com.denizenscript.denizencore.objects.properties.Property; +import com.denizenscript.denizencore.tags.Attribute; +import com.denizenscript.denizencore.utilities.CoreUtilities; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.type.RedstoneWire; + +import java.util.*; + +public class MaterialRedstoneConnection implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof RedstoneWire; + } + + public static MaterialRedstoneConnection getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialRedstoneConnection((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "redstone_connections", "redstone_connection_to" + }; + + public static final String[] handledMechs = new String[] { + "redstone_connections" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialRedstoneConnection(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private RedstoneWire getRedstoneWire() { + return (RedstoneWire) material.getModernData().data; + } + + private Set getAllowedFaces() { + return getRedstoneWire().getAllowedFaces(); + } + + private RedstoneWire.Connection getConnectionOnFace(BlockFace face) { + return getRedstoneWire().getFace(face); + } + + private Set getConnections() { + Set output = new HashSet<>(); + for (BlockFace face : getAllowedFaces()) { + if (getRedstoneWire().getFace(face) != RedstoneWire.Connection.NONE) { + output.add(face.name() + "/" + getConnectionOnFace(face).name()); + } + } + return output; + } + + private void debugValidDirection() { + Debug.echoError("Invalid direction! Must be \"NORTH\", \"EAST\", \"SOUTH\", or \"WEST\"!"); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return !getConnections().isEmpty() ? new ListTag(getConnections()).identify() : null; + } + + @Override + public String getPropertyId() { + return "redstone_connections"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ListTag(ElementTag/ElementTag) + // @mechanism MaterialTag.redstone_connections + // @group properties + // @description + // Returns a list of all connections that the redstone wire material has. + // --> + if (attribute.startsWith("redstone_connections")) { + return new ListTag(getConnections()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute ]> + // @returns ElementTag + // @mechanism MaterialTag.redstone_connections + // @group properties + // @description + // Returns the type of connection that the redstone wire material has in the specified direction. + // The direction can be NORTH, EAST, SOUTH, or WEST. The returned connection can be either SIDE or UP. + // NOTE: A connection of type SIDE also covers the case of the redstone wire going down the side of the block. + // --> + if (attribute.startsWith("redstone_connection_to") && attribute.hasContext(1)) { + String direction = attribute.getContext(1).toUpperCase(); + BlockFace face; + try { + face = BlockFace.valueOf(direction); + } + catch (IllegalArgumentException e) { + debugValidDirection(); + return null; + } + if (face != BlockFace.NORTH && face != BlockFace.EAST && face != BlockFace.SOUTH && face != BlockFace.WEST) { + debugValidDirection(); + return null; + } + return new ElementTag(getConnectionOnFace(face).name()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name redstone_connections + // @input ListTag(ElementTag/ElementTag) + // @description + // Sets the redstone wire material's connections. + // In the format DIRECTION/CONNECTION|... + // The direction can be NORTH, EAST, SOUTH, or WEST. + // The connection can be NONE, SIDE, or UP. + // NOTE: Setting a connection to NONE does nothing, as this disconnects the wire from that face. + // NOTE: A connection of type SIDE also covers the case of the redstone wire going down the side of the block. + // @tags + // + // ]> + // --> + if (mechanism.matches("redstone_connections") && mechanism.requireObject(ListTag.class)) { + for (BlockFace face : getAllowedFaces()) { + getRedstoneWire().setFace(face, RedstoneWire.Connection.NONE); + } + + for (String data : mechanism.valueAsType(ListTag.class)) { + List faceData = CoreUtilities.split(data, '/'); + + BlockFace face; + RedstoneWire.Connection connection; + if (faceData.size() != 2) { + continue; + } + try { + face = BlockFace.valueOf(faceData.get(0).toUpperCase()); + connection = RedstoneWire.Connection.valueOf(faceData.get(1).toUpperCase()); + } + catch (IllegalArgumentException e) { + continue; + } + + getRedstoneWire().setFace(face, connection); + } + } + } +}