An interface for the TeamSpeak 3 Client Query written in Java.
- Queued & asynchronous command execution
- Automatic loading of the API key (not guaranteed to work on each system)
- Event-based system for e.g. incoming messages
You are able to download the latest build from here.
!!! The usage of this API is likely to change in following releases. !!!
- Get the API key for the plugin automatically or via user-input. In order to get it automatically, instantiate
TSAPIKeyLoader
and callloadAPIKey()
. If it is unable to extract it, it will return an emptyOptional
. - Create an instance of
TSClientQueryConfiguration
. For example:new TSClientQueryConfiguration("127.0.0.1", 25639, apiKey)
- Set the configuration using
TSClientQuery.setConfiguration(configuration)
- You're now able to get the instance of the ClientQuery through
TSClientQuery.getInstance()
. The query connects after the first call.
Commands are executed by instantiating the command class and then calling BaseCommand#execute()
or BaseCommand#getResponse()
.
Keep in mind, BaseCommand#getResponse()
blocks the current Thread until the command was executed and the response was received and processed.
An alternative for BaseCommand#getResponse()
is calling BaseCommand#execute()
and using the Future
returned by BaseCommand#getResponseFuture()
.
ClientListCommand clientListCommand = new ClientListCommand();
for (Client client : clientListCommand.getResponse().getClientList()) {
new SendTextMessageCommand(client, "Your client ID is " + client.getClientID()).execute();
}
In order to listen for e.g. incoming chat messages, create a class which implements TSListener
.
In this class, create a method which has the event to listen to as the only parameter (e.g. ClientMessageReceivedEvent
) and annotate the method with @EventHandler
.
Finally, register the class with the listener using TSEventHandler.registerListener(instance)
.
The method is now called every time the event's being triggered.
public class ExampleListener implements TSListener {
@EventHandler
public void onMessageReceived(ClientMessageReceivedEvent e) {
System.out.println("Received an message: " + e.getMessage());
}
}
- Implementing most features provided by the client query API