DREAMFIRE Docs ← Back to site
Loading...
Searching...
No Matches
ChestInventoryOpener.java
Go to the documentation of this file.
1package com.dreamfirestudios.dreamcore.DreamSmartInvs.opener;
2
3import com.dreamfirestudios.dreamcore.DreamCore;
4import com.dreamfirestudios.dreamcore.DreamSmartInvs.InventoryManager;
5import com.dreamfirestudios.dreamcore.DreamSmartInvs.SmartInventory;
6import com.google.common.base.Preconditions;
7import org.bukkit.Bukkit;
8import org.bukkit.entity.Player;
9import org.bukkit.event.inventory.InventoryType;
10import org.bukkit.inventory.Inventory;
11
12public class ChestInventoryOpener implements InventoryOpener {
13
14 @Override
15 @SuppressWarnings("deprecation")
16 public Inventory open(SmartInventory inv, Player player) {
17 Preconditions.checkArgument(inv.getColumns() == 9,
18 "The column count for the chest inventory must be 9, found: %s.", inv.getColumns());
19 Preconditions.checkArgument(inv.getRows() >= 1 && inv.getRows() <= 6,
20 "The row count for the chest inventory must be between 1 and 6, found: %s", inv.getRows());
21
22 InventoryManager manager = inv.getManager();
23 Inventory handle = Bukkit.createInventory(player, inv.getRows() * inv.getColumns(), inv.getTitle());
24
25 fill(handle, manager.getContents(player).get());
26 Bukkit.getScheduler().runTask(DreamCore.DreamCore, () -> {
27 player.openInventory(handle);
28 });
29
30 return handle;
31 }
32
33 @Override
34 public boolean supports(InventoryType type) {
35 return type == InventoryType.CHEST || type == InventoryType.ENDER_CHEST;
36 }
37
38}
default void fill(Inventory handle, InventoryContents contents)