Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. package fr.redskyi.quest.utils.inventories;
  2.  
  3. import java.util.HashMap;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.inventory.Inventory;
  8.  
  9. /**
  10. * Created by Antoine on 05/02/2017.
  11. */
  12. public abstract class VirtualInventory {
  13.  
  14. private Inventory inventory;
  15. private HashMap<Integer, ItemCreator> items;
  16.  
  17. public VirtualInventory(int line, String name) {
  18. inventory = Bukkit.createInventory(null, line*9, name);
  19. items = new HashMap<>();
  20. inventories.put(inventory, this);
  21. }
  22.  
  23. public void addItem(int slot, ItemCreator item) {
  24. items.put(slot, item);
  25. }
  26.  
  27. public ItemCreator getItem(int slot) {
  28. return items.get(slot);
  29. }
  30.  
  31. public Inventory getInventory() {
  32. for(int i : items.keySet()) {
  33. inventory.setItem(i, items.get(i).create());
  34. }
  35.  
  36. return inventory;
  37. }
  38.  
  39. public abstract void setItems(Player player);
  40.  
  41. /*
  42. Statics Methods
  43. */
  44.  
  45. private static HashMap<Inventory, VirtualInventory> inventories = new HashMap<>();
  46.  
  47. public static void openInventory(VirtualInventory inventory, Player player) {
  48. inventory.setItems(player);
  49. player.openInventory(inventory.getInventory());
  50. }
  51.  
  52. public static VirtualInventory getInventory(Inventory inventory) {
  53. return inventories.get(inventory);
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement