Skip to content

Using the API

yetanotherx edited this page Jul 26, 2011 · 4 revisions

Setting up your plugin to use the API

Add as a library

After downloading ModTRS, add the JAR file to your classpath. This can be done through your IDE, or through a command line option, depending on what you use.

Initializing the plugin

To get an instance of the API, run the following code (ideally in your plugin's onEnable() method):

Somewhere where you declare variables in your main class place this variable:

Plugin modtrsPlugin = this.getServer().getPluginManager().getPlugin("ModTRS");
ModTRSAPI modtrsApi = null;
if (modtrsPlugin != null) {
        this.getServer().getPluginManager().enablePlugin(modtrsPlugin);
        modtrsApi = ((ModTRS) modtrsPlugin).getAPI();
}

modtrsApi will contain an instance of the API object. If the variable is null, then the plugin was not found.

(Thanks to TheYeti for providing this help guide which I ripped off!)

Clone this wiki locally