Class NameModifier

java.lang.Object
io.github.projectunified.craftitem.modifier.NameModifier
All Implemented Interfaces:
ItemModifier

public class NameModifier extends Object implements ItemModifier
Item modifier that sets the item's display name.

The provided name is passed through the translator before being applied to the item, allowing for variable substitution and dynamic name generation.

Example Usage:


 ItemModifier modifier = new NameModifier("Sword of ${owner}");
 modifier.modify(item, s -> s.replace("${owner}", "Player123"));
 // Item name becomes: "Sword of Player123"
 
  • Constructor Details

    • NameModifier

      public NameModifier(String name)
      Creates a new NameModifier with the specified name.
      Parameters:
      name - the display name (can contain variables for translation)
  • Method Details

    • modify

      public void modify(Item item, UnaryOperator<String> translator)
      Applies the translated name to the item.
      Specified by:
      modify in interface ItemModifier
      Parameters:
      item - the item to modify
      translator - the string translator for variable substitution