Class PlaceholderProvider

java.lang.Object
ch.andre601.advancedserverlist.api.PlaceholderProvider

public abstract class PlaceholderProvider extends Object
Abstract class used to create Placeholders in the format ${identifier values} with identifier being the name you provide through the Constructor.
  • Constructor Details

    • PlaceholderProvider

      public PlaceholderProvider(String identifier)

      Constructor used to set the identifier for the class extending the PlaceholderProvider class.

      Example
      public class MyPlaceholders extends PlaceholderProvider {
          public MyPlaceholders() {
              super("myplaceholders");
          }
          
          String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server) {
              if (placeholder.equals("hello")
                  return "Hi!";
              
              return null;
          }
      }
      
      Parameters:
      identifier - The identifier to use for the placeholder. Shouldn't be null, empty, nor contain spaces.
  • Method Details

    • parsePlaceholder

      public abstract String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server)

      This method is called by AdvancedServerList whenever a Placeholder pattern of ${identifier value} is being found.
      Your instance of the PlaceholderProvider class is only called when the identifier matches the one you provided.

      null can be returned to indicate the placeholder being invalid, having AdvancedServerList return the placeholder unchanged.

      Parameters:
      placeholder - The part of the placeholder after the identifier (${<identifier> <placeholder>})
      player - The GenericPlayer instance used.
      server - The GenericServer instance used.
      Returns:
      Parsed String based on the PlaceholderProvider or null for invalid placeholders.
    • getIdentifier

      public String getIdentifier()
      Returns the identifier used by this instance.
      Returns:
      String containing the identifier used by this instance.