Skip to content

Developer API

Nick DeGruccio edited this page Nov 4, 2020 · 6 revisions

The GTS API acts as a service, in that not only is it accessible via the API itself, but also from the respective platforms service registry. The API itself is rather simple to understand, but details regarding it will be presented below.

Hooking into the Service

With GTS 6.0.0, the service is now available following initial plugin load. In Sponge, this would be the GamePreInitializationEvent. Likewise, on BungeeCord/Waterfall, this would be during onLoad().

There will always be at least one way of connecting with the API. First, and likely the chosen method for many, will simply be to request the service from the service itself. While the service is an interface, it has a static method responsible for maintaining the implementation of the API. With this in mind, this method of retrieving the API is as simple as this:

GTSService service = GTSService.getInstance();

The second method of obtaining the API service will always be via the server platforms respective service registry. With Sponge, this is possible via their ServiceManager. An example of that looks like such:

GTSService service = Sponge.getServiceManager().provideUnchecked(GTSService.class);

Note: The above example assumes the API is registered. If you are ever unsure, use provide rather than provideUnchecked.

Creating an Extension

To create an Extension for GTS, you'll need to implement the Extension interface. One major note in regards to an Extension is that these aren't actually plugins. Rather, they are loaded by GTS itself during the plugin loading phase. Please see the section on installing extensions to see how GTS reads these files.

One thing an extension may want to do is register its own set of placeholders. The best way to do this is via the event system. Details regarding how to interact with the event system are described in the next section, but here's how you'd register your palceholders on Sponge:

@Subscribe
public void onPlaceholderRegistrationEvent(PlaceholderRegistryEvent<GameRegistryEvent.Register<PlaceholderParser>> event) {
    // The code responsible for registering your placeholders
    //
    // Typically, you'd register a placeholder like such: event.getManager().register(XXX);
}
Clone this wiki locally