mirror of
https://github.com/ME1312/SubServers-2.git
synced 2025-02-16 19:51:26 +01:00
Created SubAPI (markdown)
parent
83480357ff
commit
bfc13829dd
46
SubAPI.md
Normal file
46
SubAPI.md
Normal file
@ -0,0 +1,46 @@
|
||||
# SubAPI
|
||||
This page will go over how to properly use SubAPI.
|
||||
|
||||
## SubServers.Bungee
|
||||
This will show how to use SubAPI for SubServers.Bungee. For more detailed information visit this page:<br>
|
||||
[http://subservers.ME1312.net/Javadoc/SubServers.Bungee/](http://subservers.ME1312.net/Javadoc/SubServers.Bungee/)
|
||||
|
||||
### Using SubAPI as a Soft Dependancy
|
||||
A "Soft Dependancy" is where your plugin will use SubServers, but it is not required for your plugin to function properly.
|
||||
|
||||
First, Make a method to see if SubServers v2.11.2a+ is available using reflection:
|
||||
```
|
||||
public boolean isSubServers2() {
|
||||
try {
|
||||
net.ME1312.SubServers.Bungee.SubAPI api = net.ME1312.SubServers.Bungee.SubAPI.class.cast(net.ME1312.SubServers.Bungee.SubAPI.class.getMethod("getInstance").invoke(null));
|
||||
if (api.getWrapperVersion().compareTo(net.ME1312.SubServers.Bungee.Library.Version.Version.class.getConstructor(String.class).newInstance("2.11.2a")) >= 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
```
|
||||
So what happens here is:<br>
|
||||
1. If there is any sort of error getting these classes, return false.<br>
|
||||
2. If the SubServers Version is less than 2.11.2a, return false.<br>
|
||||
3. Otherwise, your good to go (return true)<br><br>
|
||||
|
||||
__Pro-Tips for using SubServers as a Soft-Dependancy:__
|
||||
* Make sure SubServers is available using the above method before accessing SubServers classes
|
||||
* Never use imports for classes starting with "net.ME1312" or "org.json"<br>`new Version(1);` is now `new net.ME1312.SubServers.Bungee.Library.Version.Version(1);`<br>`SubAPI.getInstance();` is now `net.ME1312.SubServers.Bungee.SubAPI.getInstance();`
|
||||
|
||||
### 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.
|
||||
|
||||
__Bungee ServerInfo:__<br>
|
||||
Just about any time you get a ServerInfo variable you can parse it to the SubServers equivalent if it exists.
|
||||
```
|
||||
Server server = (serverinfo instanceof Server)?(Server)serverinfo:null;
|
||||
// This will get you the SubServers wrapped version of a server if that server has been registered within SubServers
|
||||
|
||||
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
|
||||
```
|
Loading…
Reference in New Issue
Block a user