diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialLocked.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialLocked.java index 76fe9d9a1d..317778d4f6 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialLocked.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialLocked.java @@ -2,52 +2,46 @@ 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.Repeater; -public class MaterialLocked implements Property { +public class MaterialLocked extends MaterialProperty { - public static boolean describes(ObjectTag material) { - return material instanceof MaterialTag - && ((MaterialTag) material).hasModernData() - && ((MaterialTag) material).getModernData() instanceof Repeater; - } + // <--[property] + // @object MaterialTag + // @name is_locked + // @input ElementTag(Boolean) + // @description + // Controls whether this redstone repeater material is locked. + // --> - public static MaterialLocked getFrom(ObjectTag _material) { - if (!describes(_material)) { - return null; - } - else { - return new MaterialLocked((MaterialTag) _material); - } + public static boolean describes(MaterialTag material) { + BlockData data = material.getModernData(); + return data instanceof Repeater; } - public static final String[] handledMechs = new String[] { - "is_locked" - }; + MaterialTag material; - public MaterialLocked(MaterialTag _material) { - material = _material; + @Override + public ElementTag getPropertyValue() { + return new ElementTag(isLocked()); } - MaterialTag material; + @Override + public String getPropertyId() { + return "is_locked"; + } - public static void register() { + @Override + public void setPropertyValue(ElementTag value, Mechanism mechanism) { + if (mechanism.requireBoolean()) { + getRepeater().setLocked(value.asBoolean()); + } + } - // <--[tag] - // @attribute - // @returns ElementTag(Boolean) - // @mechanism MaterialTag.is_locked - // @group properties - // @description - // Returns whether this redstone repeater material is locked. - // --> - PropertyParser.registerStaticTag(MaterialLocked.class, ElementTag.class, "is_locked", (attribute, material) -> { - return new ElementTag(material.isLocked()); - }); + public static void register() { + autoRegister("is_locked", MaterialLocked.class, ElementTag.class, true); } public Repeater getRepeater() { @@ -57,31 +51,4 @@ public Repeater getRepeater() { public boolean isLocked() { return getRepeater().isLocked(); } - - @Override - public String getPropertyString() { - return String.valueOf(isLocked()); - } - - @Override - public String getPropertyId() { - return "is_locked"; - } - - @Override - public void adjust(Mechanism mechanism) { - - // <--[mechanism] - // @object MaterialTag - // @name is_locked - // @input ElementTag(Boolean) - // @description - // Sets this redstone repeater material to be locked. - // @tags - // - // --> - if (mechanism.matches("is_locked") && mechanism.requireBoolean()) { - getRepeater().setLocked(mechanism.getValue().asBoolean()); - } - } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialMode.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialMode.java index 3dfb61c2cc..75fb4716b5 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialMode.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialMode.java @@ -4,25 +4,35 @@ 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.ElementTag; -import com.denizenscript.denizencore.objects.properties.Property; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import com.denizenscript.denizencore.utilities.CoreUtilities; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.*; -public class MaterialMode 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(); +public class MaterialMode extends MaterialProperty { + + // <--[property] + // @object MaterialTag + // @name mode + // @input ElementTag + // @description + // Controls a block's mode. + // Valid values vary by block type. + // For comparators, either COMPARE or SUBTRACT. + // For piston_heads, either NORMAL or SHORT. + // For bubble_columns, either NORMAL or DRAG. + // For structure_blocks, either CORNER, DATA, LOAD, or SAVE. + // For sculk_sensors, either ACTIVE, COOLDOWN, or INACTIVE. + // For daylight_detectors, either INVERTED or NORMAL. + // For command_blocks, either CONDITIONAL or NORMAL. + // For big_dripleafs, either FULL, NONE, PARTIAL, or UNSTABLE. + // For sculk_catalysts, either BLOOM or NORMAL. + // For sculk_shriekers, either SHRIEKING or NORMAL. + // For tripwires, either ARMED or DISARMED. + // --> + + public static boolean describes(MaterialTag material) { + BlockData data = material.getModernData(); return data instanceof Comparator || data instanceof PistonHead || data instanceof BubbleColumn @@ -33,52 +43,93 @@ public static boolean describes(ObjectTag material) { || data instanceof BigDripleaf || data instanceof Tripwire || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && (data instanceof SculkCatalyst - || data instanceof SculkShrieker)); + || data instanceof SculkShrieker)); + } + + public MaterialTag material; + + @Override + public String getPropertyId() { + return "mode"; } - public static MaterialMode getFrom(ObjectTag _material) { - if (!describes(_material)) { - return null; + @Override + public ElementTag getPropertyValue() { + if (isComparator()) { + return new ElementTag(getComparator().getMode().name()); } - else { - return new MaterialMode((MaterialTag) _material); + else if (isBubbleColumn()) { + return new ElementTag(getBubbleColumn().isDrag() ? "DRAG" : "NORMAL"); + } + else if (isPistonHead()) { + return new ElementTag(getPistonHead().isShort() ? "SHORT" : "NORMAL"); + } + else if (isStructureBlock()) { + return new ElementTag(getStructureBlock().getMode().name()); + } + else if (isDaylightDetector()) { + return new ElementTag(getDaylightDetector().isInverted() ? "INVERTED" : "NORMAL"); + } + else if (isCommandBlock()) { + return new ElementTag(getCommandBlock().isConditional() ? "CONDITIONAL" : "NORMAL"); + } + else if (isSculkSensor()) { + return new ElementTag(getSculkSensor().getPhase().name()); } + else if (isBigDripleaf()) { + return new ElementTag(getBigDripleaf().getTilt().name()); + } + else if (isTripwire()) { + return new ElementTag(getTripwire().isDisarmed() ? "DISARMED" : "ARMED"); + } + else if (isSculkCatalyst()) { + return new ElementTag(((SculkCatalyst) material.getModernData()).isBloom() ? "BLOOM" : "NORMAL"); // TODO: 1.19 + } + else if (isSculkShrieker()) { + return new ElementTag(((SculkShrieker) material.getModernData()).isShrieking() ? "SHRIEKING" : "NORMAL"); // TODO: 1.19 + } + return null; // Unreachable } - public static final String[] handledMechs = new String[] { - "mode" - }; - - public MaterialMode(MaterialTag _material) { - material = _material; + @Override + public void setPropertyValue(ElementTag value, Mechanism mechanism) { + if (isComparator() && mechanism.requireEnum(Comparator.Mode.class)) { + getComparator().setMode(Comparator.Mode.valueOf(value.asString().toUpperCase())); + } + else if (isBubbleColumn()) { + getBubbleColumn().setDrag(CoreUtilities.equalsIgnoreCase(value.asString(), "drag")); + } + else if (isPistonHead()) { + getPistonHead().setShort(CoreUtilities.equalsIgnoreCase(value.asString(), "short")); + } + else if (isStructureBlock() && mechanism.requireEnum(StructureBlock.Mode.class)) { + getStructureBlock().setMode(StructureBlock.Mode.valueOf(value.asString().toUpperCase())); + } + else if (isDaylightDetector()) { + getDaylightDetector().setInverted(CoreUtilities.equalsIgnoreCase(value.asString(), "inverted")); + } + else if (isCommandBlock()) { + getCommandBlock().setConditional(CoreUtilities.equalsIgnoreCase(value.asString(), "conditional")); + } + else if (isSculkSensor() && mechanism.requireEnum(SculkSensor.Phase.class)) { + getSculkSensor().setPhase(SculkSensor.Phase.valueOf(value.asString().toUpperCase())); + } + else if (isBigDripleaf() && mechanism.requireEnum(BigDripleaf.Tilt.class)) { + getBigDripleaf().setTilt(BigDripleaf.Tilt.valueOf(value.asString().toUpperCase())); + } + else if (isTripwire()) { + getTripwire().setDisarmed(CoreUtilities.equalsIgnoreCase(value.asString(), "disarmed")); + } + else if (isSculkCatalyst()) { + ((SculkCatalyst) material.getModernData()).setBloom(CoreUtilities.equalsIgnoreCase(value.asString(), "bloom")); // TODO: 1.19 + } + else if (isSculkShrieker()) { + ((SculkShrieker) material.getModernData()).setShrieking(CoreUtilities.equalsIgnoreCase(value.asString(), "shrieking")); // TODO: 1.19 + } } - public MaterialTag material; - public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag - // @mechanism MaterialTag.mode - // @group properties - // @description - // Returns a block's mode. - // For comparators, output is COMPARE or SUBTRACT. - // For piston_heads, output is NORMAL or SHORT. - // For bubble_columns, output is NORMAL or DRAG. - // For structure_blocks, output is CORNER, DATA, LOAD, or SAVE. - // For sculk_sensors, output is ACTIVE, COOLDOWN, or INACTIVE. - // For daylight_detectors, output is INVERTED or NORMAL. - // For command_blocks, output is CONDITIONAL or NORMAL. - // For big_dripleafs, output is FULL, NONE, PARTIAL, or UNSTABLE. - // For sculk_catalysts, output is BLOOM or NORMAL. - // For sculk_shriekers, output is SHRIEKING or NORMAL. - // For tripwires, output is ARMED or DISARMED. - // --> - PropertyParser.registerStaticTag(MaterialMode.class, ElementTag.class, "mode", (attribute, material) -> { - return new ElementTag(material.getPropertyString()); - }); + autoRegister("mode", MaterialMode.class, ElementTag.class, true); } public boolean isComparator() { @@ -169,106 +220,4 @@ public SculkShrieker getSculkShrieker() { return (SculkShrieker) material.getModernData(); }*/ - @Override - public String getPropertyString() { - if (isComparator()) { - return getComparator().getMode().name(); - } - else if (isBubbleColumn()) { - return getBubbleColumn().isDrag() ? "DRAG" : "NORMAL"; - } - else if (isPistonHead()) { - return getPistonHead().isShort() ? "SHORT" : "NORMAL"; - } - else if (isStructureBlock()) { - return getStructureBlock().getMode().name(); - } - else if (isDaylightDetector()) { - return getDaylightDetector().isInverted() ? "INVERTED" : "NORMAL"; - } - else if (isCommandBlock()) { - return getCommandBlock().isConditional() ? "CONDITIONAL" : "NORMAL"; - } - else if (isSculkSensor()) { - return getSculkSensor().getPhase().name(); - } - else if (isBigDripleaf()) { - return getBigDripleaf().getTilt().name(); - } - else if (isTripwire()) { - return getTripwire().isDisarmed() ? "DISARMED" : "ARMED"; - } - else if (isSculkCatalyst()) { - return ((SculkCatalyst) material.getModernData()).isBloom() ? "BLOOM" : "NORMAL"; // TODO: 1.19 - } - else if (isSculkShrieker()) { - return ((SculkShrieker) material.getModernData()).isShrieking() ? "SHRIEKING" : "NORMAL"; // TODO: 1.19 - } - return null; // Unreachable - } - - @Override - public String getPropertyId() { - return "mode"; - } - - @Override - public void adjust(Mechanism mechanism) { - - // <--[mechanism] - // @object MaterialTag - // @name mode - // @input ElementTag - // @description - // Set a block's mode. - // For comparators, input is COMPARE or SUBTRACT. - // For piston_heads, input is NORMAL or SHORT. - // For bubble_columns, input is NORMAL or DRAG. - // For structure_blocks, input is CORNER, DATA, LOAD, or SAVE. - // For sculk_sensors, input is ACTIVE, COOLDOWN, or INACTIVE. - // For daylight_detectors, input is INVERTED or NORMAL. - // For command_blocks, input is CONDITIONAL or NORMAL. - // For big_dripleafs, input is FULL, NONE, PARTIAL, or UNSTABLE. - // For sculk_catalysts, input is BLOOM or NORMAL. - // For sculk_shriekers, input is SHRIEKING or NORMAL. - // For tripwires, input is ARMED or DISARMED. - // @tags - // - // --> - if (mechanism.matches("mode")) { - if (isComparator() && mechanism.requireEnum(Comparator.Mode.class)) { - getComparator().setMode(Comparator.Mode.valueOf(mechanism.getValue().asString().toUpperCase())); - } - else if (isBubbleColumn()) { - getBubbleColumn().setDrag(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "drag")); - } - else if (isPistonHead()) { - getPistonHead().setShort(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "short")); - } - else if (isStructureBlock() && mechanism.requireEnum(StructureBlock.Mode.class)) { - getStructureBlock().setMode(StructureBlock.Mode.valueOf(mechanism.getValue().asString().toUpperCase())); - } - else if (isDaylightDetector()) { - getDaylightDetector().setInverted(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "inverted")); - } - else if (isCommandBlock()) { - getCommandBlock().setConditional(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "conditional")); - } - else if (isSculkSensor() && mechanism.requireEnum(SculkSensor.Phase.class)) { - getSculkSensor().setPhase(SculkSensor.Phase.valueOf(mechanism.getValue().asString().toUpperCase())); - } - else if (isBigDripleaf() && mechanism.requireEnum(BigDripleaf.Tilt.class)) { - getBigDripleaf().setTilt(BigDripleaf.Tilt.valueOf(mechanism.getValue().asString().toUpperCase())); - } - else if (isTripwire()) { - getTripwire().setDisarmed(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "disarmed")); - } - else if (isSculkCatalyst()) { - ((SculkCatalyst) material.getModernData()).setBloom(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "bloom")); // TODO: 1.19 - } - else if (isSculkShrieker()) { - ((SculkShrieker) material.getModernData()).setShrieking(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "shrieking")); // TODO: 1.19 - } - } - } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialNote.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialNote.java index b6ca22879d..b3dde8a76e 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialNote.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialNote.java @@ -2,41 +2,49 @@ 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.Note; +import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.NoteBlock; -public class MaterialNote implements Property { +public class MaterialNote extends MaterialProperty { - public static boolean describes(ObjectTag material) { - return material instanceof MaterialTag - && ((MaterialTag) material).hasModernData() - && ((MaterialTag) material).getModernData() instanceof NoteBlock; - } + // <--[property] + // @object MaterialTag + // @name note + // @input ElementTag(Number) + // @description + // Controls the note played from this note block, as an ID number from 0 to 24. + // See also <@link tag MaterialTag.note_octave> and <@link tag MaterialTag.note_tone> + // --> - public static MaterialNote getFrom(ObjectTag _material) { - if (!describes(_material)) { - return null; - } - else { - return new MaterialNote((MaterialTag) _material); - } + public static boolean describes(MaterialTag material) { + BlockData data = material.getModernData(); + return data instanceof NoteBlock; } - public static final String[] handledMechs = new String[] { - "note" - }; + MaterialTag material; - public MaterialNote(MaterialTag _material) { - material = _material; + @Override + public String getPropertyId() { + return "note"; } - MaterialTag material; + @Override + public ElementTag getPropertyValue() { + return new ElementTag(getNoteBlock().getNote().getId()); + } + + @Override + public void setPropertyValue(ElementTag value, Mechanism mechanism) { + if (mechanism.requireInteger()) { + getNoteBlock().setNote(new Note(value.asInt())); + } + } public static void register() { + autoRegister("note", MaterialNote.class, ElementTag.class, true); // <--[tag] // @attribute @@ -63,50 +71,9 @@ public static void register() { Note note = material.getNoteBlock().getNote(); return new ElementTag(note.getTone().name() + (note.isSharped() ? "#" : "")); }); - - // <--[tag] - // @attribute - // @returns ElementTag(Number) - // @mechanism MaterialTag.note - // @group properties - // @description - // Returns the note played from this note block, as an ID number from 0 to 24. - // --> - PropertyParser.registerStaticTag(MaterialNote.class, ElementTag.class, "note", (attribute, material) -> { - return new ElementTag(material.getNoteBlock().getNote().getId()); - }); } public NoteBlock getNoteBlock() { return (NoteBlock) material.getModernData(); } - - @Override - public String getPropertyString() { - return String.valueOf(getNoteBlock().getNote().getId()); - } - - @Override - public String getPropertyId() { - return "note"; - } - - @Override - public void adjust(Mechanism mechanism) { - - // <--[mechanism] - // @object MaterialTag - // @name note - // @input ElementTag(Number) - // @description - // Sets the note played from this note block, as an ID number from 0 to 24. - // @tags - // - // - // - // --> - if (mechanism.matches("note") && mechanism.requireInteger()) { - getNoteBlock().setNote(new Note(mechanism.getValue().asInt())); - } - } }