Skip to content

Commit

Permalink
make custom_name_visible its own property
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 23, 2021
1 parent 502a231 commit ef8b602
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 33 deletions.
Expand Up @@ -55,6 +55,7 @@ public static void registermainProperties() {
PropertyParser.registerProperty(EntityColor.class, EntityTag.class);
PropertyParser.registerProperty(EntityCritical.class, EntityTag.class);
PropertyParser.registerProperty(EntityCustomName.class, EntityTag.class);
PropertyParser.registerProperty(EntityCustomNameVisible.class, EntityTag.class);
PropertyParser.registerProperty(EntityDirection.class, EntityTag.class);
PropertyParser.registerProperty(EntityDisabledSlots.class, EntityTag.class);
PropertyParser.registerProperty(EntityPotionEffects.class, EntityTag.class);
Expand Down
Expand Up @@ -22,11 +22,11 @@ public static EntityCustomName getFrom(ObjectTag entity) {
}

public static final String[] handledTags = new String[] {
"custom_name_visible", "custom_name"
"custom_name"
};

public static final String[] handledMechs = new String[] {
"custom_name_visibility", "custom_name_visible", "custom_name"
"custom_name"
};

private EntityCustomName(EntityTag ent) {
Expand All @@ -52,22 +52,6 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
return null;
}

// <--[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.
// -->
if (attribute.startsWith("custom_name_visible") || attribute.startsWith("custom_name.visible")) {
int fulfilled = 1;
if (attribute.startsWith("custom_name.visible")) {
fulfilled = 2;
}
return new ElementTag(entity.getBukkitEntity().isCustomNameVisible()).getObjectAttribute(attribute.fulfill(fulfilled));
}

// <--[tag]
// @attribute <EntityTag.custom_name>
// @returns ElementTag
Expand All @@ -93,20 +77,6 @@ else if (attribute.startsWith("custom_name")) {
@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object EntityTag
// @name custom_name_visible
// @input ElementTag(Boolean)
// @description
// Sets whether the custom name is visible.
// @tags
// <EntityTag.custom_name_visible>
// -->
if ((mechanism.matches("custom_name_visibility") || mechanism.matches("custom_name_visible"))
&& mechanism.requireBoolean()) {
entity.getBukkitEntity().setCustomNameVisible(mechanism.getValue().asBoolean());
}

// <--[mechanism]
// @object EntityTag
// @name custom_name
Expand All @@ -116,7 +86,7 @@ public void adjust(Mechanism mechanism) {
// @tags
// <EntityTag.custom_name>
// -->
else if (mechanism.matches("custom_name")) {
if (mechanism.matches("custom_name")) {
entity.getBukkitEntity().setCustomName(CoreUtilities.clearNBSPs(mechanism.getValue().asString()));
}

Expand Down
@@ -0,0 +1,86 @@
package com.denizenscript.denizen.objects.properties.entity;

import com.denizenscript.denizen.objects.EntityTag;
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.tags.Attribute;

public class EntityCustomNameVisible implements Property {

public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag;
}

public static EntityCustomNameVisible getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
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"
};

private EntityCustomNameVisible(EntityTag ent) {
entity = ent;
}

EntityTag entity;

@Override
public String getPropertyString() {
return entity.getBukkitEntity().isCustomNameVisible() ? "true" : "false";
}

@Override
public String getPropertyId() {
return "custom_name_visible";
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {

if (attribute == null) {
return null;
}

// <--[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.
// -->
if (attribute.startsWith("custom_name_visible")) {
return new ElementTag(entity.getBukkitEntity().isCustomNameVisible()).getObjectAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object EntityTag
// @name custom_name_visible
// @input ElementTag(Boolean)
// @description
// Sets whether the custom name is visible.
// @tags
// <EntityTag.custom_name_visible>
// -->
if ((mechanism.matches("custom_name_visibility") || mechanism.matches("custom_name_visible"))
&& mechanism.requireBoolean()) {
entity.getBukkitEntity().setCustomNameVisible(mechanism.getValue().asBoolean());
}
}
}

0 comments on commit ef8b602

Please sign in to comment.