You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hclewk edited this page Jan 28, 2012
·
2 revisions
You need to add JSONAPI.jar to your classpath when compiling. In Eclipse, this means adding JSONAPI.jar to the build path.
Adding/overloading JSONAPI methods is quite easy. You just need to implement 1 interface JSONAPICallHandler, which looks like this:
publicinterfaceJSONAPICallHandler {
// if you return true here, you WILL handle the API call in the handle method.// will be called twice for every API call, once to test if the method exists and once on the actuall callpublicbooleanwillHandle(APIMethodNamemethodName);
// the result of this method will be treated as the response to the API request, even if null is returned (some methods do return null)publicObjecthandle(APIMethodNamemethodName, Object[] args);
}
Here is a sample implementation:
classMyCoolPluginextendsJavaPluginimplementsJSONAPICallHandler {
publicvoidonEnable() {
...
Plugincheckplugin = this.getServer().getPluginManager().getPlugin("JSONAPI");
if(checkplugin != null) {
// get the JSONAPI instanceJSONAPIjsonapi = (JSONAPI)checkplugin;
jsonapi.registerAPICallHandler(this);
}
else {
// JSONAPI isn't loaded. Throw an error or continue on your way.
}
...
}
publicbooleanwillHandle(APIMethodNamemethodName) {
if(methodName.matches("ping")) {
returntrue;
}
}
publicObjecthandle(APIMethodNamemethodName, Object[] args) {
if(methodName.matches("ping")) {
return"pong";
}
}
}