/
RulesInventory.java
182 lines (166 loc) · 3.69 KB
/
RulesInventory.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package com.featuredepic.test;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
/**
* @author FeaturedEpic
*
*/
public class RulesInventory {
String inventoryName;
int numberOfRules = 0, numberOfSlots;
Inventory inventory;
/**
* Creates a new Inventory to display Rules in.
*
* @param inventoryName
* The Title of the Inventory.
* @param numberOfSlots
* The Number of Slots for Rules.
*/
public RulesInventory(String inventoryName, int numberOfSlots) {
this.inventoryName = inventoryName;
this.numberOfSlots = numberOfSlots;
inventory = Bukkit.createInventory(null, this.numberOfSlots, this.inventoryName);
}
/**
* Gets the Inventory object of the Rules Inventory.
*
* @return The Inventory.
*/
public Inventory getInventory() {
return this.inventory;
}
/**
* Gets the Title of the Rules Inventory.
*
* @return The Title.
*/
public String getName() {
return this.inventoryName;
}
/**
* Gets the Number of Slots that the Rules Inventory has.
*
* @return The Number of Slots.
*/
public int getNumberOfSlots() {
return this.numberOfSlots;
}
/**
* Gets the Number of Rules in the Rules Inventory.
*
* @return The Number of Rules.
*/
public int getNumberOfRules() {
return this.numberOfRules;
}
/**
* Adds a Rule to the Rules Inventory.
*
* @param item
* The Rule as an ItemStack.
* @return The Inventory
*/
public RulesInventory addRule(ItemStack item) {
getInventory().setItem(this.numberOfRules, item);
this.numberOfRules++;
return this;
}
/**
* Adds several Rules to the Rules Inventory at once.
*
* @param items
* The List of Rules as ItemStacks.
* @return The Inventory.
*/
public RulesInventory addMultipleRules(List<ItemStack> items) {
for (ItemStack item : items) {
addRule(item);
}
return this;
}
/**
* Opens the Rules Inventory for a Player.
*
* @param p
* The Player.
* @return The Inventory.
*/
public RulesInventory openFor(Player p) {
p.closeInventory();
p.openInventory(getInventory());
return this;
}
/**
* Opens the Rules Inventory for multiple Players.
*
* Deprecated: Please use openFor(Player[], Condition) or openFor(Player[], String).
*
* @param players
* The Players.
* @return The Inventory.
* @deprecated
*/
public RulesInventory openFor(Player[] players) {
for (Player p : players) {
openFor(p);
}
return this;
}
/**
* Opens the Rules Inventory for all Players on the list that match the
* Condition passed.
*
* @param players
* The Players.
* @param condition
* The Condition of the Player Filter.
* @return The Inventory.
*/
public RulesInventory openFor(Player[] players, Condition condition) {
if (condition == Condition.ALL) {
for (Player p : players) {
openFor(p);
}
return this;
}
if (condition == Condition.OP) {
for (Player p : players) {
if (p.isOp()) {
openFor(p);
}
}
return this;
}
if (condition == Condition.NOT_OP) {
for (Player p : players) {
if (!p.isOp()) {
openFor(p);
}
}
return this;
}
return this;
}
/**
* Opens the Rules Inventory for all Players on the list that have the
* Permission passed.
*
* @param players
* The Players.
* @param permission
* The Permission that the Players need.
* @return The Inventory.
*/
public RulesInventory openFor(Player[] players, String permission) {
for (Player p : players) {
if (p.hasPermission(permission)) {
openFor(p);
}
}
return this;
}
}