Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public static void register() {
DataComponentAdapter.register(new FoodAdapter());
DataComponentAdapter.register(new GliderAdapter());
DataComponentAdapter.register(new ItemModelAdapter());
DataComponentAdapter.register(new ItemNameAdapter());
DataComponentAdapter.register(new MaxDurabilityAdapter());
DataComponentAdapter.register(new MaxStackSizeAdapter());
DataComponentAdapter.register(new RarityAdapter());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.denizenscript.denizen.paper.datacomponents;

import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ElementTag;
import io.papermc.paper.datacomponent.DataComponentTypes;
import net.kyori.adventure.text.Component;
import com.denizenscript.denizen.paper.PaperModule;
import net.md_5.bungee.api.ChatColor;

public class ItemNameAdapter extends DataComponentAdapter.Valued<ElementTag, Component> {

// <--[property]
// @object ItemTag
// @name item_name
// @input ElementTag
// @description
// Controls the item's default name.
// The item's default name cannot be modified by a player and is displayed when <@link mechanism ItemTag.display> is not set.
// If a display name is set, item_name will still retain its original value but will be hidden.
// See also <@link language Item Components>.
// @mechanism
// Provide no input to reset the item to its default value.
// @tag
// By default, this will return the item's vanilla display name.
// -->

public ItemNameAdapter() {
super(ElementTag.class, DataComponentTypes.ITEM_NAME, "item_name");
}

@Override
public ElementTag toDenizen(Component value) {
return new ElementTag(PaperModule.stringifyComponent(value), true);
}

@Override
public Component fromDenizen(ElementTag value, Mechanism mechanism) {
return PaperModule.parseFormattedText(value.toString(), ChatColor.WHITE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @group properties
// @description
// Returns the display name of the item, as set by plugin or an anvil.
// See also <@link property ItemTag.item_name>.
// -->
if (attribute.startsWith("display")) {
if (hasDisplayName()) {
Expand All @@ -77,6 +78,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @group properties
// @description
// Returns whether the item has a custom set display name.
// See also <@link property ItemTag.item_name>.
// -->
if (attribute.startsWith("has_display")) {
return new ElementTag(hasDisplayName())
Expand Down Expand Up @@ -116,6 +118,7 @@ public void adjust(Mechanism mechanism) {
// @description
// Changes the item's display name.
// Give no input to remove the item's display name.
// See also <@link property ItemTag.item_name> to set the item's default name, which cannot be changed by players.
// @tags
// <ItemTag.display>
// -->
Expand Down