mirror of
https://github.com/songoda/SongodaCore.git
synced 2025-01-05 23:37:34 +01:00
Adds a lot of this.
in GUI releated classes
This commit is contained in:
parent
7ce74de993
commit
572cf3d805
@ -113,30 +113,30 @@ public class CustomizableGui extends Gui {
|
||||
customContent.disableButton(disabled);
|
||||
}
|
||||
} else {
|
||||
customContent = loadedGuis.get(guiKey);
|
||||
this.customContent = loadedGuis.get(guiKey);
|
||||
}
|
||||
|
||||
setPrivateDefaultAction(event -> {
|
||||
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;
|
||||
activationCount = 0;
|
||||
this.activationCount = 0;
|
||||
|
||||
event.player.sendMessage("Gui keys " + (showGuiKeys ? "enabled" : "disabled") + ".");
|
||||
}
|
||||
});
|
||||
|
||||
if (customContent.isButtonCustomized("__DEFAULT__")) {
|
||||
blankItem = GuiUtils.getBorderItem(customContent.getCustomizedButton("__DEFAULT__").item);
|
||||
if (this.customContent.isButtonCustomized("__DEFAULT__")) {
|
||||
this.blankItem = GuiUtils.getBorderItem(this.customContent.getCustomizedButton("__DEFAULT__").item);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui setRows(int rows) {
|
||||
int customRows = customContent.getRows();
|
||||
int customRows = this.customContent.getRows();
|
||||
|
||||
return super.setRows(customRows != -1 ? customRows : rows);
|
||||
}
|
||||
@ -154,13 +154,13 @@ public class CustomizableGui extends Gui {
|
||||
}
|
||||
|
||||
private void applyCustomItems() {
|
||||
for (CustomButton customButton : customContent.getCustomButtons().values()) {
|
||||
for (CustomButton customButton : this.customContent.getCustomButtons().values()) {
|
||||
if (customButton instanceof MirrorFill) {
|
||||
applyCustomItem(customButton);
|
||||
}
|
||||
}
|
||||
|
||||
for (CustomButton customButton : customContent.getCustomButtons().values()) {
|
||||
for (CustomButton customButton : this.customContent.getCustomButtons().values()) {
|
||||
if (!(customButton instanceof MirrorFill)) {
|
||||
applyCustomItem(customButton);
|
||||
}
|
||||
@ -191,7 +191,7 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
applyShowGuiKeys("__DEFAULT__", item);
|
||||
|
||||
if (customContent.isButtonCustomized("__DEFAULT__")) {
|
||||
if (this.customContent.isButtonCustomized("__DEFAULT__")) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -202,14 +202,14 @@ public class CustomizableGui extends Gui {
|
||||
public Gui setItem(@NotNull String key, int cell, @Nullable ItemStack item) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
applyShowGuiKeys(key, item);
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
CustomButton btn = customContent.getCustomizedButton(key);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
CustomButton btn = this.customContent.getCustomizedButton(key);
|
||||
cells = btn.applyPosition(cell);
|
||||
btn.applyItem(item);
|
||||
}
|
||||
@ -223,21 +223,21 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
ItemStack newItem = item.clone();
|
||||
boolean isShow = applyShowGuiKeys(key, newItem);
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
CustomButton btn = customContent.getCustomizedButton(key);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
CustomButton btn = this.customContent.getCustomizedButton(key);
|
||||
row = btn.applyPositionRow(row);
|
||||
col = btn.applyPositionCol(col);
|
||||
|
||||
@ -259,12 +259,12 @@ public class CustomizableGui extends Gui {
|
||||
public Gui highlightItem(@NotNull String key, int cell) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
}
|
||||
|
||||
for (int c : cells) {
|
||||
@ -276,11 +276,11 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
public Gui highlightItem(@NotNull String key, int row, int col) {
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
final int cell = col + row * inventoryType.columns;
|
||||
final int cell = col + row * this.inventoryType.columns;
|
||||
|
||||
return highlightItem(key, cell);
|
||||
}
|
||||
@ -289,12 +289,12 @@ public class CustomizableGui extends Gui {
|
||||
public Gui removeHighlight(@NotNull String key, int cell) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
}
|
||||
|
||||
for (int c : cells) {
|
||||
@ -306,34 +306,34 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
public Gui removeHighlight(@NotNull String key, int row, int col) {
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
final int cell = col + row * inventoryType.columns;
|
||||
final int cell = col + row * this.inventoryType.columns;
|
||||
|
||||
return removeHighlight(key, cell);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
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 updateItemLore(key, col + row * inventoryType.columns, lore);
|
||||
return updateItemLore(key, col + row * this.inventoryType.columns, lore);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItemLore(@NotNull String key, int cell, @NotNull String... lore) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
}
|
||||
|
||||
for (int c : cells) {
|
||||
@ -345,23 +345,23 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
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 updateItemLore(key, col + row * inventoryType.columns, lore);
|
||||
return updateItemLore(key, col + row * this.inventoryType.columns, lore);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItemLore(@NotNull String key, int cell, @Nullable List<String> lore) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
}
|
||||
|
||||
for (int c : cells) {
|
||||
@ -373,23 +373,23 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
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 updateItemName(key, col + row * inventoryType.columns, name);
|
||||
return updateItemName(key, col + row * this.inventoryType.columns, name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItemName(@NotNull String key, int cell, @Nullable String name) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
}
|
||||
|
||||
for (int c : cells) {
|
||||
@ -401,16 +401,16 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
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 updateItem(key, col + row * inventoryType.columns, name, lore);
|
||||
return updateItem(key, col + row * this.inventoryType.columns, name, lore);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
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;
|
||||
}
|
||||
|
||||
@ -419,25 +419,25 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
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 updateItem(key, col + row * inventoryType.columns, name, lore);
|
||||
return updateItem(key, col + row * this.inventoryType.columns, name, lore);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItem(@NotNull String key, int cell, @NotNull String name, @Nullable List<String> lore) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
lore = applyShowGuiKeys(key, lore);
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
}
|
||||
|
||||
for (int c : cells) {
|
||||
@ -449,23 +449,23 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
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 updateItem(key, col + row * inventoryType.columns, itemTo, title, lore);
|
||||
return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
}
|
||||
|
||||
for (int c : cells) {
|
||||
@ -477,23 +477,23 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
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 updateItem(key, col + row * inventoryType.columns, itemTo, title, lore);
|
||||
return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItem(@NotNull String key, int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable String... lore) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
}
|
||||
|
||||
for (int c : cells) {
|
||||
@ -505,23 +505,23 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
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 updateItem(key, col + row * inventoryType.columns, itemTo, title, lore);
|
||||
return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
}
|
||||
|
||||
for (int c : cells) {
|
||||
@ -533,23 +533,23 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
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 updateItem(key, col + row * inventoryType.columns, itemTo, title, lore);
|
||||
return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui updateItem(@NotNull String key, int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
}
|
||||
|
||||
for (int c : cells) {
|
||||
@ -561,7 +561,7 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
public Gui setAction(@NotNull String key, int cell, @Nullable Clickable action) {
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -572,18 +572,18 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
public Gui setAction(@NotNull String key, int row, int col, @Nullable Clickable action) {
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
setConditional(key, col + row * inventoryType.columns, null, action);
|
||||
setConditional(key, col + row * this.inventoryType.columns, null, action);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
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;
|
||||
}
|
||||
|
||||
@ -594,11 +594,11 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
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;
|
||||
}
|
||||
|
||||
setConditional(key, col + row * inventoryType.columns, type, action);
|
||||
setConditional(key, col + row * this.inventoryType.columns, type, action);
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -607,12 +607,12 @@ public class CustomizableGui extends Gui {
|
||||
public Gui clearActions(@NotNull String key, int cell) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
}
|
||||
|
||||
for (int c : cells) {
|
||||
@ -624,25 +624,25 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
public Gui clearActions(@NotNull String key, int row, int col) {
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
return clearActions(key, col + row * inventoryType.columns);
|
||||
return clearActions(key, col + row * this.inventoryType.columns);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui setButton(@NotNull String key, int cell, ItemStack item, @Nullable Clickable action) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
applyShowGuiKeys(key, item);
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
CustomButton btn = customContent.getCustomizedButton(key);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
CustomButton btn = this.customContent.getCustomizedButton(key);
|
||||
cells = btn.applyPosition(cell);
|
||||
btn.applyItem(item);
|
||||
}
|
||||
@ -657,25 +657,25 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
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 setButton(key, col + row * inventoryType.columns, item, action);
|
||||
return setButton(key, col + row * this.inventoryType.columns, item, action);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui setButton(@NotNull String key, int cell, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
applyShowGuiKeys(key, item);
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
CustomButton btn = customContent.getCustomizedButton(key);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
CustomButton btn = this.customContent.getCustomizedButton(key);
|
||||
cells = btn.applyPosition(cell);
|
||||
btn.applyItem(item);
|
||||
}
|
||||
@ -689,22 +689,22 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
@NotNull
|
||||
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 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) {
|
||||
List<Integer> cells = Collections.singletonList(cell);
|
||||
|
||||
if (customContent.isButtonDisabled(key)) {
|
||||
if (this.customContent.isButtonDisabled(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (customContent.isButtonCustomized(key)) {
|
||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
if (this.customContent.isButtonCustomized(key)) {
|
||||
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||
}
|
||||
|
||||
for (int c : cells) {
|
||||
@ -715,8 +715,8 @@ public class CustomizableGui extends Gui {
|
||||
public Gui setNextPage(ItemStack item) {
|
||||
applyShowGuiKeys("__NEXT__", item);
|
||||
|
||||
if (customContent.isButtonCustomized("__NEXT__")) {
|
||||
customContent.getCustomizedButton("__NEXT__").applyItem(item);
|
||||
if (this.customContent.isButtonCustomized("__NEXT__")) {
|
||||
this.customContent.getCustomizedButton("__NEXT__").applyItem(item);
|
||||
}
|
||||
|
||||
return super.setNextPage(item);
|
||||
@ -725,8 +725,8 @@ public class CustomizableGui extends Gui {
|
||||
public Gui setPrevPage(ItemStack item) {
|
||||
applyShowGuiKeys("__PREV__", item);
|
||||
|
||||
if (customContent.isButtonCustomized("__PREV__")) {
|
||||
customContent.getCustomizedButton("__PREV__").applyItem(item);
|
||||
if (this.customContent.isButtonCustomized("__PREV__")) {
|
||||
this.customContent.getCustomizedButton("__PREV__").applyItem(item);
|
||||
}
|
||||
|
||||
return super.setPrevPage(item);
|
||||
@ -738,8 +738,8 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
applyShowGuiKeys("__NEXT__", item);
|
||||
|
||||
if (customContent.isButtonCustomized("__NEXT__")) {
|
||||
CustomButton btn = customContent.getCustomizedButton("__NEXT__");
|
||||
if (this.customContent.isButtonCustomized("__NEXT__")) {
|
||||
CustomButton btn = this.customContent.getCustomizedButton("__NEXT__");
|
||||
cells = btn.applyPosition(cell);
|
||||
btn.applyItem(item);
|
||||
}
|
||||
@ -755,7 +755,7 @@ public class CustomizableGui extends Gui {
|
||||
public Gui setNextPage(int row, int col, @NotNull ItemStack item) {
|
||||
applyShowGuiKeys("__NEXT__", item);
|
||||
|
||||
return setNextPage(col + row * inventoryType.columns, item);
|
||||
return setNextPage(col + row * this.inventoryType.columns, item);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -764,8 +764,8 @@ public class CustomizableGui extends Gui {
|
||||
|
||||
applyShowGuiKeys("__PREV__", item);
|
||||
|
||||
if (customContent.isButtonCustomized("__PREV__")) {
|
||||
CustomButton btn = customContent.getCustomizedButton("__PREV__");
|
||||
if (this.customContent.isButtonCustomized("__PREV__")) {
|
||||
CustomButton btn = this.customContent.getCustomizedButton("__PREV__");
|
||||
cells = btn.applyPosition(cell);
|
||||
btn.applyItem(item);
|
||||
}
|
||||
@ -781,7 +781,7 @@ public class CustomizableGui extends Gui {
|
||||
public Gui setPrevPage(int row, int col, @NotNull ItemStack 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) {
|
||||
@ -850,7 +850,7 @@ public class CustomizableGui extends Gui {
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public boolean applyItem(ItemStack item) {
|
||||
@ -879,23 +879,23 @@ public class CustomizableGui extends Gui {
|
||||
private void applyMeta(ItemStack item) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if (title != null) {
|
||||
meta.setDisplayName(TextUtils.formatText(title));
|
||||
if (this.title != null) {
|
||||
meta.setDisplayName(TextUtils.formatText(this.title));
|
||||
}
|
||||
|
||||
if (lore != null) {
|
||||
meta.setLore(TextUtils.formatText(lore));
|
||||
if (this.lore != null) {
|
||||
meta.setLore(TextUtils.formatText(this.lore));
|
||||
}
|
||||
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
public List<Integer> applyPosition(int cell) {
|
||||
if (row != -1 && col != -1) {
|
||||
return Collections.singletonList(col + row * inventoryType.columns);
|
||||
if (this.row != -1 && this.col != -1) {
|
||||
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) {
|
||||
@ -919,11 +919,11 @@ public class CustomizableGui extends Gui {
|
||||
}
|
||||
|
||||
public boolean isMirrorRow() {
|
||||
return mirrorRow;
|
||||
return this.mirrorRow;
|
||||
}
|
||||
|
||||
public boolean isMirrorCol() {
|
||||
return mirrorCol;
|
||||
return this.mirrorCol;
|
||||
}
|
||||
}
|
||||
|
||||
@ -940,19 +940,19 @@ public class CustomizableGui extends Gui {
|
||||
}
|
||||
|
||||
public String getGuiKey() {
|
||||
return guiKey;
|
||||
return this.guiKey;
|
||||
}
|
||||
|
||||
public CustomButton getCustomizedButton(String key) {
|
||||
return customizedButtons.get(key);
|
||||
return this.customizedButtons.get(key);
|
||||
}
|
||||
|
||||
public CustomButton getCustomButton(String key) {
|
||||
return customizedButtons.get(key);
|
||||
return this.customizedButtons.get(key);
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -963,49 +963,49 @@ public class CustomizableGui extends Gui {
|
||||
CustomButton customButton = new CustomButton(key, positions, title, lore, item);
|
||||
|
||||
if (key.startsWith("custom_")) {
|
||||
customButtons.put(key, customButton);
|
||||
this.customButtons.put(key, customButton);
|
||||
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) {
|
||||
CustomButton customButton = new CustomButton(key, row, col, title, lore, item);
|
||||
|
||||
if (key.startsWith("custom_")) {
|
||||
customButtons.put(key, customButton);
|
||||
this.customButtons.put(key, customButton);
|
||||
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) {
|
||||
MirrorFill mirrorFill = new MirrorFill(key, row, col, mirrorRow, mirrorCol, item);
|
||||
|
||||
if (key.startsWith("custom_")) {
|
||||
customButtons.put(key, mirrorFill);
|
||||
this.customButtons.put(key, mirrorFill);
|
||||
return;
|
||||
}
|
||||
|
||||
customizedButtons.put(key, mirrorFill);
|
||||
this.customizedButtons.put(key, mirrorFill);
|
||||
}
|
||||
|
||||
public boolean isButtonCustomized(String key) {
|
||||
return customizedButtons.containsKey(key);
|
||||
return this.customizedButtons.containsKey(key);
|
||||
}
|
||||
|
||||
public void disableButton(String button) {
|
||||
disabledButtons.add(button);
|
||||
this.disabledButtons.add(button);
|
||||
}
|
||||
|
||||
public boolean isButtonDisabled(String button) {
|
||||
return disabledButtons.contains(button);
|
||||
return this.disabledButtons.contains(button);
|
||||
}
|
||||
|
||||
public int getRows() {
|
||||
return rows;
|
||||
return this.rows;
|
||||
}
|
||||
|
||||
public void setRows(int rows) {
|
||||
|
@ -32,31 +32,31 @@ public class DoubleGui extends Gui {
|
||||
|
||||
public DoubleGui() {
|
||||
super(GuiType.STANDARD);
|
||||
allowDropItems = false;
|
||||
this.allowDropItems = false;
|
||||
}
|
||||
|
||||
public DoubleGui(GuiType type) {
|
||||
super(type);
|
||||
allowDropItems = false;
|
||||
this.allowDropItems = false;
|
||||
}
|
||||
|
||||
public DoubleGui(int rows) {
|
||||
super(rows);
|
||||
allowDropItems = false;
|
||||
this.allowDropItems = false;
|
||||
}
|
||||
|
||||
public DoubleGui(int rows, Gui parent) {
|
||||
super(rows, parent);
|
||||
allowDropItems = false;
|
||||
this.allowDropItems = false;
|
||||
}
|
||||
|
||||
public DoubleGui(Gui parent) {
|
||||
super(parent);
|
||||
allowDropItems = false;
|
||||
this.allowDropItems = false;
|
||||
}
|
||||
|
||||
public int getPlayerRows() {
|
||||
return playerRows;
|
||||
return this.playerRows;
|
||||
}
|
||||
|
||||
// 9 -> 0 -> 54
|
||||
@ -78,29 +78,29 @@ public class DoubleGui extends Gui {
|
||||
}
|
||||
|
||||
public DoubleGui setPlayerUnlocked(int cell) {
|
||||
unlockedCells.put(invOffset(cell), true);
|
||||
this.unlockedCells.put(invOffset(cell), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DoubleGui setPlayerUnlocked(int row, int col) {
|
||||
unlockedCells.put(invOffset(col + row * 9), true);
|
||||
this.unlockedCells.put(invOffset(col + row * 9), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DoubleGui setPlayerUnlocked(int cell, boolean open) {
|
||||
unlockedCells.put(invOffset(cell), open);
|
||||
this.unlockedCells.put(invOffset(cell), open);
|
||||
return this;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public DoubleGui setPlayerUnlockedRange(int cellFirst, int cellLast) {
|
||||
final int last = invOffset(cellLast);
|
||||
for (int cell = invOffset(cellFirst); cell <= last; ++cell) {
|
||||
unlockedCells.put(cell, true);
|
||||
this.unlockedCells.put(cell, true);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -109,7 +109,7 @@ public class DoubleGui extends Gui {
|
||||
final int last = invOffset(cellLast);
|
||||
|
||||
for (int cell = invOffset(cellFirst); cell <= last; ++cell) {
|
||||
unlockedCells.put(cell, open);
|
||||
this.unlockedCells.put(cell, open);
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -119,7 +119,7 @@ public class DoubleGui extends Gui {
|
||||
final int last = invOffset(cellColLast + cellRowLast * 9);
|
||||
|
||||
for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) {
|
||||
unlockedCells.put(cell, true);
|
||||
this.unlockedCells.put(cell, true);
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -129,19 +129,19 @@ public class DoubleGui extends Gui {
|
||||
final int last = invOffset(cellColLast + cellRowLast * 9);
|
||||
|
||||
for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) {
|
||||
unlockedCells.put(cell, open);
|
||||
this.unlockedCells.put(cell, open);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
for (HumanEntity e : inventory.getViewers()) {
|
||||
for (HumanEntity e : this.inventory.getViewers()) {
|
||||
e.getInventory().setItem(cell, item);
|
||||
}
|
||||
}
|
||||
@ -151,12 +151,12 @@ public class DoubleGui extends Gui {
|
||||
|
||||
public DoubleGui setPlayerItem(int row, int col, ItemStack item) {
|
||||
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;
|
||||
|
||||
for (HumanEntity e : inventory.getViewers()) {
|
||||
for (HumanEntity e : this.inventory.getViewers()) {
|
||||
e.getInventory().setItem(cell, item);
|
||||
}
|
||||
}
|
||||
@ -166,7 +166,7 @@ public class DoubleGui extends Gui {
|
||||
|
||||
public DoubleGui highlightPlayerItem(int cell) {
|
||||
final int invCell = invOffset(cell);
|
||||
ItemStack item = cellItems.get(invCell);
|
||||
ItemStack item = this.cellItems.get(invCell);
|
||||
|
||||
if (item != null) {
|
||||
setPlayerItem(cell, ItemUtils.addGlow(item));
|
||||
@ -179,7 +179,7 @@ public class DoubleGui extends Gui {
|
||||
final int cell = col + row * 9;
|
||||
final int invCell = invOffset(cell);
|
||||
|
||||
ItemStack item = cellItems.get(invCell);
|
||||
ItemStack item = this.cellItems.get(invCell);
|
||||
if (item != null) {
|
||||
setPlayerItem(cell, ItemUtils.addGlow(item));
|
||||
}
|
||||
@ -244,13 +244,13 @@ public class DoubleGui extends Gui {
|
||||
}
|
||||
|
||||
public DoubleGui clearPlayerActions(int cell) {
|
||||
conditionalButtons.remove(invOffset(cell));
|
||||
this.conditionalButtons.remove(invOffset(cell));
|
||||
return this;
|
||||
}
|
||||
|
||||
public DoubleGui clearPlayerActions(int row, int col) {
|
||||
final int cell = invOffset(col + row * 9);
|
||||
conditionalButtons.remove(cell);
|
||||
this.conditionalButtons.remove(cell);
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -290,7 +290,7 @@ public class DoubleGui extends Gui {
|
||||
@Override
|
||||
protected boolean onClickPlayerInventory(GuiManager manager, Player player, Inventory openInv, InventoryClickEvent event) {
|
||||
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;
|
||||
|
||||
if (conditionals != null
|
||||
@ -301,15 +301,15 @@ public class DoubleGui extends Gui {
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onClickOutside(GuiManager manager, Player player, InventoryClickEvent event) {
|
||||
if (dropper != null) {
|
||||
return dropper.onDrop(new GuiDropItemEvent(manager, this, player, event));
|
||||
if (this.dropper != null) {
|
||||
return this.dropper.onDrop(new GuiDropItemEvent(manager, this, player, event));
|
||||
}
|
||||
|
||||
// do not allow by default
|
||||
@ -319,7 +319,7 @@ public class DoubleGui extends Gui {
|
||||
@Override
|
||||
public void onOpen(GuiManager manager, Player player) {
|
||||
// replace the player's inventory
|
||||
if (startStashed) {
|
||||
if (this.startStashed) {
|
||||
stashItems(player);
|
||||
}
|
||||
|
||||
@ -337,15 +337,15 @@ public class DoubleGui extends Gui {
|
||||
}
|
||||
|
||||
protected void restoreStash(Player player) {
|
||||
if (stash.containsKey(player)) {
|
||||
player.getInventory().setContents(stash.remove(player));
|
||||
if (this.stash.containsKey(player)) {
|
||||
player.getInventory().setContents(this.stash.remove(player));
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
protected void stashItems(Player player) {
|
||||
if (!stash.containsKey(player)) {
|
||||
stash.put(player, player.getInventory().getContents().clone());
|
||||
if (!this.stash.containsKey(player)) {
|
||||
this.stash.put(player, player.getInventory().getContents().clone());
|
||||
player.getInventory().clear();
|
||||
}
|
||||
}
|
||||
|
@ -96,11 +96,11 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
public List<Player> getPlayers() {
|
||||
if (inventory == null) {
|
||||
if (this.inventory == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return inventory.getViewers().stream()
|
||||
return this.inventory.getViewers().stream()
|
||||
.filter(Player.class::isInstance)
|
||||
.map(Player.class::cast)
|
||||
.collect(Collectors.toList());
|
||||
@ -108,15 +108,15 @@ public class Gui {
|
||||
|
||||
public boolean isOpen() {
|
||||
// double check
|
||||
if (inventory != null && inventory.getViewers().isEmpty()) {
|
||||
open = false;
|
||||
if (this.inventory != null && this.inventory.getViewers().isEmpty()) {
|
||||
this.open = false;
|
||||
}
|
||||
|
||||
return open;
|
||||
return this.open;
|
||||
}
|
||||
|
||||
public boolean getAcceptsItems() {
|
||||
return acceptsItems;
|
||||
return this.acceptsItems;
|
||||
}
|
||||
|
||||
public Gui setAcceptsItems(boolean acceptsItems) {
|
||||
@ -129,7 +129,7 @@ public class Gui {
|
||||
* will be cleared
|
||||
*/
|
||||
public boolean getAllowDrops() {
|
||||
return allowDropItems;
|
||||
return this.allowDropItems;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,7 +142,7 @@ public class Gui {
|
||||
}
|
||||
|
||||
public boolean getAllowClose() {
|
||||
return allowClose;
|
||||
return this.allowClose;
|
||||
}
|
||||
|
||||
public Gui setAllowClose(boolean allow) {
|
||||
@ -155,10 +155,10 @@ public class Gui {
|
||||
* GUIs
|
||||
*/
|
||||
public void exit() {
|
||||
allowClose = true;
|
||||
open = false;
|
||||
this.allowClose = true;
|
||||
this.open = false;
|
||||
|
||||
inventory.getViewers().stream()
|
||||
this.inventory.getViewers().stream()
|
||||
.filter(Player.class::isInstance)
|
||||
.map(Player.class::cast)
|
||||
.collect(Collectors.toList())
|
||||
@ -169,9 +169,9 @@ public class Gui {
|
||||
* Close the GUI as if the player closed it normally
|
||||
*/
|
||||
public void close() {
|
||||
allowClose = true;
|
||||
this.allowClose = true;
|
||||
|
||||
inventory.getViewers().stream()
|
||||
this.inventory.getViewers().stream()
|
||||
.filter(Player.class::isInstance)
|
||||
.map(Player.class::cast)
|
||||
.collect(Collectors.toList())
|
||||
@ -180,19 +180,19 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
public GuiType getType() {
|
||||
return inventoryType;
|
||||
return this.inventoryType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui setUnlocked(int cell) {
|
||||
unlockedCells.put(cell, true);
|
||||
this.unlockedCells.put(cell, true);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui setUnlocked(int row, int col) {
|
||||
final int cell = col + row * inventoryType.columns;
|
||||
unlockedCells.put(cell, true);
|
||||
final int cell = col + row * this.inventoryType.columns;
|
||||
this.unlockedCells.put(cell, true);
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -200,7 +200,7 @@ public class Gui {
|
||||
@NotNull
|
||||
public Gui setUnlockedRange(int cellFirst, int cellLast) {
|
||||
for (int cell = cellFirst; cell <= cellLast; ++cell) {
|
||||
unlockedCells.put(cell, true);
|
||||
this.unlockedCells.put(cell, true);
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -209,7 +209,7 @@ public class Gui {
|
||||
@NotNull
|
||||
public Gui setUnlockedRange(int cellFirst, int cellLast, boolean open) {
|
||||
for (int cell = cellFirst; cell <= cellLast; ++cell) {
|
||||
unlockedCells.put(cell, open);
|
||||
this.unlockedCells.put(cell, open);
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -217,10 +217,10 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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) {
|
||||
unlockedCells.put(cell, true);
|
||||
for (int cell = cellColFirst + cellRowFirst * this.inventoryType.columns; cell <= last; ++cell) {
|
||||
this.unlockedCells.put(cell, true);
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -228,10 +228,10 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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) {
|
||||
unlockedCells.put(cell, open);
|
||||
for (int cell = cellColFirst + cellRowFirst * this.inventoryType.columns; cell <= last; ++cell) {
|
||||
this.unlockedCells.put(cell, open);
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -239,14 +239,14 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
public Gui setUnlocked(int cell, boolean open) {
|
||||
unlockedCells.put(cell, open);
|
||||
this.unlockedCells.put(cell, open);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui setUnlocked(int row, int col, boolean open) {
|
||||
final int cell = col + row * inventoryType.columns;
|
||||
unlockedCells.put(cell, open);
|
||||
final int cell = col + row * this.inventoryType.columns;
|
||||
this.unlockedCells.put(cell, open);
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -260,19 +260,19 @@ public class Gui {
|
||||
if (!title.equals(this.title)) {
|
||||
this.title = title;
|
||||
|
||||
if (inventory != null) {
|
||||
if (this.inventory != null) {
|
||||
// update active inventory
|
||||
List<Player> toUpdate = getPlayers();
|
||||
boolean isAllowClose = allowClose;
|
||||
boolean isAllowClose = this.allowClose;
|
||||
exit();
|
||||
|
||||
Inventory oldInv = inventory;
|
||||
Inventory oldInv = this.inventory;
|
||||
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() {
|
||||
return rows;
|
||||
return this.rows;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui setRows(int rows) {
|
||||
switch (inventoryType) {
|
||||
switch (this.inventoryType) {
|
||||
case HOPPER:
|
||||
case DISPENSER:
|
||||
break;
|
||||
@ -299,53 +299,53 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
public Gui setDefaultAction(@Nullable Clickable action) {
|
||||
defaultClicker = action;
|
||||
this.defaultClicker = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Gui setPrivateDefaultAction(@Nullable Clickable action) {
|
||||
privateDefaultClicker = action;
|
||||
this.privateDefaultClicker = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui setDefaultItem(@Nullable ItemStack item) {
|
||||
blankItem = item;
|
||||
this.blankItem = item;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getDefaultItem() {
|
||||
return blankItem;
|
||||
return this.blankItem;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getItem(int cell) {
|
||||
if (inventory != null && unlockedCells.getOrDefault(cell, false)) {
|
||||
return inventory.getItem(cell);
|
||||
if (this.inventory != null && this.unlockedCells.getOrDefault(cell, false)) {
|
||||
return this.inventory.getItem(cell);
|
||||
}
|
||||
|
||||
return cellItems.get(cell);
|
||||
return this.cellItems.get(cell);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
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)) {
|
||||
return inventory.getItem(cell);
|
||||
if (this.inventory != null && this.unlockedCells.getOrDefault(cell, false)) {
|
||||
return this.inventory.getItem(cell);
|
||||
}
|
||||
|
||||
return cellItems.get(cell);
|
||||
return this.cellItems.get(cell);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
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()) {
|
||||
inventory.setItem(cell, item);
|
||||
if (this.inventory != null && cell >= 0 && cell < this.inventory.getSize()) {
|
||||
this.inventory.setItem(cell, item);
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -353,7 +353,7 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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);
|
||||
}
|
||||
|
||||
@ -362,7 +362,7 @@ public class Gui {
|
||||
setItem(row, col, item);
|
||||
|
||||
if (mirrorRow) {
|
||||
setItem(rows - row - 1, col, item);
|
||||
setItem(this.rows - row - 1, col, item);
|
||||
}
|
||||
|
||||
if (mirrorCol) {
|
||||
@ -370,7 +370,7 @@ public class Gui {
|
||||
}
|
||||
|
||||
if (mirrorRow && mirrorCol) {
|
||||
setItem(rows - row - 1, 8 - col, item);
|
||||
setItem(this.rows - row - 1, 8 - col, item);
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -378,7 +378,7 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
public Gui highlightItem(int cell) {
|
||||
ItemStack item = cellItems.get(cell);
|
||||
ItemStack item = this.cellItems.get(cell);
|
||||
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
setItem(cell, ItemUtils.addGlow(item));
|
||||
@ -389,14 +389,14 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui removeHighlight(int cell) {
|
||||
ItemStack item = cellItems.get(cell);
|
||||
ItemStack item = this.cellItems.get(cell);
|
||||
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
setItem(cell, ItemUtils.removeGlow(item));
|
||||
@ -407,18 +407,18 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
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
|
||||
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) {
|
||||
setItem(cell, GuiUtils.updateItemLore(item, lore));
|
||||
@ -429,12 +429,12 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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
|
||||
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) {
|
||||
setItem(cell, GuiUtils.updateItemLore(item, lore));
|
||||
@ -445,12 +445,12 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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
|
||||
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) {
|
||||
setItem(cell, GuiUtils.updateItemName(item, name));
|
||||
@ -461,7 +461,7 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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
|
||||
@ -471,12 +471,12 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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
|
||||
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) {
|
||||
setItem(cell, GuiUtils.updateItem(item, name, lore));
|
||||
@ -487,12 +487,12 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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
|
||||
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) {
|
||||
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
||||
@ -503,12 +503,12 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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
|
||||
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) {
|
||||
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
||||
@ -519,12 +519,12 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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
|
||||
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) {
|
||||
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
||||
@ -535,12 +535,12 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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
|
||||
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) {
|
||||
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
||||
@ -557,7 +557,7 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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;
|
||||
}
|
||||
|
||||
@ -569,7 +569,7 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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;
|
||||
}
|
||||
|
||||
@ -584,9 +584,9 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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);
|
||||
}
|
||||
|
||||
@ -604,9 +604,9 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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);
|
||||
}
|
||||
|
||||
@ -615,13 +615,13 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
public Gui clearActions(int cell) {
|
||||
conditionalButtons.remove(cell);
|
||||
this.conditionalButtons.remove(cell);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui clearActions(int row, int col) {
|
||||
return clearActions(col + row * inventoryType.columns);
|
||||
return clearActions(col + row * this.inventoryType.columns);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -634,7 +634,7 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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);
|
||||
setConditional(cell, null, action);
|
||||
@ -652,7 +652,7 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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);
|
||||
setConditional(cell, type, action);
|
||||
@ -661,62 +661,62 @@ public class Gui {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui setOnOpen(@Nullable Openable action) {
|
||||
opener = action;
|
||||
this.opener = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui setOnClose(@Nullable Closable action) {
|
||||
closer = action;
|
||||
this.closer = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui setOnDrop(@Nullable Droppable action) {
|
||||
dropper = action;
|
||||
this.dropper = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui setOnPage(@Nullable Pagable action) {
|
||||
pager = action;
|
||||
this.pager = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Gui setNextPage(ItemStack item) {
|
||||
nextPage = item;
|
||||
this.nextPage = item;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Gui setPrevPage(ItemStack item) {
|
||||
prevPage = item;
|
||||
this.prevPage = item;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
if (inventory != null) {
|
||||
inventory.clear();
|
||||
if (this.inventory != null) {
|
||||
this.inventory.clear();
|
||||
}
|
||||
|
||||
setActionForRange(0, 53, null);
|
||||
cellItems.clear();
|
||||
this.cellItems.clear();
|
||||
update();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Gui setNextPage(int cell, @NotNull ItemStack item) {
|
||||
nextPageItem = cellItems.get(cell);
|
||||
nextPageIndex = cell;
|
||||
nextPage = item;
|
||||
this.nextPageItem = this.cellItems.get(cell);
|
||||
this.nextPageIndex = cell;
|
||||
this.nextPage = item;
|
||||
|
||||
if (page < pages) {
|
||||
setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage());
|
||||
if (this.page < this.pages) {
|
||||
setButton(this.nextPageIndex, this.nextPage, ClickType.LEFT, (event) -> this.nextPage());
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -724,17 +724,17 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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
|
||||
public Gui setPrevPage(int cell, @NotNull ItemStack item) {
|
||||
prevPageItem = cellItems.get(cell);
|
||||
prevPageIndex = cell;
|
||||
prevPage = item;
|
||||
this.prevPageItem = this.cellItems.get(cell);
|
||||
this.prevPageIndex = cell;
|
||||
this.prevPage = item;
|
||||
|
||||
if (page > 1) {
|
||||
setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage());
|
||||
if (this.page > 1) {
|
||||
setButton(this.prevPageIndex, this.prevPage, ClickType.LEFT, (event) -> this.prevPage());
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -742,23 +742,23 @@ public class Gui {
|
||||
|
||||
@NotNull
|
||||
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) {
|
||||
this.pages = Math.max(1, pages);
|
||||
|
||||
if (page > pages) {
|
||||
if (this.page > pages) {
|
||||
setPage(pages);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPage(int 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) {
|
||||
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
|
||||
if (this.pager != null && this.page != lastPage) {
|
||||
this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, page));
|
||||
|
||||
// page markers
|
||||
updatePageNavigation();
|
||||
@ -766,11 +766,11 @@ public class Gui {
|
||||
}
|
||||
|
||||
public void changePage(int direction) {
|
||||
int lastPage = page;
|
||||
this.page = Math.max(1, Math.min(pages, page + direction));
|
||||
int lastPage = this.page;
|
||||
this.page = Math.max(1, Math.min(this.pages, this.page + direction));
|
||||
|
||||
if (pager != null && this.page != lastPage) {
|
||||
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
|
||||
if (this.pager != null && this.page != lastPage) {
|
||||
this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, this.page));
|
||||
|
||||
// page markers
|
||||
updatePageNavigation();
|
||||
@ -778,13 +778,13 @@ public class Gui {
|
||||
}
|
||||
|
||||
public void nextPage() {
|
||||
if (page < pages) {
|
||||
int lastPage = page;
|
||||
++page;
|
||||
if (this.page < this.pages) {
|
||||
int lastPage = this.page;
|
||||
++this.page;
|
||||
|
||||
// page switch events
|
||||
if (pager != null) {
|
||||
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
|
||||
if (this.pager != null) {
|
||||
this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, this.page));
|
||||
|
||||
// page markers
|
||||
updatePageNavigation();
|
||||
@ -797,12 +797,12 @@ public class Gui {
|
||||
}
|
||||
|
||||
public void prevPage() {
|
||||
if (page > 1) {
|
||||
int lastPage = page;
|
||||
--page;
|
||||
if (this.page > 1) {
|
||||
int lastPage = this.page;
|
||||
--this.page;
|
||||
|
||||
if (pager != null) {
|
||||
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
|
||||
if (this.pager != null) {
|
||||
this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, this.page));
|
||||
|
||||
// page markers
|
||||
updatePageNavigation();
|
||||
@ -815,75 +815,75 @@ public class Gui {
|
||||
}
|
||||
|
||||
protected void updatePageNavigation() {
|
||||
if (prevPage != null) {
|
||||
if (page > 1) {
|
||||
this.setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage());
|
||||
if (this.prevPage != null) {
|
||||
if (this.page > 1) {
|
||||
this.setButton(this.prevPageIndex, this.prevPage, ClickType.LEFT, (event) -> this.prevPage());
|
||||
} else {
|
||||
this.setItem(prevPageIndex, prevPageItem);
|
||||
this.clearActions(prevPageIndex);
|
||||
this.setItem(this.prevPageIndex, this.prevPageItem);
|
||||
this.clearActions(this.prevPageIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (nextPage != null) {
|
||||
if (pages > 1 && page != pages) {
|
||||
this.setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage());
|
||||
if (this.nextPage != null) {
|
||||
if (this.pages > 1 && this.page != this.pages) {
|
||||
this.setButton(this.nextPageIndex, this.nextPage, ClickType.LEFT, (event) -> this.nextPage());
|
||||
} else {
|
||||
this.setItem(nextPageIndex, nextPageItem);
|
||||
this.clearActions(nextPageIndex);
|
||||
this.setItem(this.nextPageIndex, this.nextPageItem);
|
||||
this.clearActions(this.nextPageIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Inventory getOrCreateInventory(@NotNull GuiManager manager) {
|
||||
return inventory != null ? inventory : generateInventory(manager);
|
||||
return this.inventory != null ? this.inventory : generateInventory(manager);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Inventory generateInventory(@NotNull GuiManager manager) {
|
||||
this.guiManager = manager;
|
||||
final int cells = rows * inventoryType.columns;
|
||||
final int cells = this.rows * this.inventoryType.columns;
|
||||
|
||||
createInventory();
|
||||
|
||||
for (int i = 0; i < cells; ++i) {
|
||||
final ItemStack item = cellItems.get(i);
|
||||
inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem));
|
||||
final ItemStack item = this.cellItems.get(i);
|
||||
this.inventory.setItem(i, item != null ? item : (this.unlockedCells.getOrDefault(i, false) ? AIR : this.blankItem));
|
||||
}
|
||||
|
||||
return inventory;
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
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) {
|
||||
case DISPENSER:
|
||||
case HOPPER:
|
||||
inventory = new GuiHolder(guiManager, this).newInventory(t,
|
||||
title == null ? "" : trimTitle(title));
|
||||
this.inventory = new GuiHolder(this.guiManager, this).newInventory(t,
|
||||
this.title == null ? "" : trimTitle(this.title));
|
||||
break;
|
||||
default:
|
||||
inventory = new GuiHolder(guiManager, this).newInventory(rows * 9,
|
||||
title == null ? "" : trimTitle(title));
|
||||
this.inventory = new GuiHolder(this.guiManager, this).newInventory(this.rows * 9,
|
||||
this.title == null ? "" : trimTitle(this.title));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Gui getParent() {
|
||||
return parent;
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (inventory == null) {
|
||||
if (this.inventory == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int cells = rows * inventoryType.columns;
|
||||
final int cells = this.rows * this.inventoryType.columns;
|
||||
for (int i = 0; i < cells; ++i) {
|
||||
final ItemStack item = cellItems.get(i);
|
||||
inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem));
|
||||
final ItemStack item = this.cellItems.get(i);
|
||||
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) {
|
||||
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) {
|
||||
final int cell = event.getSlot();
|
||||
Map<ClickType, Clickable> conditionals = conditionalButtons.get(cell);
|
||||
Map<ClickType, Clickable> conditionals = this.conditionalButtons.get(cell);
|
||||
|
||||
Clickable button;
|
||||
if (conditionals != null
|
||||
@ -913,14 +913,14 @@ public class Gui {
|
||||
button.onClick(new GuiClickEvent(manager, this, player, event, cell, true));
|
||||
} else {
|
||||
// no event for this button
|
||||
if (defaultClicker != null) {
|
||||
if (this.defaultClicker != null) {
|
||||
// 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
|
||||
privateDefaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true));
|
||||
this.privateDefaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true));
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -935,36 +935,36 @@ public class Gui {
|
||||
}
|
||||
|
||||
public void onOpen(@NotNull GuiManager manager, @NotNull Player player) {
|
||||
open = true;
|
||||
guiManager = manager;
|
||||
this.open = true;
|
||||
this.guiManager = manager;
|
||||
|
||||
if (opener != null) {
|
||||
opener.onOpen(new GuiOpenEvent(manager, this, player));
|
||||
if (this.opener != null) {
|
||||
this.opener.onOpen(new GuiOpenEvent(manager, this, player));
|
||||
}
|
||||
}
|
||||
|
||||
public void onClose(@NotNull GuiManager manager, @NotNull Player player) {
|
||||
if (!allowClose) {
|
||||
if (!this.allowClose) {
|
||||
manager.showGUI(player, this);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean showParent = open && parent != null;
|
||||
boolean showParent = this.open && this.parent != null;
|
||||
|
||||
if (closer != null) {
|
||||
closer.onClose(new GuiCloseEvent(manager, this, player));
|
||||
if (this.closer != null) {
|
||||
this.closer.onClose(new GuiCloseEvent(manager, this, player));
|
||||
}
|
||||
|
||||
if (showParent) {
|
||||
manager.showGUI(player, parent);
|
||||
manager.showGUI(player, this.parent);
|
||||
}
|
||||
}
|
||||
|
||||
public XSound getDefaultSound() {
|
||||
return defaultSound;
|
||||
return this.defaultSound;
|
||||
}
|
||||
|
||||
public void setDefaultSound(XSound sound) {
|
||||
defaultSound = sound;
|
||||
this.defaultSound = sound;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Internal class for marking an inventory as a GUI inventory
|
||||
@ -18,12 +19,12 @@ class GuiHolder implements InventoryHolder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return gui.inventory;
|
||||
public @NotNull Inventory getInventory() {
|
||||
return this.gui.inventory;
|
||||
}
|
||||
|
||||
public Gui getGUI() {
|
||||
return gui;
|
||||
return this.gui;
|
||||
}
|
||||
|
||||
public Inventory newInventory(int size, String title) {
|
||||
|
@ -43,17 +43,17 @@ public class GuiManager {
|
||||
}
|
||||
|
||||
public Plugin getPlugin() {
|
||||
return plugin;
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the GUI handlers
|
||||
*/
|
||||
public void init() {
|
||||
Bukkit.getPluginManager().registerEvents(listener, plugin);
|
||||
Bukkit.getPluginManager().registerEvents(this.listener, this.plugin);
|
||||
|
||||
initialized = true;
|
||||
shutdown = false;
|
||||
this.initialized = true;
|
||||
this.shutdown = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,7 +62,7 @@ public class GuiManager {
|
||||
* @return true if the owning plugin has shutdown
|
||||
*/
|
||||
public boolean isClosed() {
|
||||
return shutdown;
|
||||
return this.shutdown;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,20 +72,20 @@ public class GuiManager {
|
||||
* @param gui GUI to use
|
||||
*/
|
||||
public void showGUI(Player player, Gui gui) {
|
||||
if (shutdown) {
|
||||
if (!plugin.isEnabled()) {
|
||||
if (this.shutdown) {
|
||||
if (!this.plugin.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// recover if reloaded without calling init manually
|
||||
init();
|
||||
} else if (!initialized) {
|
||||
} else if (!this.initialized) {
|
||||
init();
|
||||
}
|
||||
|
||||
if (gui instanceof AnvilGui) {
|
||||
// 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) {
|
||||
openInv.open = false;
|
||||
@ -95,15 +95,15 @@ public class GuiManager {
|
||||
((AnvilGui) gui).open();
|
||||
gui.onOpen(this, player);
|
||||
|
||||
synchronized (lock) {
|
||||
openInventories.put(player, gui);
|
||||
synchronized (this.lock) {
|
||||
this.openInventories.put(player, gui);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
Gui openInv = openInventories.get(player);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
Gui openInv = this.openInventories.get(player);
|
||||
|
||||
if (openInv != null) {
|
||||
openInv.open = false;
|
||||
@ -111,12 +111,12 @@ public class GuiManager {
|
||||
|
||||
Inventory inv = gui.getOrCreateInventory(this);
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
Bukkit.getScheduler().runTask(this.plugin, () -> {
|
||||
player.openInventory(inv);
|
||||
gui.onOpen(this, player);
|
||||
|
||||
synchronized (lock) {
|
||||
openInventories.put(player, gui);
|
||||
synchronized (this.lock) {
|
||||
this.openInventories.put(player, gui);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -132,11 +132,11 @@ public class GuiManager {
|
||||
|
||||
public void showPopup(Player player, String message, XMaterial icon, BackgroundType background) {
|
||||
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.grant(player);
|
||||
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(this.plugin, () -> {
|
||||
popup.revoke(player);
|
||||
popup.remove();
|
||||
}, 70);
|
||||
@ -156,13 +156,13 @@ public class GuiManager {
|
||||
* Close all active GUIs
|
||||
*/
|
||||
public void closeAll() {
|
||||
synchronized (lock) {
|
||||
openInventories.entrySet().stream()
|
||||
synchronized (this.lock) {
|
||||
this.openInventories.entrySet().stream()
|
||||
.filter(e -> e.getKey().getOpenInventory().getTopInventory().getHolder() instanceof GuiHolder)
|
||||
.collect(Collectors.toList()) // to prevent concurrency exceptions
|
||||
.forEach(e -> e.getKey().closeInventory());
|
||||
|
||||
openInventories.clear();
|
||||
this.openInventories.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ public class GuiManager {
|
||||
Inventory openInv = event.getInventory();
|
||||
Gui gui;
|
||||
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();
|
||||
|
||||
if (event.getRawSlots().stream()
|
||||
@ -205,7 +205,7 @@ public class GuiManager {
|
||||
|
||||
Gui gui;
|
||||
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();
|
||||
|
||||
if (event.getClick() == ClickType.DOUBLE_CLICK) {
|
||||
@ -228,7 +228,7 @@ public class GuiManager {
|
||||
}
|
||||
|
||||
if (event.getSlotType() == SlotType.OUTSIDE) {
|
||||
if (!gui.onClickOutside(manager, player, event)) {
|
||||
if (!gui.onClickOutside(this.manager, player, event)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} // did we click the gui or in the user's inventory?
|
||||
@ -260,7 +260,7 @@ public class GuiManager {
|
||||
Inventory openInv = event.getInventory();
|
||||
|
||||
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();
|
||||
|
||||
if (gui instanceof AnvilGui) {
|
||||
@ -277,23 +277,23 @@ public class GuiManager {
|
||||
player.setItemOnCursor(null);
|
||||
}
|
||||
|
||||
if (manager.shutdown) {
|
||||
gui.onClose(manager, player);
|
||||
if (this.manager.shutdown) {
|
||||
gui.onClose(this.manager, player);
|
||||
} 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
|
||||
void onDisable(PluginDisableEvent event) {
|
||||
if (event.getPlugin() == manager.plugin) {
|
||||
if (event.getPlugin() == this.manager.plugin) {
|
||||
// uh-oh! Abandon ship!!
|
||||
manager.shutdown = true;
|
||||
manager.closeAll();
|
||||
manager.initialized = false;
|
||||
this.manager.shutdown = true;
|
||||
this.manager.closeAll();
|
||||
this.manager.initialized = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,13 +36,13 @@ class PopupMessage {
|
||||
BackgroundType background = BackgroundType.ADVENTURE;
|
||||
|
||||
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.icon = icon;
|
||||
}
|
||||
|
||||
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.icon = icon;
|
||||
this.background = background;
|
||||
@ -64,7 +64,7 @@ class PopupMessage {
|
||||
}
|
||||
|
||||
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("frame", this.frame.id);
|
||||
advDisplay.addProperty("announce_to_chat", false);
|
||||
@ -110,11 +110,11 @@ class PopupMessage {
|
||||
}
|
||||
|
||||
protected void add() {
|
||||
if (!registeredMessages.contains(id)) {
|
||||
registeredMessages.add(id);
|
||||
if (!registeredMessages.contains(this.id)) {
|
||||
registeredMessages.add(this.id);
|
||||
|
||||
try {
|
||||
Bukkit.getUnsafe().loadAdvancement(key, getJSON());
|
||||
Bukkit.getUnsafe().loadAdvancement(this.key, getJSON());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Bukkit.getLogger().warning("Failed to create popup advancement!");
|
||||
}
|
||||
@ -122,14 +122,14 @@ class PopupMessage {
|
||||
}
|
||||
|
||||
protected void remove() {
|
||||
if (registeredMessages.contains(id)) {
|
||||
registeredMessages.remove(id);
|
||||
Bukkit.getUnsafe().removeAdvancement(key);
|
||||
if (registeredMessages.contains(this.id)) {
|
||||
registeredMessages.remove(this.id);
|
||||
Bukkit.getUnsafe().removeAdvancement(this.key);
|
||||
}
|
||||
}
|
||||
|
||||
public Advancement getAdvancement() {
|
||||
return Bukkit.getAdvancement(key);
|
||||
return Bukkit.getAdvancement(this.key);
|
||||
}
|
||||
|
||||
public enum FrameType {
|
||||
@ -140,7 +140,7 @@ class PopupMessage {
|
||||
final String id;
|
||||
|
||||
FrameType() {
|
||||
id = name().toLowerCase();
|
||||
this.id = name().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ class PopupMessage {
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
return this.key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ public class SimplePagedGui extends Gui {
|
||||
public SimplePagedGui(Gui parent) {
|
||||
super(parent);
|
||||
|
||||
nextPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Next Page");
|
||||
prevPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Previous Page");
|
||||
this.nextPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Next Page");
|
||||
this.prevPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Previous Page");
|
||||
}
|
||||
|
||||
public SimplePagedGui setUseHeader(boolean useHeader) {
|
||||
@ -40,7 +40,7 @@ public class SimplePagedGui extends Gui {
|
||||
}
|
||||
|
||||
public ItemStack getHeaderBackItem() {
|
||||
return headerBackItem;
|
||||
return this.headerBackItem;
|
||||
}
|
||||
|
||||
public SimplePagedGui setHeaderBackItem(ItemStack headerBackItem) {
|
||||
@ -49,7 +49,7 @@ public class SimplePagedGui extends Gui {
|
||||
}
|
||||
|
||||
public ItemStack getFooterBackItem() {
|
||||
return footerBackItem;
|
||||
return this.footerBackItem;
|
||||
}
|
||||
|
||||
public SimplePagedGui setFooterBackItem(ItemStack footerBackItem) {
|
||||
@ -65,11 +65,11 @@ public class SimplePagedGui extends Gui {
|
||||
@Override
|
||||
public SimplePagedGui setItem(int cell, ItemStack item) {
|
||||
// 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);
|
||||
if (open && cell >= 0 && cell < inventory.getSize()) {
|
||||
inventory.setItem(cell, item);
|
||||
this.cellItems.put(cellIndex, item);
|
||||
if (this.open && cell >= 0 && cell < this.inventory.getSize()) {
|
||||
this.inventory.setItem(cell, item);
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -77,27 +77,27 @@ public class SimplePagedGui extends Gui {
|
||||
|
||||
@Override
|
||||
public void nextPage() {
|
||||
if (page < pages) {
|
||||
++page;
|
||||
if (this.page < this.pages) {
|
||||
++this.page;
|
||||
showPage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prevPage() {
|
||||
if (page > 1) {
|
||||
--page;
|
||||
if (this.page > 1) {
|
||||
--this.page;
|
||||
showPage();
|
||||
}
|
||||
}
|
||||
|
||||
public void showPage() {
|
||||
int startCell = useHeader ? 9 : 0;
|
||||
int cellIndex = startCell + (page - 1) * (rowsPerPage * 9);
|
||||
int startCell = this.useHeader ? 9 : 0;
|
||||
int cellIndex = startCell + (this.page - 1) * (this.rowsPerPage * 9);
|
||||
|
||||
for (int i = startCell; i < (rows - 1) * 9; ++i) {
|
||||
final ItemStack item = cellItems.get(cellIndex++);
|
||||
inventory.setItem(i, item != null ? item : blankItem);
|
||||
for (int i = startCell; i < (this.rows - 1) * 9; ++i) {
|
||||
final ItemStack item = this.cellItems.get(cellIndex++);
|
||||
this.inventory.setItem(i, item != null ? item : this.blankItem);
|
||||
}
|
||||
|
||||
// page markers
|
||||
@ -106,26 +106,26 @@ public class SimplePagedGui extends Gui {
|
||||
|
||||
@Override
|
||||
protected void updatePageNavigation() {
|
||||
if (page > 1) {
|
||||
inventory.setItem(inventory.getSize() - prevPageIndex, prevPage);
|
||||
if (this.page > 1) {
|
||||
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 {
|
||||
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.clearActions(-prevPageIndex);
|
||||
this.setItem(-this.prevPageIndex, null);
|
||||
this.clearActions(-this.prevPageIndex);
|
||||
}
|
||||
|
||||
if (pages > 1 && page != pages) {
|
||||
inventory.setItem(inventory.getSize() - nextPageIndex, nextPage);
|
||||
if (this.pages > 1 && this.page != this.pages) {
|
||||
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 {
|
||||
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.clearActions(-nextPageIndex);
|
||||
this.setItem(-this.nextPageIndex, null);
|
||||
this.clearActions(-this.nextPageIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,65 +134,65 @@ public class SimplePagedGui extends Gui {
|
||||
this.guiManager = manager;
|
||||
|
||||
// calculate pages here
|
||||
rowsPerPage = useHeader ? 4 : 5;
|
||||
maxCellSlot = this.cellItems.keySet().stream().max(Integer::compare).orElse(0) + 1;
|
||||
int maxRows = (int) Math.ceil(maxCellSlot / 9.);
|
||||
pages = (int) Math.max(1, Math.ceil(maxRows / (double) rowsPerPage));
|
||||
this.setRows(maxRows + (useHeader ? 1 : 0));
|
||||
this.rowsPerPage = this.useHeader ? 4 : 5;
|
||||
this.maxCellSlot = this.cellItems.keySet().stream().max(Integer::compare).orElse(0) + 1;
|
||||
int maxRows = (int) Math.ceil(this.maxCellSlot / 9.);
|
||||
this.pages = (int) Math.max(1, Math.ceil(maxRows / (double) this.rowsPerPage));
|
||||
this.setRows(maxRows + (this.useHeader ? 1 : 0));
|
||||
|
||||
// create inventory view
|
||||
createInventory();
|
||||
|
||||
// populate and return the display inventory
|
||||
setPage(Math.min(page, pages));
|
||||
setPage(Math.min(this.page, this.pages));
|
||||
update();
|
||||
|
||||
return inventory;
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createInventory() {
|
||||
final int cells = rows * 9;
|
||||
final int cells = this.rows * 9;
|
||||
|
||||
inventory = Bukkit.getServer().createInventory(new GuiHolder(guiManager, this), cells,
|
||||
title == null ? "" : trimTitle(title));
|
||||
this.inventory = Bukkit.getServer().createInventory(new GuiHolder(this.guiManager, this), cells,
|
||||
this.title == null ? "" : trimTitle(this.title));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (inventory == null) {
|
||||
if (this.inventory == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// calculate pages here
|
||||
rowsPerPage = useHeader ? 4 : 5;
|
||||
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.));
|
||||
pages = (int) Math.ceil(maxRows / rowsPerPage);
|
||||
this.rowsPerPage = this.useHeader ? 4 : 5;
|
||||
this.maxCellSlot = (this.cellItems.isEmpty() ? 0 : this.cellItems.keySet().stream().max(Integer::compare).get()) + 1;
|
||||
int maxRows = Math.max((this.useHeader ? 1 : 0), (int) Math.ceil(this.maxCellSlot / 9.));
|
||||
this.pages = (int) Math.ceil(maxRows / this.rowsPerPage);
|
||||
|
||||
// create a new inventory if needed
|
||||
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();
|
||||
|
||||
this.setRows(maxRows + (useHeader ? 1 : 0));
|
||||
this.setRows(maxRows + (this.useHeader ? 1 : 0));
|
||||
|
||||
createInventory();
|
||||
}
|
||||
|
||||
// populate header
|
||||
if (useHeader) {
|
||||
if (this.useHeader) {
|
||||
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
|
||||
final int cells = rows * 9;
|
||||
final int cells = this.rows * 9;
|
||||
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
|
||||
@ -202,7 +202,7 @@ public class SimplePagedGui extends Gui {
|
||||
if (toUpdate != null) {
|
||||
// whoopsie!
|
||||
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();
|
||||
Map<ClickType, Clickable> conditionals;
|
||||
|
||||
if (useHeader && cell < 9) {
|
||||
conditionals = conditionalButtons.get(cell);
|
||||
} else if (cell >= (rows - 1) * 9) {
|
||||
if (this.useHeader && cell < 9) {
|
||||
conditionals = this.conditionalButtons.get(cell);
|
||||
} else if (cell >= (this.rows - 1) * 9) {
|
||||
// footer row
|
||||
conditionals = conditionalButtons.get(cell - (rows * 9));
|
||||
conditionals = this.conditionalButtons.get(cell - (this.rows * 9));
|
||||
} else {
|
||||
int cellIndex = page == 1 ? cell : cell + (page - 1) * rowsPerPage * 9;
|
||||
conditionals = conditionalButtons.get(cellIndex);
|
||||
int cellIndex = this.page == 1 ? cell : cell + (this.page - 1) * this.rowsPerPage * 9;
|
||||
conditionals = this.conditionalButtons.get(cellIndex);
|
||||
}
|
||||
|
||||
Clickable button;
|
||||
|
Loading…
Reference in New Issue
Block a user