diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialCount.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialCount.java index 560c24d862..5a63886d1f 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialCount.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialCount.java @@ -2,9 +2,7 @@ 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.Candle; @@ -12,44 +10,34 @@ import org.bukkit.block.data.type.SeaPickle; import org.bukkit.block.data.type.TurtleEgg; -public class MaterialCount 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 MaterialCount extends MaterialProperty { + + // <--[property] + // @object MaterialTag + // @name count + // @input ElementTag(Number) + // @description + // Controls the amount of pickles in a Sea Pickle material, eggs in a Turtle Egg material, charges in a Respawn Anchor material, or candles in a Candle material. + // See also: + // <@link tag MaterialTag.count> + // <@link tag MaterialTag.count_min> + // <@link tag MaterialTag.count_max> + // --> + + public static boolean describes(MaterialTag material) { + BlockData data = material.getModernData(); return data instanceof SeaPickle || data instanceof TurtleEgg || data instanceof RespawnAnchor || data instanceof Candle; } - public static MaterialCount getFrom(ObjectTag _material) { - if (!describes(_material)) { - return null; - } - else { - return new MaterialCount((MaterialTag) _material); - } - } - - public static final String[] handledMechs = new String[] { - "count", "pickle_count" - }; - - public MaterialCount(MaterialTag _material) { - material = _material; - } - MaterialTag material; public static void register() { + autoRegister("count", MaterialCount.class, ElementTag.class, true, "pickle_count"); + // <--[tag] // @attribute // @returns ElementTag(Number) @@ -168,47 +156,36 @@ else if (isCandle()) { } @Override - public String getPropertyString() { - return String.valueOf(getCurrent()); + public ElementTag getPropertyValue() { + return new ElementTag(getCurrent()); } @Override - public String getPropertyId() { - return "count"; + public void setPropertyValue(ElementTag elementTag, Mechanism mechanism) { + if (!mechanism.requireInteger()) { + return; + } + int count = elementTag.asInt(); + if (count < getMin() || count > getMax()) { + mechanism.echoError("Material count mechanism value '" + count + "' is not valid. Must be between " + getMin() + " and " + getMax() + "."); + return; + } + if (isSeaPickle()) { + getSeaPickle().setPickles(count); + } + else if (isTurtleEgg()) { + getTurtleEgg().setEggs(count); + } + else if (isRespawnAnchor()) { + getRespawnAnchor().setCharges(count); + } + else if (isCandle()) { + getCandle().setCandles(count); + } } @Override - public void adjust(Mechanism mechanism) { - - // <--[mechanism] - // @object MaterialTag - // @name count - // @input ElementTag(Number) - // @description - // Sets the amount of pickles in a Sea Pickle material, eggs in a Turtle Egg material, charges in a Respawn Anchor material, or candles in a Candle material. - // @tags - // - // - // - // --> - if ((mechanism.matches("count") || (mechanism.matches("pickle_count"))) && mechanism.requireInteger()) { - int count = mechanism.getValue().asInt(); - if (count < getMin() || count > getMax()) { - mechanism.echoError("Material count mechanism value '" + count + "' is not valid. Must be between " + getMin() + " and " + getMax() + "."); - return; - } - if (isSeaPickle()) { - getSeaPickle().setPickles(count); - } - else if (isTurtleEgg()) { - getTurtleEgg().setEggs(count); - } - else if (isRespawnAnchor()) { - getRespawnAnchor().setCharges(count); - } - else if (isCandle()) { - getCandle().setCandles(count); - } - } + public String getPropertyId() { + return "count"; } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialUnstable.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialUnstable.java index b150b20160..c723e0fb2a 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialUnstable.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialUnstable.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.TNT; -public class MaterialUnstable implements Property { +public class MaterialUnstable extends MaterialProperty { - public static boolean describes(ObjectTag material) { - return material instanceof MaterialTag - && ((MaterialTag) material).hasModernData() - && ((MaterialTag) material).getModernData() instanceof TNT; - } + // <--[property] + // @object MaterialTag + // @name unstable + // @input ElementTag(Boolean) + // @description + // Controls whether this TNT block is unstable (explodes when punched). + // --> - public static MaterialUnstable getFrom(ObjectTag _material) { - if (!describes(_material)) { - return null; - } - else { - return new MaterialUnstable((MaterialTag) _material); - } + public static boolean describes(MaterialTag material) { + BlockData data = material.getModernData(); + return data instanceof TNT; } - public static final String[] handledMechs = new String[] { - "unstable" - }; + MaterialTag material; - public MaterialUnstable(MaterialTag _material) { - material = _material; + @Override + public String getPropertyId() { + return "unstable"; } - MaterialTag material; + @Override + public ElementTag getPropertyValue() { + return new ElementTag(isUnstable()); + } - public static void register() { + @Override + public void setPropertyValue(ElementTag value, Mechanism mechanism) { + if (mechanism.requireBoolean()) { + getTNT().setUnstable(value.asBoolean()); + } + } - // <--[tag] - // @attribute - // @returns ElementTag(Boolean) - // @mechanism MaterialTag.unstable - // @group properties - // @description - // Returns whether this TNT block is unstable (explodes when punched). - // --> - PropertyParser.registerStaticTag(MaterialUnstable.class, ElementTag.class, "unstable", (attribute, material) -> { - return new ElementTag(material.isUnstable()); - }); + public static void register() { + autoRegister("unstable", MaterialUnstable.class, ElementTag.class, true); } public TNT getTNT() { @@ -57,31 +51,4 @@ public TNT getTNT() { public boolean isUnstable() { return getTNT().isUnstable(); } - - @Override - public String getPropertyString() { - return String.valueOf(isUnstable()); - } - - @Override - public String getPropertyId() { - return "unstable"; - } - - @Override - public void adjust(Mechanism mechanism) { - - // <--[mechanism] - // @object MaterialTag - // @name unstable - // @input ElementTag(Boolean) - // @description - // Sets whether this TNT block is unstable (explodes when punched). - // @tags - // - // --> - if (mechanism.matches("unstable") && mechanism.requireBoolean()) { - getTNT().setUnstable(mechanism.getValue().asBoolean()); - } - } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialWaterlogged.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialWaterlogged.java index b7c7ad7816..7b39804579 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialWaterlogged.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialWaterlogged.java @@ -2,86 +2,45 @@ 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.Waterlogged; -public class MaterialWaterlogged implements Property { +public class MaterialWaterlogged extends MaterialProperty { - public static boolean describes(ObjectTag material) { - return material instanceof MaterialTag - && ((MaterialTag) material).hasModernData() - && ((MaterialTag) material).getModernData() instanceof Waterlogged; - } - - public static MaterialWaterlogged getFrom(ObjectTag _material) { - if (!describes(_material)) { - return null; - } - else { - return new MaterialWaterlogged((MaterialTag) _material); - } - } - - public static final String[] handledMechs = new String[] { - "waterlogged" - }; + // <--[property] + // @object MaterialTag + // @name waterlogged + // @input ElementTag(Boolean) + // @description + // Controls whether this block is waterlogged. + // --> - public MaterialWaterlogged(MaterialTag _material) { - material = _material; + public static boolean describes(MaterialTag material) { + BlockData data = material.getModernData(); + return data instanceof Waterlogged; } MaterialTag material; - public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Boolean) - // @mechanism MaterialTag.waterlogged - // @group properties - // @description - // Returns whether this block is waterlogged or not. - // --> - PropertyParser.registerStaticTag(MaterialWaterlogged.class, ElementTag.class, "waterlogged", (attribute, material) -> { - return new ElementTag(material.isWaterlogged()); - }); - } - - public Waterlogged getWaterlogged() { - return (Waterlogged) material.getModernData(); - } - - public boolean isWaterlogged() { - return getWaterlogged().isWaterlogged(); - } - - @Override - public String getPropertyString() { - return String.valueOf(isWaterlogged()); - } - @Override public String getPropertyId() { return "waterlogged"; } @Override - public void adjust(Mechanism mechanism) { + public ElementTag getPropertyValue() { + return new ElementTag(((Waterlogged) material.getModernData()).isWaterlogged()); + } - // <--[mechanism] - // @object MaterialTag - // @name waterlogged - // @input ElementTag(Boolean) - // @description - // Sets this block to be waterlogged, or not. - // @tags - // - // --> - if (mechanism.matches("waterlogged") && mechanism.requireBoolean()) { - getWaterlogged().setWaterlogged(mechanism.getValue().asBoolean()); + @Override + public void setPropertyValue(ElementTag value, Mechanism mechanism) { + if (mechanism.requireBoolean()) { + ((Waterlogged) material.getModernData()).setWaterlogged(value.asBoolean()); } } + + public static void register() { + autoRegister("waterlogged", MaterialWaterlogged.class, ElementTag.class, true); + } }