MCPcopy Index your code
hub / github.com/Cortex-MC/SimpAPI / Menu

Class Menu

src/main/java/me/kodysimpson/simpapi/menu/Menu.java:22–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20 Defines the behavior and attributes of all menus in our plugin
21 */
22public abstract class Menu implements InventoryHolder {
23
24 //Protected values that can be accessed in the menus
25 protected PlayerMenuUtility playerMenuUtility;
26 protected Player player;
27 protected Inventory inventory;
28 protected ItemStack FILLER_GLASS = makeItem(Material.GRAY_STAINED_GLASS_PANE, " ");
29
30 //Constructor for Menu. Pass in a PlayerMenuUtility so that
31 // we have information on whose menu this is and
32 // what info is to be transferred
33 public Menu(PlayerMenuUtility playerMenuUtility) {
34 this.playerMenuUtility = playerMenuUtility;
35 this.player = playerMenuUtility.getOwner();
36 }
37
38 //let each menu decide their name
39 public abstract String getMenuName();
40
41 //let each menu decide their slot amount
42 public abstract int getSlots();
43
44 public abstract boolean cancelAllClicks();
45
46 //let each menu decide how the items in the menu will be handled when clicked
47 public abstract void handleMenu(InventoryClickEvent e) throws MenuManagerNotSetupException, MenuManagerException;
48
49 //let each menu decide what items are to be placed in the inventory menu
50 public abstract void setMenuItems();
51
52 //When called, an inventory is created and opened for the player
53 public void open() {
54 //The owner of the inventory created is the Menu itself,
55 // so we are able to reverse engineer the Menu object from the
56 // inventoryHolder in the MenuListener class when handling clicks
57 inventory = Bukkit.createInventory(this, getSlots(), getMenuName());
58
59 //grab all the items specified to be used for this menu and add to inventory
60 this.setMenuItems();
61
62 //open the inventory for the player
63 playerMenuUtility.getOwner().openInventory(inventory);
64 playerMenuUtility.pushMenu(this);
65 }
66
67 public void back() throws MenuManagerException, MenuManagerNotSetupException {
68 MenuManager.openMenu(playerMenuUtility.lastMenu().getClass(), playerMenuUtility.getOwner());
69 }
70
71 protected void reloadItems() {
72 for (int i = 0; i < inventory.getSize(); i++) {
73 inventory.setItem(i, null);
74 }
75 setMenuItems();
76 }
77
78 protected void reload() throws MenuManagerException, MenuManagerNotSetupException {
79 player.closeInventory();

Callers

nothing calls this directly

Calls 1

makeItemMethod · 0.95

Tested by

no test coverage detected