⚙️payment settings and command

Took 11 minutes
This commit is contained in:
Kiran Hart 2023-03-03 12:50:42 -05:00
parent 35579ebe44
commit ddae21c659
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
3 changed files with 225 additions and 0 deletions

View File

@ -0,0 +1,78 @@
/*
* Auction House
* Copyright 2018-2022 Kiran Hart
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.guis.GUIPaymentCollection;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
/**
* The current file has been created by Kiran Hart
* Date Created: March 15 2021
* Time Created: 4:32 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class CommandPayments extends AbstractCommand {
public CommandPayments() {
super(CommandType.PLAYER_ONLY, "payments");
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
final Player player = (Player) sender;
if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;
final AuctionHouse instance = AuctionHouse.getInstance();
if (instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) {
instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player));
}
instance.getGuiManager().showGUI(player, new GUIPaymentCollection(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId())));
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "auctionhouse.cmd.payments";
}
@Override
public String getSyntax() {
return "payments";
}
@Override
public String getDescription() {
return "Opens payment collection gui";
}
@Override
protected List<String> onTab(CommandSender sender, String... args) {
return null;
}
}

View File

@ -0,0 +1,129 @@
/*
* Auction House
* Copyright 2018-2022 Kiran Hart
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ca.tweetzy.auctionhouse.guis;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionPayment;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.managers.SoundManager;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.flight.utils.QuickItem;
import org.bukkit.event.inventory.ClickType;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/**
* The current file has been created by Kiran Hart
* Date Created: March 15 2021
* Time Created: 3:19 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class GUIPaymentCollection extends AbstractPlaceholderGui {
final AuctionPlayer auctionPlayer;
private List<AuctionPayment> payments;
private Long lastClicked = null;
public GUIPaymentCollection(AuctionPlayer auctionPlayer) {
super(auctionPlayer);
this.auctionPlayer = auctionPlayer;
setTitle(TextUtils.formatText(Settings.GUI_PAYMENT_COLLECTION_TITLE.getString()));
setRows(6);
setAcceptsItems(false);
draw();
}
public GUIPaymentCollection(AuctionPlayer auctionPlayer, Long lastClicked) {
this(auctionPlayer);
this.lastClicked = lastClicked;
}
private void draw() {
reset();
setButton(5, 0, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_CLOSE_BTN_ITEM.getString(), Settings.GUI_CLOSE_BTN_NAME.getString(), Settings.GUI_CLOSE_BTN_LORE.getStringList(), null), e -> e.manager.showGUI(e.player, new GUIExpiredItems(this.auctionPlayer)));
AuctionHouse.newChain().asyncFirst(() -> {
this.payments = AuctionHouse.getInstance().getPaymentsManager().getPaymentsByPlayer(this.player);
return this.payments.stream().sorted(Comparator.comparingLong(AuctionPayment::getTime)).skip((page - 1) * 45L).limit(45).collect(Collectors.toList());
}).asyncLast((data) -> {
pages = (int) Math.max(1, Math.ceil(AuctionHouse.getInstance().getPaymentsManager().getPaymentsByPlayer(this.player).size() / (double) 45));
setPrevPage(5, 3, getPreviousPageItem());
setButton(5, 4, getRefreshButtonItem(), e -> draw());
setNextPage(5, 5, getNextPageItem());
setOnPage(e -> {
draw();
SoundManager.getInstance().playSound(this.auctionPlayer.getPlayer(), Settings.SOUNDS_NAVIGATE_GUI_PAGES.getString());
});
setButton(5, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_PAYMENT_COLLECTION_ITEM.getString(), Settings.GUI_PAYMENT_COLLECTION_NAME.getString(), Settings.GUI_PAYMENT_COLLECTION_LORE.getStringList(), null), 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();
}
for (AuctionPayment auctionPayment : data) {
auctionPayment.pay(e.player);
}
AuctionHouse.getInstance().getDataManager().deletePayments(data.stream().map(AuctionPayment::getId).collect(Collectors.toList()));
data.forEach(payment -> AuctionHouse.getInstance().getPaymentsManager().removePayment(payment.getId()));
e.manager.showGUI(e.player, new GUIPaymentCollection(this.auctionPlayer, this.lastClicked));
});
int slot = 0;
for (AuctionPayment auctionPayment : data) {
setButton(slot++, QuickItem
.of(Settings.GUI_PAYMENT_COLLECTION_PAYMENT_ITEM.getString())
.name(Settings.GUI_PAYMENT_COLLECTION_PAYMENT_NAME.getString().replace("%payment_amount%", AuctionAPI.getInstance().formatNumber(auctionPayment.getAmount())))
.lore(Settings.GUI_PAYMENT_COLLECTION_PAYMENT_LORE.getStringList())
.make(), 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();
}
}

View File

@ -665,6 +665,24 @@ public class Settings {
"&7Click here to claim all of your expired auctions"
));
/* ===============================
* PAYMENT COLLECTION GUI
* ===============================*/
public static final ConfigSetting GUI_PAYMENT_COLLECTION_TITLE = new ConfigSetting(config, "gui.payment collection.title", "&7Payment Collection");
public static final ConfigSetting GUI_PAYMENT_COLLECTION_ITEM = new ConfigSetting(config, "gui.payment collection.claim all.item", "ENDER_CHEST");
public static final ConfigSetting GUI_PAYMENT_COLLECTION_NAME = new ConfigSetting(config, "gui.payment collection.claim all.name", "&e&lClaim All");
public static final ConfigSetting GUI_PAYMENT_COLLECTION_LORE = new ConfigSetting(config, "gui.payment collection.claim all.lore", Collections.singletonList(
"&7Click here to claim all of your payments"
));
public static final ConfigSetting GUI_PAYMENT_COLLECTION_PAYMENT_ITEM = new ConfigSetting(config, "gui.payment collection.payment.item", "PAPER");
public static final ConfigSetting GUI_PAYMENT_COLLECTION_PAYMENT_NAME = new ConfigSetting(config, "gui.payment collection.payment.name", "&a&l$%payment_amount%");
public static final ConfigSetting GUI_PAYMENT_COLLECTION_PAYMENT_LORE = new ConfigSetting(config, "gui.payment collection.payment.lore", Collections.singletonList(
"&7Click here to claim this payment"
));
/* ===============================
* TRANSACTIONS TYPE GUI
* ===============================*/