mirror of
https://github.com/kiranhart/Auction-House.git
synced 2025-02-27 21:31:33 +01:00
switch to title input for ranged deletion of transaction as well
Took 5 minutes
This commit is contained in:
parent
9af0b48e0c
commit
356e850625
@ -23,9 +23,9 @@ import ca.tweetzy.auctionhouse.api.AuctionAPI;
|
||||
import ca.tweetzy.auctionhouse.guis.AbstractPlaceholderGui;
|
||||
import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse;
|
||||
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
|
||||
import ca.tweetzy.auctionhouse.helpers.input.TitleInput;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.auctionhouse.transaction.Transaction;
|
||||
import ca.tweetzy.core.input.PlayerChatInput;
|
||||
import ca.tweetzy.core.utils.NumberUtils;
|
||||
import ca.tweetzy.core.utils.TextUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -75,47 +75,50 @@ public final class GUITransactionType extends AbstractPlaceholderGui {
|
||||
if (player.isOp() || player.hasPermission("auctionhouse.admin")) {
|
||||
setButton(3, 8, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_TRANSACTIONS_TYPE_ITEMS_DELETE_ITEM.getString(), Settings.GUI_TRANSACTIONS_TYPE_ITEMS_DELETE_NAME.getString(), Settings.GUI_TRANSACTIONS_TYPE_ITEMS_DELETE_LORE.getStringList(), null), e -> {
|
||||
e.gui.close();
|
||||
PlayerChatInput.PlayerChatInputBuilder<Long> builder = new PlayerChatInput.PlayerChatInputBuilder<>(instance, e.player);
|
||||
builder.isValidInput((p, str) -> {
|
||||
String[] parts = ChatColor.stripColor(str).split(" ");
|
||||
if (parts.length == 2) {
|
||||
return NumberUtils.isInt(parts[0]) && Arrays.asList("second", "minute", "hour", "day", "week", "month", "year").contains(parts[1].toLowerCase());
|
||||
|
||||
new TitleInput(player, AuctionHouse.getInstance().getLocale().getMessage("titles.enter deletion range.title").getMessage(), AuctionHouse.getInstance().getLocale().getMessage("titles.enter deletion range.subtitle").getMessage()) {
|
||||
|
||||
@Override
|
||||
public void onExit(Player player) {
|
||||
e.manager.showGUI(e.player, GUITransactionType.this);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
builder.sendValueMessage(TextUtils.formatText(instance.getLocale().getMessage("prompts.enter deletion range").getMessage()));
|
||||
builder.invalidInputMessage(TextUtils.formatText(instance.getLocale().getMessage("prompts.enter valid deletion range").getMessage()));
|
||||
builder.toCancel("cancel");
|
||||
builder.onCancel(p -> e.manager.showGUI(e.player, new GUITransactionType(e.player)));
|
||||
builder.setValue((p, value) -> AuctionAPI.toTicks(ChatColor.stripColor(value)));
|
||||
builder.onFinish((p, value) -> {
|
||||
int seconds = value.intValue();
|
||||
|
||||
AuctionHouse.newChain().async(() -> {
|
||||
instance.getLocale().getMessage("general.transaction delete begin").sendPrefixedMessage(e.player);
|
||||
List<UUID> toRemove = new ArrayList<>();
|
||||
@Override
|
||||
public boolean onResult(String string) {
|
||||
string = ChatColor.stripColor(string);
|
||||
|
||||
Set<Map.Entry<UUID, Transaction>> entrySet = instance.getTransactionManager().getTransactions().entrySet();
|
||||
Iterator<Map.Entry<UUID, Transaction>> entryIterator = entrySet.iterator();
|
||||
final String[] parts = ChatColor.stripColor(string).split(" ");
|
||||
|
||||
while (entryIterator.hasNext()) {
|
||||
Map.Entry<UUID, Transaction> entry = entryIterator.next();
|
||||
Transaction transaction = entry.getValue();
|
||||
|
||||
if (Instant.ofEpochMilli(transaction.getTransactionTime()).isBefore(Instant.now().minus(Duration.ofSeconds(seconds)))) {
|
||||
toRemove.add(transaction.getId());
|
||||
entryIterator.remove();
|
||||
}
|
||||
if (!NumberUtils.isInt(parts[0]) && Arrays.asList("second", "minute", "hour", "day", "week", "month", "year").contains(parts[1].toLowerCase())) {
|
||||
instance.getLocale().getMessage("prompts.enter deletion range").sendPrefixedMessage(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
instance.getDataManager().deleteTransactions(toRemove);
|
||||
instance.getLocale().getMessage("general.deleted transactions").processPlaceholder("deleted_transactions", toRemove.size()).sendPrefixedMessage(e.player);
|
||||
}).execute();
|
||||
});
|
||||
final long ticks = AuctionAPI.toTicks(string);
|
||||
|
||||
PlayerChatInput<Long> input = builder.build();
|
||||
input.start();
|
||||
AuctionHouse.newChain().async(() -> {
|
||||
instance.getLocale().getMessage("general.transaction delete begin").sendPrefixedMessage(e.player);
|
||||
List<UUID> toRemove = new ArrayList<>();
|
||||
|
||||
Set<Map.Entry<UUID, Transaction>> entrySet = instance.getTransactionManager().getTransactions().entrySet();
|
||||
Iterator<Map.Entry<UUID, Transaction>> entryIterator = entrySet.iterator();
|
||||
|
||||
while (entryIterator.hasNext()) {
|
||||
Map.Entry<UUID, Transaction> entry = entryIterator.next();
|
||||
Transaction transaction = entry.getValue();
|
||||
|
||||
if (Instant.ofEpochMilli(transaction.getTransactionTime()).isBefore(Instant.now().minus(Duration.ofSeconds(ticks)))) {
|
||||
toRemove.add(transaction.getId());
|
||||
entryIterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
instance.getDataManager().deleteTransactions(toRemove);
|
||||
instance.getLocale().getMessage("general.deleted transactions").processPlaceholder("deleted_transactions", toRemove.size()).sendPrefixedMessage(e.player);
|
||||
}).execute();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,7 @@ public class LocaleSettings {
|
||||
languageNodes.put("general.added min price", "&aSuccessfully set minimum price for %item% &ato &2$%price%");
|
||||
languageNodes.put("general.qtybuydisabled", "&4%item_owner%&c is only accepting purchases of the entire stack.");
|
||||
languageNodes.put("general.invalid bid amount", "&cBid either too low or too high");
|
||||
languageNodes.put("general.invalid deletion range", "&cPlease enter a valid deletion range");
|
||||
|
||||
|
||||
languageNodes.put("pricing.minbaseprice", "&cThe minimum base price must be &a$%price%");
|
||||
@ -114,8 +115,8 @@ public class LocaleSettings {
|
||||
languageNodes.put("titles.enter bid.title", "&ePlace Bid");
|
||||
languageNodes.put("titles.enter bid.subtitle", "&fEnter new bid amount in chat");
|
||||
|
||||
languageNodes.put("prompts.enter deletion range", "&aPlease enter deletion range (ex. 1 day):");
|
||||
languageNodes.put("prompts.enter valid deletion range", "&cPlease enter a valid deletion range");
|
||||
languageNodes.put("titles.enter deletion range.title", "&eDeletion Range");
|
||||
languageNodes.put("titles.enter deletion range.subtitle", "&fEnter deletion range in chat");
|
||||
|
||||
languageNodes.put("transaction.sale_type.bid_won", "Won Auction");
|
||||
languageNodes.put("transaction.sale_type.immediate_buy", "Bought Immediately");
|
||||
|
Loading…
Reference in New Issue
Block a user