java.lang.Object
com.winterhavenmc.library.messagebuilder.pipeline.adapters.protection.ProtectionAdapter
All Implemented Interfaces:
Adapter

public class ProtectionAdapter extends Object implements Adapter
An Adapter implementation for adapting objects that implement the Protectable interface.

This adapter is responsible for identifying objects that expose a protection period via a Instant (i.e., a protection expiration timestamp). If the provided object implements Protectable, it is wrapped and returned as an Optional<Protectable>; otherwise, an empty Optional is returned.

Once adapted, the object can be used to populate macro placeholders such as:

  • [OBJECT.PROTECTION.DURATION} – a localized string showing the remaining protection time
  • [OBJECT.PROTECTION.INSTANT} – the formatted expiration date/time

These macros are generated using the Protectable.extractProtection(com.winterhavenmc.library.messagebuilder.keys.MacroKey, java.time.temporal.ChronoUnit, java.time.format.FormatStyle, com.winterhavenmc.library.messagebuilder.pipeline.adapters.AdapterContextContainer) method.

  • Constructor Details

    • ProtectionAdapter

      public ProtectionAdapter()
  • Method Details

    • adapt

      public Optional<Protectable> adapt(Object obj)
      Attempts to adapt the given object to the Protectable interface.
      Specified by:
      adapt in interface Adapter
      Parameters:
      obj - the object to test for Protectable compatibility
      Returns:
      an Optional<Protectable> if the object implements Protectable, otherwise Optional.empty()