Working with the API
Brief introduction to Sonar's API and event system
Using the API
maven(url = "https://repo.jonesdev.xyz/releases/")compileOnly("xyz.jonesdev.sonar:sonar-api:2.1.43")Events
import xyz.jonesdev.sonar.api.event.SonarEvent;
import xyz.jonesdev.sonar.api.event.SonarEventListener;
import xyz.jonesdev.sonar.api.event.impl.UserVerifySuccessEvent;
public final class TestListener implements SonarEventListener {
@Override
public void handle(final SonarEvent event) {
// Check for the event you want to listen for
// (This is supposed to be a simple API, don't expect annotations, priorities, etc.)
if (event instanceof UserVerifySuccessEvent) {
// Cast the event to the event class you previously checked for
final UserVerifySuccessEvent successEvent = (UserVerifySuccessEvent) event;
// ...
System.out.printf("Test: %s (%s) (took %d ms to verify)%n",
successEvent.getUsername(), successEvent.getOfflineUuid(), successEvent.getTimeTakenToVerify());
System.out.println("You can also get the raw user data: " + successEvent.getUser());
}
// etc.
}
}Last updated