diff --git a/pom.xml b/pom.xml index 5f36890..75e7733 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 ca.tweetzy auctionhouse - 2.18.3 + 2.18.4 UTF-8 diff --git a/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java index 0946faa..fa0a62c 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java @@ -187,7 +187,6 @@ public class AuctionHouse extends TweetyPlugin { this.auctionItemManager.saveItems(Settings.DATABASE_USE.getBoolean(), false); this.transactionManager.saveTransactions(Settings.DATABASE_USE.getBoolean(), false); this.filterManager.saveFilterWhitelist(Settings.DATABASE_USE.getBoolean(), false); - instance = null; } @Override diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java index 6cfee6b..84b288f 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java @@ -23,7 +23,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java index b1075b5..6afffb2 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java @@ -47,7 +47,7 @@ public class CommandUpload extends AbstractCommand { AuctionHouse.getInstance().getData().save(); AuctionHouse.getInstance().getDataManager().saveItems(new ArrayList<>(AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().values()), true); - AuctionHouse.getInstance().getDataManager().saveTransactions(AuctionHouse.getInstance().getTransactionManager().getTransactions(), true); + AuctionHouse.getInstance().getDataManager().saveTransactions(new ArrayList<>(AuctionHouse.getInstance().getTransactionManager().getTransactions().values()), true); AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&aLoaded file items/transactions and saved them to the database.")).sendPrefixedMessage(sender); return ReturnType.SUCCESS; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java index 7103224..d501438 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java @@ -49,7 +49,7 @@ public class DataManager extends DataManagerAbstract { statement.executeBatch(); })); } else { - this.sync(() -> this.databaseConnector.connect(connection -> { + this.databaseConnector.connect(connection -> { String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "items SET data = ?"; String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "items"; connection.prepareStatement(truncate).executeUpdate(); @@ -63,11 +63,11 @@ public class DataManager extends DataManagerAbstract { } }); statement.executeBatch(); - })); + }); } } - public void saveFilterWhitelist(List filterItems, boolean async){ + public void saveFilterWhitelist(List filterItems, boolean async) { if (async) { this.async(() -> this.databaseConnector.connect(connection -> { String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "filter_whitelist SET data = ?"; @@ -88,7 +88,7 @@ public class DataManager extends DataManagerAbstract { statement.executeBatch(); })); } else { - this.sync(() -> this.databaseConnector.connect(connection -> { + this.databaseConnector.connect(connection -> { String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "filter_whitelist SET data = ?"; String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "filter_whitelist"; try (PreparedStatement statement = connection.prepareStatement(truncate)) { @@ -105,7 +105,7 @@ public class DataManager extends DataManagerAbstract { } }); statement.executeBatch(); - })); + }); } } @@ -130,7 +130,7 @@ public class DataManager extends DataManagerAbstract { statement.executeBatch(); })); } else { - this.sync(() -> this.databaseConnector.connect(connection -> { + this.databaseConnector.connect(connection -> { String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "transactions SET data = ?"; String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "transactions"; try (PreparedStatement statement = connection.prepareStatement(truncate)) { @@ -147,7 +147,7 @@ public class DataManager extends DataManagerAbstract { } }); statement.executeBatch(); - })); + }); } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java index a30175e..8750601 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java @@ -309,8 +309,8 @@ public class GUIAuctionHouse extends Gui { drawFilterButton(); setButton(5, 6, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_LORE.getStringList(), new HashMap() {{ - put("%total_items_bought%", AuctionHouse.getInstance().getTransactionManager().getTransactions().stream().filter(transaction -> transaction.getBuyer().equals(auctionPlayer.getPlayer().getUniqueId())).count()); - put("%total_items_sold%", AuctionHouse.getInstance().getTransactionManager().getTransactions().stream().filter(transaction -> transaction.getSeller().equals(auctionPlayer.getPlayer().getUniqueId())).count()); + put("%total_items_bought%", AuctionHouse.getInstance().getTransactionManager().getTotalItemsBought(auctionPlayer.getPlayer().getUniqueId())); + put("%total_items_sold%", AuctionHouse.getInstance().getTransactionManager().getTotalItemsSold(auctionPlayer.getPlayer().getUniqueId())); }}), e -> e.manager.showGUI(e.player, new GUITransactionList(this.auctionPlayer))); setButton(5, 7, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_LORE.getStringList(), null), null); diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java index 638af28..0e45682 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java @@ -13,10 +13,7 @@ import ca.tweetzy.core.utils.TextUtils; import ca.tweetzy.core.utils.items.TItemBuilder; import org.bukkit.Bukkit; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** @@ -34,7 +31,7 @@ public class GUITransactionList extends Gui { public GUITransactionList(AuctionPlayer auctionPlayer) { this.auctionPlayer = auctionPlayer; - this.transactions = AuctionHouse.getInstance().getTransactionManager().getTransactions(); + this.transactions = new ArrayList<>(AuctionHouse.getInstance().getTransactionManager().getTransactions().values()); this.showOwnOnly = true; setTitle(TextUtils.formatText(Settings.GUI_TRANSACTIONS_TITLE.getString())); setRows(6); diff --git a/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionItemManager.java b/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionItemManager.java index bad7368..396af89 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionItemManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionItemManager.java @@ -7,7 +7,10 @@ import ca.tweetzy.core.utils.TextUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; diff --git a/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionPlayerManager.java b/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionPlayerManager.java index 9370192..ac457e7 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionPlayerManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionPlayerManager.java @@ -5,7 +5,8 @@ import ca.tweetzy.auctionhouse.settings.Settings; import lombok.Getter; import org.bukkit.inventory.ItemStack; -import java.util.*; +import java.util.HashMap; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; /** diff --git a/src/main/java/ca/tweetzy/auctionhouse/managers/TransactionManager.java b/src/main/java/ca/tweetzy/auctionhouse/managers/TransactionManager.java index b016040..1991936 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/managers/TransactionManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/managers/TransactionManager.java @@ -7,7 +7,11 @@ import ca.tweetzy.core.utils.TextUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; /** @@ -18,24 +22,32 @@ import java.util.stream.Collectors; */ public class TransactionManager { - private final ArrayList transactions = new ArrayList<>(); + private final ConcurrentHashMap transactions = new ConcurrentHashMap<>(); private final HashMap prePurchaseHolding = new HashMap<>(); public void addTransaction(Transaction transaction) { if (transaction == null) return; - this.transactions.add(transaction); + this.transactions.put(transaction.getId(), transaction); } public void removeTransaction(UUID uuid) { - this.transactions.removeIf(item -> item.getId().equals(uuid)); + this.transactions.remove(uuid); } public Transaction getTransaction(UUID uuid) { - return this.transactions.stream().filter(item -> item.getId().equals(uuid)).findFirst().orElse(null); + return this.transactions.getOrDefault(uuid, null); } - public List getTransactions() { - return Collections.unmodifiableList(this.transactions); + public ConcurrentHashMap getTransactions() { + return this.transactions; + } + + public int getTotalItemsBought(UUID buyer) { + return (int) this.transactions.entrySet().stream().filter(set -> set.getValue().getBuyer().equals(buyer)).count(); + } + + public int getTotalItemsSold(UUID seller) { + return (int) this.transactions.entrySet().stream().filter(set -> set.getValue().getSeller().equals(seller)).count(); } public void addPrePurchase(Player player, UUID uuid) { @@ -69,9 +81,9 @@ public class TransactionManager { public void saveTransactions(boolean useDatabase, boolean async) { if (useDatabase) { - AuctionHouse.getInstance().getDataManager().saveTransactions(getTransactions(), async); + AuctionHouse.getInstance().getDataManager().saveTransactions(new ArrayList<>(getTransactions().values()), async); } else { - AuctionHouse.getInstance().getData().set("transactions", this.transactions.stream().map(AuctionAPI.getInstance()::convertToBase64).collect(Collectors.toList())); + AuctionHouse.getInstance().getData().set("transactions", this.transactions.values().stream().map(AuctionAPI.getInstance()::convertToBase64).collect(Collectors.toList())); AuctionHouse.getInstance().getData().save(); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 2f17388..de55a02 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,7 +5,7 @@ main: ca.tweetzy.auctionhouse.AuctionHouse description: Auction House is a premium auction solution for your server. website: https://tweetzy.ca/ authors: [Kiran Hart] -depend: [Vault] +softdepend: [Vault, PlayerPoints] commands: auctionhouse: