Developer API - ValeraShimchuck/SimpleItemGenerator GitHub Wiki
You can import the plugin's api from maven central repository
<dependency>
<groupId>io.github.valerashimchuck</groupId>
<artifactId>simpleitemgenerator-api</artifactId>
<version>1.10.0</version>
<scope>compile</scope>
</dependency>
compileOnly("io.github.valerashimchuck:simpleitemgenerator-api:1.10.0")
name: YourPlugin
version: ...
main: ...
depend:
- SimpleItemGenerator
- ...
boolean itemExists = SimpleItemGenerator.get().hasKey("test-item");
SimpleItemGenerator's config.yml:
items:
test-item:
material: STICK
name: '<red>Custom name'
Player player = ...; // obtaining a player from somewhere in bukkit
Optional<ItemStack> resultOpt = SimpleItemGenerator.get().bakeItem("test-item", player); // also player can be null
ItemStack item = resultOpt.orElse(null); // get item or null
ItemStack item2 = resultOpt.get(); // get item or an error will be thrown
SimpleItemGenerator's config.yml:
items:
test-item:
material: STICK
name: '<red>Custom name'
ItemStack item = ...; // getting item somewhere
Optional<String> optKey = SimpleItemGenerator.get().getCustomItemKey(item);
String keyOrNull = optKey.orElse(null); // get or null
String key = optKey.get(); // get or an error will be thrown
ItemStack item = ...; // getting item somewhere
boolean result = SimpleItemGenerator.get().isCustomItem(item); // true if the item is an SIG's custom item
If you are using SIG within packet-menus you can update the item manually
Player player = ...;
ItemStack item = ...; // An item obtained from some packet-environment space
boolean result = SimpleItemGenerator.get().updateItem(item, player) // if item is an SIG's custom item then the item will be update and result will be true, otherwise false
Because of SimpleItemGenerator's support of HeadDatabase, it waits for HeadDatabase to load its database and then boots itself up, this happens after server is considered enabled(after Done
message).
So you have several options for hooking when SimpleItemGenerator is fully enabled.
You can listen to this bukkit event like you do with the other bukkit events:
public class ExampleListener implements Listener {
@EventHandler
private void onSIGLoad(SimpleItemGeneratorLoadEvent event) {
// your code here
}
}
It runs only when the plugin is reloaded with command. It is not run when plugin boots.
public class ExampleListener implements Listener {
@EventHandler
private void onSIGReload(SimpleItemGeneratorReloadEvent event) {
// your code here
}
}
If you need a more simple way to hook into SIG when it's fully loaded, then you can try SimpleItemGenerator.onInit
.
SimpleItemGenerator.onInit(simpleItemGenerator -> {
// your code here
});
If you need a flexible way of hooking into SIG, then you can use SimpleItemGenerator.loadFuture()
that will return java's CompletableFuture.
SimpleItemGenerator.loadFuture().thenAccept(simpleItemGenerator -> {
// your code here
});