Creating Parameterized Placeholder

Introduction

This class allows you to replace parameterized placeholder.

Implementing the class

public class ExamplePlaceholder implements ParameterizedPlaceholder {

    public ExamplePlaceholder() {
        // register the placeholder
        PlaceholderManager.register(this);
    }
    
    @Override
    public boolean accept(String placeholder) {
        return "example".equals(placeholder);
    }
    
    @Override
    public String provide(String placeholder, String param, ExtraData data) {
        if (param != null) {
            Player player = Bukkit.getPlayer(param);
            if (player != null) {
                return String.valueOf(player.getHealth());
            }
        }
        return "NOT_FOUND";
    }

}

/*
    To use your parameterized placeholder:
    {example} will result NOT_FOUND
    {example_Septogeddon} will result 20.0 (assuming that player Septogeddon is online)
    {example_Notch} will result NOT_FOUND (assuming that player Notch is offline)
*/

Last updated