Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several bugfixes & improvements to stats #1461

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/src/main/java/tc/oc/pgm/ffa/Tribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public Collection<MatchPlayer> getPlayers() {
return this.players;
}

@Nullable
public MatchPlayer getPlayer() {
return this.player;
}

@Override
public @Nullable MatchPlayer getPlayer(final UUID playerId) {
return player != null && player.getId().equals(playerId) ? player : null;
Expand Down
29 changes: 11 additions & 18 deletions core/src/main/java/tc/oc/pgm/menu/InventoryMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ public InventoryMenu(
Component title, int rows, MatchPlayer viewer, @Nullable SmartInventory parent) {
this.viewer = viewer;

SmartInventory.Builder builder =
SmartInventory.builder()
.manager(PGM.get().getInventoryManager())
.title(translateLegacy(title, getBukkit()))
.size(rows, 9)
.provider(this);
SmartInventory.Builder builder = SmartInventory.builder()
.manager(PGM.get().getInventoryManager())
.title(translateLegacy(title, getBukkit()))
.size(rows, 9)
.provider(this);

if (parent != null) {
builder.parent(parent);
Expand All @@ -70,6 +69,10 @@ public SmartInventory getInventory() {
return inventory;
}

public int lastRow() {
return inventory.getRows() - 1;
}

public void addBackButton(
InventoryContents contents, Component parentMenuTitle, int row, int col) {
Component back = translatable("menu.page.return", NamedTextColor.GRAY, parentMenuTitle);
Expand All @@ -78,18 +81,8 @@ public void addBackButton(
row,
col,
ClickableItem.of(
new ItemBuilder()
.material(Material.BARRIER)
.name(translateLegacy(back, getBukkit()))
.build(),
c -> {
getInventory()
.getParent()
.ifPresent(
parent -> {
parent.open(getBukkit());
});
}));
new ItemBuilder().material(Material.BARRIER).name(getBukkit(), back).build(),
c -> getInventory().getParent().ifPresent(parent -> parent.open(getBukkit()))));
}

@Override
Expand Down
14 changes: 10 additions & 4 deletions core/src/main/java/tc/oc/pgm/menu/PagedInventoryMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,18 @@ public void setupPageContents(Player player, InventoryContents contents) {
*
* @return a {@link SlotPos} where previous page button will be located.
*/
public abstract SlotPos getPreviousPageSlot();
public SlotPos getPreviousPageSlot() {
return SlotPos.of(lastRow(), 0);
}

/**
* The position of the next page button.
*
* @return a {@link SlotPos} where next page button will be located.
*/
public abstract SlotPos getNextPageSlot();
public SlotPos getNextPageSlot() {
return SlotPos.of(lastRow(), 8);
}

/**
* The position of the no page contents button, only displayed when page contents is empty or
Expand All @@ -112,8 +116,10 @@ public void setupPageContents(Player player, InventoryContents contents) {

protected ClickableItem getEmptyContentsButton(Player viewer) {
Component name = translatable("menu.page.empty", NamedTextColor.DARK_RED, TextDecoration.BOLD);
return ClickableItem.empty(
new ItemBuilder().material(Material.BARRIER).name(translateLegacy(name, viewer)).build());
return ClickableItem.empty(new ItemBuilder()
.material(Material.BARRIER)
.name(translateLegacy(name, viewer))
.build());
}

protected ClickableItem getPageItem(Player player, int page, String key) {
Expand Down
Loading
Loading