diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityCritical.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityCritical.java index 9563877a2b..c5f17e5f74 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityCritical.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityCritical.java @@ -5,13 +5,14 @@ import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.properties.Property; -import com.denizenscript.denizencore.tags.Attribute; -import org.bukkit.entity.Arrow; +import com.denizenscript.denizencore.objects.properties.PropertyParser; +import org.bukkit.entity.AbstractArrow; public class EntityCritical implements Property { public static boolean describes(ObjectTag entity) { - return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntity() instanceof Arrow; + return entity instanceof EntityTag + && ((EntityTag) entity).getBukkitEntity() instanceof AbstractArrow; } public static EntityCritical getFrom(ObjectTag entity) { @@ -23,10 +24,6 @@ public static EntityCritical getFrom(ObjectTag entity) { } } - public static final String[] handledTags = new String[] { - "critical" - }; - public static final String[] handledMechs = new String[] { "critical" }; @@ -39,12 +36,7 @@ private EntityCritical(EntityTag entity) { @Override public String getPropertyString() { - if (!((Arrow) critical.getBukkitEntity()).isCritical()) { - return null; - } - else { - return "true"; - } + return getAbstractArrow().isCritical() ? "true" : null; } @Override @@ -52,12 +44,11 @@ public String getPropertyId() { return "critical"; } - @Override - public ObjectTag getObjectAttribute(Attribute attribute) { + public AbstractArrow getAbstractArrow() { + return (AbstractArrow) critical.getBukkitEntity(); + } - if (attribute == null) { - return null; - } + public static void registerTags() { // <--[tag] // @attribute @@ -67,12 +58,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) { // @description // If the entity is an arrow or trident, returns whether the arrow/trident is critical. // --> - if (attribute.startsWith("critical")) { - return new ElementTag(((Arrow) critical.getBukkitEntity()).isCritical()) - .getObjectAttribute(attribute.fulfill(1)); - } - - return null; + PropertyParser.registerTag(ElementTag.class, "critical", (attribute, object) -> { + return new ElementTag(object.getAbstractArrow().isCritical()); + }); } @Override @@ -88,7 +76,7 @@ public void adjust(Mechanism mechanism) { // // --> if (mechanism.matches("critical") && mechanism.requireBoolean()) { - ((Arrow) critical.getBukkitEntity()).setCritical(mechanism.getValue().asBoolean()); + getAbstractArrow().setCritical(mechanism.getValue().asBoolean()); } } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityCustomName.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityCustomName.java index 0c86498739..8fab1dcff2 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityCustomName.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityCustomName.java @@ -6,7 +6,7 @@ import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.properties.Property; -import com.denizenscript.denizencore.tags.Attribute; +import com.denizenscript.denizencore.objects.properties.PropertyParser; import com.denizenscript.denizencore.utilities.CoreUtilities; public class EntityCustomName implements Property { @@ -19,13 +19,11 @@ public static EntityCustomName getFrom(ObjectTag entity) { if (!describes(entity)) { return null; } - return new EntityCustomName((EntityTag) entity); + else { + return new EntityCustomName((EntityTag) entity); + } } - public static final String[] handledTags = new String[] { - "custom_name" - }; - public static final String[] handledMechs = new String[] { "custom_name" }; @@ -46,12 +44,7 @@ public String getPropertyId() { return "custom_name"; } - @Override - public ObjectTag getObjectAttribute(Attribute attribute) { - - if (attribute == null) { - return null; - } + public static void registerTags() { // <--[tag] // @attribute @@ -61,18 +54,13 @@ public ObjectTag getObjectAttribute(Attribute attribute) { // @description // Returns the entity's custom name (as set by plugin or name tag item), if any. // --> - else if (attribute.startsWith("custom_name")) { - String name = AdvancedTextImpl.instance.getCustomName(entity.getBukkitEntity()); + PropertyParser.registerTag(ElementTag.class, "custom_name", (attribute, object) -> { + String name = AdvancedTextImpl.instance.getCustomName(object.entity.getBukkitEntity()); if (name == null) { return null; } - else { - return new ElementTag(name, true).getObjectAttribute(attribute.fulfill(1)); - } - } - else { - return null; - } + return new ElementTag(name, true); + }); } @Override diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityCustomNameVisible.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityCustomNameVisible.java index 3f7e22e3f6..3660e3852b 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityCustomNameVisible.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityCustomNameVisible.java @@ -5,7 +5,7 @@ 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 com.denizenscript.denizencore.objects.properties.PropertyParser; public class EntityCustomNameVisible implements Property { @@ -17,13 +17,11 @@ public static EntityCustomNameVisible getFrom(ObjectTag entity) { if (!describes(entity)) { return null; } - return new EntityCustomNameVisible((EntityTag) entity); + else { + return new EntityCustomNameVisible((EntityTag) entity); + } } - public static final String[] handledTags = new String[] { - "custom_name_visible" - }; - public static final String[] handledMechs = new String[] { "custom_name_visibility", "custom_name_visible" }; @@ -44,12 +42,7 @@ public String getPropertyId() { return "custom_name_visible"; } - @Override - public ObjectTag getObjectAttribute(Attribute attribute) { - - if (attribute == null) { - return null; - } + public static void registerTags() { // <--[tag] // @attribute @@ -57,13 +50,11 @@ public ObjectTag getObjectAttribute(Attribute attribute) { // @mechanism EntityTag.custom_name_visible // @group attributes // @description - // Returns true if the entity's custom name is visible. + // Returns whether the entity's custom name is visible. // --> - if (attribute.startsWith("custom_name_visible")) { - return new ElementTag(entity.getBukkitEntity().isCustomNameVisible()).getObjectAttribute(attribute.fulfill(1)); - } - - return null; + PropertyParser.registerTag(ElementTag.class, "custom_name_visible", (attribute, object) -> { + return new ElementTag(object.entity.getBukkitEntity().isCustomNameVisible()); + }); } @Override @@ -74,7 +65,7 @@ public void adjust(Mechanism mechanism) { // @name custom_name_visible // @input ElementTag(Boolean) // @description - // Sets whether the custom name is visible. + // Sets whether the entity's custom name is visible. // @tags // // -->