Skip to content

Creating Custom Placeholders

Daniel Norris edited this page Jul 24, 2021 · 6 revisions

Adding build support

Add the follow to your build.gradle:

    repositories {
        maven { url 'https://jitpack.io' }
    }

    dependencies {
        compileOnly 'com.github.Pixelmon-Development.ForgePlaceholderAPI:api:0.0.1'
    }

The repository allows you to add the dependency directly from jitpack. Ensure to replace the version tag (0.0.1) with the latest release from this repository.

Custom Placeholders

Upon adding the dependency you will then be able to extend the PlaceholderManager interface like so:

public class ReforgedPlaceholders implements PlaceholderManager<EntityPlayerMP> {

    @Override
    public String getIdentifier() {
        return "reforged";
    }

    @Override
    public String[] getAuthors() {
        return new String[] { "Envyful" };
    }

    @Override
    public String getVersion() {
        return "1.0.0";
    }

    @Override
    public String getName() {
        return getIdentifier();
    }

    @Override
    public String onPlaceholderRequest(EntityPlayerMP player, String placeholder) {
        PlayerPartyStorage party = Pixelmon.storageManager.getParty(player);

        switch (placeholder.toLowerCase()) {
            case "dex":
                return String.format(
                        "%.2f",
                        ((party.pokedex.countCaught() + 0.000) / Pokedex.pokedexSize) * 100
                ) + "%";
        }

        return "UNDEFINED";
    }
}

Once this interface is registered it will add the "%reforged_dex%" placeholder returning the logic found in the switch statement.

Registering Placeholders

In order for your Placeholders to be registered place your jar file inside the mods/ForgePlaceholderAPI/ directory on your server. Alternatively, you can register the placeholder directly using the method PlaceholderFactory#register

Clone this wiki locally