Skip to content

Commit 4027f09

Browse files
committed
Add pageable item method that accepts an index arg
1 parent f83de0a commit 4027f09

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
allprojects {
22
group = 'com.focamacho'
3-
version = '1.0.5'
3+
version = '1.0.6'
44
}
55

66
subprojects {

sealmenus-bukkit/src/main/java/com/focamacho/sealmenus/bukkit/PageableChestMenu.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,26 @@ private PageableChestMenu(PageableChestMenu father) {
6060
* to pre-set slots for pageable items.
6161
*
6262
* @param item the item to add.
63+
* @param index the index to put the item in.
6364
* @return this menu.
6465
*/
65-
public PageableChestMenu addPageableItem(MenuItem item) {
66-
pageableItems.add(item);
66+
public PageableChestMenu addPageableItem(MenuItem item, int index) {
67+
pageableItems.add(Math.min(index, pageableItems.size()), item);
6768
requireUpdate(null);
6869
return this;
6970
}
7071

72+
/**
73+
* Adds an item that will automatically go
74+
* to pre-set slots for pageable items.
75+
*
76+
* @param item the item to add.
77+
* @return this menu.
78+
*/
79+
public PageableChestMenu addPageableItem(MenuItem item) {
80+
return addPageableItem(item, pageableItems.size());
81+
}
82+
7183
/**
7284
* Remove an item inserted as pageable.
7385
*
@@ -136,7 +148,7 @@ public int getPageCount() {
136148
public PageableChestMenu setNextPageItem(ItemStack item, int slot) {
137149
if(slot < 0 || slot >= this.getRows() * 9) throw new IllegalArgumentException("The slot can't be less than zero or greater than the inventory size.");
138150
for(int slotIndex : itemSlots) {
139-
if(slot == slotIndex) throw new IllegalArgumentException("You can't add an item in a slot reserved for pageable items. Use PageableChestMenu#addPageableItem instead.");
151+
if(slot == slotIndex) throw new IllegalArgumentException("You can't add an item in a slot reserved for pageable items.");
140152
}
141153

142154
if(fatherMenu == null) mirrorMenus.forEach(menu -> menu.setNextPageItem(item, slot));
@@ -173,7 +185,7 @@ public PageableChestMenu setNextPageItem(ItemStack item, int slot) {
173185
public PageableChestMenu setPreviousPageItem(ItemStack item, int slot) {
174186
if(slot < 0 || slot >= this.getRows() * 9) throw new IllegalArgumentException("The slot can't be less than zero or greater than the inventory size.");
175187
for(int slotIndex : itemSlots) {
176-
if(slot == slotIndex) throw new IllegalArgumentException("You can't add an item in a slot reserved for pageable items. Use PageableChestMenu#addPageableItem instead.");
188+
if(slot == slotIndex) throw new IllegalArgumentException("You can't add an item in a slot reserved for pageable items.");
177189
}
178190

179191
if(fatherMenu == null) mirrorMenus.forEach(menu -> menu.setPreviousPageItem(item, slot));
@@ -201,7 +213,7 @@ public PageableChestMenu setPreviousPageItem(ItemStack item, int slot) {
201213
@Override
202214
public ChestMenu addItem(MenuItem item, int slot) {
203215
for(int slotIndex : itemSlots) {
204-
if(slot == slotIndex) throw new IllegalArgumentException("You can't add an item in a slot reserved for pageable items. Use PageableChestMenu#addPageableItem instead.");
216+
if(slot == slotIndex) throw new IllegalArgumentException("You can't add an item in a slot reserved for pageable items.");
205217
}
206218

207219
return super.addItem(item, slot);

sealmenus-sponge/src/main/java/com/focamacho/sealmenus/sponge/PageableChestMenu.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,26 @@ private PageableChestMenu(PageableChestMenu father) {
5858
* to pre-set slots for pageable items.
5959
*
6060
* @param item the item to add.
61+
* @param index the index to put the item in.
6162
* @return this menu.
6263
*/
63-
public PageableChestMenu addPageableItem(MenuItem item) {
64-
pageableItems.add(item);
64+
public PageableChestMenu addPageableItem(MenuItem item, int index) {
65+
pageableItems.add(Math.min(index, pageableItems.size()), item);
6566
requireUpdate(null);
6667
return this;
6768
}
6869

70+
/**
71+
* Adds an item that will automatically go
72+
* to pre-set slots for pageable items.
73+
*
74+
* @param item the item to add.
75+
* @return this menu.
76+
*/
77+
public PageableChestMenu addPageableItem(MenuItem item) {
78+
return addPageableItem(item, pageableItems.size());
79+
}
80+
6981
/**
7082
* Remove an item inserted as pageable.
7183
*
@@ -134,7 +146,7 @@ public int getPageCount() {
134146
public PageableChestMenu setNextPageItem(ItemStack item, int slot) {
135147
if(slot < 0 || slot >= this.getRows() * 9) throw new IllegalArgumentException("The slot can't be less than zero or greater than the inventory size.");
136148
for(int slotIndex : itemSlots) {
137-
if(slot == slotIndex) throw new IllegalArgumentException("You can't add an item in a slot reserved for pageable items. Use PageableChestMenu#addPageableItem instead.");
149+
if(slot == slotIndex) throw new IllegalArgumentException("You can't add an item in a slot reserved for pageable items.");
138150
}
139151

140152
if(fatherMenu == null) mirrorMenus.forEach(menu -> menu.setNextPageItem(item, slot));
@@ -171,7 +183,7 @@ public PageableChestMenu setNextPageItem(ItemStack item, int slot) {
171183
public PageableChestMenu setPreviousPageItem(ItemStack item, int slot) {
172184
if(slot < 0 || slot >= this.getRows() * 9) throw new IllegalArgumentException("The slot can't be less than zero or greater than the inventory size.");
173185
for(int slotIndex : itemSlots) {
174-
if(slot == slotIndex) throw new IllegalArgumentException("You can't add an item in a slot reserved for pageable items. Use PageableChestMenu#addPageableItem instead.");
186+
if(slot == slotIndex) throw new IllegalArgumentException("You can't add an item in a slot reserved for pageable items.");
175187
}
176188

177189
if(fatherMenu == null) mirrorMenus.forEach(menu -> menu.setPreviousPageItem(item, slot));
@@ -199,7 +211,7 @@ public PageableChestMenu setPreviousPageItem(ItemStack item, int slot) {
199211
@Override
200212
public ChestMenu addItem(MenuItem item, int slot) {
201213
for(int slotIndex : itemSlots) {
202-
if(slot == slotIndex) throw new IllegalArgumentException("You can't add an item in a slot reserved for pageable items. Use PageableChestMenu#addPageableItem instead.");
214+
if(slot == slotIndex) throw new IllegalArgumentException("You can't add an item in a slot reserved for pageable items.");
203215
}
204216

205217
return super.addItem(item, slot);

0 commit comments

Comments
 (0)