java.lang.Object
com.winterhavenmc.library.messagebuilder.pipeline.adapters.name.NameAdapter
All Implemented Interfaces:
Adapter

public class NameAdapter extends Object implements Adapter
An Adapter for extracting name information from objects that expose a getName() method.

This adapter wraps supported objects into the Nameable interface, which unifies access to name-like properties through a standard Nameable.getName() accessor. The resulting Nameable can then be used in the message pipeline to perform macro substitution for placeholders such as {OBJECT.NAME}.

Supported types include:

  • CommandSender
  • OfflinePlayer
  • PlayerProfile
  • World
  • Server
  • Plugin

If the provided object is already an instance of Nameable, it is returned directly. Otherwise, the adapter attempts to map a known getName() source into a Nameable lambda reference. If no match is found, an empty Optional is returned.

See Also:
  • Constructor Details

    • NameAdapter

      public NameAdapter()
  • Method Details

    • adapt

      public Optional<Nameable> adapt(Object obj)
      Attempts to adapt the given object to a Nameable, if it exposes a name field.

      Returns a Optional containing a Nameable wrapper if the object is a known type that provides a getName() method, either directly or indirectly. Returns an empty Optional if the object does not expose a supported name source.

      Specified by:
      adapt in interface Adapter
      Parameters:
      obj - the object to evaluate and adapt
      Returns:
      an optional Nameable if the object is name-compatible, otherwise empty