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 8bf9b31087..9632775e7a 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 @@ -278,7 +278,7 @@ public static void registerMainProperties() { PropertyParser.registerProperty(MaterialAttached.class, MaterialTag.class); PropertyParser.registerProperty(MaterialAttachmentFace.class, MaterialTag.class); PropertyParser.registerProperty(MaterialBlockType.class, MaterialTag.class); - PropertyParser.registerProperty(MaterialBrewingStand.class, MaterialTag.class); + PropertyParser.registerProperty(MaterialBottles.class, MaterialTag.class); PropertyParser.registerProperty(MaterialCampfire.class, MaterialTag.class); PropertyParser.registerProperty(MaterialCount.class, MaterialTag.class); PropertyParser.registerProperty(MaterialDelay.class, MaterialTag.class); diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialBottles.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialBottles.java new file mode 100644 index 0000000000..52c786a864 --- /dev/null +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialBottles.java @@ -0,0 +1,68 @@ +package com.denizenscript.denizen.objects.properties.material; + +import com.denizenscript.denizen.objects.MaterialTag; +import com.denizenscript.denizencore.objects.Mechanism; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.objects.core.ListTag; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.type.BrewingStand; + +public class MaterialBottles extends MaterialProperty { + + // <--[property] + // @object MaterialTag + // @name bottles + // @input ListTag + // @description + // Controls the list of booleans that represent whether a slot in a brewing stand has a bottle. + // Under current implementation, this always returns/requires exactly 3 values, like "true|false|true". + // --> + + public static boolean describes(MaterialTag material) { + BlockData data = material.getModernData(); + return data instanceof BrewingStand; + } + + MaterialTag material; + + @Override + public String getPropertyId() { + return "bottles"; + } + + @Override + public ListTag getPropertyValue() { + return getBottleBooleans(); + } + + @Override + public void setPropertyValue(ListTag list, Mechanism mechanism) { + if (list.size() > getMaxBottles()) { + mechanism.echoError("Too many values specified! Brewing stand has a maximum of " + getMaxBottles() + " bottles."); + return; + } + for (int i = 0; i < list.size(); i++) { + getBrewingStand().setBottle(i, new ElementTag(list.get(i)).asBoolean()); + } + } + + public static void register() { + autoRegister("bottles", MaterialBottles.class, ListTag.class, true); + } + + public BrewingStand getBrewingStand() { + return (BrewingStand) material.getModernData(); + } + + public int getMaxBottles() { + return getBrewingStand().getMaximumBottles(); + } + + public ListTag getBottleBooleans() { + ListTag result = new ListTag(); + for (int i = 0; i < getMaxBottles(); i++) { + result.addObject(new ElementTag(getBrewingStand().hasBottle(i))); + } + return result; + } +} diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialBrewingStand.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialBrewingStand.java deleted file mode 100644 index 02eb693c35..0000000000 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialBrewingStand.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.denizenscript.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.core.ListTag; -import com.denizenscript.denizencore.objects.properties.Property; -import com.denizenscript.denizencore.objects.properties.PropertyParser; -import org.bukkit.block.data.type.BrewingStand; - -public class MaterialBrewingStand implements Property { - - public static boolean describes(ObjectTag material) { - return material instanceof MaterialTag - && ((MaterialTag) material).hasModernData() - && ((MaterialTag) material).getModernData() instanceof BrewingStand; - } - - public static MaterialBrewingStand getFrom(ObjectTag _material) { - if (!describes(_material)) { - return null; - } - else { - return new MaterialBrewingStand((MaterialTag) _material); - } - } - - public static final String[] handledMechs = new String[] { - "bottles" - }; - - public MaterialBrewingStand(MaterialTag _material) { - material = _material; - } - - MaterialTag material; - - public static void register() { - - // <--[tag] - // @attribute - // @returns ListTag - // @mechanism MaterialTag.bottles - // @group properties - // @description - // Returns a list of booleans that represent whether a slot in a brewing stand has a bottle. - // Under current implementation this always returns exactly 3 values, like "true|false|true". - // --> - PropertyParser.registerStaticTag(MaterialBrewingStand.class, ListTag.class, "bottles", (attribute, material) -> { - return material.getBottleBooleans(); - }); - } - - public BrewingStand getBrewingStand() { - return (BrewingStand) material.getModernData(); - } - - public int getMaxBottles() { - return getBrewingStand().getMaximumBottles(); - } - - public ListTag getBottleBooleans() { - ListTag result = new ListTag(); - for (int i = 0; i < getMaxBottles(); i++) { - result.addObject(new ElementTag(getBrewingStand().hasBottle(i))); - } - return result; - } - - @Override - public String getPropertyString() { - return getBottleBooleans().identify(); - } - - @Override - public String getPropertyId() { - return "bottles"; - } - - @Override - public void adjust(Mechanism mechanism) { - - // <--[mechanism] - // @object MaterialTag - // @name bottles - // @input ListTag - // @description - // Sets the bottles in a brewing stand. Input is a list of booleans representing whether that slot has a bottle. - // @tags - // - // --> - if (mechanism.matches("bottles")) { - ListTag bottles = mechanism.valueAsType(ListTag.class); - if (bottles.size() > getMaxBottles()) { - mechanism.echoError("Too many values specified! Brewing stand has a maximum of " + getMaxBottles() + " bottles."); - return; - } - for (int i = 0; i < bottles.size(); i++) { - getBrewingStand().setBottle(i, new ElementTag(bottles.get(i)).asBoolean()); - } - } - } - -}