Skip to content
Stephan edited this page Sep 14, 2023 · 12 revisions

Contents: Replacement API | Ban API | Maven repository

Replacement API

Requires ServerListPlus v3.3 or newer. The older versions of the API are not documented.

The plugin already provides a lot of placeholders by default, however you may feel like you want to add your own ones for your plugins. You can use the API to add custom placeholders.

Overview

The Replacement API is divided in 2 parts: static replacers and dynamic replacers. The static replacers are applied once when the configuration is reloaded. Dynamic replacers are called on each server status ping to provide the latest information.

Note: Because all replacements are registered when the configuration is reloaded it is important that you register your custom replacements before the plugin will be enabled. This might be fixed in a future version.

Usage

Dependency

Add the ServerListPlus JAR to your project, the best way is to choose the correct implementation from the latest release from the Jenkins Server (look for builds marked with a star).

Registration

Registration of custom replacers is done in the ReplacementManager class of ServerListPlus. There you find two methods getStatic() and getDynamic() which represent the set of all registered replacers.

Base classes

For static replacers simply implement the StaticReplacer or StaticPlaceholder interface, register it and you're already done.

For dynamic replacers you can implement the interfaces DynamicReplacer or DynamicPlaceholder, however there are also 2 base classes which should help in most cases.

  • LiteralPlaceholder - Extend this class if you want to create a literal placeholder, for example %online% or %player%.
  • PatternPlaceholder - The same as above, but using a regular expression instead. They are always slower then the literal placeholders.

Example

As already mentioned you need to register your replacers before ServerListPlus is enabled. For that to work, the first thing you need to do is to either declare ServerListPlus as required dependency (depend, depends in plugin.yml) or as optional dependency (softdepend, softdepends in plugin.yml).

To make sure the replacer is registered before ServerListPlus is enabled you can use the onLoad() method in the plugins. It works just like onEnable() but is called way earlier.

For example you want to create a placeholder called %money% that is replaced with the player's amount of money on the server. You have a method getMoney(String playerName) that will return the amount of money a player has. Then you could implement it like this:

@Override
public void onLoad() {
    ReplacementManager.getDynamic().add(new LiteralPlaceholder("%money%") {
        @Override
        public String replace(StatusResponse response, String s) {
            PlayerIdentity identity = response.getRequest().getIdentity();
            if (identity != null) {
                return this.replace(s, getMoney(identity.getName()));

            } else // Use the method below if player is unknown
                return super.replace(response, s);
        }

        @Override
        public String replace(ServerListPlusCore core, String s) {
            // Unknown player, so let's just replace it with something unknown
            return "???";
        }
    });
}

Ban API

Requires ServerListPlus v3.5 or newer.

First you need to implement the interface net.minecrell.serverlistplus.core.player.ban.BanProvider.

Then get an instance of the Core (ServerListPlusCore.getInstance()) and set your ban provider core.setBanProvider(new MyBanProvider());. Make sure to initialize your plugin after ServerListPlus, or to register your ban provider after the initialization. ServerListPlusCore.getInstance() will return null, when you try it too early.

Maven repository

ServerListPlus is available on the CodeMC Maven repository:

Gradle

repositories {
    maven {
        name = 'codemc-releases'
        url = 'https://repo.codemc.io/repository/maven-releases/'
    }
}

dependencies {
    compile 'net.minecrell:ServerListPlus:3.5.0' // Core
    compile 'net.minecrell:ServerListPlus:3.5.0:<platform>' // e.g. 'Bukkit', includes core
}

Maven

    <repositories>
        <repository>
            <id>codemc-releases</id>
            <url>https://repo.codemc.io/repository/maven-releases/</url>
        </repository>
    </repositories>

    <dependencies>
        <!-- Core -->
        <dependency>
            <groupId>net.minecrell</groupId>
            <artifactId>ServerListPlus</artifactId>
            <version>3.5.0</version>
        </dependency>

        <!-- e.g. 'Bukkit', includes core -->
        <dependency>
            <groupId>net.minecrell</groupId>
            <artifactId>ServerListPlus</artifactId>
            <version>3.5.0</version>
            <classifier>Bukkit</classifier>
        </dependency>
    </dependencies>

Tip: Snapshots are available at https://repo.codemc.io/repository/maven-snapshots/

Clone this wiki locally