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..2f12a493c1 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.*; @@ -167,15 +166,22 @@ public static void registermainProperties() { PropertyParser.registerProperty(MaterialLeaves.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(MaterialRailShape.class, MaterialTag.class); PropertyParser.registerProperty(MaterialRedstonePower.class, MaterialTag.class); - PropertyParser.registerProperty(MaterialRotation.class, MaterialTag.class); - PropertyParser.registerProperty(MaterialSnowy.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialRepeaterDelay.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialSaplingStage.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialSeaPickles.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialSnowLayers.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialStairsShape.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialStructureBlockMode.class, MaterialTag.class); PropertyParser.registerProperty(MaterialSwitchFace.class, MaterialTag.class); - PropertyParser.registerProperty(MaterialWaterlogged.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialTntUnstable.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialTripwireDisarmed.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialTurtleEggsAmount.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialTurtleEggsHatch.class, MaterialTag.class); + } + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_14)) { + PropertyParser.registerProperty(MaterialScaffoldingBottom.class,MaterialTag.class); + PropertyParser.registerProperty(MaterialScaffoldingDistanceToBottom.class, MaterialTag.class); } // register core TradeTag properties diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialRepeaterDelay.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialRepeaterDelay.java new file mode 100644 index 0000000000..883ddb14ca --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialRepeaterDelay.java @@ -0,0 +1,146 @@ +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.Repeater; + +public class MaterialRepeaterDelay implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Repeater; + } + + public static MaterialRepeaterDelay getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialRepeaterDelay((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "delay", "max_delay", "min_delay" + }; + + public static final String[] handledMechs = new String[] { + "delay" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialRepeaterDelay(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Repeater getRepeater() { + return (Repeater) material.getModernData().data; + } + + private int getDelay() { + return getRepeater().getDelay(); + } + + private int getMaxDelay() { + return getRepeater().getMaximumDelay(); + } + + private int getMinDelay() { + return getRepeater().getMinimumDelay(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return getDelay() != getMinDelay() ? String.valueOf(getDelay()) : null; + } + + @Override + public String getPropertyId() { + return "delay"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @group properties + // @description + // Returns the maximum delay the redstone repeater material can have. + // --> + if (attribute.startsWith("max_delay")) { + return new ElementTag(getMaxDelay()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @group properties + // @description + // Returns the minimum delay the redstone repeater material can have. + // --> + if (attribute.startsWith("min_delay")) { + return new ElementTag(getMinDelay()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @mechanism MaterialTag.delay + // @group properties + // @description + // Returns the delay the redstone repeater material currently has. + // --> + if (attribute.startsWith("delay")) { + return new ElementTag(getDelay()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name delay + // @input ElementTag(Number) + // @description + // Sets the delay of the redstone repeater material. + // @tags + // + // + // + // --> + if (mechanism.matches("delay") && mechanism.requireInteger()) { + int delay = mechanism.getValue().asInt(); + if (delay < getMinDelay() || delay > getMaxDelay()) { + Debug.echoError("Invalid delay specified! Must be between '" + getMinDelay() + "' and '" + getMaxDelay() + "'!"); + return; + } + getRepeater().setDelay(delay); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialSaplingStage.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialSaplingStage.java new file mode 100644 index 0000000000..ef37d64c4b --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialSaplingStage.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.Sapling; + +public class MaterialSaplingStage implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Sapling; + } + + public static MaterialSaplingStage getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialSaplingStage((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "growth_stage", "max_growth_stage" + }; + + public static final String[] handledMechs = new String[] { + "growth_stage" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialSaplingStage(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Sapling getSapling() { + return (Sapling) material.getModernData().data; + } + + private int getStage() { + return getSapling().getStage(); + } + + private int getMaxStage() { + return getSapling().getMaximumStage(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return getStage() != 0 ? String.valueOf(getStage()) : null; + } + + @Override + public String getPropertyId() { + return "growth_stage"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @group properties + // @description + // Returns the maximum growth stage of the sapling or bamboo material. + // Once the material's growth stage reaches this number, the material will attempt to grow into a tree as its next stage. + // --> + if (attribute.startsWith("max_growth_stage")) { + return new ElementTag(getMaxStage()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @mechanism MaterialTag.growth_stage + // @group properties + // @description + // Returns the growth stage of the sapling or bamboo material. + // --> + if (attribute.startsWith("growth_stage")) { + return new ElementTag(getStage()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name growth_stage + // @input ElementTag(Number) + // @description + // Sets the growth stage of the sapling or bamboo material. + // @tags + // + // + // --> + if (mechanism.matches("growth_stage") && mechanism.requireInteger()) { + int stage = mechanism.getValue().asInt(); + if (stage < 0 || stage > getMaxStage()) { + Debug.echoError("The growth stage must be between '0' and '" + getMaxStage() + "'!"); + return; + } + getSapling().setStage(stage); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialScaffoldingBottom.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialScaffoldingBottom.java new file mode 100644 index 0000000000..23424e870e --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialScaffoldingBottom.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.Scaffolding; + +public class MaterialScaffoldingBottom implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Scaffolding; + } + + public static MaterialScaffoldingBottom getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialScaffoldingBottom((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "is_bottom" + }; + + public static final String[] handledMechs = new String[] { + "is_bottom" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialScaffoldingBottom(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Scaffolding getScaffolding() { + return (Scaffolding) material.getModernData().data; + } + + private boolean isBottom() { + return getScaffolding().isBottom(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return isBottom() ? "true" : null; + } + + @Override + public String getPropertyId() { + return "is_bottom"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @mechanism MaterialTag.is_bottom + // @group properties + // @description + // Returns whether this scaffolding material is a "bottom" scaffolding. + // If false, then the scaffolding should be on top of another scaffolding. + // --> + if (attribute.startsWith("is_bottom")) { + return new ElementTag(isBottom()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name is_bottom + // @input ElementTag(Boolean) + // @description + // Sets whether this scaffolding material is a "bottom" scaffolding. + // @tags + // + // --> + if (mechanism.matches("is_bottom") && mechanism.requireBoolean()) { + getScaffolding().setBottom(mechanism.getValue().asBoolean()); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialScaffoldingDistanceToBottom.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialScaffoldingDistanceToBottom.java new file mode 100644 index 0000000000..716d1d1685 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialScaffoldingDistanceToBottom.java @@ -0,0 +1,119 @@ +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.Scaffolding; + +public class MaterialScaffoldingDistanceToBottom implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Scaffolding; + } + + public static MaterialScaffoldingDistanceToBottom getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialScaffoldingDistanceToBottom((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "distance_to_bottom", "max_distance_to_bottom" + }; + + public static final String[] handledMechs = new String[] { + "distance_to_bottom" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialScaffoldingDistanceToBottom(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Scaffolding getScaffolding() { + return (Scaffolding) material.getModernData().data; + } + + private int getDistance() { + return getScaffolding().getDistance(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return !getScaffolding().isBottom() ? String.valueOf(getDistance()) : null; + } + + @Override + public String getPropertyId() { + return "distance_to_bottom"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @group properties + // @description + // Returns the maximum distance the scaffolding material can have from a "bottom" scaffolding. + // --> + if (attribute.startsWith("distance_to_bottom")) { + return new ElementTag(getDistance()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @mechanism MaterialTag.distance_to_bottom + // @group properties + // @description + // Returns how far the scaffolding material is from a "bottom" scaffolding. + // --> + if (attribute.startsWith("distance_to_bottom")) { + return new ElementTag(getDistance()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name distance_to_bottom + // @input ElementTag(Boolean) + // @description + // Sets how far the scaffolding material is from a "bottom" scaffolding. + // @tags + // + // --> + if (mechanism.matches("distance_to_bottom") && mechanism.requireInteger()) { + getScaffolding().setDistance(mechanism.getValue().asInt()); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialSeaPickles.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialSeaPickles.java new file mode 100644 index 0000000000..2d7721e909 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialSeaPickles.java @@ -0,0 +1,146 @@ +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.SeaPickle; + +public class MaterialSeaPickles implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof SeaPickle; + } + + public static MaterialSeaPickles getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialSeaPickles((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "pickles", "min_pickles", "max_pickles" + }; + + public static final String[] handledMechs = new String[] { + "pickles" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialSeaPickles(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private SeaPickle getSeaPickle() { + return (SeaPickle) material.getModernData().data; + } + + private int getPickles() { + return getSeaPickle().getPickles(); + } + + private int getMinPickles() { + return getSeaPickle().getMinimumPickles(); + } + + private int getMaxPickles() { + return getSeaPickle().getMaximumPickles(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return getPickles() != getMinPickles() ? String.valueOf(getPickles()) : null; + } + + @Override + public String getPropertyId() { + return "pickles"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @group properties + // @description + // Returns the maximum number of pickles the sea pickle material can have. + // --> + if (attribute.startsWith("min_pickles")) { + return new ElementTag(getMinPickles()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @group properties + // @description + // Returns the minimum number of pickles the sea pickle material can have. + // --> + if (attribute.startsWith("max_pickles")) { + return new ElementTag(getMaxPickles()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @mechanism MaterialTag.pickles + // @group properties + // @description + // Returns how many pickles the sea pickle material has. + // --> + if (attribute.startsWith("pickles")) { + return new ElementTag(getPickles()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name pickles + // @input ElementTag(Number) + // @description + // Sets how many pickles the sea pickle material has. + // @tags + // + // + // + // --> + if (mechanism.matches("pickles") && mechanism.requireInteger()) { + int pickles = mechanism.getValue().asInt(); + if (pickles < getMinPickles() || pickles > getMaxPickles()) { + Debug.echoError("The number of pickles must be between '" + getMinPickles() + "' and '" + getMaxPickles() + "'!"); + return; + } + getSeaPickle().setPickles(pickles); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialSnowLayers.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialSnowLayers.java new file mode 100644 index 0000000000..553318824a --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialSnowLayers.java @@ -0,0 +1,146 @@ +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.Snow; + +public class MaterialSnowLayers implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Snow; + } + + public static MaterialSnowLayers getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialSnowLayers((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "snow_layers", "min_snow_layers", "max_snow_layers" + }; + + public static final String[] handledMechs = new String[] { + "snow_layers" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialSnowLayers(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Snow getSnow() { + return (Snow) material.getModernData().data; + } + + private int getLayers() { + return getSnow().getLayers(); + } + + private int getMinLayers() { + return getSnow().getMinimumLayers(); + } + + private int getMaxLayers() { + return getSnow().getMaximumLayers(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return getLayers() != getMinLayers() ? String.valueOf(getLayers()) : null; + } + + @Override + public String getPropertyId() { + return "snow_layers"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @group properties + // @description + // Returns the minimum amount of layers this snow layer material can have. + // --> + if (attribute.startsWith("min_snow_layers")) { + return new ElementTag(getMinLayers()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @group properties + // @description + // Returns the maximum amount of layers this snow layer material can have. + // --> + if (attribute.startsWith("max_snow_layers")) { + return new ElementTag(getMaxLayers()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @mechanism MaterialTag.snow_layers + // @group properties + // @description + // Returns the amount of layers this snow layer material can have. + // --> + if (attribute.startsWith("snow_layers")) { + return new ElementTag(getLayers()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name snow_layers + // @input ElementTag(Number) + // @description + // Sets the amount of layers this snow layer can have. + // @tags + // + // + // + // --> + if (mechanism.matches("snow_layers") && mechanism.requireInteger()) { + int layers = mechanism.getValue().asInt(); + if (layers < getMinLayers() || layers > getMaxLayers()) { + Debug.echoError("The number of snow layers must be between '" + getMinLayers() + "' and '" + getMaxLayers() + "'!"); + return; + } + getSnow().setLayers(layers); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialStairsShape.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialStairsShape.java new file mode 100644 index 0000000000..3130e41bf3 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialStairsShape.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.Stairs; + +public class MaterialStairsShape implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Stairs; + } + + public static MaterialStairsShape getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialStairsShape((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "stair_shape" + }; + + public static final String[] handledMechs = new String[] { + "stair_shape" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialStairsShape(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Stairs getStairs() { + return (Stairs) material.getModernData().data; + } + + private String getShape() { + return getStairs().getShape().name(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return getStairs().getShape() != Stairs.Shape.STRAIGHT ? getShape() : null; + } + + @Override + public String getPropertyId() { + return "stair_shape"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @mechanism MaterialTag.stair_shape + // @group properties + // @description + // Returns the shape of the stairs material. + // Can be any of: <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/type/Stairs.Shape.html> + // --> + if (attribute.startsWith("stair_shape")) { + return new ElementTag(getShape()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name stair_shape + // @input ElementTag + // @description + // Sets the shape of the stairs material. + // Can be any of: <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/type/Stairs.Shape.html> + // @tags + // + // --> + if (mechanism.matches("stair_shape") && mechanism.requireEnum(false, Stairs.Shape.values())) { + getStairs().setShape(Stairs.Shape.valueOf(mechanism.getValue().asString().toUpperCase())); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialStructureBlockMode.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialStructureBlockMode.java new file mode 100644 index 0000000000..637f85b75c --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialStructureBlockMode.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.StructureBlock; + +public class MaterialStructureBlockMode implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof StructureBlock; + } + + public static MaterialStructureBlockMode getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialStructureBlockMode((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "mode" + }; + + public static final String[] handledMechs = new String[] { + "mode" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialStructureBlockMode(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private StructureBlock getStructureBlock() { + return (StructureBlock) material.getModernData().data; + } + + private String getMode() { + return getStructureBlock().getMode().name(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return getMode(); + } + + @Override + public String getPropertyId() { + return "mode"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag + // @mechanism MaterialTag.mode + // @group properties + // @description + // Returns the mode of the structure block material. + // Can be any of: <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/type/StructureBlock.Mode.html> + // --> + if (attribute.startsWith("mode")) { + return new ElementTag(getMode()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name mode + // @input ElementTag + // @description + // Sets the mode of the structure block material. + // Can be any of: <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/type/StructureBlock.Mode.html> + // @tags + // + // --> + if (mechanism.matches("mode") && mechanism.requireEnum(false, StructureBlock.Mode.values())) { + getStructureBlock().setMode(StructureBlock.Mode.valueOf(mechanism.getValue().asString().toUpperCase())); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialTntUnstable.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialTntUnstable.java new file mode 100644 index 0000000000..f05fc15a65 --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialTntUnstable.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.TNT; + +public class MaterialTntUnstable implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof TNT; + } + + public static MaterialTntUnstable getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialTntUnstable((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "unstable" + }; + + public static final String[] handledMechs = new String[] { + "unstable" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialTntUnstable(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private TNT getTnt() { + return (TNT) material.getModernData().data; + } + + private boolean isUnstable() { + return getTnt().isUnstable(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return isUnstable() ? "true" : null; + } + + @Override + public String getPropertyId() { + return "unstable"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @mechanism MaterialTag.unstable + // @group properties + // @description + // Returns whether the TNT material is unstable. + // If true, then punching the material will cause it to explode. + // --> + if (attribute.startsWith("unstable")) { + return new ElementTag(isUnstable()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name unstable + // @input ElementTag(Boolean) + // @description + // Sets whether the TNT material is unstable. + // If true, then punching the material will cause it to explode. + // @tags + // + // --> + if (mechanism.matches("unstable") && mechanism.requireBoolean()) { + getTnt().setUnstable(mechanism.getValue().asBoolean()); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialTripwireDisarmed.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialTripwireDisarmed.java new file mode 100644 index 0000000000..473e64697b --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialTripwireDisarmed.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.Tripwire; + +public class MaterialTripwireDisarmed implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof Tripwire; + } + + public static MaterialTripwireDisarmed getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialTripwireDisarmed((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "disarmed" + }; + + public static final String[] handledMechs = new String[] { + "disarmed" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialTripwireDisarmed(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private Tripwire getTripwire() { + return (Tripwire) material.getModernData().data; + } + + private boolean isDisarmed() { + return getTripwire().isDisarmed(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + // The natural state of a tripwire string is disarmed. + return !isDisarmed() ? "false" : null; + } + + @Override + public String getPropertyId() { + return "disarmed"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @mechanism MaterialTag.disarmed + // @group properties + // @description + // Returns whether this tripwire material is disarmed. + // If true, then breaking the material will not produce a current. + // --> + if (attribute.startsWith("disarmed")) { + return new ElementTag(isDisarmed()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name disarmed + // @input ElementTag(Boolean) + // @description + // Sets whether this tripwire material is disarmed. + // If true, then breaking the material will not produce a current. + // @tags + // + // --> + if (mechanism.matches("disarmed") && mechanism.requireBoolean()) { + getTripwire().setDisarmed(mechanism.getValue().asBoolean()); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialTurtleEggsAmount.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialTurtleEggsAmount.java new file mode 100644 index 0000000000..b29ceba6ad --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialTurtleEggsAmount.java @@ -0,0 +1,146 @@ +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.TurtleEgg; + +public class MaterialTurtleEggsAmount implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof TurtleEgg; + } + + public static MaterialTurtleEggsAmount getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialTurtleEggsAmount((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "eggs" + }; + + public static final String[] handledMechs = new String[] { + "eggs" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialTurtleEggsAmount(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private TurtleEgg getTurtleEgg() { + return (TurtleEgg) material.getModernData().data; + } + + private int getAmount() { + return getTurtleEgg().getEggs(); + } + + private int getMinAmount() { + return getTurtleEgg().getMinimumEggs(); + } + + private int getMaxAmount() { + return getTurtleEgg().getMaximumEggs(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return getAmount() != getMinAmount() ? String.valueOf(getAmount()) : null; + } + + @Override + public String getPropertyId() { + return "eggs"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @group properties + // @description + // Returns the minimum number of eggs that the turtle egg material can have. + // --> + if (attribute.startsWith("min_eggs")) { + return new ElementTag(getMinAmount()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @group properties + // @description + // Returns the maximum number of eggs that the turtle egg material can have. + // --> + if (attribute.startsWith("max_eggs")) { + return new ElementTag(getMaxAmount()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @mechanism MaterialTag.eggs + // @group properties + // @description + // Returns the number of eggs that the turtle egg material has. + // --> + if (attribute.startsWith("eggs")) { + return new ElementTag(getAmount()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name eggs + // @input ElementTag(Number) + // @description + // Sets how many eggs this turtle egg material has. + // @tags + // + // + // + // --> + if (mechanism.matches("eggs") && mechanism.requireInteger()) { + int eggs = mechanism.getValue().asInt(); + if (eggs < getMinAmount() || eggs > getMaxAmount()) { + Debug.echoError("The egg count must be between '" + getMinAmount() + "' and '" + getMaxAmount() + "'!"); + return; + } + getTurtleEgg().setEggs(eggs); + } + } +} diff --git a/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialTurtleEggsHatch.java b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialTurtleEggsHatch.java new file mode 100644 index 0000000000..8e1c9fec5a --- /dev/null +++ b/plugin/src/main/java/dev/unizen/denizen/objects/properties/material/MaterialTurtleEggsHatch.java @@ -0,0 +1,147 @@ +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.TurtleEgg; + +public class MaterialTurtleEggsHatch implements Property { + + public static boolean describes(ObjectTag material) { + return material instanceof MaterialTag + && ((MaterialTag) material).hasModernData() + && ((MaterialTag) material).getModernData().data instanceof TurtleEgg; + } + + public static MaterialTurtleEggsHatch getFrom(ObjectTag material) { + if (!describes(material)) { + return null; + } + return new MaterialTurtleEggsHatch((MaterialTag) material); + } + + public static final String[] handledTags = new String[] { + "hatch", "min_hatch", "max_hatch" + }; + + public static final String[] handledMechs = new String[] { + "hatch" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private MaterialTurtleEggsHatch(MaterialTag material) { + this.material = material; + } + + private MaterialTag material; + + private TurtleEgg getTurtleEgg() { + return (TurtleEgg) material.getModernData().data; + } + + private int getHatch() { + return getTurtleEgg().getHatch(); + } + + private int getMinHatch() { + return getTurtleEgg().getMinimumEggs(); + } + + private int getMaxHatch() { + return getTurtleEgg().getMaximumHatch(); + } + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return getHatch() != getMinHatch() ? String.valueOf(getHatch()) : null; + } + + @Override + public String getPropertyId() { + return "hatch"; + } + + /////////// + // ObjectTag Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + if (attribute == null) { + return null; + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @group properties + // @description + // Returns the minimum value that the hatch property of the turtle egg material may have. + // --> + if (attribute.startsWith("min_hatch")) { + return new ElementTag(getMinHatch()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @group properties + // @description + // Returns the maximum value that the hatch property of the turtle egg material may have. + // --> + if (attribute.startsWith("max_hatch")) { + return new ElementTag(getMaxHatch()).getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @mechanism MaterialTag.hatch + // @group properties + // @description + // Returns the value of the hatch property of the turtle egg material. + // --> + if (attribute.startsWith("hatch")) { + return new ElementTag(getHatch()).getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object MaterialTag + // @name hatch + // @input ElementTag(Number) + // @description + // Sets the value of the hatch property of the turtle egg material. + // When the hatch value is at the maximum allowed value, the turtle egg will be very close to hatching. + // @tags + // + // + // + // --> + if (mechanism.matches("hatch") && mechanism.requireInteger()) { + int hatch = mechanism.getValue().asInt(); + if (hatch < getMinHatch() || hatch > getMinHatch()) { + Debug.echoError("The value of the hatch property must be between '" + getMinHatch() + "' and '" + getMaxHatch() + "'!"); + return; + } + getTurtleEgg().setHatch(hatch); + } + } +}