From 4fd96839180dbee787847aa752cd65bae3c33757 Mon Sep 17 00:00:00 2001 From: hyper Date: Thu, 31 Oct 2024 18:13:43 -0400 Subject: [PATCH 1/5] Modernized and renamed brewing stand property --- .../objects/properties/PropertyRegistry.java | 2 +- .../properties/material/MaterialBottles.java | 68 ++++++++++++ .../material/MaterialBrewingStand.java | 105 ------------------ 3 files changed, 69 insertions(+), 106 deletions(-) create mode 100644 plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialBottles.java delete mode 100644 plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialBrewingStand.java 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 529ea7aa35..d70371d683 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 @@ -265,7 +265,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()); - } - } - } - -} From c56ee55cbef60e807268827e457355965d33e152 Mon Sep 17 00:00:00 2001 From: hyper Date: Thu, 31 Oct 2024 18:14:21 -0400 Subject: [PATCH 2/5] Slight format changes to attachment face property --- .../material/MaterialAttachmentFace.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttachmentFace.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttachmentFace.java index b6dc6e9aa0..a4b24df814 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttachmentFace.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttachmentFace.java @@ -21,13 +21,19 @@ public class MaterialAttachmentFace extends MaterialProperty { // --> public static boolean describes(MaterialTag material) { - return material.getModernData() instanceof FaceAttachable || material.getModernData() instanceof Bell; + return material.getModernData() instanceof FaceAttachable + || material.getModernData() instanceof Bell; } public MaterialAttachmentFace(MaterialTag material) { super(material); } + @Override + public String getPropertyId() { + return "attachment_face"; + } + @Override public ElementTag getPropertyValue() { if (getBlockData() instanceof FaceAttachable attachable) { @@ -39,11 +45,6 @@ else if (getBlockData() instanceof Bell bell) { return null; } - @Override - public String getPropertyId() { - return "attachment_face"; - } - @Override public void setPropertyValue(ElementTag value, Mechanism mechanism) { if (getBlockData() instanceof FaceAttachable attachable) { @@ -58,6 +59,10 @@ else if (getBlockData() instanceof Bell bell) { } } + public static void register() { + autoRegister("attachment_face", MaterialAttachmentFace.class, ElementTag.class, false, "switch_face"); + } + public BlockFace getAttachedTo() { if (getBlockData() instanceof FaceAttachable attachable) { return switch (attachable.getAttachedFace()) { @@ -75,8 +80,4 @@ else if (getBlockData() instanceof Bell bell) { } return null; } - - public static void register() { - autoRegister("attachment_face", MaterialAttachmentFace.class, ElementTag.class, false, "switch_face"); - } } From 1166d011598b05adce4b3a8cd1eb64abf408d564 Mon Sep 17 00:00:00 2001 From: hyper Date: Thu, 31 Oct 2024 18:14:33 -0400 Subject: [PATCH 3/5] More formatting changes --- .../objects/properties/material/MaterialAge.java | 13 ++++++------- .../properties/material/MaterialAttached.java | 10 +++++----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAge.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAge.java index f200242860..f48a57dad2 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAge.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAge.java @@ -36,6 +36,11 @@ public MaterialAge(MaterialTag material) { // NOTE: BlockGrowsScriptEvent needs super(material); } + @Override + public String getPropertyId() { + return "age"; + } + @Override public ElementTag getPropertyValue() { return new ElementTag(getCurrent()); @@ -66,12 +71,8 @@ else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) && data instanceof } } - @Override - public String getPropertyId() { - return "age"; - } - public static void register() { + autoRegister("age", MaterialAge.class, ElementTag.class, true, "plant_growth"); // <--[tag] // @attribute @@ -83,8 +84,6 @@ public static void register() { PropertyParser.registerStaticTag(MaterialAge.class, ElementTag.class, "maximum_age", (attribute, prop) -> { return new ElementTag(prop.getMax()); }, "maximum_plant_growth"); - - autoRegister("age", MaterialAge.class, ElementTag.class, true, "plant_growth"); } public int getCurrent() { diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttached.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttached.java index 29d22ed9dc..2aa5091fc0 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttached.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttached.java @@ -35,6 +35,11 @@ public static boolean describes(MaterialTag material) { || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && data instanceof Hangable); } + @Override + public String getPropertyId() { + return "attached"; + } + @Override public ElementTag getPropertyValue() { return new ElementTag(isAttached()); @@ -61,11 +66,6 @@ else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && data instanceof } } - @Override - public String getPropertyId() { - return "attached"; - } - public static void register() { autoRegister("attached", MaterialAttached.class, ElementTag.class, true, "attached_to_wall"); } From 609c2435cdfa4306b6c2f6b0b6eceabc16905749 Mon Sep 17 00:00:00 2001 From: hyper Date: Mon, 23 Dec 2024 10:26:56 -0500 Subject: [PATCH 4/5] Revert "Slight format changes to attachment face property" This reverts commit c56ee55cbef60e807268827e457355965d33e152. --- .../material/MaterialAttachmentFace.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttachmentFace.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttachmentFace.java index a4b24df814..b6dc6e9aa0 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttachmentFace.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttachmentFace.java @@ -21,19 +21,13 @@ public class MaterialAttachmentFace extends MaterialProperty { // --> public static boolean describes(MaterialTag material) { - return material.getModernData() instanceof FaceAttachable - || material.getModernData() instanceof Bell; + return material.getModernData() instanceof FaceAttachable || material.getModernData() instanceof Bell; } public MaterialAttachmentFace(MaterialTag material) { super(material); } - @Override - public String getPropertyId() { - return "attachment_face"; - } - @Override public ElementTag getPropertyValue() { if (getBlockData() instanceof FaceAttachable attachable) { @@ -45,6 +39,11 @@ else if (getBlockData() instanceof Bell bell) { return null; } + @Override + public String getPropertyId() { + return "attachment_face"; + } + @Override public void setPropertyValue(ElementTag value, Mechanism mechanism) { if (getBlockData() instanceof FaceAttachable attachable) { @@ -59,10 +58,6 @@ else if (getBlockData() instanceof Bell bell) { } } - public static void register() { - autoRegister("attachment_face", MaterialAttachmentFace.class, ElementTag.class, false, "switch_face"); - } - public BlockFace getAttachedTo() { if (getBlockData() instanceof FaceAttachable attachable) { return switch (attachable.getAttachedFace()) { @@ -80,4 +75,8 @@ else if (getBlockData() instanceof Bell bell) { } return null; } + + public static void register() { + autoRegister("attachment_face", MaterialAttachmentFace.class, ElementTag.class, false, "switch_face"); + } } From 3947088fd2d9b9c92efee665e4bb3f2dd0b009a7 Mon Sep 17 00:00:00 2001 From: hyper Date: Mon, 23 Dec 2024 10:26:57 -0500 Subject: [PATCH 5/5] Revert "More formatting changes" This reverts commit 1166d011598b05adce4b3a8cd1eb64abf408d564. --- .../objects/properties/material/MaterialAge.java | 13 +++++++------ .../properties/material/MaterialAttached.java | 10 +++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAge.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAge.java index f48a57dad2..f200242860 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAge.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAge.java @@ -36,11 +36,6 @@ public MaterialAge(MaterialTag material) { // NOTE: BlockGrowsScriptEvent needs super(material); } - @Override - public String getPropertyId() { - return "age"; - } - @Override public ElementTag getPropertyValue() { return new ElementTag(getCurrent()); @@ -71,8 +66,12 @@ else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) && data instanceof } } + @Override + public String getPropertyId() { + return "age"; + } + public static void register() { - autoRegister("age", MaterialAge.class, ElementTag.class, true, "plant_growth"); // <--[tag] // @attribute @@ -84,6 +83,8 @@ public static void register() { PropertyParser.registerStaticTag(MaterialAge.class, ElementTag.class, "maximum_age", (attribute, prop) -> { return new ElementTag(prop.getMax()); }, "maximum_plant_growth"); + + autoRegister("age", MaterialAge.class, ElementTag.class, true, "plant_growth"); } public int getCurrent() { diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttached.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttached.java index 2aa5091fc0..29d22ed9dc 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttached.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttached.java @@ -35,11 +35,6 @@ public static boolean describes(MaterialTag material) { || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && data instanceof Hangable); } - @Override - public String getPropertyId() { - return "attached"; - } - @Override public ElementTag getPropertyValue() { return new ElementTag(isAttached()); @@ -66,6 +61,11 @@ else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && data instanceof } } + @Override + public String getPropertyId() { + return "attached"; + } + public static void register() { autoRegister("attached", MaterialAttached.class, ElementTag.class, true, "attached_to_wall"); }