Skip to content

Commit

Permalink
Entity Properties Update - Part 3 (#2333)
Browse files Browse the repository at this point in the history
* Update `EntityCritical`

* Update `EntityCustomName`

* Update `EntityCustomNameVisible`

* Make `registerTags` static

* `EntityCustomNameVisible` meta fix
  • Loading branch information
tal5 committed May 5, 2022
1 parent 0ceaad0 commit dbc4f52
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 65 deletions.
Expand Up @@ -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) {
Expand All @@ -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"
};
Expand All @@ -39,25 +36,19 @@ private EntityCritical(EntityTag entity) {

@Override
public String getPropertyString() {
if (!((Arrow) critical.getBukkitEntity()).isCritical()) {
return null;
}
else {
return "true";
}
return getAbstractArrow().isCritical() ? "true" : null;
}

@Override
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 <EntityTag.critical>
Expand All @@ -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.<EntityCritical, ElementTag>registerTag(ElementTag.class, "critical", (attribute, object) -> {
return new ElementTag(object.getAbstractArrow().isCritical());
});
}

@Override
Expand All @@ -88,7 +76,7 @@ public void adjust(Mechanism mechanism) {
// <EntityTag.critical>
// -->
if (mechanism.matches("critical") && mechanism.requireBoolean()) {
((Arrow) critical.getBukkitEntity()).setCritical(mechanism.getValue().asBoolean());
getAbstractArrow().setCritical(mechanism.getValue().asBoolean());
}
}
}
Expand Up @@ -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 {
Expand All @@ -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"
};
Expand All @@ -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 <EntityTag.custom_name>
Expand All @@ -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.<EntityCustomName, ElementTag>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
Expand Down
Expand Up @@ -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 {

Expand All @@ -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"
};
Expand All @@ -44,26 +42,19 @@ public String getPropertyId() {
return "custom_name_visible";
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {

if (attribute == null) {
return null;
}
public static void registerTags() {

// <--[tag]
// @attribute <EntityTag.custom_name_visible>
// @returns ElementTag(Boolean)
// @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.<EntityCustomNameVisible, ElementTag>registerTag(ElementTag.class, "custom_name_visible", (attribute, object) -> {
return new ElementTag(object.entity.getBukkitEntity().isCustomNameVisible());
});
}

@Override
Expand All @@ -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
// <EntityTag.custom_name_visible>
// -->
Expand Down

0 comments on commit dbc4f52

Please sign in to comment.