Adds a lot of this. in GUI releated classes

This commit is contained in:
Christian Koop 2023-06-24 15:56:58 +02:00
parent 7ce74de993
commit 572cf3d805
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
7 changed files with 434 additions and 433 deletions

View File

@ -113,30 +113,30 @@ public class CustomizableGui extends Gui {
customContent.disableButton(disabled); customContent.disableButton(disabled);
} }
} else { } else {
customContent = loadedGuis.get(guiKey); this.customContent = loadedGuis.get(guiKey);
} }
setPrivateDefaultAction(event -> { setPrivateDefaultAction(event -> {
if (event.clickType == ClickType.SHIFT_RIGHT) { if (event.clickType == ClickType.SHIFT_RIGHT) {
activationCount++; this.activationCount++;
} }
if (activationCount >= 8 && event.player.hasPermission("songoda.admin")) { if (this.activationCount >= 8 && event.player.hasPermission("songoda.admin")) {
showGuiKeys = !showGuiKeys; showGuiKeys = !showGuiKeys;
activationCount = 0; this.activationCount = 0;
event.player.sendMessage("Gui keys " + (showGuiKeys ? "enabled" : "disabled") + "."); event.player.sendMessage("Gui keys " + (showGuiKeys ? "enabled" : "disabled") + ".");
} }
}); });
if (customContent.isButtonCustomized("__DEFAULT__")) { if (this.customContent.isButtonCustomized("__DEFAULT__")) {
blankItem = GuiUtils.getBorderItem(customContent.getCustomizedButton("__DEFAULT__").item); this.blankItem = GuiUtils.getBorderItem(this.customContent.getCustomizedButton("__DEFAULT__").item);
} }
} }
@NotNull @NotNull
public Gui setRows(int rows) { public Gui setRows(int rows) {
int customRows = customContent.getRows(); int customRows = this.customContent.getRows();
return super.setRows(customRows != -1 ? customRows : rows); return super.setRows(customRows != -1 ? customRows : rows);
} }
@ -154,13 +154,13 @@ public class CustomizableGui extends Gui {
} }
private void applyCustomItems() { private void applyCustomItems() {
for (CustomButton customButton : customContent.getCustomButtons().values()) { for (CustomButton customButton : this.customContent.getCustomButtons().values()) {
if (customButton instanceof MirrorFill) { if (customButton instanceof MirrorFill) {
applyCustomItem(customButton); applyCustomItem(customButton);
} }
} }
for (CustomButton customButton : customContent.getCustomButtons().values()) { for (CustomButton customButton : this.customContent.getCustomButtons().values()) {
if (!(customButton instanceof MirrorFill)) { if (!(customButton instanceof MirrorFill)) {
applyCustomItem(customButton); applyCustomItem(customButton);
} }
@ -191,7 +191,7 @@ public class CustomizableGui extends Gui {
applyShowGuiKeys("__DEFAULT__", item); applyShowGuiKeys("__DEFAULT__", item);
if (customContent.isButtonCustomized("__DEFAULT__")) { if (this.customContent.isButtonCustomized("__DEFAULT__")) {
return this; return this;
} }
@ -202,14 +202,14 @@ public class CustomizableGui extends Gui {
public Gui setItem(@NotNull String key, int cell, @Nullable ItemStack item) { public Gui setItem(@NotNull String key, int cell, @Nullable ItemStack item) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
applyShowGuiKeys(key, item); applyShowGuiKeys(key, item);
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
CustomButton btn = customContent.getCustomizedButton(key); CustomButton btn = this.customContent.getCustomizedButton(key);
cells = btn.applyPosition(cell); cells = btn.applyPosition(cell);
btn.applyItem(item); btn.applyItem(item);
} }
@ -223,21 +223,21 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui setItem(@NotNull String key, int row, int col, @Nullable ItemStack item) { public Gui setItem(@NotNull String key, int row, int col, @Nullable ItemStack item) {
final int cell = col + row * inventoryType.columns; final int cell = col + row * this.inventoryType.columns;
return setItem(key, cell, item); return setItem(key, cell, item);
} }
public Gui mirrorFill(@NotNull String key, int row, int col, boolean mirrorRow, boolean mirrorCol, @NotNull ItemStack item) { public Gui mirrorFill(@NotNull String key, int row, int col, boolean mirrorRow, boolean mirrorCol, @NotNull ItemStack item) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
ItemStack newItem = item.clone(); ItemStack newItem = item.clone();
boolean isShow = applyShowGuiKeys(key, newItem); boolean isShow = applyShowGuiKeys(key, newItem);
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
CustomButton btn = customContent.getCustomizedButton(key); CustomButton btn = this.customContent.getCustomizedButton(key);
row = btn.applyPositionRow(row); row = btn.applyPositionRow(row);
col = btn.applyPositionCol(col); col = btn.applyPositionCol(col);
@ -259,12 +259,12 @@ public class CustomizableGui extends Gui {
public Gui highlightItem(@NotNull String key, int cell) { public Gui highlightItem(@NotNull String key, int cell) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell); cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
} }
for (int c : cells) { for (int c : cells) {
@ -276,11 +276,11 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui highlightItem(@NotNull String key, int row, int col) { public Gui highlightItem(@NotNull String key, int row, int col) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
final int cell = col + row * inventoryType.columns; final int cell = col + row * this.inventoryType.columns;
return highlightItem(key, cell); return highlightItem(key, cell);
} }
@ -289,12 +289,12 @@ public class CustomizableGui extends Gui {
public Gui removeHighlight(@NotNull String key, int cell) { public Gui removeHighlight(@NotNull String key, int cell) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell); cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
} }
for (int c : cells) { for (int c : cells) {
@ -306,34 +306,34 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui removeHighlight(@NotNull String key, int row, int col) { public Gui removeHighlight(@NotNull String key, int row, int col) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
final int cell = col + row * inventoryType.columns; final int cell = col + row * this.inventoryType.columns;
return removeHighlight(key, cell); return removeHighlight(key, cell);
} }
@NotNull @NotNull
public Gui updateItemLore(@NotNull String key, int row, int col, @NotNull String... lore) { public Gui updateItemLore(@NotNull String key, int row, int col, @NotNull String... lore) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
return updateItemLore(key, col + row * inventoryType.columns, lore); return updateItemLore(key, col + row * this.inventoryType.columns, lore);
} }
@NotNull @NotNull
public Gui updateItemLore(@NotNull String key, int cell, @NotNull String... lore) { public Gui updateItemLore(@NotNull String key, int cell, @NotNull String... lore) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell); cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
} }
for (int c : cells) { for (int c : cells) {
@ -345,23 +345,23 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui updateItemLore(@NotNull String key, int row, int col, @Nullable List<String> lore) { public Gui updateItemLore(@NotNull String key, int row, int col, @Nullable List<String> lore) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
return updateItemLore(key, col + row * inventoryType.columns, lore); return updateItemLore(key, col + row * this.inventoryType.columns, lore);
} }
@NotNull @NotNull
public Gui updateItemLore(@NotNull String key, int cell, @Nullable List<String> lore) { public Gui updateItemLore(@NotNull String key, int cell, @Nullable List<String> lore) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell); cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
} }
for (int c : cells) { for (int c : cells) {
@ -373,23 +373,23 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui updateItemName(@NotNull String key, int row, int col, @Nullable String name) { public Gui updateItemName(@NotNull String key, int row, int col, @Nullable String name) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
return updateItemName(key, col + row * inventoryType.columns, name); return updateItemName(key, col + row * this.inventoryType.columns, name);
} }
@NotNull @NotNull
public Gui updateItemName(@NotNull String key, int cell, @Nullable String name) { public Gui updateItemName(@NotNull String key, int cell, @Nullable String name) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell); cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
} }
for (int c : cells) { for (int c : cells) {
@ -401,16 +401,16 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui updateItem(@NotNull String key, int row, int col, @Nullable String name, @NotNull String... lore) { public Gui updateItem(@NotNull String key, int row, int col, @Nullable String name, @NotNull String... lore) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
return updateItem(key, col + row * inventoryType.columns, name, lore); return updateItem(key, col + row * this.inventoryType.columns, name, lore);
} }
@NotNull @NotNull
public Gui updateItem(@NotNull String key, int cell, @Nullable String name, @NotNull String... lore) { public Gui updateItem(@NotNull String key, int cell, @Nullable String name, @NotNull String... lore) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
@ -419,25 +419,25 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui updateItem(@NotNull String key, int row, int col, @Nullable String name, @Nullable List<String> lore) { public Gui updateItem(@NotNull String key, int row, int col, @Nullable String name, @Nullable List<String> lore) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
return updateItem(key, col + row * inventoryType.columns, name, lore); return updateItem(key, col + row * this.inventoryType.columns, name, lore);
} }
@NotNull @NotNull
public Gui updateItem(@NotNull String key, int cell, @NotNull String name, @Nullable List<String> lore) { public Gui updateItem(@NotNull String key, int cell, @NotNull String name, @Nullable List<String> lore) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
lore = applyShowGuiKeys(key, lore); lore = applyShowGuiKeys(key, lore);
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell); cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
} }
for (int c : cells) { for (int c : cells) {
@ -449,23 +449,23 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui updateItem(@NotNull String key, int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) { public Gui updateItem(@NotNull String key, int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore); return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
} }
@NotNull @NotNull
public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) { public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell); cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
} }
for (int c : cells) { for (int c : cells) {
@ -477,23 +477,23 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui updateItem(@NotNull String key, int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @NotNull String... lore) { public Gui updateItem(@NotNull String key, int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @NotNull String... lore) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore); return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
} }
@NotNull @NotNull
public Gui updateItem(@NotNull String key, int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable String... lore) { public Gui updateItem(@NotNull String key, int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable String... lore) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell); cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
} }
for (int c : cells) { for (int c : cells) {
@ -505,23 +505,23 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui updateItem(@NotNull String key, int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) { public Gui updateItem(@NotNull String key, int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore); return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
} }
@NotNull @NotNull
public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) { public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell); cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
} }
for (int c : cells) { for (int c : cells) {
@ -533,23 +533,23 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui updateItem(@NotNull String key, int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) { public Gui updateItem(@NotNull String key, int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore); return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
} }
@NotNull @NotNull
public Gui updateItem(@NotNull String key, int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) { public Gui updateItem(@NotNull String key, int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell); cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
} }
for (int c : cells) { for (int c : cells) {
@ -561,7 +561,7 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui setAction(@NotNull String key, int cell, @Nullable Clickable action) { public Gui setAction(@NotNull String key, int cell, @Nullable Clickable action) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
@ -572,18 +572,18 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui setAction(@NotNull String key, int row, int col, @Nullable Clickable action) { public Gui setAction(@NotNull String key, int row, int col, @Nullable Clickable action) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
setConditional(key, col + row * inventoryType.columns, null, action); setConditional(key, col + row * this.inventoryType.columns, null, action);
return this; return this;
} }
@NotNull @NotNull
public Gui setAction(@NotNull String key, int cell, @Nullable ClickType type, @Nullable Clickable action) { public Gui setAction(@NotNull String key, int cell, @Nullable ClickType type, @Nullable Clickable action) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
@ -594,11 +594,11 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui setAction(@NotNull String key, int row, int col, @Nullable ClickType type, @Nullable Clickable action) { public Gui setAction(@NotNull String key, int row, int col, @Nullable ClickType type, @Nullable Clickable action) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
setConditional(key, col + row * inventoryType.columns, type, action); setConditional(key, col + row * this.inventoryType.columns, type, action);
return this; return this;
} }
@ -607,12 +607,12 @@ public class CustomizableGui extends Gui {
public Gui clearActions(@NotNull String key, int cell) { public Gui clearActions(@NotNull String key, int cell) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell); cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
} }
for (int c : cells) { for (int c : cells) {
@ -624,25 +624,25 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui clearActions(@NotNull String key, int row, int col) { public Gui clearActions(@NotNull String key, int row, int col) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
return clearActions(key, col + row * inventoryType.columns); return clearActions(key, col + row * this.inventoryType.columns);
} }
@NotNull @NotNull
public Gui setButton(@NotNull String key, int cell, ItemStack item, @Nullable Clickable action) { public Gui setButton(@NotNull String key, int cell, ItemStack item, @Nullable Clickable action) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
applyShowGuiKeys(key, item); applyShowGuiKeys(key, item);
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
CustomButton btn = customContent.getCustomizedButton(key); CustomButton btn = this.customContent.getCustomizedButton(key);
cells = btn.applyPosition(cell); cells = btn.applyPosition(cell);
btn.applyItem(item); btn.applyItem(item);
} }
@ -657,25 +657,25 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui setButton(@NotNull String key, int row, int col, @Nullable ItemStack item, @Nullable Clickable action) { public Gui setButton(@NotNull String key, int row, int col, @Nullable ItemStack item, @Nullable Clickable action) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
return setButton(key, col + row * inventoryType.columns, item, action); return setButton(key, col + row * this.inventoryType.columns, item, action);
} }
@NotNull @NotNull
public Gui setButton(@NotNull String key, int cell, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) { public Gui setButton(@NotNull String key, int cell, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
applyShowGuiKeys(key, item); applyShowGuiKeys(key, item);
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
CustomButton btn = customContent.getCustomizedButton(key); CustomButton btn = this.customContent.getCustomizedButton(key);
cells = btn.applyPosition(cell); cells = btn.applyPosition(cell);
btn.applyItem(item); btn.applyItem(item);
} }
@ -689,22 +689,22 @@ public class CustomizableGui extends Gui {
@NotNull @NotNull
public Gui setButton(@NotNull String key, int row, int col, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) { public Gui setButton(@NotNull String key, int row, int col, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) {
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return this; return this;
} }
return setButton(key, col + row + inventoryType.columns, item, type, action); return setButton(key, col + row + this.inventoryType.columns, item, type, action);
} }
protected void setConditional(@NotNull String key, int cell, @Nullable ClickType type, @Nullable Clickable action) { protected void setConditional(@NotNull String key, int cell, @Nullable ClickType type, @Nullable Clickable action) {
List<Integer> cells = Collections.singletonList(cell); List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) { if (this.customContent.isButtonDisabled(key)) {
return; return;
} }
if (customContent.isButtonCustomized(key)) { if (this.customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell); cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
} }
for (int c : cells) { for (int c : cells) {
@ -715,8 +715,8 @@ public class CustomizableGui extends Gui {
public Gui setNextPage(ItemStack item) { public Gui setNextPage(ItemStack item) {
applyShowGuiKeys("__NEXT__", item); applyShowGuiKeys("__NEXT__", item);
if (customContent.isButtonCustomized("__NEXT__")) { if (this.customContent.isButtonCustomized("__NEXT__")) {
customContent.getCustomizedButton("__NEXT__").applyItem(item); this.customContent.getCustomizedButton("__NEXT__").applyItem(item);
} }
return super.setNextPage(item); return super.setNextPage(item);
@ -725,8 +725,8 @@ public class CustomizableGui extends Gui {
public Gui setPrevPage(ItemStack item) { public Gui setPrevPage(ItemStack item) {
applyShowGuiKeys("__PREV__", item); applyShowGuiKeys("__PREV__", item);
if (customContent.isButtonCustomized("__PREV__")) { if (this.customContent.isButtonCustomized("__PREV__")) {
customContent.getCustomizedButton("__PREV__").applyItem(item); this.customContent.getCustomizedButton("__PREV__").applyItem(item);
} }
return super.setPrevPage(item); return super.setPrevPage(item);
@ -738,8 +738,8 @@ public class CustomizableGui extends Gui {
applyShowGuiKeys("__NEXT__", item); applyShowGuiKeys("__NEXT__", item);
if (customContent.isButtonCustomized("__NEXT__")) { if (this.customContent.isButtonCustomized("__NEXT__")) {
CustomButton btn = customContent.getCustomizedButton("__NEXT__"); CustomButton btn = this.customContent.getCustomizedButton("__NEXT__");
cells = btn.applyPosition(cell); cells = btn.applyPosition(cell);
btn.applyItem(item); btn.applyItem(item);
} }
@ -755,7 +755,7 @@ public class CustomizableGui extends Gui {
public Gui setNextPage(int row, int col, @NotNull ItemStack item) { public Gui setNextPage(int row, int col, @NotNull ItemStack item) {
applyShowGuiKeys("__NEXT__", item); applyShowGuiKeys("__NEXT__", item);
return setNextPage(col + row * inventoryType.columns, item); return setNextPage(col + row * this.inventoryType.columns, item);
} }
@NotNull @NotNull
@ -764,8 +764,8 @@ public class CustomizableGui extends Gui {
applyShowGuiKeys("__PREV__", item); applyShowGuiKeys("__PREV__", item);
if (customContent.isButtonCustomized("__PREV__")) { if (this.customContent.isButtonCustomized("__PREV__")) {
CustomButton btn = customContent.getCustomizedButton("__PREV__"); CustomButton btn = this.customContent.getCustomizedButton("__PREV__");
cells = btn.applyPosition(cell); cells = btn.applyPosition(cell);
btn.applyItem(item); btn.applyItem(item);
} }
@ -781,7 +781,7 @@ public class CustomizableGui extends Gui {
public Gui setPrevPage(int row, int col, @NotNull ItemStack item) { public Gui setPrevPage(int row, int col, @NotNull ItemStack item) {
applyShowGuiKeys("__PREV__", item); applyShowGuiKeys("__PREV__", item);
return setPrevPage(col + row * inventoryType.columns, item); return setPrevPage(col + row * this.inventoryType.columns, item);
} }
private boolean applyShowGuiKeys(String key, ItemStack item) { private boolean applyShowGuiKeys(String key, ItemStack item) {
@ -850,7 +850,7 @@ public class CustomizableGui extends Gui {
} }
public String getKey() { public String getKey() {
return key; return this.key;
} }
public boolean applyItem(ItemStack item) { public boolean applyItem(ItemStack item) {
@ -879,23 +879,23 @@ public class CustomizableGui extends Gui {
private void applyMeta(ItemStack item) { private void applyMeta(ItemStack item) {
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (title != null) { if (this.title != null) {
meta.setDisplayName(TextUtils.formatText(title)); meta.setDisplayName(TextUtils.formatText(this.title));
} }
if (lore != null) { if (this.lore != null) {
meta.setLore(TextUtils.formatText(lore)); meta.setLore(TextUtils.formatText(this.lore));
} }
item.setItemMeta(meta); item.setItemMeta(meta);
} }
public List<Integer> applyPosition(int cell) { public List<Integer> applyPosition(int cell) {
if (row != -1 && col != -1) { if (this.row != -1 && this.col != -1) {
return Collections.singletonList(col + row * inventoryType.columns); return Collections.singletonList(this.col + this.row * CustomizableGui.this.inventoryType.columns);
} }
return positions == null ? Collections.singletonList(cell) : positions; return this.positions == null ? Collections.singletonList(cell) : this.positions;
} }
public int applyPositionRow(int row) { public int applyPositionRow(int row) {
@ -919,11 +919,11 @@ public class CustomizableGui extends Gui {
} }
public boolean isMirrorRow() { public boolean isMirrorRow() {
return mirrorRow; return this.mirrorRow;
} }
public boolean isMirrorCol() { public boolean isMirrorCol() {
return mirrorCol; return this.mirrorCol;
} }
} }
@ -940,19 +940,19 @@ public class CustomizableGui extends Gui {
} }
public String getGuiKey() { public String getGuiKey() {
return guiKey; return this.guiKey;
} }
public CustomButton getCustomizedButton(String key) { public CustomButton getCustomizedButton(String key) {
return customizedButtons.get(key); return this.customizedButtons.get(key);
} }
public CustomButton getCustomButton(String key) { public CustomButton getCustomButton(String key) {
return customizedButtons.get(key); return this.customizedButtons.get(key);
} }
public Map<String, CustomButton> getCustomButtons() { public Map<String, CustomButton> getCustomButtons() {
return Collections.unmodifiableMap(customButtons); return Collections.unmodifiableMap(this.customButtons);
} }
public void addButton(String key, String position, String title, List<String> lore, XMaterial item) { public void addButton(String key, String position, String title, List<String> lore, XMaterial item) {
@ -963,49 +963,49 @@ public class CustomizableGui extends Gui {
CustomButton customButton = new CustomButton(key, positions, title, lore, item); CustomButton customButton = new CustomButton(key, positions, title, lore, item);
if (key.startsWith("custom_")) { if (key.startsWith("custom_")) {
customButtons.put(key, customButton); this.customButtons.put(key, customButton);
return; return;
} }
customizedButtons.put(key, customButton); this.customizedButtons.put(key, customButton);
} }
public void addButton(String key, int row, int col, String title, List<String> lore, XMaterial item) { public void addButton(String key, int row, int col, String title, List<String> lore, XMaterial item) {
CustomButton customButton = new CustomButton(key, row, col, title, lore, item); CustomButton customButton = new CustomButton(key, row, col, title, lore, item);
if (key.startsWith("custom_")) { if (key.startsWith("custom_")) {
customButtons.put(key, customButton); this.customButtons.put(key, customButton);
return; return;
} }
customizedButtons.put(key, customButton); this.customizedButtons.put(key, customButton);
} }
public void addButton(String key, int row, int col, boolean mirrorRow, boolean mirrorCol, XMaterial item) { public void addButton(String key, int row, int col, boolean mirrorRow, boolean mirrorCol, XMaterial item) {
MirrorFill mirrorFill = new MirrorFill(key, row, col, mirrorRow, mirrorCol, item); MirrorFill mirrorFill = new MirrorFill(key, row, col, mirrorRow, mirrorCol, item);
if (key.startsWith("custom_")) { if (key.startsWith("custom_")) {
customButtons.put(key, mirrorFill); this.customButtons.put(key, mirrorFill);
return; return;
} }
customizedButtons.put(key, mirrorFill); this.customizedButtons.put(key, mirrorFill);
} }
public boolean isButtonCustomized(String key) { public boolean isButtonCustomized(String key) {
return customizedButtons.containsKey(key); return this.customizedButtons.containsKey(key);
} }
public void disableButton(String button) { public void disableButton(String button) {
disabledButtons.add(button); this.disabledButtons.add(button);
} }
public boolean isButtonDisabled(String button) { public boolean isButtonDisabled(String button) {
return disabledButtons.contains(button); return this.disabledButtons.contains(button);
} }
public int getRows() { public int getRows() {
return rows; return this.rows;
} }
public void setRows(int rows) { public void setRows(int rows) {

View File

@ -32,31 +32,31 @@ public class DoubleGui extends Gui {
public DoubleGui() { public DoubleGui() {
super(GuiType.STANDARD); super(GuiType.STANDARD);
allowDropItems = false; this.allowDropItems = false;
} }
public DoubleGui(GuiType type) { public DoubleGui(GuiType type) {
super(type); super(type);
allowDropItems = false; this.allowDropItems = false;
} }
public DoubleGui(int rows) { public DoubleGui(int rows) {
super(rows); super(rows);
allowDropItems = false; this.allowDropItems = false;
} }
public DoubleGui(int rows, Gui parent) { public DoubleGui(int rows, Gui parent) {
super(rows, parent); super(rows, parent);
allowDropItems = false; this.allowDropItems = false;
} }
public DoubleGui(Gui parent) { public DoubleGui(Gui parent) {
super(parent); super(parent);
allowDropItems = false; this.allowDropItems = false;
} }
public int getPlayerRows() { public int getPlayerRows() {
return playerRows; return this.playerRows;
} }
// 9 -> 0 -> 54 // 9 -> 0 -> 54
@ -78,29 +78,29 @@ public class DoubleGui extends Gui {
} }
public DoubleGui setPlayerUnlocked(int cell) { public DoubleGui setPlayerUnlocked(int cell) {
unlockedCells.put(invOffset(cell), true); this.unlockedCells.put(invOffset(cell), true);
return this; return this;
} }
public DoubleGui setPlayerUnlocked(int row, int col) { public DoubleGui setPlayerUnlocked(int row, int col) {
unlockedCells.put(invOffset(col + row * 9), true); this.unlockedCells.put(invOffset(col + row * 9), true);
return this; return this;
} }
public DoubleGui setPlayerUnlocked(int cell, boolean open) { public DoubleGui setPlayerUnlocked(int cell, boolean open) {
unlockedCells.put(invOffset(cell), open); this.unlockedCells.put(invOffset(cell), open);
return this; return this;
} }
public DoubleGui setPlayerUnlocked(int row, int col, boolean open) { public DoubleGui setPlayerUnlocked(int row, int col, boolean open) {
unlockedCells.put(invOffset(col + row * 9), open); this.unlockedCells.put(invOffset(col + row * 9), open);
return this; return this;
} }
public DoubleGui setPlayerUnlockedRange(int cellFirst, int cellLast) { public DoubleGui setPlayerUnlockedRange(int cellFirst, int cellLast) {
final int last = invOffset(cellLast); final int last = invOffset(cellLast);
for (int cell = invOffset(cellFirst); cell <= last; ++cell) { for (int cell = invOffset(cellFirst); cell <= last; ++cell) {
unlockedCells.put(cell, true); this.unlockedCells.put(cell, true);
} }
return this; return this;
} }
@ -109,7 +109,7 @@ public class DoubleGui extends Gui {
final int last = invOffset(cellLast); final int last = invOffset(cellLast);
for (int cell = invOffset(cellFirst); cell <= last; ++cell) { for (int cell = invOffset(cellFirst); cell <= last; ++cell) {
unlockedCells.put(cell, open); this.unlockedCells.put(cell, open);
} }
return this; return this;
@ -119,7 +119,7 @@ public class DoubleGui extends Gui {
final int last = invOffset(cellColLast + cellRowLast * 9); final int last = invOffset(cellColLast + cellRowLast * 9);
for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) { for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) {
unlockedCells.put(cell, true); this.unlockedCells.put(cell, true);
} }
return this; return this;
@ -129,19 +129,19 @@ public class DoubleGui extends Gui {
final int last = invOffset(cellColLast + cellRowLast * 9); final int last = invOffset(cellColLast + cellRowLast * 9);
for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) { for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) {
unlockedCells.put(cell, open); this.unlockedCells.put(cell, open);
} }
return this; return this;
} }
public DoubleGui setPlayerItem(int cell, ItemStack item) { public DoubleGui setPlayerItem(int cell, ItemStack item) {
cellItems.put(invOffset(cell), item); this.cellItems.put(invOffset(cell), item);
if (open && cell >= 0 && cell < 36) { if (this.open && cell >= 0 && cell < 36) {
cell = cell >= 27 ? cell - 27 : cell + 9; cell = cell >= 27 ? cell - 27 : cell + 9;
for (HumanEntity e : inventory.getViewers()) { for (HumanEntity e : this.inventory.getViewers()) {
e.getInventory().setItem(cell, item); e.getInventory().setItem(cell, item);
} }
} }
@ -151,12 +151,12 @@ public class DoubleGui extends Gui {
public DoubleGui setPlayerItem(int row, int col, ItemStack item) { public DoubleGui setPlayerItem(int row, int col, ItemStack item) {
int cell = col + row * 9; int cell = col + row * 9;
cellItems.put(invOffset(cell), item); this.cellItems.put(invOffset(cell), item);
if (open && cell >= 0 && cell < 36) { if (this.open && cell >= 0 && cell < 36) {
cell = cell >= 27 ? cell - 27 : cell + 9; cell = cell >= 27 ? cell - 27 : cell + 9;
for (HumanEntity e : inventory.getViewers()) { for (HumanEntity e : this.inventory.getViewers()) {
e.getInventory().setItem(cell, item); e.getInventory().setItem(cell, item);
} }
} }
@ -166,7 +166,7 @@ public class DoubleGui extends Gui {
public DoubleGui highlightPlayerItem(int cell) { public DoubleGui highlightPlayerItem(int cell) {
final int invCell = invOffset(cell); final int invCell = invOffset(cell);
ItemStack item = cellItems.get(invCell); ItemStack item = this.cellItems.get(invCell);
if (item != null) { if (item != null) {
setPlayerItem(cell, ItemUtils.addGlow(item)); setPlayerItem(cell, ItemUtils.addGlow(item));
@ -179,7 +179,7 @@ public class DoubleGui extends Gui {
final int cell = col + row * 9; final int cell = col + row * 9;
final int invCell = invOffset(cell); final int invCell = invOffset(cell);
ItemStack item = cellItems.get(invCell); ItemStack item = this.cellItems.get(invCell);
if (item != null) { if (item != null) {
setPlayerItem(cell, ItemUtils.addGlow(item)); setPlayerItem(cell, ItemUtils.addGlow(item));
} }
@ -244,13 +244,13 @@ public class DoubleGui extends Gui {
} }
public DoubleGui clearPlayerActions(int cell) { public DoubleGui clearPlayerActions(int cell) {
conditionalButtons.remove(invOffset(cell)); this.conditionalButtons.remove(invOffset(cell));
return this; return this;
} }
public DoubleGui clearPlayerActions(int row, int col) { public DoubleGui clearPlayerActions(int row, int col) {
final int cell = invOffset(col + row * 9); final int cell = invOffset(col + row * 9);
conditionalButtons.remove(cell); this.conditionalButtons.remove(cell);
return this; return this;
} }
@ -290,7 +290,7 @@ public class DoubleGui extends Gui {
@Override @Override
protected boolean onClickPlayerInventory(GuiManager manager, Player player, Inventory openInv, InventoryClickEvent event) { protected boolean onClickPlayerInventory(GuiManager manager, Player player, Inventory openInv, InventoryClickEvent event) {
final int cell = event.getSlot(), offsetCell = clickOffset(cell); final int cell = event.getSlot(), offsetCell = clickOffset(cell);
Map<ClickType, Clickable> conditionals = conditionalButtons.get(offsetCell); Map<ClickType, Clickable> conditionals = this.conditionalButtons.get(offsetCell);
Clickable button; Clickable button;
if (conditionals != null if (conditionals != null
@ -301,15 +301,15 @@ public class DoubleGui extends Gui {
return false; return false;
} }
event.setCancelled(unlockedCells.entrySet().stream().noneMatch(e -> offsetCell == e.getKey() && e.getValue())); event.setCancelled(this.unlockedCells.entrySet().stream().noneMatch(e -> offsetCell == e.getKey() && e.getValue()));
return true; return true;
} }
@Override @Override
protected boolean onClickOutside(GuiManager manager, Player player, InventoryClickEvent event) { protected boolean onClickOutside(GuiManager manager, Player player, InventoryClickEvent event) {
if (dropper != null) { if (this.dropper != null) {
return dropper.onDrop(new GuiDropItemEvent(manager, this, player, event)); return this.dropper.onDrop(new GuiDropItemEvent(manager, this, player, event));
} }
// do not allow by default // do not allow by default
@ -319,7 +319,7 @@ public class DoubleGui extends Gui {
@Override @Override
public void onOpen(GuiManager manager, Player player) { public void onOpen(GuiManager manager, Player player) {
// replace the player's inventory // replace the player's inventory
if (startStashed) { if (this.startStashed) {
stashItems(player); stashItems(player);
} }
@ -337,15 +337,15 @@ public class DoubleGui extends Gui {
} }
protected void restoreStash(Player player) { protected void restoreStash(Player player) {
if (stash.containsKey(player)) { if (this.stash.containsKey(player)) {
player.getInventory().setContents(stash.remove(player)); player.getInventory().setContents(this.stash.remove(player));
player.updateInventory(); player.updateInventory();
} }
} }
protected void stashItems(Player player) { protected void stashItems(Player player) {
if (!stash.containsKey(player)) { if (!this.stash.containsKey(player)) {
stash.put(player, player.getInventory().getContents().clone()); this.stash.put(player, player.getInventory().getContents().clone());
player.getInventory().clear(); player.getInventory().clear();
} }
} }

View File

@ -96,11 +96,11 @@ public class Gui {
@NotNull @NotNull
public List<Player> getPlayers() { public List<Player> getPlayers() {
if (inventory == null) { if (this.inventory == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
return inventory.getViewers().stream() return this.inventory.getViewers().stream()
.filter(Player.class::isInstance) .filter(Player.class::isInstance)
.map(Player.class::cast) .map(Player.class::cast)
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -108,15 +108,15 @@ public class Gui {
public boolean isOpen() { public boolean isOpen() {
// double check // double check
if (inventory != null && inventory.getViewers().isEmpty()) { if (this.inventory != null && this.inventory.getViewers().isEmpty()) {
open = false; this.open = false;
} }
return open; return this.open;
} }
public boolean getAcceptsItems() { public boolean getAcceptsItems() {
return acceptsItems; return this.acceptsItems;
} }
public Gui setAcceptsItems(boolean acceptsItems) { public Gui setAcceptsItems(boolean acceptsItems) {
@ -129,7 +129,7 @@ public class Gui {
* will be cleared * will be cleared
*/ */
public boolean getAllowDrops() { public boolean getAllowDrops() {
return allowDropItems; return this.allowDropItems;
} }
/** /**
@ -142,7 +142,7 @@ public class Gui {
} }
public boolean getAllowClose() { public boolean getAllowClose() {
return allowClose; return this.allowClose;
} }
public Gui setAllowClose(boolean allow) { public Gui setAllowClose(boolean allow) {
@ -155,10 +155,10 @@ public class Gui {
* GUIs * GUIs
*/ */
public void exit() { public void exit() {
allowClose = true; this.allowClose = true;
open = false; this.open = false;
inventory.getViewers().stream() this.inventory.getViewers().stream()
.filter(Player.class::isInstance) .filter(Player.class::isInstance)
.map(Player.class::cast) .map(Player.class::cast)
.collect(Collectors.toList()) .collect(Collectors.toList())
@ -169,9 +169,9 @@ public class Gui {
* Close the GUI as if the player closed it normally * Close the GUI as if the player closed it normally
*/ */
public void close() { public void close() {
allowClose = true; this.allowClose = true;
inventory.getViewers().stream() this.inventory.getViewers().stream()
.filter(Player.class::isInstance) .filter(Player.class::isInstance)
.map(Player.class::cast) .map(Player.class::cast)
.collect(Collectors.toList()) .collect(Collectors.toList())
@ -180,19 +180,19 @@ public class Gui {
@NotNull @NotNull
public GuiType getType() { public GuiType getType() {
return inventoryType; return this.inventoryType;
} }
@NotNull @NotNull
public Gui setUnlocked(int cell) { public Gui setUnlocked(int cell) {
unlockedCells.put(cell, true); this.unlockedCells.put(cell, true);
return this; return this;
} }
@NotNull @NotNull
public Gui setUnlocked(int row, int col) { public Gui setUnlocked(int row, int col) {
final int cell = col + row * inventoryType.columns; final int cell = col + row * this.inventoryType.columns;
unlockedCells.put(cell, true); this.unlockedCells.put(cell, true);
return this; return this;
} }
@ -200,7 +200,7 @@ public class Gui {
@NotNull @NotNull
public Gui setUnlockedRange(int cellFirst, int cellLast) { public Gui setUnlockedRange(int cellFirst, int cellLast) {
for (int cell = cellFirst; cell <= cellLast; ++cell) { for (int cell = cellFirst; cell <= cellLast; ++cell) {
unlockedCells.put(cell, true); this.unlockedCells.put(cell, true);
} }
return this; return this;
@ -209,7 +209,7 @@ public class Gui {
@NotNull @NotNull
public Gui setUnlockedRange(int cellFirst, int cellLast, boolean open) { public Gui setUnlockedRange(int cellFirst, int cellLast, boolean open) {
for (int cell = cellFirst; cell <= cellLast; ++cell) { for (int cell = cellFirst; cell <= cellLast; ++cell) {
unlockedCells.put(cell, open); this.unlockedCells.put(cell, open);
} }
return this; return this;
@ -217,10 +217,10 @@ public class Gui {
@NotNull @NotNull
public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast) { public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast) {
final int last = cellColLast + cellRowLast * inventoryType.columns; final int last = cellColLast + cellRowLast * this.inventoryType.columns;
for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) { for (int cell = cellColFirst + cellRowFirst * this.inventoryType.columns; cell <= last; ++cell) {
unlockedCells.put(cell, true); this.unlockedCells.put(cell, true);
} }
return this; return this;
@ -228,10 +228,10 @@ public class Gui {
@NotNull @NotNull
public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, boolean open) { public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, boolean open) {
final int last = cellColLast + cellRowLast * inventoryType.columns; final int last = cellColLast + cellRowLast * this.inventoryType.columns;
for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) { for (int cell = cellColFirst + cellRowFirst * this.inventoryType.columns; cell <= last; ++cell) {
unlockedCells.put(cell, open); this.unlockedCells.put(cell, open);
} }
return this; return this;
@ -239,14 +239,14 @@ public class Gui {
@NotNull @NotNull
public Gui setUnlocked(int cell, boolean open) { public Gui setUnlocked(int cell, boolean open) {
unlockedCells.put(cell, open); this.unlockedCells.put(cell, open);
return this; return this;
} }
@NotNull @NotNull
public Gui setUnlocked(int row, int col, boolean open) { public Gui setUnlocked(int row, int col, boolean open) {
final int cell = col + row * inventoryType.columns; final int cell = col + row * this.inventoryType.columns;
unlockedCells.put(cell, open); this.unlockedCells.put(cell, open);
return this; return this;
} }
@ -260,19 +260,19 @@ public class Gui {
if (!title.equals(this.title)) { if (!title.equals(this.title)) {
this.title = title; this.title = title;
if (inventory != null) { if (this.inventory != null) {
// update active inventory // update active inventory
List<Player> toUpdate = getPlayers(); List<Player> toUpdate = getPlayers();
boolean isAllowClose = allowClose; boolean isAllowClose = this.allowClose;
exit(); exit();
Inventory oldInv = inventory; Inventory oldInv = this.inventory;
createInventory(); createInventory();
inventory.setContents(oldInv.getContents()); this.inventory.setContents(oldInv.getContents());
toUpdate.forEach(player -> player.openInventory(inventory)); toUpdate.forEach(player -> player.openInventory(this.inventory));
allowClose = isAllowClose; this.allowClose = isAllowClose;
} }
} }
@ -280,12 +280,12 @@ public class Gui {
} }
public int getRows() { public int getRows() {
return rows; return this.rows;
} }
@NotNull @NotNull
public Gui setRows(int rows) { public Gui setRows(int rows) {
switch (inventoryType) { switch (this.inventoryType) {
case HOPPER: case HOPPER:
case DISPENSER: case DISPENSER:
break; break;
@ -299,53 +299,53 @@ public class Gui {
@NotNull @NotNull
public Gui setDefaultAction(@Nullable Clickable action) { public Gui setDefaultAction(@Nullable Clickable action) {
defaultClicker = action; this.defaultClicker = action;
return this; return this;
} }
@NotNull @NotNull
protected Gui setPrivateDefaultAction(@Nullable Clickable action) { protected Gui setPrivateDefaultAction(@Nullable Clickable action) {
privateDefaultClicker = action; this.privateDefaultClicker = action;
return this; return this;
} }
@NotNull @NotNull
public Gui setDefaultItem(@Nullable ItemStack item) { public Gui setDefaultItem(@Nullable ItemStack item) {
blankItem = item; this.blankItem = item;
return this; return this;
} }
@Nullable @Nullable
public ItemStack getDefaultItem() { public ItemStack getDefaultItem() {
return blankItem; return this.blankItem;
} }
@Nullable @Nullable
public ItemStack getItem(int cell) { public ItemStack getItem(int cell) {
if (inventory != null && unlockedCells.getOrDefault(cell, false)) { if (this.inventory != null && this.unlockedCells.getOrDefault(cell, false)) {
return inventory.getItem(cell); return this.inventory.getItem(cell);
} }
return cellItems.get(cell); return this.cellItems.get(cell);
} }
@Nullable @Nullable
public ItemStack getItem(int row, int col) { public ItemStack getItem(int row, int col) {
final int cell = col + row * inventoryType.columns; final int cell = col + row * this.inventoryType.columns;
if (inventory != null && unlockedCells.getOrDefault(cell, false)) { if (this.inventory != null && this.unlockedCells.getOrDefault(cell, false)) {
return inventory.getItem(cell); return this.inventory.getItem(cell);
} }
return cellItems.get(cell); return this.cellItems.get(cell);
} }
@NotNull @NotNull
public Gui setItem(int cell, @Nullable ItemStack item) { public Gui setItem(int cell, @Nullable ItemStack item) {
cellItems.put(cell, item); this.cellItems.put(cell, item);
if (inventory != null && cell >= 0 && cell < inventory.getSize()) { if (this.inventory != null && cell >= 0 && cell < this.inventory.getSize()) {
inventory.setItem(cell, item); this.inventory.setItem(cell, item);
} }
return this; return this;
@ -353,7 +353,7 @@ public class Gui {
@NotNull @NotNull
public Gui setItem(int row, int col, @Nullable ItemStack item) { public Gui setItem(int row, int col, @Nullable ItemStack item) {
final int cell = col + row * inventoryType.columns; final int cell = col + row * this.inventoryType.columns;
return setItem(cell, item); return setItem(cell, item);
} }
@ -362,7 +362,7 @@ public class Gui {
setItem(row, col, item); setItem(row, col, item);
if (mirrorRow) { if (mirrorRow) {
setItem(rows - row - 1, col, item); setItem(this.rows - row - 1, col, item);
} }
if (mirrorCol) { if (mirrorCol) {
@ -370,7 +370,7 @@ public class Gui {
} }
if (mirrorRow && mirrorCol) { if (mirrorRow && mirrorCol) {
setItem(rows - row - 1, 8 - col, item); setItem(this.rows - row - 1, 8 - col, item);
} }
return this; return this;
@ -378,7 +378,7 @@ public class Gui {
@NotNull @NotNull
public Gui highlightItem(int cell) { public Gui highlightItem(int cell) {
ItemStack item = cellItems.get(cell); ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
setItem(cell, ItemUtils.addGlow(item)); setItem(cell, ItemUtils.addGlow(item));
@ -389,14 +389,14 @@ public class Gui {
@NotNull @NotNull
public Gui highlightItem(int row, int col) { public Gui highlightItem(int row, int col) {
final int cell = col + row * inventoryType.columns; final int cell = col + row * this.inventoryType.columns;
return highlightItem(cell); return highlightItem(cell);
} }
@NotNull @NotNull
public Gui removeHighlight(int cell) { public Gui removeHighlight(int cell) {
ItemStack item = cellItems.get(cell); ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
setItem(cell, ItemUtils.removeGlow(item)); setItem(cell, ItemUtils.removeGlow(item));
@ -407,18 +407,18 @@ public class Gui {
@NotNull @NotNull
public Gui removeHighlight(int row, int col) { public Gui removeHighlight(int row, int col) {
final int cell = col + row * inventoryType.columns; final int cell = col + row * this.inventoryType.columns;
return removeHighlight(cell); return removeHighlight(cell);
} }
@NotNull @NotNull
public Gui updateItemLore(int row, int col, @NotNull String... lore) { public Gui updateItemLore(int row, int col, @NotNull String... lore) {
return updateItemLore(col + row * inventoryType.columns, lore); return updateItemLore(col + row * this.inventoryType.columns, lore);
} }
@NotNull @NotNull
public Gui updateItemLore(int cell, @NotNull String... lore) { public Gui updateItemLore(int cell, @NotNull String... lore) {
ItemStack item = cellItems.get(cell); ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItemLore(item, lore)); setItem(cell, GuiUtils.updateItemLore(item, lore));
@ -429,12 +429,12 @@ public class Gui {
@NotNull @NotNull
public Gui updateItemLore(int row, int col, @Nullable List<String> lore) { public Gui updateItemLore(int row, int col, @Nullable List<String> lore) {
return updateItemLore(col + row * inventoryType.columns, lore); return updateItemLore(col + row * this.inventoryType.columns, lore);
} }
@NotNull @NotNull
public Gui updateItemLore(int cell, @Nullable List<String> lore) { public Gui updateItemLore(int cell, @Nullable List<String> lore) {
ItemStack item = cellItems.get(cell); ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItemLore(item, lore)); setItem(cell, GuiUtils.updateItemLore(item, lore));
@ -445,12 +445,12 @@ public class Gui {
@NotNull @NotNull
public Gui updateItemName(int row, int col, @Nullable String name) { public Gui updateItemName(int row, int col, @Nullable String name) {
return updateItemName(col + row * inventoryType.columns, name); return updateItemName(col + row * this.inventoryType.columns, name);
} }
@NotNull @NotNull
public Gui updateItemName(int cell, @Nullable String name) { public Gui updateItemName(int cell, @Nullable String name) {
ItemStack item = cellItems.get(cell); ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItemName(item, name)); setItem(cell, GuiUtils.updateItemName(item, name));
@ -461,7 +461,7 @@ public class Gui {
@NotNull @NotNull
public Gui updateItem(int row, int col, @Nullable String name, @NotNull String... lore) { public Gui updateItem(int row, int col, @Nullable String name, @NotNull String... lore) {
return updateItem(col + row * inventoryType.columns, name, lore); return updateItem(col + row * this.inventoryType.columns, name, lore);
} }
@NotNull @NotNull
@ -471,12 +471,12 @@ public class Gui {
@NotNull @NotNull
public Gui updateItem(int row, int col, @Nullable String name, @Nullable List<String> lore) { public Gui updateItem(int row, int col, @Nullable String name, @Nullable List<String> lore) {
return updateItem(col + row * inventoryType.columns, name, lore); return updateItem(col + row * this.inventoryType.columns, name, lore);
} }
@NotNull @NotNull
public Gui updateItem(int cell, @NotNull String name, @Nullable List<String> lore) { public Gui updateItem(int cell, @NotNull String name, @Nullable List<String> lore) {
ItemStack item = cellItems.get(cell); ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, name, lore)); setItem(cell, GuiUtils.updateItem(item, name, lore));
@ -487,12 +487,12 @@ public class Gui {
@NotNull @NotNull
public Gui updateItem(int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) { public Gui updateItem(int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
return updateItem(col + row * inventoryType.columns, itemTo, title, lore); return updateItem(col + row * this.inventoryType.columns, itemTo, title, lore);
} }
@NotNull @NotNull
public Gui updateItem(int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) { public Gui updateItem(int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
ItemStack item = cellItems.get(cell); ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
@ -503,12 +503,12 @@ public class Gui {
@NotNull @NotNull
public Gui updateItem(int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @NotNull String... lore) { public Gui updateItem(int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @NotNull String... lore) {
return updateItem(col + row * inventoryType.columns, itemTo, title, lore); return updateItem(col + row * this.inventoryType.columns, itemTo, title, lore);
} }
@NotNull @NotNull
public Gui updateItem(int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable String... lore) { public Gui updateItem(int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable String... lore) {
ItemStack item = cellItems.get(cell); ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
@ -519,12 +519,12 @@ public class Gui {
@NotNull @NotNull
public Gui updateItem(int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) { public Gui updateItem(int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
return updateItem(col + row * inventoryType.columns, itemTo, title, lore); return updateItem(col + row * this.inventoryType.columns, itemTo, title, lore);
} }
@NotNull @NotNull
public Gui updateItem(int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) { public Gui updateItem(int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
ItemStack item = cellItems.get(cell); ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
@ -535,12 +535,12 @@ public class Gui {
@NotNull @NotNull
public Gui updateItem(int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) { public Gui updateItem(int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
return updateItem(col + row * inventoryType.columns, itemTo, title, lore); return updateItem(col + row * this.inventoryType.columns, itemTo, title, lore);
} }
@NotNull @NotNull
public Gui updateItem(int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) { public Gui updateItem(int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
ItemStack item = cellItems.get(cell); ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
@ -557,7 +557,7 @@ public class Gui {
@NotNull @NotNull
public Gui setAction(int row, int col, @Nullable Clickable action) { public Gui setAction(int row, int col, @Nullable Clickable action) {
setConditional(col + row * inventoryType.columns, null, action); setConditional(col + row * this.inventoryType.columns, null, action);
return this; return this;
} }
@ -569,7 +569,7 @@ public class Gui {
@NotNull @NotNull
public Gui setAction(int row, int col, @Nullable ClickType type, @Nullable Clickable action) { public Gui setAction(int row, int col, @Nullable ClickType type, @Nullable Clickable action) {
setConditional(col + row * inventoryType.columns, type, action); setConditional(col + row * this.inventoryType.columns, type, action);
return this; return this;
} }
@ -584,9 +584,9 @@ public class Gui {
@NotNull @NotNull
public Gui setActionForRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, @Nullable Clickable action) { public Gui setActionForRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, @Nullable Clickable action) {
final int last = cellColLast + cellRowLast * inventoryType.columns; final int last = cellColLast + cellRowLast * this.inventoryType.columns;
for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) { for (int cell = cellColFirst + cellRowFirst * this.inventoryType.columns; cell <= last; ++cell) {
setConditional(cell, null, action); setConditional(cell, null, action);
} }
@ -604,9 +604,9 @@ public class Gui {
@NotNull @NotNull
public Gui setActionForRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, @Nullable ClickType type, @Nullable Clickable action) { public Gui setActionForRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, @Nullable ClickType type, @Nullable Clickable action) {
final int last = cellColLast + cellRowLast * inventoryType.columns; final int last = cellColLast + cellRowLast * this.inventoryType.columns;
for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) { for (int cell = cellColFirst + cellRowFirst * this.inventoryType.columns; cell <= last; ++cell) {
setConditional(cell, type, action); setConditional(cell, type, action);
} }
@ -615,13 +615,13 @@ public class Gui {
@NotNull @NotNull
public Gui clearActions(int cell) { public Gui clearActions(int cell) {
conditionalButtons.remove(cell); this.conditionalButtons.remove(cell);
return this; return this;
} }
@NotNull @NotNull
public Gui clearActions(int row, int col) { public Gui clearActions(int row, int col) {
return clearActions(col + row * inventoryType.columns); return clearActions(col + row * this.inventoryType.columns);
} }
@NotNull @NotNull
@ -634,7 +634,7 @@ public class Gui {
@NotNull @NotNull
public Gui setButton(int row, int col, @Nullable ItemStack item, @Nullable Clickable action) { public Gui setButton(int row, int col, @Nullable ItemStack item, @Nullable Clickable action) {
final int cell = col + row * inventoryType.columns; final int cell = col + row * this.inventoryType.columns;
setItem(cell, item); setItem(cell, item);
setConditional(cell, null, action); setConditional(cell, null, action);
@ -652,7 +652,7 @@ public class Gui {
@NotNull @NotNull
public Gui setButton(int row, int col, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) { public Gui setButton(int row, int col, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) {
final int cell = col + row * inventoryType.columns; final int cell = col + row * this.inventoryType.columns;
setItem(cell, item); setItem(cell, item);
setConditional(cell, type, action); setConditional(cell, type, action);
@ -661,62 +661,62 @@ public class Gui {
} }
protected void setConditional(int cell, @Nullable ClickType type, @Nullable Clickable action) { protected void setConditional(int cell, @Nullable ClickType type, @Nullable Clickable action) {
Map<ClickType, Clickable> conditionals = conditionalButtons.computeIfAbsent(cell, k -> new HashMap<>()); Map<ClickType, Clickable> conditionals = this.conditionalButtons.computeIfAbsent(cell, k -> new HashMap<>());
conditionals.put(type, action); conditionals.put(type, action);
} }
@NotNull @NotNull
public Gui setOnOpen(@Nullable Openable action) { public Gui setOnOpen(@Nullable Openable action) {
opener = action; this.opener = action;
return this; return this;
} }
@NotNull @NotNull
public Gui setOnClose(@Nullable Closable action) { public Gui setOnClose(@Nullable Closable action) {
closer = action; this.closer = action;
return this; return this;
} }
@NotNull @NotNull
public Gui setOnDrop(@Nullable Droppable action) { public Gui setOnDrop(@Nullable Droppable action) {
dropper = action; this.dropper = action;
return this; return this;
} }
@NotNull @NotNull
public Gui setOnPage(@Nullable Pagable action) { public Gui setOnPage(@Nullable Pagable action) {
pager = action; this.pager = action;
return this; return this;
} }
public Gui setNextPage(ItemStack item) { public Gui setNextPage(ItemStack item) {
nextPage = item; this.nextPage = item;
return this; return this;
} }
public Gui setPrevPage(ItemStack item) { public Gui setPrevPage(ItemStack item) {
prevPage = item; this.prevPage = item;
return this; return this;
} }
public void reset() { public void reset() {
if (inventory != null) { if (this.inventory != null) {
inventory.clear(); this.inventory.clear();
} }
setActionForRange(0, 53, null); setActionForRange(0, 53, null);
cellItems.clear(); this.cellItems.clear();
update(); update();
} }
@NotNull @NotNull
public Gui setNextPage(int cell, @NotNull ItemStack item) { public Gui setNextPage(int cell, @NotNull ItemStack item) {
nextPageItem = cellItems.get(cell); this.nextPageItem = this.cellItems.get(cell);
nextPageIndex = cell; this.nextPageIndex = cell;
nextPage = item; this.nextPage = item;
if (page < pages) { if (this.page < this.pages) {
setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage()); setButton(this.nextPageIndex, this.nextPage, ClickType.LEFT, (event) -> this.nextPage());
} }
return this; return this;
@ -724,17 +724,17 @@ public class Gui {
@NotNull @NotNull
public Gui setNextPage(int row, int col, @NotNull ItemStack item) { public Gui setNextPage(int row, int col, @NotNull ItemStack item) {
return setNextPage(col + row * inventoryType.columns, item); return setNextPage(col + row * this.inventoryType.columns, item);
} }
@NotNull @NotNull
public Gui setPrevPage(int cell, @NotNull ItemStack item) { public Gui setPrevPage(int cell, @NotNull ItemStack item) {
prevPageItem = cellItems.get(cell); this.prevPageItem = this.cellItems.get(cell);
prevPageIndex = cell; this.prevPageIndex = cell;
prevPage = item; this.prevPage = item;
if (page > 1) { if (this.page > 1) {
setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage()); setButton(this.prevPageIndex, this.prevPage, ClickType.LEFT, (event) -> this.prevPage());
} }
return this; return this;
@ -742,23 +742,23 @@ public class Gui {
@NotNull @NotNull
public Gui setPrevPage(int row, int col, @NotNull ItemStack item) { public Gui setPrevPage(int row, int col, @NotNull ItemStack item) {
return setPrevPage(col + row * inventoryType.columns, item); return setPrevPage(col + row * this.inventoryType.columns, item);
} }
public void setPages(int pages) { public void setPages(int pages) {
this.pages = Math.max(1, pages); this.pages = Math.max(1, pages);
if (page > pages) { if (this.page > pages) {
setPage(pages); setPage(pages);
} }
} }
public void setPage(int page) { public void setPage(int page) {
int lastPage = this.page; int lastPage = this.page;
this.page = Math.max(1, Math.min(pages, page)); this.page = Math.max(1, Math.min(this.pages, page));
if (pager != null && this.page != lastPage) { if (this.pager != null && this.page != lastPage) {
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page)); this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, page));
// page markers // page markers
updatePageNavigation(); updatePageNavigation();
@ -766,11 +766,11 @@ public class Gui {
} }
public void changePage(int direction) { public void changePage(int direction) {
int lastPage = page; int lastPage = this.page;
this.page = Math.max(1, Math.min(pages, page + direction)); this.page = Math.max(1, Math.min(this.pages, this.page + direction));
if (pager != null && this.page != lastPage) { if (this.pager != null && this.page != lastPage) {
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page)); this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, this.page));
// page markers // page markers
updatePageNavigation(); updatePageNavigation();
@ -778,13 +778,13 @@ public class Gui {
} }
public void nextPage() { public void nextPage() {
if (page < pages) { if (this.page < this.pages) {
int lastPage = page; int lastPage = this.page;
++page; ++this.page;
// page switch events // page switch events
if (pager != null) { if (this.pager != null) {
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page)); this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, this.page));
// page markers // page markers
updatePageNavigation(); updatePageNavigation();
@ -797,12 +797,12 @@ public class Gui {
} }
public void prevPage() { public void prevPage() {
if (page > 1) { if (this.page > 1) {
int lastPage = page; int lastPage = this.page;
--page; --this.page;
if (pager != null) { if (this.pager != null) {
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page)); this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, this.page));
// page markers // page markers
updatePageNavigation(); updatePageNavigation();
@ -815,75 +815,75 @@ public class Gui {
} }
protected void updatePageNavigation() { protected void updatePageNavigation() {
if (prevPage != null) { if (this.prevPage != null) {
if (page > 1) { if (this.page > 1) {
this.setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage()); this.setButton(this.prevPageIndex, this.prevPage, ClickType.LEFT, (event) -> this.prevPage());
} else { } else {
this.setItem(prevPageIndex, prevPageItem); this.setItem(this.prevPageIndex, this.prevPageItem);
this.clearActions(prevPageIndex); this.clearActions(this.prevPageIndex);
} }
} }
if (nextPage != null) { if (this.nextPage != null) {
if (pages > 1 && page != pages) { if (this.pages > 1 && this.page != this.pages) {
this.setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage()); this.setButton(this.nextPageIndex, this.nextPage, ClickType.LEFT, (event) -> this.nextPage());
} else { } else {
this.setItem(nextPageIndex, nextPageItem); this.setItem(this.nextPageIndex, this.nextPageItem);
this.clearActions(nextPageIndex); this.clearActions(this.nextPageIndex);
} }
} }
} }
@NotNull @NotNull
protected Inventory getOrCreateInventory(@NotNull GuiManager manager) { protected Inventory getOrCreateInventory(@NotNull GuiManager manager) {
return inventory != null ? inventory : generateInventory(manager); return this.inventory != null ? this.inventory : generateInventory(manager);
} }
@NotNull @NotNull
protected Inventory generateInventory(@NotNull GuiManager manager) { protected Inventory generateInventory(@NotNull GuiManager manager) {
this.guiManager = manager; this.guiManager = manager;
final int cells = rows * inventoryType.columns; final int cells = this.rows * this.inventoryType.columns;
createInventory(); createInventory();
for (int i = 0; i < cells; ++i) { for (int i = 0; i < cells; ++i) {
final ItemStack item = cellItems.get(i); final ItemStack item = this.cellItems.get(i);
inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem)); this.inventory.setItem(i, item != null ? item : (this.unlockedCells.getOrDefault(i, false) ? AIR : this.blankItem));
} }
return inventory; return this.inventory;
} }
protected void createInventory() { protected void createInventory() {
final InventoryType t = inventoryType == null ? InventoryType.CHEST : inventoryType.type; final InventoryType t = this.inventoryType == null ? InventoryType.CHEST : this.inventoryType.type;
switch (t) { switch (t) {
case DISPENSER: case DISPENSER:
case HOPPER: case HOPPER:
inventory = new GuiHolder(guiManager, this).newInventory(t, this.inventory = new GuiHolder(this.guiManager, this).newInventory(t,
title == null ? "" : trimTitle(title)); this.title == null ? "" : trimTitle(this.title));
break; break;
default: default:
inventory = new GuiHolder(guiManager, this).newInventory(rows * 9, this.inventory = new GuiHolder(this.guiManager, this).newInventory(this.rows * 9,
title == null ? "" : trimTitle(title)); this.title == null ? "" : trimTitle(this.title));
break; break;
} }
} }
@Nullable @Nullable
public Gui getParent() { public Gui getParent() {
return parent; return this.parent;
} }
public void update() { public void update() {
if (inventory == null) { if (this.inventory == null) {
return; return;
} }
final int cells = rows * inventoryType.columns; final int cells = this.rows * this.inventoryType.columns;
for (int i = 0; i < cells; ++i) { for (int i = 0; i < cells; ++i) {
final ItemStack item = cellItems.get(i); final ItemStack item = this.cellItems.get(i);
inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem)); this.inventory.setItem(i, item != null ? item : (this.unlockedCells.getOrDefault(i, false) ? AIR : this.blankItem));
} }
} }
@ -900,12 +900,12 @@ public class Gui {
} }
protected boolean onClickOutside(@NotNull GuiManager manager, @NotNull Player player, @NotNull InventoryClickEvent event) { protected boolean onClickOutside(@NotNull GuiManager manager, @NotNull Player player, @NotNull InventoryClickEvent event) {
return dropper == null || dropper.onDrop(new GuiDropItemEvent(manager, this, player, event)); return this.dropper == null || this.dropper.onDrop(new GuiDropItemEvent(manager, this, player, event));
} }
protected boolean onClick(@NotNull GuiManager manager, @NotNull Player player, @NotNull Inventory inventory, @NotNull InventoryClickEvent event) { protected boolean onClick(@NotNull GuiManager manager, @NotNull Player player, @NotNull Inventory inventory, @NotNull InventoryClickEvent event) {
final int cell = event.getSlot(); final int cell = event.getSlot();
Map<ClickType, Clickable> conditionals = conditionalButtons.get(cell); Map<ClickType, Clickable> conditionals = this.conditionalButtons.get(cell);
Clickable button; Clickable button;
if (conditionals != null if (conditionals != null
@ -913,14 +913,14 @@ public class Gui {
button.onClick(new GuiClickEvent(manager, this, player, event, cell, true)); button.onClick(new GuiClickEvent(manager, this, player, event, cell, true));
} else { } else {
// no event for this button // no event for this button
if (defaultClicker != null) { if (this.defaultClicker != null) {
// this is a default action, not a triggered action // this is a default action, not a triggered action
defaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true)); this.defaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true));
} }
if (privateDefaultClicker != null) { if (this.privateDefaultClicker != null) {
// this is a private default action, not a triggered action // this is a private default action, not a triggered action
privateDefaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true)); this.privateDefaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true));
} }
return false; return false;
@ -935,36 +935,36 @@ public class Gui {
} }
public void onOpen(@NotNull GuiManager manager, @NotNull Player player) { public void onOpen(@NotNull GuiManager manager, @NotNull Player player) {
open = true; this.open = true;
guiManager = manager; this.guiManager = manager;
if (opener != null) { if (this.opener != null) {
opener.onOpen(new GuiOpenEvent(manager, this, player)); this.opener.onOpen(new GuiOpenEvent(manager, this, player));
} }
} }
public void onClose(@NotNull GuiManager manager, @NotNull Player player) { public void onClose(@NotNull GuiManager manager, @NotNull Player player) {
if (!allowClose) { if (!this.allowClose) {
manager.showGUI(player, this); manager.showGUI(player, this);
return; return;
} }
boolean showParent = open && parent != null; boolean showParent = this.open && this.parent != null;
if (closer != null) { if (this.closer != null) {
closer.onClose(new GuiCloseEvent(manager, this, player)); this.closer.onClose(new GuiCloseEvent(manager, this, player));
} }
if (showParent) { if (showParent) {
manager.showGUI(player, parent); manager.showGUI(player, this.parent);
} }
} }
public XSound getDefaultSound() { public XSound getDefaultSound() {
return defaultSound; return this.defaultSound;
} }
public void setDefaultSound(XSound sound) { public void setDefaultSound(XSound sound) {
defaultSound = sound; this.defaultSound = sound;
} }
} }

View File

@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
/** /**
* Internal class for marking an inventory as a GUI inventory * Internal class for marking an inventory as a GUI inventory
@ -18,12 +19,12 @@ class GuiHolder implements InventoryHolder {
} }
@Override @Override
public Inventory getInventory() { public @NotNull Inventory getInventory() {
return gui.inventory; return this.gui.inventory;
} }
public Gui getGUI() { public Gui getGUI() {
return gui; return this.gui;
} }
public Inventory newInventory(int size, String title) { public Inventory newInventory(int size, String title) {

View File

@ -43,17 +43,17 @@ public class GuiManager {
} }
public Plugin getPlugin() { public Plugin getPlugin() {
return plugin; return this.plugin;
} }
/** /**
* Initialize the GUI handlers * Initialize the GUI handlers
*/ */
public void init() { public void init() {
Bukkit.getPluginManager().registerEvents(listener, plugin); Bukkit.getPluginManager().registerEvents(this.listener, this.plugin);
initialized = true; this.initialized = true;
shutdown = false; this.shutdown = false;
} }
/** /**
@ -62,7 +62,7 @@ public class GuiManager {
* @return true if the owning plugin has shutdown * @return true if the owning plugin has shutdown
*/ */
public boolean isClosed() { public boolean isClosed() {
return shutdown; return this.shutdown;
} }
/** /**
@ -72,20 +72,20 @@ public class GuiManager {
* @param gui GUI to use * @param gui GUI to use
*/ */
public void showGUI(Player player, Gui gui) { public void showGUI(Player player, Gui gui) {
if (shutdown) { if (this.shutdown) {
if (!plugin.isEnabled()) { if (!this.plugin.isEnabled()) {
return; return;
} }
// recover if reloaded without calling init manually // recover if reloaded without calling init manually
init(); init();
} else if (!initialized) { } else if (!this.initialized) {
init(); init();
} }
if (gui instanceof AnvilGui) { if (gui instanceof AnvilGui) {
// bukkit throws a fit now if you try to set anvil stuff asynchronously // bukkit throws a fit now if you try to set anvil stuff asynchronously
Gui openInv = openInventories.get(player); Gui openInv = this.openInventories.get(player);
if (openInv != null) { if (openInv != null) {
openInv.open = false; openInv.open = false;
@ -95,15 +95,15 @@ public class GuiManager {
((AnvilGui) gui).open(); ((AnvilGui) gui).open();
gui.onOpen(this, player); gui.onOpen(this, player);
synchronized (lock) { synchronized (this.lock) {
openInventories.put(player, gui); this.openInventories.put(player, gui);
} }
return; return;
} }
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
Gui openInv = openInventories.get(player); Gui openInv = this.openInventories.get(player);
if (openInv != null) { if (openInv != null) {
openInv.open = false; openInv.open = false;
@ -111,12 +111,12 @@ public class GuiManager {
Inventory inv = gui.getOrCreateInventory(this); Inventory inv = gui.getOrCreateInventory(this);
Bukkit.getScheduler().runTask(plugin, () -> { Bukkit.getScheduler().runTask(this.plugin, () -> {
player.openInventory(inv); player.openInventory(inv);
gui.onOpen(this, player); gui.onOpen(this, player);
synchronized (lock) { synchronized (this.lock) {
openInventories.put(player, gui); this.openInventories.put(player, gui);
} }
}); });
}); });
@ -132,11 +132,11 @@ public class GuiManager {
public void showPopup(Player player, String message, XMaterial icon, BackgroundType background) { public void showPopup(Player player, String message, XMaterial icon, BackgroundType background) {
if (ClientVersion.getClientVersion(player).isAtLeast(ServerVersion.V1_12)) { if (ClientVersion.getClientVersion(player).isAtLeast(ServerVersion.V1_12)) {
PopupMessage popup = new PopupMessage(plugin, icon, message, background); PopupMessage popup = new PopupMessage(this.plugin, icon, message, background);
popup.add(); popup.add();
popup.grant(player); popup.grant(player);
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> { Bukkit.getScheduler().runTaskLaterAsynchronously(this.plugin, () -> {
popup.revoke(player); popup.revoke(player);
popup.remove(); popup.remove();
}, 70); }, 70);
@ -156,13 +156,13 @@ public class GuiManager {
* Close all active GUIs * Close all active GUIs
*/ */
public void closeAll() { public void closeAll() {
synchronized (lock) { synchronized (this.lock) {
openInventories.entrySet().stream() this.openInventories.entrySet().stream()
.filter(e -> e.getKey().getOpenInventory().getTopInventory().getHolder() instanceof GuiHolder) .filter(e -> e.getKey().getOpenInventory().getTopInventory().getHolder() instanceof GuiHolder)
.collect(Collectors.toList()) // to prevent concurrency exceptions .collect(Collectors.toList()) // to prevent concurrency exceptions
.forEach(e -> e.getKey().closeInventory()); .forEach(e -> e.getKey().closeInventory());
openInventories.clear(); this.openInventories.clear();
} }
} }
@ -182,7 +182,7 @@ public class GuiManager {
Inventory openInv = event.getInventory(); Inventory openInv = event.getInventory();
Gui gui; Gui gui;
if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder
&& ((GuiHolder) openInv.getHolder()).manager.uuid.equals(manager.uuid)) { && ((GuiHolder) openInv.getHolder()).manager.uuid.equals(this.manager.uuid)) {
gui = ((GuiHolder) openInv.getHolder()).getGUI(); gui = ((GuiHolder) openInv.getHolder()).getGUI();
if (event.getRawSlots().stream() if (event.getRawSlots().stream()
@ -205,7 +205,7 @@ public class GuiManager {
Gui gui; Gui gui;
if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder && if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder &&
((GuiHolder) openInv.getHolder()).manager.uuid.equals(manager.uuid)) { ((GuiHolder) openInv.getHolder()).manager.uuid.equals(this.manager.uuid)) {
gui = ((GuiHolder) openInv.getHolder()).getGUI(); gui = ((GuiHolder) openInv.getHolder()).getGUI();
if (event.getClick() == ClickType.DOUBLE_CLICK) { if (event.getClick() == ClickType.DOUBLE_CLICK) {
@ -228,7 +228,7 @@ public class GuiManager {
} }
if (event.getSlotType() == SlotType.OUTSIDE) { if (event.getSlotType() == SlotType.OUTSIDE) {
if (!gui.onClickOutside(manager, player, event)) { if (!gui.onClickOutside(this.manager, player, event)) {
event.setCancelled(true); event.setCancelled(true);
} }
} // did we click the gui or in the user's inventory? } // did we click the gui or in the user's inventory?
@ -260,7 +260,7 @@ public class GuiManager {
Inventory openInv = event.getInventory(); Inventory openInv = event.getInventory();
if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder && if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder &&
((GuiHolder) openInv.getHolder()).manager.uuid.equals(manager.uuid)) { ((GuiHolder) openInv.getHolder()).manager.uuid.equals(this.manager.uuid)) {
Gui gui = ((GuiHolder) openInv.getHolder()).getGUI(); Gui gui = ((GuiHolder) openInv.getHolder()).getGUI();
if (gui instanceof AnvilGui) { if (gui instanceof AnvilGui) {
@ -277,23 +277,23 @@ public class GuiManager {
player.setItemOnCursor(null); player.setItemOnCursor(null);
} }
if (manager.shutdown) { if (this.manager.shutdown) {
gui.onClose(manager, player); gui.onClose(this.manager, player);
} else { } else {
Bukkit.getScheduler().runTaskLater(manager.plugin, () -> gui.onClose(manager, player), 1); Bukkit.getScheduler().runTaskLater(this.manager.plugin, () -> gui.onClose(this.manager, player), 1);
} }
manager.openInventories.remove(player); this.manager.openInventories.remove(player);
} }
} }
@EventHandler @EventHandler
void onDisable(PluginDisableEvent event) { void onDisable(PluginDisableEvent event) {
if (event.getPlugin() == manager.plugin) { if (event.getPlugin() == this.manager.plugin) {
// uh-oh! Abandon ship!! // uh-oh! Abandon ship!!
manager.shutdown = true; this.manager.shutdown = true;
manager.closeAll(); this.manager.closeAll();
manager.initialized = false; this.manager.initialized = false;
} }
} }
} }

View File

@ -36,13 +36,13 @@ class PopupMessage {
BackgroundType background = BackgroundType.ADVENTURE; BackgroundType background = BackgroundType.ADVENTURE;
PopupMessage(Plugin source, XMaterial icon, String title) { PopupMessage(Plugin source, XMaterial icon, String title) {
this.key = new NamespacedKey(source, "popup/" + id); this.key = new NamespacedKey(source, "popup/" + this.id);
this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "...")); this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "..."));
this.icon = icon; this.icon = icon;
} }
PopupMessage(Plugin source, XMaterial icon, String title, BackgroundType background) { PopupMessage(Plugin source, XMaterial icon, String title, BackgroundType background) {
this.key = new NamespacedKey(source, "popup/" + id); this.key = new NamespacedKey(source, "popup/" + this.id);
this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "...")); this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "..."));
this.icon = icon; this.icon = icon;
this.background = background; this.background = background;
@ -64,7 +64,7 @@ class PopupMessage {
} }
advDisplay.add("title", gson.fromJson(ComponentSerializer.toString(this.title), JsonElement.class)); advDisplay.add("title", gson.fromJson(ComponentSerializer.toString(this.title), JsonElement.class));
advDisplay.addProperty("background", background.key); advDisplay.addProperty("background", this.background.key);
advDisplay.addProperty("description", ""); advDisplay.addProperty("description", "");
advDisplay.addProperty("frame", this.frame.id); advDisplay.addProperty("frame", this.frame.id);
advDisplay.addProperty("announce_to_chat", false); advDisplay.addProperty("announce_to_chat", false);
@ -110,11 +110,11 @@ class PopupMessage {
} }
protected void add() { protected void add() {
if (!registeredMessages.contains(id)) { if (!registeredMessages.contains(this.id)) {
registeredMessages.add(id); registeredMessages.add(this.id);
try { try {
Bukkit.getUnsafe().loadAdvancement(key, getJSON()); Bukkit.getUnsafe().loadAdvancement(this.key, getJSON());
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
Bukkit.getLogger().warning("Failed to create popup advancement!"); Bukkit.getLogger().warning("Failed to create popup advancement!");
} }
@ -122,14 +122,14 @@ class PopupMessage {
} }
protected void remove() { protected void remove() {
if (registeredMessages.contains(id)) { if (registeredMessages.contains(this.id)) {
registeredMessages.remove(id); registeredMessages.remove(this.id);
Bukkit.getUnsafe().removeAdvancement(key); Bukkit.getUnsafe().removeAdvancement(this.key);
} }
} }
public Advancement getAdvancement() { public Advancement getAdvancement() {
return Bukkit.getAdvancement(key); return Bukkit.getAdvancement(this.key);
} }
public enum FrameType { public enum FrameType {
@ -140,7 +140,7 @@ class PopupMessage {
final String id; final String id;
FrameType() { FrameType() {
id = name().toLowerCase(); this.id = name().toLowerCase();
} }
} }
@ -192,7 +192,7 @@ class PopupMessage {
} }
public String getKey() { public String getKey() {
return key; return this.key;
} }
} }
} }

View File

@ -30,8 +30,8 @@ public class SimplePagedGui extends Gui {
public SimplePagedGui(Gui parent) { public SimplePagedGui(Gui parent) {
super(parent); super(parent);
nextPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Next Page"); this.nextPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Next Page");
prevPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Previous Page"); this.prevPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Previous Page");
} }
public SimplePagedGui setUseHeader(boolean useHeader) { public SimplePagedGui setUseHeader(boolean useHeader) {
@ -40,7 +40,7 @@ public class SimplePagedGui extends Gui {
} }
public ItemStack getHeaderBackItem() { public ItemStack getHeaderBackItem() {
return headerBackItem; return this.headerBackItem;
} }
public SimplePagedGui setHeaderBackItem(ItemStack headerBackItem) { public SimplePagedGui setHeaderBackItem(ItemStack headerBackItem) {
@ -49,7 +49,7 @@ public class SimplePagedGui extends Gui {
} }
public ItemStack getFooterBackItem() { public ItemStack getFooterBackItem() {
return footerBackItem; return this.footerBackItem;
} }
public SimplePagedGui setFooterBackItem(ItemStack footerBackItem) { public SimplePagedGui setFooterBackItem(ItemStack footerBackItem) {
@ -65,11 +65,11 @@ public class SimplePagedGui extends Gui {
@Override @Override
public SimplePagedGui setItem(int cell, ItemStack item) { public SimplePagedGui setItem(int cell, ItemStack item) {
// set the cell relative to the current page // set the cell relative to the current page
int cellIndex = cell < 0 ? cell : (page == 1 || (useHeader && cell < 9) ? cell : (cell + (page - 1) * (rowsPerPage * 9))); int cellIndex = cell < 0 ? cell : (this.page == 1 || (this.useHeader && cell < 9) ? cell : (cell + (this.page - 1) * (this.rowsPerPage * 9)));
cellItems.put(cellIndex, item); this.cellItems.put(cellIndex, item);
if (open && cell >= 0 && cell < inventory.getSize()) { if (this.open && cell >= 0 && cell < this.inventory.getSize()) {
inventory.setItem(cell, item); this.inventory.setItem(cell, item);
} }
return this; return this;
@ -77,27 +77,27 @@ public class SimplePagedGui extends Gui {
@Override @Override
public void nextPage() { public void nextPage() {
if (page < pages) { if (this.page < this.pages) {
++page; ++this.page;
showPage(); showPage();
} }
} }
@Override @Override
public void prevPage() { public void prevPage() {
if (page > 1) { if (this.page > 1) {
--page; --this.page;
showPage(); showPage();
} }
} }
public void showPage() { public void showPage() {
int startCell = useHeader ? 9 : 0; int startCell = this.useHeader ? 9 : 0;
int cellIndex = startCell + (page - 1) * (rowsPerPage * 9); int cellIndex = startCell + (this.page - 1) * (this.rowsPerPage * 9);
for (int i = startCell; i < (rows - 1) * 9; ++i) { for (int i = startCell; i < (this.rows - 1) * 9; ++i) {
final ItemStack item = cellItems.get(cellIndex++); final ItemStack item = this.cellItems.get(cellIndex++);
inventory.setItem(i, item != null ? item : blankItem); this.inventory.setItem(i, item != null ? item : this.blankItem);
} }
// page markers // page markers
@ -106,26 +106,26 @@ public class SimplePagedGui extends Gui {
@Override @Override
protected void updatePageNavigation() { protected void updatePageNavigation() {
if (page > 1) { if (this.page > 1) {
inventory.setItem(inventory.getSize() - prevPageIndex, prevPage); this.inventory.setItem(this.inventory.getSize() - this.prevPageIndex, this.prevPage);
this.setButton(-prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage()); this.setButton(-this.prevPageIndex, this.prevPage, ClickType.LEFT, (event) -> this.prevPage());
} else { } else {
inventory.setItem(inventory.getSize() - prevPageIndex, footerBackItem != null ? footerBackItem : blankItem); this.inventory.setItem(this.inventory.getSize() - this.prevPageIndex, this.footerBackItem != null ? this.footerBackItem : this.blankItem);
this.setItem(-prevPageIndex, null); this.setItem(-this.prevPageIndex, null);
this.clearActions(-prevPageIndex); this.clearActions(-this.prevPageIndex);
} }
if (pages > 1 && page != pages) { if (this.pages > 1 && this.page != this.pages) {
inventory.setItem(inventory.getSize() - nextPageIndex, nextPage); this.inventory.setItem(this.inventory.getSize() - this.nextPageIndex, this.nextPage);
this.setButton(-nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage()); this.setButton(-this.nextPageIndex, this.nextPage, ClickType.LEFT, (event) -> this.nextPage());
} else { } else {
inventory.setItem(inventory.getSize() - nextPageIndex, footerBackItem != null ? footerBackItem : blankItem); this.inventory.setItem(this.inventory.getSize() - this.nextPageIndex, this.footerBackItem != null ? this.footerBackItem : this.blankItem);
this.setItem(-nextPageIndex, null); this.setItem(-this.nextPageIndex, null);
this.clearActions(-nextPageIndex); this.clearActions(-this.nextPageIndex);
} }
} }
@ -134,65 +134,65 @@ public class SimplePagedGui extends Gui {
this.guiManager = manager; this.guiManager = manager;
// calculate pages here // calculate pages here
rowsPerPage = useHeader ? 4 : 5; this.rowsPerPage = this.useHeader ? 4 : 5;
maxCellSlot = this.cellItems.keySet().stream().max(Integer::compare).orElse(0) + 1; this.maxCellSlot = this.cellItems.keySet().stream().max(Integer::compare).orElse(0) + 1;
int maxRows = (int) Math.ceil(maxCellSlot / 9.); int maxRows = (int) Math.ceil(this.maxCellSlot / 9.);
pages = (int) Math.max(1, Math.ceil(maxRows / (double) rowsPerPage)); this.pages = (int) Math.max(1, Math.ceil(maxRows / (double) this.rowsPerPage));
this.setRows(maxRows + (useHeader ? 1 : 0)); this.setRows(maxRows + (this.useHeader ? 1 : 0));
// create inventory view // create inventory view
createInventory(); createInventory();
// populate and return the display inventory // populate and return the display inventory
setPage(Math.min(page, pages)); setPage(Math.min(this.page, this.pages));
update(); update();
return inventory; return this.inventory;
} }
@Override @Override
protected void createInventory() { protected void createInventory() {
final int cells = rows * 9; final int cells = this.rows * 9;
inventory = Bukkit.getServer().createInventory(new GuiHolder(guiManager, this), cells, this.inventory = Bukkit.getServer().createInventory(new GuiHolder(this.guiManager, this), cells,
title == null ? "" : trimTitle(title)); this.title == null ? "" : trimTitle(this.title));
} }
@Override @Override
public void update() { public void update() {
if (inventory == null) { if (this.inventory == null) {
return; return;
} }
// calculate pages here // calculate pages here
rowsPerPage = useHeader ? 4 : 5; this.rowsPerPage = this.useHeader ? 4 : 5;
maxCellSlot = (this.cellItems.isEmpty() ? 0 : this.cellItems.keySet().stream().max(Integer::compare).get()) + 1; this.maxCellSlot = (this.cellItems.isEmpty() ? 0 : this.cellItems.keySet().stream().max(Integer::compare).get()) + 1;
int maxRows = Math.max((useHeader ? 1 : 0), (int) Math.ceil(maxCellSlot / 9.)); int maxRows = Math.max((this.useHeader ? 1 : 0), (int) Math.ceil(this.maxCellSlot / 9.));
pages = (int) Math.ceil(maxRows / rowsPerPage); this.pages = (int) Math.ceil(maxRows / this.rowsPerPage);
// create a new inventory if needed // create a new inventory if needed
List<Player> toUpdate = null; List<Player> toUpdate = null;
if (Math.min(54, (maxRows + (useHeader ? 1 : 0)) * 9) != inventory.getSize()) { if (Math.min(54, (maxRows + (this.useHeader ? 1 : 0)) * 9) != this.inventory.getSize()) {
toUpdate = getPlayers(); toUpdate = getPlayers();
this.setRows(maxRows + (useHeader ? 1 : 0)); this.setRows(maxRows + (this.useHeader ? 1 : 0));
createInventory(); createInventory();
} }
// populate header // populate header
if (useHeader) { if (this.useHeader) {
for (int i = 0; i < 9; ++i) { for (int i = 0; i < 9; ++i) {
final ItemStack item = cellItems.get(i); final ItemStack item = this.cellItems.get(i);
inventory.setItem(i, item != null ? item : (headerBackItem != null ? headerBackItem : blankItem)); this.inventory.setItem(i, item != null ? item : (this.headerBackItem != null ? this.headerBackItem : this.blankItem));
} }
} }
// last row is dedicated to pagation // last row is dedicated to pagation
final int cells = rows * 9; final int cells = this.rows * 9;
for (int i = cells - 9; i < cells; ++i) { for (int i = cells - 9; i < cells; ++i) {
inventory.setItem(i, footerBackItem != null ? footerBackItem : blankItem); this.inventory.setItem(i, this.footerBackItem != null ? this.footerBackItem : this.blankItem);
} }
// fill out the rest of the page // fill out the rest of the page
@ -202,7 +202,7 @@ public class SimplePagedGui extends Gui {
if (toUpdate != null) { if (toUpdate != null) {
// whoopsie! // whoopsie!
exit(); exit();
toUpdate.forEach(player -> guiManager.showGUI(player, this)); toUpdate.forEach(player -> this.guiManager.showGUI(player, this));
} }
} }
@ -211,14 +211,14 @@ public class SimplePagedGui extends Gui {
int cell = event.getSlot(); int cell = event.getSlot();
Map<ClickType, Clickable> conditionals; Map<ClickType, Clickable> conditionals;
if (useHeader && cell < 9) { if (this.useHeader && cell < 9) {
conditionals = conditionalButtons.get(cell); conditionals = this.conditionalButtons.get(cell);
} else if (cell >= (rows - 1) * 9) { } else if (cell >= (this.rows - 1) * 9) {
// footer row // footer row
conditionals = conditionalButtons.get(cell - (rows * 9)); conditionals = this.conditionalButtons.get(cell - (this.rows * 9));
} else { } else {
int cellIndex = page == 1 ? cell : cell + (page - 1) * rowsPerPage * 9; int cellIndex = this.page == 1 ? cell : cell + (this.page - 1) * this.rowsPerPage * 9;
conditionals = conditionalButtons.get(cellIndex); conditionals = this.conditionalButtons.get(cellIndex);
} }
Clickable button; Clickable button;