Skip to content

Commit

Permalink
Allow removing custom names (#2416)
Browse files Browse the repository at this point in the history
  • Loading branch information
tal5 committed Dec 22, 2022
1 parent d0546ef commit 7bc1dab
Showing 1 changed file with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.utilities.PaperAPITools;
import com.denizenscript.denizencore.objects.core.ElementTag;
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.objects.properties.PropertyParser;
import com.denizenscript.denizencore.utilities.CoreUtilities;
Expand All @@ -24,10 +23,6 @@ public static EntityCustomName getFrom(ObjectTag entity) {
}
}

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

private EntityCustomName(EntityTag ent) {
entity = ent;
}
Expand Down Expand Up @@ -61,23 +56,19 @@ public static void register() {
}
return new ElementTag(name, true);
});
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object EntityTag
// @name custom_name
// @input ElementTag
// @description
// Sets the custom name (equivalent to a name tag item) of the entity.
// Provide no input to remove the custom name.
// @tags
// <EntityTag.custom_name>
// -->
if (mechanism.matches("custom_name")) {
PaperAPITools.instance.setCustomName(entity.getBukkitEntity(), CoreUtilities.clearNBSPs(mechanism.getValue().asString()));
}

PropertyParser.registerMechanism(EntityCustomName.class, "custom_name", (object, mechanism) -> {
PaperAPITools.instance.setCustomName(object.entity.getBukkitEntity(), mechanism.value != null ? CoreUtilities.clearNBSPs(mechanism.getValue().asString()) : null);
});
}
}

0 comments on commit 7bc1dab

Please sign in to comment.