Update README.md

This commit is contained in:
GeorgH93 2020-04-19 17:46:27 +02:00
parent 785d56271c
commit b4095db9b5
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8

View File

@ -43,9 +43,10 @@ cd Minepacks
mvn -pl Minepacks-API mvn -pl Minepacks-API
``` ```
## Usage:
### Get access to the API: ### Get access to the API:
```java ```java
public MinepacksPlugin getMinepacks() { public static MinepacksPlugin getMinepacks() {
Plugin bukkitPlugin = Bukkit.getPluginManager().getPlugin("Minepacks"); Plugin bukkitPlugin = Bukkit.getPluginManager().getPlugin("Minepacks");
if(!(bukkitPlugin instanceof MinepacksPlugin)) { if(!(bukkitPlugin instanceof MinepacksPlugin)) {
// Do something if Minepacks is not available // Do something if Minepacks is not available
@ -56,6 +57,16 @@ public MinepacksPlugin getMinepacks() {
``` ```
You can now use the returned `MinepacksPlugin` object to interact with the Minepacks plugin. You can now use the returned `MinepacksPlugin` object to interact with the Minepacks plugin.
### Access a players backpack inventory:
```java
public static Inventory getPlayerBackpackInventory(Player player) {
Backpack bp = getMinepacks().getBackpackCachedOnly(player);
if(bp == null) return null; //Backpack not loaded (retry later)
return bp.getInventory();
}
```
This will return null if the backpack is not loaded or the inventory of the backpack if the backpack is already loaded.
## Links: ## Links:
* [JavaDoc][apiJavaDoc] * [JavaDoc][apiJavaDoc]
* [API Build Server][apiBuilds] * [API Build Server][apiBuilds]