Skip to content

Commit

Permalink
🔨 2.25.0 ✨ Added toggle for switching between viewing all transaction…
Browse files Browse the repository at this point in the history
…s and just yours. By default the button is hidden unless you have the perm:

  markets.viewalltransactions or if you disable the permission requirement.

Took 9 minutes
  • Loading branch information
kiranhart committed Oct 25, 2024
1 parent 56197f3 commit 0538706
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public CommandTransactions() {
@Override
protected ReturnType execute(CommandSender sender, String... args) {
if (sender instanceof final Player player) {
Markets.getGuiManager().showGUI(player, new TransactionsGUI(null, player));
Markets.getGuiManager().showGUI(player, new TransactionsGUI(null, player, false));
}
return ReturnType.SUCCESS;
}
Expand Down
34 changes: 32 additions & 2 deletions src/main/java/ca/tweetzy/markets/gui/user/TransactionsGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
public final class TransactionsGUI extends MarketsPagedGUI<Transaction> {

private final Player player;
private boolean viewAll;

public TransactionsGUI(Gui parent, @NonNull final Player player) {
super(parent, player, TranslationManager.string(player, Translations.GUI_TRANSACTIONS_TITLE), 6, new ArrayList<>(Markets.getTransactionManager().getManagerContent()));
public TransactionsGUI(Gui parent, @NonNull final Player player, boolean viewAll) {
super(parent, player, TranslationManager.string(player, Translations.GUI_TRANSACTIONS_TITLE), 6, new ArrayList<>());
this.player = player;
this.viewAll = viewAll;
setAcceptsItems(true);
setDefaultItem(QuickItem.bg(Settings.GUI_TRANSACTIONS_BACKGROUND.getItemStack()));

Expand All @@ -33,9 +35,37 @@ public TransactionsGUI(Gui parent, @NonNull final Player player) {

@Override
protected void prePopulate() {
if (this.viewAll) {
this.items = new ArrayList<>(Markets.getTransactionManager().getManagerContent());
} else {
this.items = new ArrayList<>(Markets.getTransactionManager().getOfflineTransactionsFor(this.player.getUniqueId()));
}

this.items.sort(Comparator.comparing(Transaction::getTimeCreated).reversed());
}

@Override
protected void drawFixed() {
if (!Settings.USE_ADDITIONAL_CONFIRMS.getBoolean()) {
setTransactionViewButton();
} else {
if (this.player.hasPermission("markets.viewalltransactions"))
setTransactionViewButton();
}
}

private void setTransactionViewButton() {
setButton(getRows() - 1, 8, QuickItem
.of(Settings.GUI_TRANSACTIONS_VIEW_ALL_ITEM.getItemStack())
.name(TranslationManager.string(Translations.GUI_TRANSACTIONS_ITEMS_VIEW_ALL_NAME))
.lore(TranslationManager.list(Translations.GUI_TRANSACTIONS_ITEMS_VIEW_ALL_LORE, "is_true", TranslationManager.string(this.viewAll ? Translations.TRUE : Translations.FALSE), "left_click", TranslationManager.string(Translations.MOUSE_LEFT_CLICK)))
.make(), click -> {

this.viewAll = !this.viewAll;
draw();
});
}

@Override
protected ItemStack makeDisplayItem(Transaction transaction) {
final ItemStack item = transaction.getItem();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ca/tweetzy/markets/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public final class Settings extends FlightSettings {
public static ConfigEntry PURCHASE_ITEM_SHIFT_MULTI_AMT = create("settings.purchase item.shift multiply amount", 10).withComment("Ex. if the player shift clicks the increase 5 button it becomes 50, 1 -> 10, 10 -> 100");
public static ConfigEntry REQUEST_MENU_SHOWS_OWN_FIRST = create("settings.request menu shows own first", true).withComment("If false, the request menu will show global requests by default instead of your own.");
public static ConfigEntry USE_ADDITIONAL_CONFIRMS = create("settings.additional confirmations.enabled", true).withComment("If true, markets will ask the player to confirm sensitive actions (ie. deleting, creating) ");
public static ConfigEntry TRANSACTION_VIEW_ALL_NEEDS_PERM = create("settings.require permission to view all transactions", true).withComment("If true, players will need the perm: markets.viewalltransactions to see the toggle button.");

/*
========================= COMMAND ALIASES =========================
Expand Down Expand Up @@ -211,6 +212,7 @@ public final class Settings extends FlightSettings {
public static ConfigEntry GUI_OFFER_CREATE_ITEMS_AMOUNT = create("gui.offer creation.items.offered amount.item", CompMaterial.SUNFLOWER.name());
public static ConfigEntry GUI_OFFER_CREATE_ITEMS_CURRENCY = create("gui.offer creation.items.currency.item", CompMaterial.GOLD_INGOT.name());
public static ConfigEntry GUI_TRANSACTIONS_BACKGROUND = create("gui.transactions.items.background", CompMaterial.BLACK_STAINED_GLASS_PANE.name());
public static ConfigEntry GUI_TRANSACTIONS_VIEW_ALL_ITEM = create("gui.transactions.items.view all", CompMaterial.NETHER_STAR.name());
public static ConfigEntry GUI_BANK_BACKGROUND = create("gui.bank.items.background", CompMaterial.BLACK_STAINED_GLASS_PANE.name());
public static ConfigEntry GUI_BANK_ITEMS_ADD = create("gui.bank.items.add.item", CompMaterial.LIME_DYE.name());

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/ca/tweetzy/markets/settings/Translations.java
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,16 @@ public Translations(@NonNull JavaPlugin plugin) {
);

public static TranslationEntry GUI_TRANSACTIONS_TITLE = create("gui.transactions.title", "&eMarkets &f- &7Transactions");
public static TranslationEntry GUI_TRANSACTIONS_ITEMS_VIEW_ALL_NAME= create("gui.transactions.items.view all.name", "<GRADIENT:65B1B4>&lSwitch View Mode</GRADIENT:2B6F8A>");
public static TranslationEntry GUI_TRANSACTIONS_ITEMS_VIEW_ALL_LORE = create("gui.transactions.items.view all.lore",
"&7Used to toggle whether you see every transaction",
"&7or just the transactions related to you.",
"",
"&7Viewing all&f: %is_true%",
"",
"&e&l%left_click% &7to toggle view all"
);

public static TranslationEntry GUI_TRANSACTIONS_ITEMS_ENTRY_LORE = create("gui.transactions.items.entry.lore",
"&7----------------------------",
"&7Quantity&f: &E%item_quantity%",
Expand Down

0 comments on commit 0538706

Please sign in to comment.