Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.redskyi.quest.utils.inventories;
- import java.util.HashMap;
- import org.bukkit.Bukkit;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.Inventory;
- /**
- * Created by Antoine on 05/02/2017.
- */
- public abstract class VirtualInventory {
- private Inventory inventory;
- private HashMap<Integer, ItemCreator> items;
- public VirtualInventory(int line, String name) {
- inventory = Bukkit.createInventory(null, line*9, name);
- items = new HashMap<>();
- inventories.put(inventory, this);
- }
- public void addItem(int slot, ItemCreator item) {
- items.put(slot, item);
- }
- public ItemCreator getItem(int slot) {
- return items.get(slot);
- }
- public Inventory getInventory() {
- for(int i : items.keySet()) {
- inventory.setItem(i, items.get(i).create());
- }
- return inventory;
- }
- public abstract void setItems(Player player);
- /*
- Statics Methods
- */
- private static HashMap<Inventory, VirtualInventory> inventories = new HashMap<>();
- public static void openInventory(VirtualInventory inventory, Player player) {
- inventory.setItems(player);
- player.openInventory(inventory.getInventory());
- }
- public static VirtualInventory getInventory(Inventory inventory) {
- return inventories.get(inventory);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement