πFull Examples
Here you can find examples for each method for the RyseInventory.Builder and RyseInventory.
These are possible implementations. It is not recommended to copy anything randomly.
Description
We have implemented the methods update and init by the InventoryProvider.
By .delay(3, TimeSetting.SECONDS) the method update is called only after 3 seconds.
Code
RyseInventory.builder()
.title("Delay Preview")
.rows(3)
.delay(3, TimeSetting.SECONDS)
.provider(new InventoryProvider() {
@Override
public void update(Player player, InventoryContents contents) {
Material material = Material.values()[new Random().nextInt(Material.values().length)];
contents.update(0, new ItemStack(material));
}
@Override
public void init(Player player, InventoryContents contents) {
contents.set(0, new ItemStack(Material.DIAMOND_SWORD));
}
})
.build(this)
.openAll();
Preview
Description
We have implemented the method init by the InventoryProvider.
By .openDelay(3, TimeSettings.SECONDS), the inventory will be opened only after 3 seconds.
Code
RyseInventory.builder()
.title("OpenDelay Preview")
.rows(3)
.openDelay(3, TimeSetting.SECONDS)
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
}
})
.build(this)
.openAll();
Preview
Description
We have implemented the methods init and update by the InventoryProvider.
With .period(3, TimeSettings.SECONDS) the update method is called every 3 seconds.
Code
RyseInventory.builder()
.title("Period Preview")
.rows(3)
.period(3, TimeSetting.SECONDS)
.provider(new InventoryProvider() {
@Override
public void update(Player player, InventoryContents contents) {
Material material = Material.values()[new Random().nextInt(Material.values().length)];
contents.update(0, new ItemStack(material));
}
@Override
public void init(Player player, InventoryContents contents) {
contents.set(0, new ItemStack(Material.DIAMOND_SWORD));
}
})
.build(this)
.openAll();
Preview
Description
With .closeAfter(3, TimeSettings.SECONDS) the inventory is closed after 3 seconds.
Code
RyseInventory.builder()
.title("closeAfter Preview")
.rows(3)
.closeAfter(3, TimeSetting.SECONDS)
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
}
})
.build(this)
.openAll();
Preview
Description
With #ignoreEvents you can ignore certain events that are blocked by RyseInventory by default. Like for example the InventoryDragEvent
Code
RyseInventory.builder()
.title("ignoreEvents preview")
.rows(3)
.ignoreEvents(DisabledEvents.INVENTORY_DRAG)
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
}
})
.build(this)
.openAll();
Preview
Description
With #ignoredSlots you can ignore certain slots. There no InventoryClickEvent will take effect from the API's point of view.
Code
RyseInventory.builder()
.title("ignoredSlots preview")
.rows(3)
.ignoredSlots(0,1,2,3)
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
}
})
.build(this)
.openAll();
Preview
Description
If you call this method, the content of the player inventory is emptied and cached. When the inventory is closed, its contents are restored.
Code
RyseInventory.builder()
.title("clearAndSafe preview")
.rows(3)
.clearAndSafe()
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
}
})
.build(this)
.openAll();
Preview
Description
Gives the inventory a unique identification.
Code
RyseInventory.builder()
.title("identifier preview")
.rows(3)
.identifier("TEST")
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
Bukkit.getScheduler().runTaskLater(RyseInventoryPlugin.this, () -> {
Optional<RyseInventory> optional = inventoryManager.getInventory("TEST");
optional.ifPresent(inventory -> inventory.updateTitle(player, "identifier successful"));
}, 20*2L);
}
})
.build(this)
.openAll();
Preview
Description
With this method you can assign a direct event to the inventory. Like for example an InventoryClickEvent. If slot 1 is clicked, a diamond is placed at slot 5.
Code
RyseInventory.builder()
.title("listener preview")
.rows(3)
.listener(new EventCreator<>(InventoryClickEvent.class, event -> {
if(event.getClickedInventory() == null) return;
if(event.getSlot() == 1)
event.getClickedInventory().setItem(5, new ItemStack(Material.DIAMOND));
}))
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
}
})
.build(this)
.openAll();
Preview
Description
The player who has the inventory open can no longer close the inventory. The inventory can only be closed using the #close method.
Code
RyseInventory.builder()
.title("preventClose preview")
.rows(3)
.preventClose()
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
}
})
.build(this)
.openAll();
Preview
Description
ErmΓΆglicht es ein Inventar mit einem anderen Typen zu erstellen.
Code
RyseInventory.builder()
.title("type preview")
.rows(3)
.type(InventoryOpenerType.DROPPER)
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
}
})
.build(this)
.openAll();
Preview
Description
With #fixedPageSize(5) we say that we always want to have 5 pages. There it doesn't matter how many items are in the pagination.
Code
RyseInventory.builder()
.title("fixedPageSize preview")
.rows(3)
.fixedPageSize(5)
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
Pagination pagination = contents.pagination();
contents.set(0, IntelligentItem.of(new ItemStack(Material.ARROW), event -> {
if (pagination.isFirst()) {
player.sendMessage("You are on the first page");
return;
}
RyseInventory currentInventory = pagination.inventory();
currentInventory.open(player, pagination.previous().page());
}));
contents.set(4, new ItemBuilder(getRandomMaterial()).displayName("TEST - " + getRandomNumber(1, Integer.MAX_VALUE - 1)).build());
contents.set(8, IntelligentItem.of(new ItemStack(Material.ARROW), event -> {
if (pagination.isLast()) {
player.sendMessage("You are on the last page");
return;
}
RyseInventory currentInventory = pagination.inventory();
currentInventory.open(player, pagination.next().page());
}));
}
})
.build(this)
.openAll();
Preview
Description
The #titleHolder method is used in conjunction with the #loadTitle method. If we say #loadTitle(3, TimeSetting.SECONDS) the title we define in the #titleHolder method will be displayed for 3 seconds. After that the title we define with #title will be displayed.
Code
RyseInventory.builder()
.title("titleHolder preview")
.titleHolder("Β§cThis is a temporary Title")
.loadTitle(3, TimeSetting.SECONDS)
.rows(3)
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
}
})
.build(this)
.openAll();
Preview
Description
Delays the InventoryProvider. That means the content you have under your implemented method "init" will be loaded after 3 seconds in this case.
Code
RyseInventory.builder()
.title("loadDelay preview")
.loadDelay(3, TimeSetting.SECONDS)
.rows(3)
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
contents.set(0, new ItemStack(Material.DIAMOND));
}
})
.build(this)
.openAll();
Preview
Description
Closes the inventory. In this case the inventory will be closed 3 seconds after opening.
Code
RyseInventory.builder()
.title("close preview")
.rows(3)
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
Bukkit.getScheduler().runTaskLater(RyseInventoryPlugin.this, () ->
contents.pagination().inventory().close(player), 20 * 3);
}
})
.build(this)
.openAll();
Description
Creates a "SlideAnimation". Items can slide in from left->right or from right->left or from top->bottom or from bottom->top or diagonally.
Attention! In this case you must implement the Init method that contains SlideAnimation. Then you can say "animation.animate(contents);".
Code
RyseInventory.builder()
.title("animation preview")
.rows(3)
.animation(SlideAnimation.builder(this)
.direction(AnimatorDirection.HORIZONTAL_LEFT_RIGHT)
.from(Arrays.asList(9, 9))
.to(Arrays.asList(14, 12))
.item(IntelligentItem.empty(new ItemStack(Material.DIAMOND)),
IntelligentItem.empty(new ItemStack(Material.EMERALD)))
.period(5, TimeSetting.MILLISECONDS)
.delay(0, TimeSetting.SECONDS)
.build())
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents, SlideAnimation animation) {
animation.animate(contents);
}
})
.build(this)
.openAll();
Preview
Description
You can enable different actions that are disabled by the API by default. In this case I allow you to move items between inventories. Moving the items is restricted. I can move the item in slot 0, because I told there with #ignoredSlots that this slot is ignored.
Code
RyseInventory.builder()
.title("enableAction preview")
.rows(3)
.ignoredSlots(0)
.enableAction(Action.MOVE_TO_OTHER_INVENTORY)
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
}
})
.build(this)
.openAll();
Preview
Description
Often one creates an inventory without the need of the method "update" from the InventoryProvider. Initially a scheduler was created for it anyway. A scheduler will still be created, but it is recommended that if you do not implement an update method, that you use #disableUpdateTask to say that no scheduler should be started at all.
Code
RyseInventory.builder()
.title("enableAction preview")
.rows(3)
.disableUpdateTask()
.provider(new InventoryProvider() {
@Override
public void update(Player player, InventoryContents contents) {
player.sendMessage("The player will NEVER get this message, because I disabled the task.");
}
@Override
public void init(Player player, InventoryContents contents) {
}
})
.build(this)
.openAll();
Last updated