Skip to content

API

AdvancedServerList offers an API that other plugins can use to add their own placeholder to the plugin, listen for specific events or even modify Server List Profiles on the fly.

Add dependency

Add the following to your pom.xml, build.gradle or build.gradle.kts depending on what you use:

pom.xml
<repositories>
  <repository>
    <id>codeberg</id>
    <url>https://codeberg.org/api/packages/Andre601/maven/</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>ch.andre601.asl-api</groupId>
    <artifactId>api</artifactId>
    <version>{apiVersion}</version>
    <scope>provided</scope>
  </dependency>

  <!-- Optional platform dependencies -->
  <dependency>
    <groupId>ch.andre601.asl-api</groupId>
    <artifactId>platform-bukkit</artifactId>
    <version>{apiVersion}</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
    <groupId>ch.andre601.asl-api</groupId>
    <artifactId>platform-bungeecord</artifactId>
    <version>{apiVersion}</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
    <groupId>ch.andre601.asl-api</groupId>
    <artifactId>platform-velocity</artifactId>
    <version>{apiVersion}</version>
    <scope>provided</scope>
  </dependency>
</dependencies>
build.gradle
repositorories {
    maven { url = 'https://codeberg.org/api/packages/Andre601/maven/' }
}

dependencies {
    compileOnly 'ch.andre601.asl-api:api:{apiVersion}'

    // Optional platform dependencies
    compileOnly 'ch.andre601.asl-api:platform-bukkit:{apiVersion}'
    compileOnly 'ch.andre601.asl-api:platform-bungeecord:{apiVersion}'
    compileOnly 'ch.andre601.asl-api:platform-velocity:{apiVersion}'
}
build.gradle.kts
repositories {
    maven("https://codeberg.org/api/packages/Andre601/maven/")
}

dependencies {
    compileOnly("ch.andre601.asl-api:api:{apiVersion}")

    // Optional platform dependencies
    compileOnly("ch.andre601.asl-api:platform-bukkit:{apiVersion}")
    compileOnly("ch.andre601.asl-api:platform-bungeecord:{apiVersion}")
    compileOnly("ch.andre601.asl-api:platform-velocity:{apiVersion}")
}

Adding your own Placeholders

This requires the main api module

The API allows you to add your own placeholders which would be available through the ${<identifier> <values>} placeholder Pattern in a Server List profile.

To add your own placeholders, follow these steps:

1. Create a Placeholder class

You should first create a new class and make it extend the abstract PlaceholderProvider. This class includes a constructor and a method you need to add, so do that:

public class MyPlaceholders extends PlaceholderProvider {

    public MyPlaceholders(String identifier) {
        super(identifier);
    }

    @Override
    public String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server) {
        return null;
    }
}

Tip

You can replace the Constructor with a String argument with a no-args constructor and set the identifier directly in the super:

public MyPlaceholders() {
    super("myplaceholders");
}

The parsePlaceholder(String, GenericPlayer, GenericServer) method is used by AdvancedServerList to replace a matching placeholder with a value.
What you return is completely up to you. Just keep in mind that returning null will be treated as an invalid placeholder by AdvancedServerList, resulting in the placeholder being returned as-is without any changes.

Example of final class
public class MyPlaceholders extends PlaceholderProvider {

    public MyPlaceholders() {
        super("myplaceholders");
    }

    @Override
    public String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server) {
        if(placeholder.equalsIgnoreCase("hello"))
            return "Hello " + player.getName();

        return null;
    }
}

2. Register the Placeholders

Next step should be to register the placeholder. To achieve this, first obtain an instance of the AdvancedServerListAPI by using the static get() method. After that call addPlaceholderProvider(PlaceholderProvider placeholderProvider).
Your code may look similar to this:

Registering PlaceholderProvider class
public class MyPlugin extends JavaPlugin {

    @Override
    public void onEnable() {
        AdvancedServerListAPI api = AdvancedServerListAPI.get();

        api.addPlaceholderProvider(new MyPlaceholders());
    }
}

This should register your PlaceholderExpansion as long as it is valid, meaning that the identifier...

  • ...is not null
  • ...is not containing spaces
  • ...is not using a name already registered in the API

3. Declare AdvancedServerList as (soft)depend

The final thing you should make sure is to define AdvancedServerList as a depend or soft-depend for your plugin, to make sure it loads after AdvancedServerList.

Below are example setups for Spigot, Paper, BungeeCord and Velocity:

plugin.yml
name: "MyPlugin"
author: "author"
version: "1.0.0"

main: "com.example.plugin.ExamplePlugin"

softdepend:
  - AdvancedServerList
plugin.yml
name: "MyPlugin"
author: "author"
version: "1.0.0"

main: "com.example.plugin.ExamplePlugin"

depend:
  - AdvancedServerList
paper-plugin.yml
name: "MyPlugin"
author: "author"
version: "1.0.0"

main: "com.example.plugin.ExamplePlugin"

dependencies:
  server:
    AdvancedServerList:
      load: BEFORE
      required: false # Default, not required
paper-plugin.yml
name: "MyPlugin"
author: "author"
version: "1.0.0"

main: "com.example.plugin.ExamplePlugin"

dependencies:
  server:
    AdvancedServerList:
      load: BEFORE
      required: true
bungee.yml
name: "MyPlugin"
author: "author"
version: "1.0.0"

main: "com.example.plugin.ExamplePlugin"

softDepends:
  - AdvancedServerList
bungee.yml
name: "MyPlugin"
author: "author"
version: "1.0.0"

main: "com.example.plugin.ExamplePlugin"

depends:
  - AdvancedServerList
velocity-plugin.json
{
  "id": "myplugin",
  "name": "MyPlugin",
  "version": "1.0.0",
  "authors": [
    "author"
  ],
  "main": "com.example.plugin.ExamplePlugin",
  "dependencies": [
    {
      "id": "advancedserverlist",
      "optional": true
    }
  ]
}
velocity-plugin.json
{
  "id": "myplugin",
  "name": "MyPlugin",
  "version": "1.0.0",
  "authors": [
    "author"
  ],
  "main": "com.example.plugin.ExamplePlugin",
  "dependencies": [
    {
      "id": "advancedserverlist",
      "optional": false // Default, not required
    }
  ]
}
MyPlugin.java
@Plugin(
  id = "myplugin",
  name = "MyPlugin",
  version = "1.0.0",
  authors = {"author"},
  dependencies = {
    @Dependency(
      id = "advancedserverlist",
      optional = true
    )
  }
)
public class MyPlugin {

  // ...

}
MyPlugin.java
@Plugin(
  id = "myplugin",
  name = "MyPlugin",
  version = "1.0.0",
  authors = {"author"},
  dependencies = {
    @Dependency(
      id = "advancedserverlist",
      optional = false // Default, not required
    )
  }
)
public class MyPlugin {

  // ...

}

4. You're done!

Your plugin should now hook into AdvancedServerList and register its own custom placeholders to use.

Listening for events

These events require the platform-specific APIs

AdvancedServerList provides Events that your plugin can listen for specific situations.

PreServerListSetEvent

This event is called before AdvancedServerList starts handling the PingEvent of the Server/Proxy.
It allows you to get and alter the ProfileEntry used in the PingEvent, or even outright cancel the event itself.

The event offers the following methods:

Please check the server/proxy's documentation on how to listen for events with your plugin.

PostServerListSetEvent

This event is called after AdvancedServerList has completed its handling of the Server's/Proxy's PingEvent.

It provides a method to retrieve the ProfileEntry used during the PingEvent.
Do note that this ProfileEntry is not a representation of what is actually displayed in the server list, but rather what has been used by AdvancedServerList. It may also be null should the event handling get cancelled for any reason.

ProfileEntry

The ProfileEntry record is the core class used within the PreServerListSetEvent. It sets what values (MOTD, Favicon, Players, etc.) should be displayed.
Note that the record is - by nature - immutable and that the Builder class should be used to create a new ProfileEntry instance to use.

A convenience method (builder()) exists to create a Builder instance from an existing ProfileEntry in case you only want to alter certain options while everything else should remain unchanged.

This allows you to customize the Server list using your plugin. Just keep in mind that other plugins may also do the same, overriding your changes.