Skip to content

Commit

Permalink
Add new InventoryView methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo committed Jun 13, 2024
1 parent 45fc76f commit 9978c92
Showing 1 changed file with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

import com.lishid.openinv.OpenInv;
import com.lishid.openinv.util.lang.Replacement;
import java.util.Objects;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class OpenInventoryView extends InventoryView {

private final @NotNull Player player;
Expand Down Expand Up @@ -68,17 +69,28 @@ public OpenInventoryView(
@Override
public @NotNull String getTitle() {
if (title == null) {
HumanEntity owner = inventory.getPlayer();

String localTitle = OpenInv.getPlugin(OpenInv.class)
.getLocalizedMessage(
player,
titleKey,
new Replacement("%player%", owner.getName()));
title = Objects.requireNonNullElseGet(localTitle, () -> owner.getName() + titleDefaultSuffix);
title = getOriginalTitle();
}

return title;
}

@NotNull
@Override
public String getOriginalTitle() {
HumanEntity owner = inventory.getPlayer();

String localTitle = OpenInv.getPlugin(OpenInv.class)
.getLocalizedMessage(
player,
titleKey,
new Replacement("%player%", owner.getName()));
return Objects.requireNonNullElseGet(localTitle, () -> owner.getName() + titleDefaultSuffix);
}

@Override
public void setTitle(@NotNull String title) {
this.title = title;
}

}

0 comments on commit 9978c92

Please sign in to comment.