11 KiB
icon
| icon |
|---|
| octicons/command-palette-24 |
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:
/// tab | :simple-apachemaven: Maven
<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>
///
/// tab | :simple-gradle: 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}'
}
///
/// tab | :simple-gradle: 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
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.
/// details | Example of final class type: example
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:
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:
/// tab | :simple-spigotmc: Spigot //// tab | Softdepend
name: "MyPlugin"
author: "author"
version: "1.0.0"
main: "com.example.plugin.ExamplePlugin"
softdepend:
- AdvancedServerList
////
//// tab | Depend
name: "MyPlugin"
author: "author"
version: "1.0.0"
main: "com.example.plugin.ExamplePlugin"
depend:
- AdvancedServerList
//// ///
/// tab | :fontawesome-solid-paper-plane: Paper //// tab | Softdepend
name: "MyPlugin"
author: "author"
version: "1.0.0"
main: "com.example.plugin.ExamplePlugin"
dependencies:
server:
AdvancedServerList:
load: BEFORE
required: false # Default, not required
////
//// tab | Depend
name: "MyPlugin"
author: "author"
version: "1.0.0"
main: "com.example.plugin.ExamplePlugin"
dependencies:
server:
AdvancedServerList:
load: BEFORE
required: true
//// ///
/// tab | :octicons-git-merge-24: BungeeCord //// tab | Softdepend
name: "MyPlugin"
author: "author"
version: "1.0.0"
main: "com.example.plugin.ExamplePlugin"
softDepends:
- AdvancedServerList
////
//// tab | Depend
name: "MyPlugin"
author: "author"
version: "1.0.0"
main: "com.example.plugin.ExamplePlugin"
depends:
- AdvancedServerList
//// ///
/// tab | :octicons-git-merge-24: Velocity //// tab | Softdepend (File)
{
"id": "myplugin",
"name": "MyPlugin",
"version": "1.0.0",
"authors": [
"author"
],
"main": "com.example.plugin.ExamplePlugin",
"dependencies": [
{
"id": "advancedserverlist",
"optional": true
}
]
}
////
//// tab | Depend (File)
{
"id": "myplugin",
"name": "MyPlugin",
"version": "1.0.0",
"authors": [
"author"
],
"main": "com.example.plugin.ExamplePlugin",
"dependencies": [
{
"id": "advancedserverlist",
"optional": false // Default, not required
}
]
}
////
//// tab | Softdepend (Annotation)
@Plugin(
id = "myplugin",
name = "MyPlugin",
version = "1.0.0",
authors = {"author"},
dependencies = {
@Dependency(
id = "advancedserverlist",
optional = true
)
}
)
public class MyPlugin {
// ...
}
////
//// tab | Depend (Annotation)
@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
AdvancedServerList provides an Event that your plugin can listen for.
The event is called PreServerListSetEvent and provides the following methods to use:
getEntry()- Gets the currently setProfileEntry.setEntry(ProfileEntry)- Sets a newProfileEntryto use.isCancelled()- Gets the current cancelled state of the event.setCancelled(boolean)- Sets the current cancelled state.
Setting the event's cancelled state to true will result in AdvancedServerList not altering the Server list.
Please check the server/proxy's documentation on how to listen for events with your plugin.
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 exists to create a Builder instance from an existing ProfileEntry in case you only want to alter certain options while everything else 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.