下面列出了怎么用org.bukkit.event.inventory.InventoryEvent的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Calls the specified consumer (if it's not null) with the specified parameter,
* catching and logging all exceptions it might throw.
*
* @param callback the consumer to call if it isn't null
* @param event the value the consumer should accept
* @param callbackName the name of the action, used for logging
* @param <T> the type of the value the consumer is accepting
*/
private <T extends InventoryEvent> void callCallback(@Nullable Consumer<T> callback,
@NotNull T event, @NotNull String callbackName) {
if (callback == null) {
return;
}
try {
callback.accept(event);
} catch (Throwable t) {
Logger logger = JavaPlugin.getProvidingPlugin(getClass()).getLogger();
String message = "Exception while handling " + callbackName + " in inventory '" + title + "', state=" + state;
if (event instanceof InventoryClickEvent) {
InventoryClickEvent clickEvent = (InventoryClickEvent) event;
message += ", slot=" + clickEvent.getSlot();
}
logger.log(Level.SEVERE, message, t);
}
}
public Inventory getInventory() {
return ((InventoryEvent) event).getInventory();
}