Listening for Events
AdvancedServerList provides some events that your plugin can listen to.
These events are structurally the same across all platforms, yet still require the usage of Platform-specific APIs due to how some events are registered and handled on some platforms.
The plugin currently offers the following events:
PreServerListSetEvent¶
This event is executed before AdvancedServerList tries to modify the player list.
Methods¶
The following methods are available to use:
Method | Description |
---|---|
getEntry() |
Returns the ProfileEntry that AdvancedServerList should use. |
setEntry(ProfileEntry) |
Sets the ProfileEntry that should be used. |
isCancelled() |
Returns wether this event was cancelled or not. |
setCancelled(boolean) |
Sets the event's cancelled state. |
Notes¶
- Providing
null
as theProfileEntry
forsetEntry(ProfileEntry)
is not allowed. Also, a copy of the providedProfileEntry
is made and used.
PostServerListSetEvent¶
This event is executed after AdvancedServerList completed the server list modifications.
Methods¶
Method | Description |
---|---|
getEntry() |
Returns the ProfileEntry that AdvancedServerList used. |
Notes¶
- The returned
ProfileEntry
is not an actual representation of what is being displayed to the player and rather an instance of values the plugin received. The returned value may also benull
should the Ping Event be cancelled due to things such as an invalid Protocol or thePreServerListSetEvent
being cancelled.
Registering the Events¶
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
// (1)
Bukkit.getPluginManager().registerEvents(new ASLEventListener(), this);
}
}
getServer()
from theJavaPlugin
class can be used here too instead of theBukkit
singleton.
public class ASLEventListener implements Listener {
@EventHandler
public void onPreServerListSet(PreServerListSetEvent event) {
System.out.println("PreServerListSetEvent fired!");
}
@EventHandler
public void onPostServerListSetEvent(PostServerListSetEvent event) {
System.out.println("PostServerListSetEvent fired!");
}
}
public class MyPlugin extends Plugin {
@Override
public void onEnable() {
getProxy().getPluginManager().registerListener(this, new ASLEventListener());
}
}
public class ASLEventListener implements Listener {
@EventHandler
public void onPreServerListSet(PreServerListSetEvent event) {
System.out.println("PreServerListSetEvent fired!");
}
@EventHandler
public void onPostServerListSetEvent(PostServerListSetEvent event) {
System.out.println("PostServerListSetEvent fired!");
}
}
@Plugin(
id = "myplugin",
name = "MyPlugin",
version = "1.0.0",
authors = {"author"},
dependencies = {
@Dependency(
id = "advancedserverlist",
)
}
)
public class MyPlugin {
private final ProxyServer proxy;
@Inject
public MyPlugin(ProxyServer server) {
this.proxy = proxy;
}
@Subscribe
public void init(ProxyInitializeEvent event) {
proxy.getEventManager().register(this, new ASLEventListener());
}
}
public class ASLEventListener {
@Subscribe
public void onPreServerListSet(PreServerListSetEvent event) {
System.out.println("PreServerListSetEvent fired!");
}
@Subscribe
public void onPostServerListSetEvent(PostServerListSetEvent event) {
System.out.println("PostServerListSetEvent fired!");
}
}
What is a ProfileEntry?¶
Both events provide and use a so called ProfileEntry
.
The ProfileEntry
is a record, representing the values of a Server List Profile, meaning all values you can set in the profile configuration (Except condition and priority) will be available as a ProfileEntry
.
It is important to note, that the ProfileEntry
can be a representation of the profiles
option, the global options or a mixture of both.
If you want to create your own instance, you'll need to use the ProfileEntry.Builder
class as the ProfileEntry
is unmodifiable.
A convenience method in the form of builder()
exists to create a Builder instance of the ProfileEntry with its values already pre-set.