mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 10:15:52 +01:00
Updated SubAPI (markdown)
parent
a1fa12de2e
commit
dffbcd5dfb
56
SubAPI.md
56
SubAPI.md
@ -35,6 +35,21 @@ __Pro-Tips for using SubServers as a Soft-Dependancy:__
|
||||
### Using SubAPI for Bungee
|
||||
Most of SubAPI can be accessed using this simple method `SubAPI.getInstance()`, however there's a bit more to it than just that. SubServers.Bungee works by extending BungeeCord classes to add more functionality, and overriding the methods to serve the extended classes. Knowing this, you can use it to your advantage.
|
||||
|
||||
__SubAPI Status Listener:__<br>
|
||||
If you need to listen to the status of SubAPI, you can do so like this:
|
||||
```
|
||||
@Override
|
||||
public void onEnable() {
|
||||
SubAPI.getInstance().addListener(this::subEnable, this::subDisable);
|
||||
}
|
||||
public void subEnable() {
|
||||
// SubAPI has now ready to be called
|
||||
}
|
||||
public void subDisable() {
|
||||
// SubAPI is about to be disabled
|
||||
}
|
||||
```
|
||||
|
||||
__Bungee ServerInfo:__<br>
|
||||
Just about any time you get a ServerInfo variable you can parse it to the SubServers equivalent if it exists.
|
||||
```
|
||||
@ -43,4 +58,43 @@ Server server = (serverinfo instanceof Server)?(Server)serverinfo:null;
|
||||
|
||||
SubServer subserver = (serverinfo instanceof SubServer)?(SubServer)serverinfo:null;
|
||||
// This will get you the server as a SubServer if it was registered as a SubServer in the first place
|
||||
```
|
||||
```
|
||||
|
||||
## SubServers.Host
|
||||
This will show how to use SubAPI for SubServers.Host. For more detailed information visit this page:<br>
|
||||
[http://subservers.ME1312.net/Javadoc/SubServers.Host/](http://subservers.ME1312.net/Javadoc/SubServers.Host/)
|
||||
|
||||
### Creating your plugin
|
||||
To use SubAPI here, you must create a SubPlugin. This section will detail how this is done, step by step.
|
||||
|
||||
__package.yml:__<br>
|
||||
On the root of your jar you must have a file named package.yml or SubAPI won't be able to find your plugin. You can specify multiple main classes by adding multiple `<class>` elements.
|
||||
```
|
||||
<package>
|
||||
<class>path.to.your.main.plugin.class</class>
|
||||
</package>
|
||||
```
|
||||
|
||||
__Plugin Main Class:__<br>
|
||||
Moving on, now you have to create a main class. This class will be added as a Listener automatically.
|
||||
```
|
||||
import net.ME1312.SubServers.Host.API.Event.SubDisableEvent;
|
||||
import net.ME1312.SubServers.Host.API.Event.SubEnableEvent;
|
||||
import net.ME1312.SubServers.Host.API.SubPlugin;
|
||||
import net.ME1312.SubServers.Host.Library.Event.EventHandler;
|
||||
|
||||
@SubPlugin(name = "ExamplePlugin", version = "1.0a", authors = "ME1312")
|
||||
public class ExamplePlugin {
|
||||
@EventHandler
|
||||
public void onEnable(SubEnableEvent event) {
|
||||
// Write enable code here
|
||||
}
|
||||
@EventHandler
|
||||
public void onDisable(SubDisableEvent event) {
|
||||
// Write disable code here
|
||||
}
|
||||
}
|
||||
```
|
||||
So, what happens here is:<br>
|
||||
1. You've given SubAPI info about your plugin through `@SubPlugin`<br>
|
||||
2. You're listening to `SubEnableEvent` and `SubDisableEvent` to enable and disable your plugin respectively.<br>
|
Loading…
Reference in New Issue
Block a user