✈️ moved payment collection gui to new layout

Took 6 minutes

Took 26 minutes
This commit is contained in:
Kiran Hart 2024-05-29 14:05:10 -04:00
parent 5e6e1869ed
commit 59b4e1987e
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3

View File

@ -22,16 +22,17 @@ import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionPayment; import ca.tweetzy.auctionhouse.auction.AuctionPayment;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper; import ca.tweetzy.auctionhouse.guis.abstraction.AuctionPagedGUI;
import ca.tweetzy.auctionhouse.hooks.PlaceholderAPIHook;
import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.utils.TextUtils; import ca.tweetzy.core.gui.Gui;
import org.bukkit.event.inventory.ClickType; import ca.tweetzy.core.gui.events.GuiClickEvent;
import ca.tweetzy.flight.utils.QuickItem;
import ca.tweetzy.flight.utils.Replacer;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -40,96 +41,81 @@ import java.util.stream.Collectors;
* Time Created: 3:19 p.m. * Time Created: 3:19 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise * Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/ */
public class GUIPaymentCollection extends AbstractPlaceholderGui { public class GUIPaymentCollection extends AuctionPagedGUI<AuctionPayment> {
final AuctionPlayer auctionPlayer; final AuctionPlayer auctionPlayer;
private List<AuctionPayment> payments;
private Long lastClicked = null; private Long lastClicked = null;
public GUIPaymentCollection(AuctionPlayer auctionPlayer) { public GUIPaymentCollection(Gui parent, AuctionPlayer auctionPlayer) {
super(auctionPlayer); super(parent, auctionPlayer.getPlayer(), Settings.GUI_PAYMENT_COLLECTION_TITLE.getString(), 6, new ArrayList<>(AuctionHouse.getInstance().getPaymentsManager().getPaymentsByPlayer(auctionPlayer.getPlayer())));
this.auctionPlayer = auctionPlayer; this.auctionPlayer = auctionPlayer;
setTitle(TextUtils.formatText(Settings.GUI_PAYMENT_COLLECTION_TITLE.getString()));
setRows(6);
setAcceptsItems(false);
draw(); draw();
} }
public GUIPaymentCollection(AuctionPlayer auctionPlayer, Long lastClicked) { public GUIPaymentCollection(AuctionPlayer auctionPlayer, Long lastClicked) {
this(auctionPlayer); this(null, auctionPlayer);
this.lastClicked = lastClicked; this.lastClicked = lastClicked;
} }
private void draw() { @Override
reset(); protected void prePopulate() {
setButton(5, 0, getBackButtonItem(), e -> e.manager.showGUI(e.player, new GUIExpiredItems(this.auctionPlayer))); this.items.sort(Comparator.comparingLong(AuctionPayment::getTime));
}
AuctionHouse.newChain().asyncFirst(() -> { @Override
this.payments = AuctionHouse.getInstance().getPaymentsManager().getPaymentsByPlayer(this.player); protected ItemStack makeDisplayItem(AuctionPayment payment) {
return this.payments.stream().sorted(Comparator.comparingLong(AuctionPayment::getTime)).skip((page - 1) * 45L).limit(45).collect(Collectors.toList()); return QuickItem
}).asyncLast((data) -> { .of(Settings.GUI_PAYMENT_COLLECTION_PAYMENT_ITEM.getString())
pages = (int) Math.max(1, Math.ceil(AuctionHouse.getInstance().getPaymentsManager().getPaymentsByPlayer(this.player).size() / (double) 45)); .name(Replacer.replaceVariables(Settings.GUI_PAYMENT_COLLECTION_PAYMENT_NAME.getString(), "payment_amount", AuctionAPI.getInstance().formatNumber(payment.getAmount())))
setPrevPage(5, 3, getPreviousPageItem()); .lore(Replacer.replaceVariables(Settings.GUI_PAYMENT_COLLECTION_PAYMENT_LORE.getStringList(),
// setButton(5, 4, getRefreshButtonItem(), e -> draw()); "item_name", AuctionAPI.getInstance().getItemName(payment.getItem()),
setNextPage(5, 5, getNextPageItem()); "from_name", payment.getFromName(),
setOnPage(e -> draw()); "payment_reason", payment.getReason().getTranslation()
)).make();
}
@Override
protected void onClick(AuctionPayment auctionPayment, GuiClickEvent click) {
setButton(5, 1, ConfigurationItemHelper.createConfigurationItem(this.player, if (this.lastClicked == null) {
Settings.GUI_PAYMENT_COLLECTION_ITEM.getString(), this.lastClicked = System.currentTimeMillis() + Settings.CLAIM_MS_DELAY.getInt();
PlaceholderAPIHook.PAPIReplacer.tryReplace(this.player, Settings.GUI_PAYMENT_COLLECTION_NAME.getString()), } else if (this.lastClicked > System.currentTimeMillis()) {
PlaceholderAPIHook.PAPIReplacer.tryReplace(this.player, Settings.GUI_PAYMENT_COLLECTION_LORE.getStringList()), null), e -> { return;
} else {
this.lastClicked = System.currentTimeMillis() + Settings.CLAIM_MS_DELAY.getInt();
}
if (this.lastClicked == null) { auctionPayment.pay(click.player);
this.lastClicked = System.currentTimeMillis() + Settings.CLAIM_MS_DELAY.getInt(); AuctionHouse.getInstance().getDataManager().deletePayments(Collections.singleton(auctionPayment.getId()));
} else if (this.lastClicked > System.currentTimeMillis()) { AuctionHouse.getInstance().getPaymentsManager().removePayment(auctionPayment.getId());
return;
} else {
this.lastClicked = System.currentTimeMillis() + Settings.CLAIM_MS_DELAY.getInt();
}
for (AuctionPayment auctionPayment : data) { click.manager.showGUI(click.player, new GUIPaymentCollection(this.auctionPlayer, this.lastClicked));
auctionPayment.pay(e.player); }
}
AuctionHouse.getInstance().getDataManager().deletePayments(data.stream().map(AuctionPayment::getId).collect(Collectors.toList())); @Override
data.forEach(payment -> AuctionHouse.getInstance().getPaymentsManager().removePayment(payment.getId())); protected void drawFixed() {
applyBackExit();
e.manager.showGUI(e.player, new GUIPaymentCollection(this.auctionPlayer, this.lastClicked)); setButton(5, 1, QuickItem.of(Settings.GUI_PAYMENT_COLLECTION_ITEM.getString())
}); .name(Settings.GUI_PAYMENT_COLLECTION_NAME.getString())
.lore(Settings.GUI_PAYMENT_COLLECTION_LORE.getStringList())
.make(), e -> {
int slot = 0; if (this.lastClicked == null) {
for (AuctionPayment auctionPayment : data) { this.lastClicked = System.currentTimeMillis() + Settings.CLAIM_MS_DELAY.getInt();
} else if (this.lastClicked > System.currentTimeMillis()) {
setButton(slot++, ConfigurationItemHelper.createConfigurationItem(this.player, return;
Settings.GUI_PAYMENT_COLLECTION_PAYMENT_ITEM.getString(), } else {
PlaceholderAPIHook.PAPIReplacer.tryReplace(this.player, Settings.GUI_PAYMENT_COLLECTION_PAYMENT_NAME.getString()), this.lastClicked = System.currentTimeMillis() + Settings.CLAIM_MS_DELAY.getInt();
PlaceholderAPIHook.PAPIReplacer.tryReplace(this.player, Settings.GUI_PAYMENT_COLLECTION_PAYMENT_LORE.getStringList()),
new HashMap<String, Object>() {{
put("%payment_amount%", AuctionAPI.getInstance().formatNumber(auctionPayment.getAmount()));
put("%item_name%", auctionPayment.getItem() == null ? "&cN/A" : AuctionAPI.getInstance().getItemName(auctionPayment.getItem()));
put("%from_name%", auctionPayment.getFromName());
put("%payment_reason%", auctionPayment.getReason().getTranslation());
}}
), ClickType.LEFT, e -> {
if (this.lastClicked == null) {
this.lastClicked = System.currentTimeMillis() + Settings.CLAIM_MS_DELAY.getInt();
} else if (this.lastClicked > System.currentTimeMillis()) {
return;
} else {
this.lastClicked = System.currentTimeMillis() + Settings.CLAIM_MS_DELAY.getInt();
}
auctionPayment.pay(e.player);
AuctionHouse.getInstance().getDataManager().deletePayments(Collections.singleton(auctionPayment.getId()));
AuctionHouse.getInstance().getPaymentsManager().removePayment(auctionPayment.getId());
e.manager.showGUI(e.player, new GUIPaymentCollection(this.auctionPlayer, this.lastClicked));
});
} }
}).execute(); for (AuctionPayment auctionPayment : this.items) {
auctionPayment.pay(e.player);
}
AuctionHouse.getInstance().getDataManager().deletePayments(this.items.stream().map(AuctionPayment::getId).collect(Collectors.toList()));
this.items.forEach(payment -> AuctionHouse.getInstance().getPaymentsManager().removePayment(payment.getId()));
e.manager.showGUI(e.player, new GUIPaymentCollection(this.auctionPlayer, this.lastClicked));
});
} }
} }