mirror of
https://github.com/kiranhart/Auction-House.git
synced 2025-01-23 15:21:20 +01:00
transaction recording, number formatting fix, confirming the purchase in the confirm gui, now opens the main auction menu.
This commit is contained in:
parent
c345178dd0
commit
ad2d51b6f0
@ -7,6 +7,7 @@ import ca.tweetzy.auctionhouse.listeners.AuctionListeners;
|
||||
import ca.tweetzy.auctionhouse.listeners.PlayerListeners;
|
||||
import ca.tweetzy.auctionhouse.managers.AuctionItemManager;
|
||||
import ca.tweetzy.auctionhouse.managers.AuctionPlayerManager;
|
||||
import ca.tweetzy.auctionhouse.managers.TransactionManager;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.auctionhouse.tasks.TickAuctionsTask;
|
||||
import ca.tweetzy.core.TweetyCore;
|
||||
@ -43,6 +44,7 @@ public class AuctionHouse extends TweetyPlugin {
|
||||
private CommandManager commandManager;
|
||||
private AuctionPlayerManager auctionPlayerManager;
|
||||
private AuctionItemManager auctionItemManager;
|
||||
private TransactionManager transactionManager;
|
||||
|
||||
private UpdateChecker.UpdateStatus status;
|
||||
|
||||
@ -88,6 +90,10 @@ public class AuctionHouse extends TweetyPlugin {
|
||||
this.auctionItemManager = new AuctionItemManager();
|
||||
this.auctionItemManager.loadItems();
|
||||
|
||||
// load transactions
|
||||
this.transactionManager = new TransactionManager();
|
||||
this.transactionManager.loadTransactions();
|
||||
|
||||
// gui manager
|
||||
this.guiManager.init();
|
||||
|
||||
@ -115,6 +121,7 @@ public class AuctionHouse extends TweetyPlugin {
|
||||
@Override
|
||||
public void onPluginDisable() {
|
||||
this.auctionItemManager.saveItems();
|
||||
this.transactionManager.saveTransactions();
|
||||
instance = null;
|
||||
}
|
||||
|
||||
@ -155,6 +162,10 @@ public class AuctionHouse extends TweetyPlugin {
|
||||
return auctionPlayerManager;
|
||||
}
|
||||
|
||||
public TransactionManager getTransactionManager() {
|
||||
return transactionManager;
|
||||
}
|
||||
|
||||
public GuiManager getGuiManager() {
|
||||
return guiManager;
|
||||
}
|
||||
|
@ -81,12 +81,12 @@ public class CommandSell extends AbstractCommand {
|
||||
double basePrice = Double.parseDouble(args[0]);
|
||||
|
||||
if (basePrice < Settings.MIN_AUCTION_PRICE.getDouble()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.minbaseprice").processPlaceholder("price", args[0]).sendPrefixedMessage(player);
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.minbaseprice").processPlaceholder("price", Settings.MIN_AUCTION_PRICE.getDouble()).sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (basePrice > Settings.MAX_AUCTION_PRICE.getDouble()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.maxbaseprice").processPlaceholder("price", args[0]).sendPrefixedMessage(player);
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.maxbaseprice").processPlaceholder("price", Settings.MAX_AUCTION_PRICE.getDouble()).sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ public class CommandSell extends AbstractCommand {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.listed.nobid")
|
||||
.processPlaceholder("amount", itemToSell.getAmount())
|
||||
.processPlaceholder("item", WordUtils.capitalizeFully(itemToSell.getType().name().replace("_", " ")))
|
||||
.processPlaceholder("base_price", basePrice)
|
||||
.processPlaceholder("base_price", String.format("%,.2f", basePrice))
|
||||
.sendPrefixedMessage(player);
|
||||
|
||||
PlayerUtils.takeActiveItem(player, CompatibleHand.MAIN_HAND, itemToSell.getAmount());
|
||||
@ -143,33 +143,33 @@ public class CommandSell extends AbstractCommand {
|
||||
|
||||
// check min
|
||||
if (basePrice < Settings.MIN_AUCTION_PRICE.getDouble()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.minbaseprice").processPlaceholder("price", args[0]).sendPrefixedMessage(player);
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.minbaseprice").processPlaceholder("price", Settings.MIN_AUCTION_PRICE.getDouble()).sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (bidStartPrice < Settings.MIN_AUCTION_START_PRICE.getDouble()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.minstartingprice").processPlaceholder("price", args[1]).sendPrefixedMessage(player);
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.minstartingprice").processPlaceholder("price", Settings.MIN_AUCTION_START_PRICE.getDouble()).sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (bidIncPrice < Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.minbidincrementprice").processPlaceholder("price", args[2]).sendPrefixedMessage(player);
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.minbidincrementprice").processPlaceholder("price", Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble()).sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
// check max
|
||||
if (basePrice > Settings.MAX_AUCTION_PRICE.getDouble()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.maxbaseprice").processPlaceholder("price", args[0]).sendPrefixedMessage(player);
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.maxbaseprice").processPlaceholder("price", Settings.MAX_AUCTION_PRICE.getDouble()).sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (bidStartPrice > Settings.MAX_AUCTION_START_PRICE.getDouble()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.maxstartingprice").processPlaceholder("price", args[1]).sendPrefixedMessage(player);
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.maxstartingprice").processPlaceholder("price", Settings.MAX_AUCTION_START_PRICE.getDouble()).sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (bidIncPrice > Settings.MAX_AUCTION_INCREMENT_PRICE.getDouble()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.maxbidincrementprice").processPlaceholder("price", args[2]).sendPrefixedMessage(player);
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.maxbidincrementprice").processPlaceholder("price", Settings.MAX_AUCTION_INCREMENT_PRICE.getDouble()).sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@ -196,9 +196,9 @@ public class CommandSell extends AbstractCommand {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.listed.withbid")
|
||||
.processPlaceholder("amount", itemToSell.getAmount())
|
||||
.processPlaceholder("item", WordUtils.capitalizeFully(itemToSell.getType().name().replace("_", " ")))
|
||||
.processPlaceholder("base_price", basePrice)
|
||||
.processPlaceholder("start_price", bidStartPrice)
|
||||
.processPlaceholder("increment_price", bidIncPrice)
|
||||
.processPlaceholder("base_price", String.format("%,.2f", basePrice))
|
||||
.processPlaceholder("start_price", String.format("%,.2f", bidStartPrice))
|
||||
.processPlaceholder("increment_price", String.format("%,.2f", bidIncPrice))
|
||||
.sendPrefixedMessage(player);
|
||||
|
||||
PlayerUtils.takeActiveItem(player, CompatibleHand.MAIN_HAND, itemToSell.getAmount());
|
||||
|
@ -60,24 +60,29 @@ public class GUIConfirmPurchase extends Gui {
|
||||
return;
|
||||
}
|
||||
|
||||
AuctionEndEvent auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(this.auctionItem.getOwner()), e.player, this.auctionItem, AuctionSaleType.WITHOUT_BIDDING_SYSTEM);
|
||||
Bukkit.getServer().getPluginManager().callEvent(auctionEndEvent);
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> {
|
||||
AuctionEndEvent auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(this.auctionItem.getOwner()), e.player, this.auctionItem, AuctionSaleType.WITHOUT_BIDDING_SYSTEM);
|
||||
Bukkit.getServer().getPluginManager().callEvent(auctionEndEvent);
|
||||
|
||||
if (auctionEndEvent.isCancelled()) return;
|
||||
if (auctionEndEvent.isCancelled()) return;
|
||||
|
||||
AuctionHouse.getInstance().getEconomy().withdrawPlayer(e.player, located.getBasePrice());
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(located.getKey());
|
||||
PlayerUtils.giveItem(e.player, AuctionAPI.getInstance().deserializeItem(located.getRawItem()));
|
||||
AuctionHouse.getInstance().getEconomy().withdrawPlayer(e.player, located.getBasePrice());
|
||||
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(this.auctionItem.getOwner()), located.getBasePrice());
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(located.getKey());
|
||||
PlayerUtils.giveItem(e.player, AuctionAPI.getInstance().deserializeItem(located.getRawItem()));
|
||||
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", String.format("%,.2f", located.getCurrentPrice())).sendPrefixedMessage(e.player);
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", String.format("%,.2f", located.getCurrentPrice())).sendPrefixedMessage(e.player);
|
||||
|
||||
if (Bukkit.getOfflinePlayer(located.getOwner()).isOnline()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
|
||||
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(located.getRawItem()).getType().name().replace("_", " ")))
|
||||
.processPlaceholder("price", String.format("%,.2f", located.getCurrentPrice()))
|
||||
.sendPrefixedMessage(Bukkit.getOfflinePlayer(located.getOwner()).getPlayer());
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", String.format("%,.2f", located.getCurrentPrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(located.getOwner()).getPlayer());
|
||||
}
|
||||
if (Bukkit.getOfflinePlayer(located.getOwner()).isOnline()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
|
||||
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(located.getRawItem()).getType().name().replace("_", " ")))
|
||||
.processPlaceholder("price", String.format("%,.2f", located.getCurrentPrice()))
|
||||
.sendPrefixedMessage(Bukkit.getOfflinePlayer(located.getOwner()).getPlayer());
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", String.format("%,.2f", located.getCurrentPrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(located.getOwner()).getPlayer());
|
||||
}
|
||||
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
}, 1L);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,13 @@ import ca.tweetzy.auctionhouse.api.events.AuctionEndEvent;
|
||||
import ca.tweetzy.auctionhouse.api.events.AuctionStartEvent;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionSaleType;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.auctionhouse.transaction.Transaction;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: February 27 2021
|
||||
@ -28,7 +31,19 @@ public class AuctionListeners implements Listener {
|
||||
@EventHandler
|
||||
public void onAuctionEnd(AuctionEndEvent e) {
|
||||
if (Settings.DISCORD_ENABLED.getBoolean() && Settings.DISCORD_ALERT_ON_AUCTION_FINISH.getBoolean()) {
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> AuctionAPI.getInstance().sendDiscordMessage(hook, e.getOriginalOwner(), e.getBuyer(), e.getAuctionItem(), e.getSaleType(), false, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM)), 1L);
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> {
|
||||
if (Settings.RECORD_TRANSACTIONS.getBoolean()) {
|
||||
AuctionHouse.getInstance().getTransactionManager().addTransaction(new Transaction(
|
||||
UUID.randomUUID(),
|
||||
e.getOriginalOwner().getUniqueId(),
|
||||
e.getBuyer().getUniqueId(),
|
||||
System.currentTimeMillis(),
|
||||
e.getAuctionItem(),
|
||||
e.getSaleType()
|
||||
));
|
||||
}
|
||||
Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> AuctionAPI.getInstance().sendDiscordMessage(hook, e.getOriginalOwner(), e.getBuyer(), e.getAuctionItem(), e.getSaleType(), false, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM));
|
||||
}, 1L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,10 +53,9 @@ public class AuctionItemManager {
|
||||
public void loadItems() {
|
||||
if (AuctionHouse.getInstance().getData().contains("auction items") && AuctionHouse.getInstance().getData().isList("auction items")) {
|
||||
List<AuctionItem> items = AuctionHouse.getInstance().getData().getStringList("auction items").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (AuctionItem) object).collect(Collectors.toList());
|
||||
items.forEach(item -> {
|
||||
this.addItem(item);
|
||||
Bukkit.getConsoleSender().sendMessage(TextUtils.formatText(String.format("&aLoaded Item&f: &e%s &f(&a$%s&f) (&a$%.2f&f) (&a$%.2f&f) (&a$%.2f&f)", item.getKey().toString(), item.getBasePrice(), item.getBidStartPrice(), item.getBidIncPrice(), item.getCurrentPrice())));
|
||||
});
|
||||
long start = System.currentTimeMillis();
|
||||
items.forEach(this::addItem);
|
||||
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText(String.format("&aLoaded &2%d &aauction items(s) in &e%d&fms", items.size(), System.currentTimeMillis() - start))).sendPrefixedMessage(Bukkit.getConsoleSender());
|
||||
AuctionHouse.getInstance().getData().set("auction items", null);
|
||||
AuctionHouse.getInstance().getData().save();
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
package ca.tweetzy.auctionhouse.managers;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.auctionhouse.api.AuctionAPI;
|
||||
import ca.tweetzy.auctionhouse.transaction.Transaction;
|
||||
import ca.tweetzy.core.utils.TextUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: March 22 2021
|
||||
* Time Created: 3:34 p.m.
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
|
||||
*/
|
||||
public class TransactionManager {
|
||||
|
||||
private final ArrayList<Transaction> transactions = new ArrayList<>();
|
||||
|
||||
public void addTransaction(Transaction transaction) {
|
||||
if (transaction == null) return;
|
||||
this.transactions.add(transaction);
|
||||
}
|
||||
|
||||
public void removeTransaction(UUID uuid) {
|
||||
this.transactions.removeIf(item -> item.getId().equals(uuid));
|
||||
}
|
||||
|
||||
public Transaction getTransaction(UUID uuid) {
|
||||
return this.transactions.stream().filter(item -> item.getId().equals(uuid)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public List<Transaction> getTransactions() {
|
||||
return Collections.unmodifiableList(this.transactions);
|
||||
}
|
||||
|
||||
public void loadTransactions() {
|
||||
if (AuctionHouse.getInstance().getData().contains("transactions") && AuctionHouse.getInstance().getData().isList("transactions")) {
|
||||
List<Transaction> transactions = AuctionHouse.getInstance().getData().getStringList("transactions").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (Transaction) object).collect(Collectors.toList());
|
||||
long start = System.currentTimeMillis();
|
||||
transactions.forEach(this::addTransaction);
|
||||
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText(String.format("&aLoaded &2%d &atransaction(s) in &e%d&fms", transactions.size(), System.currentTimeMillis() - start))).sendPrefixedMessage(Bukkit.getConsoleSender());
|
||||
}
|
||||
}
|
||||
|
||||
public void saveTransactions() {
|
||||
AuctionHouse.getInstance().getData().set("transactions", this.transactions.stream().map(AuctionAPI.getInstance()::convertToBase64).collect(Collectors.toList()));
|
||||
AuctionHouse.getInstance().getData().save();
|
||||
}
|
||||
}
|
@ -37,6 +37,7 @@ public class Settings {
|
||||
public static final ConfigSetting TIME_TO_INCREASE_BY_ON_BID = new ConfigSetting(config, "auction setting.time to increase by on the bid", 20, "How many seconds should be added to the remaining time?");
|
||||
public static final ConfigSetting TICK_UPDATE_TIME = new ConfigSetting(config, "auction setting.tick auctions every", 1, "How many seconds should pass before the plugin updates all the times on items?");
|
||||
public static final ConfigSetting REFRESH_GUI_WHEN_BID = new ConfigSetting(config, "auction setting.refresh gui when bid", true, "Should the auction gui be re-opened (not redrawn) when a user places a bid, so they get the latest items?");
|
||||
public static final ConfigSetting RECORD_TRANSACTIONS = new ConfigSetting(config, "auction setting.record transactions", true, "Should every transaction be recorded (everything an auction is won or an item is bought)");
|
||||
|
||||
/* ===============================
|
||||
* DISCORD WEBHOOK
|
||||
|
@ -2,6 +2,8 @@ package ca.tweetzy.auctionhouse.transaction;
|
||||
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionItem;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionSaleType;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
@ -12,6 +14,9 @@ import java.util.UUID;
|
||||
* Time Created: 12:53 a.m.
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Transaction implements Serializable {
|
||||
|
||||
private final UUID id;
|
||||
|
Loading…
Reference in New Issue
Block a user