/
MenuContext.java
61 lines (49 loc) · 1.54 KB
/
MenuContext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package net.citizensnpcs.api.gui;
import java.util.Collections;
import java.util.Map;
import org.bukkit.inventory.Inventory;
import com.google.common.collect.Maps;
/**
* A context class passed into the constructor of a {@link Menu} instance.
*/
public class MenuContext implements SlotSource {
private final Map<String, Object> data = Maps.newHashMap();
private final Inventory inventory;
private final InventoryMenu menu;
private final InventoryMenuSlot[] slots;
private String title;
public MenuContext(InventoryMenu menu, InventoryMenuSlot[] slots, Inventory inventory, String title) {
this(menu, slots, inventory, title, Collections.emptyMap());
}
public MenuContext(InventoryMenu menu, InventoryMenuSlot[] slots, Inventory inventory, String title,
Map<String, Object> data) {
this.inventory = inventory;
this.title = title;
this.slots = slots;
this.menu = menu;
this.data.putAll(data);
}
public Map<String, Object> data() {
return data;
}
public Inventory getInventory() {
return inventory;
}
public InventoryMenu getMenu() {
return menu;
}
@Override
public InventoryMenuSlot getSlot(int i) {
if (slots[i] == null) {
return slots[i] = new InventoryMenuSlot(this, i);
}
return slots[i];
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
this.menu.updateTitle(title);
}
}