Skip to content

Developer API

Nick DeGruccio edited this page Apr 1, 2018 · 3 revisions

The GTS API Service

The GTS API Service aids in the development of extensions planning to integrate into the GTS internals. With it, you may add your own types of listings and prices, as well as add tokens that can be parsed by Nucleus for commands and messages.

Details on how to use each component will be listed below.

Hooking into the Service

As of GTS 3.8.0, you may request the GTS Service from Sponge's ServiceManager, via the call like such:

gts = Sponge.getServiceManager().provideUnchecked(GtsService.class);

There is only one gripe with this, and that is that you are fetching the Service expecting it to be present, and in the event things go south, it wont be pleasant. You can either use the optional route, or, go about using the ChangeServiceProvider event directly from your main class. As an example, here's this:

@Listener
public void registerServices(ChangeServiceProviderEvent e){
    if(e.getService().equals(GtsService.class)) {
        this.gts = (GtsService) e.getNewProviderRegistration().getProvider();
    }
}

Once connection with the Service is established, you may then go about doing what you need with GTS.

Registering Your Own Entry/Price

With the Service now established, you can add your own types of entries and prices via this service. For this example, we will look into how to register your own Entry. Simply create a class which extends the abstract Entry class. To help aid the Entry parent class, pass the type of object your entry will be as a generic. With this settled, you will then be able to have your entry read its type properly. Within GTS 4.0, the command system of the API will be replaced by a UI service. Until then, all extending entries must declare a subcommand for the /gts sell command. This is not the preferred strategy to handle this, but due to time constraints, the UI concept was pushed back to 4.0.

Once your class is created, you may then register it with the GTS Service. Simply call the service (lets assume we called it gts), and run either the registerEntry or registerEntries methods. An example can be seen below:

MainClass.getInstance().gts.registerEntry(MyCustomEntry.class);

If you have more than one entry, I highly recommend using the registerEntries method, to help prevent against redundant method calling.

Adding a Minimum Price Option

If an entry extends the Minable interface, then you have the option to add additional min price options to a supporting class. For instance, the default PokemonEntry class is the only default class that extends Minable as of 3.8.0. To add an additional option to that class, you'd call the service method like such:

MainClass.getInstance().gts.addMinPriceOption(PokemonEntry.class, element -> <function>);

This function uses the element typing, and returns a Price to be used for calculation.

Adding a Token

Finally, we have the TokenService. Via the GTS Service, you can add your own Nucleus Tokens right through GTS. To add a token, you can use the addToken method to allow Nucleus to be able to parse your own tokens. The Token class holds a builder for you to easily create your own tokens with named help. These methods are known as key and translator. The translator is where you define how your token is handled, and the key is just simply what is required for it to parse.

Clone this wiki locally
You can’t perform that action at this time.