Skip to content

Commit

Permalink
- Fix the back button on the switch/itemuse/allowedblocks GUIs not
Browse files Browse the repository at this point in the history
working from the first page.
    - Closes #6027.
  • Loading branch information
LlmDl committed Jul 18, 2022
1 parent 55f27d8 commit d25022e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7601,4 +7601,6 @@ v0.92.0.11:
- Bump language files to 0.152.
- Fix jailcells being able to be placed where a jailcell already exists.
- Make the plot perm hud translatable.
- Fix potential NPE in SelectionGUI.
- Fix potential NPE in SelectionGUI.
- Fix the back button on the switch/itemuse/allowedblocks GUIs not working from the first page.
- Closes #6027.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void onClick(InventoryClickEvent event) {
case ITEMUSE -> Translatable.of("gui_title_towny_itemuse").forLocale(resident);
};

resident.setGUISelectionType(selectionGUI.getType());
selectionGUI.playClickSound(player);
ResidentUtil.openGUIInventory(resident, materialSet, title);
} else {
Expand Down
10 changes: 10 additions & 0 deletions src/com/palmergames/bukkit/towny/object/Resident.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.palmergames.bukkit.towny.invites.InviteReceiver;
import com.palmergames.bukkit.towny.invites.exceptions.TooManyInvitesException;
import com.palmergames.bukkit.towny.object.economy.Account;
import com.palmergames.bukkit.towny.object.gui.SelectionGUI.SelectionType;
import com.palmergames.bukkit.towny.object.jail.Jail;
import com.palmergames.bukkit.towny.object.metadata.BooleanDataField;
import com.palmergames.bukkit.towny.object.metadata.CustomDataField;
Expand Down Expand Up @@ -78,6 +79,7 @@ public class Resident extends TownyObject implements InviteReceiver, EconomyHand

private ArrayList<Inventory> guiPages;
private int guiPageNum = 0;
private SelectionType guiSelectionType;
private int respawnProtectionTaskID = -1;
private boolean respawnPickupWarningShown = false; // Prevents chat spam when a player attempts to pick up an item while under respawn protection.

Expand Down Expand Up @@ -845,6 +847,14 @@ public void setGUIPageNum(int currentInventoryPage) {
this.guiPageNum = currentInventoryPage;
}

public SelectionType getGUISelectionType() {
return guiSelectionType;
}

public void setGUISelectionType(SelectionType selectionType) {
this.guiSelectionType = selectionType;
}

@Override
public void save() {
TownyUniverse.getInstance().getDataSource().saveResident(this);
Expand Down
6 changes: 6 additions & 0 deletions src/com/palmergames/bukkit/towny/object/TownyInventory.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.palmergames.bukkit.towny.object;

import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.utils.ResidentUtil;
import com.palmergames.bukkit.util.Colors;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
Expand Down Expand Up @@ -56,6 +57,11 @@ public void tryPaginate(ItemStack clickedItem, Player player, Resident resident,
resident.setGUIPageNum(--currentPage);
new TownyInventory(resident, resident.getGUIPage(), inventoryView.getTitle());
playClickSound(player);
} else if (resident.getGUIPageNum() == 0) {
// No page to go back from: go back to the SelectionGUI for the SelectionType
// that the resident is currently browsing, let them choose a different plot type.
playClickSound(player);
ResidentUtil.openSelectionGUI(resident, resident.getGUISelectionType());
}
}
} catch (Exception ignored) {}
Expand Down

0 comments on commit d25022e

Please sign in to comment.