2.18.4 fixed stuff

This commit is contained in:
Kiran Hart 2021-07-07 15:20:53 -04:00
parent d12b1ece28
commit 2623277ef4
11 changed files with 41 additions and 30 deletions

View File

@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>ca.tweetzy</groupId> <groupId>ca.tweetzy</groupId>
<artifactId>auctionhouse</artifactId> <artifactId>auctionhouse</artifactId>
<version>2.18.3</version> <version>2.18.4</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -187,7 +187,6 @@ public class AuctionHouse extends TweetyPlugin {
this.auctionItemManager.saveItems(Settings.DATABASE_USE.getBoolean(), false); this.auctionItemManager.saveItems(Settings.DATABASE_USE.getBoolean(), false);
this.transactionManager.saveTransactions(Settings.DATABASE_USE.getBoolean(), false); this.transactionManager.saveTransactions(Settings.DATABASE_USE.getBoolean(), false);
this.filterManager.saveFilterWhitelist(Settings.DATABASE_USE.getBoolean(), false); this.filterManager.saveFilterWhitelist(Settings.DATABASE_USE.getBoolean(), false);
instance = null;
} }
@Override @Override

View File

@ -23,7 +23,6 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -47,7 +47,7 @@ public class CommandUpload extends AbstractCommand {
AuctionHouse.getInstance().getData().save(); AuctionHouse.getInstance().getData().save();
AuctionHouse.getInstance().getDataManager().saveItems(new ArrayList<>(AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().values()), true); 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); AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&aLoaded file items/transactions and saved them to the database.")).sendPrefixedMessage(sender);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;

View File

@ -49,7 +49,7 @@ public class DataManager extends DataManagerAbstract {
statement.executeBatch(); statement.executeBatch();
})); }));
} else { } else {
this.sync(() -> this.databaseConnector.connect(connection -> { this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "items SET data = ?"; String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "items SET data = ?";
String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "items"; String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "items";
connection.prepareStatement(truncate).executeUpdate(); connection.prepareStatement(truncate).executeUpdate();
@ -63,11 +63,11 @@ public class DataManager extends DataManagerAbstract {
} }
}); });
statement.executeBatch(); statement.executeBatch();
})); });
} }
} }
public void saveFilterWhitelist(List<AuctionFilterItem> filterItems, boolean async){ public void saveFilterWhitelist(List<AuctionFilterItem> filterItems, boolean async) {
if (async) { if (async) {
this.async(() -> this.databaseConnector.connect(connection -> { this.async(() -> this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "filter_whitelist SET data = ?"; String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "filter_whitelist SET data = ?";
@ -88,7 +88,7 @@ public class DataManager extends DataManagerAbstract {
statement.executeBatch(); statement.executeBatch();
})); }));
} else { } else {
this.sync(() -> this.databaseConnector.connect(connection -> { this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "filter_whitelist SET data = ?"; String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "filter_whitelist SET data = ?";
String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "filter_whitelist"; String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "filter_whitelist";
try (PreparedStatement statement = connection.prepareStatement(truncate)) { try (PreparedStatement statement = connection.prepareStatement(truncate)) {
@ -105,7 +105,7 @@ public class DataManager extends DataManagerAbstract {
} }
}); });
statement.executeBatch(); statement.executeBatch();
})); });
} }
} }
@ -130,7 +130,7 @@ public class DataManager extends DataManagerAbstract {
statement.executeBatch(); statement.executeBatch();
})); }));
} else { } else {
this.sync(() -> this.databaseConnector.connect(connection -> { this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "transactions SET data = ?"; String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "transactions SET data = ?";
String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "transactions"; String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "transactions";
try (PreparedStatement statement = connection.prepareStatement(truncate)) { try (PreparedStatement statement = connection.prepareStatement(truncate)) {
@ -147,7 +147,7 @@ public class DataManager extends DataManagerAbstract {
} }
}); });
statement.executeBatch(); statement.executeBatch();
})); });
} }
} }

View File

@ -309,8 +309,8 @@ public class GUIAuctionHouse extends Gui {
drawFilterButton(); 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<String, Object>() {{ 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<String, Object>() {{
put("%total_items_bought%", AuctionHouse.getInstance().getTransactionManager().getTransactions().stream().filter(transaction -> transaction.getBuyer().equals(auctionPlayer.getPlayer().getUniqueId())).count()); put("%total_items_bought%", AuctionHouse.getInstance().getTransactionManager().getTotalItemsBought(auctionPlayer.getPlayer().getUniqueId()));
put("%total_items_sold%", AuctionHouse.getInstance().getTransactionManager().getTransactions().stream().filter(transaction -> transaction.getSeller().equals(auctionPlayer.getPlayer().getUniqueId())).count()); put("%total_items_sold%", AuctionHouse.getInstance().getTransactionManager().getTotalItemsSold(auctionPlayer.getPlayer().getUniqueId()));
}}), e -> e.manager.showGUI(e.player, new GUITransactionList(this.auctionPlayer))); }}), 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); 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);

View File

@ -13,10 +13,7 @@ import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.core.utils.items.TItemBuilder; import ca.tweetzy.core.utils.items.TItemBuilder;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.util.Comparator; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -34,7 +31,7 @@ public class GUITransactionList extends Gui {
public GUITransactionList(AuctionPlayer auctionPlayer) { public GUITransactionList(AuctionPlayer auctionPlayer) {
this.auctionPlayer = auctionPlayer; this.auctionPlayer = auctionPlayer;
this.transactions = AuctionHouse.getInstance().getTransactionManager().getTransactions(); this.transactions = new ArrayList<>(AuctionHouse.getInstance().getTransactionManager().getTransactions().values());
this.showOwnOnly = true; this.showOwnOnly = true;
setTitle(TextUtils.formatText(Settings.GUI_TRANSACTIONS_TITLE.getString())); setTitle(TextUtils.formatText(Settings.GUI_TRANSACTIONS_TITLE.getString()));
setRows(6); setRows(6);

View File

@ -7,7 +7,10 @@ import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; 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.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -5,7 +5,8 @@ import ca.tweetzy.auctionhouse.settings.Settings;
import lombok.Getter; import lombok.Getter;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.*; import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**

View File

@ -7,7 +7,11 @@ import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; 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; import java.util.stream.Collectors;
/** /**
@ -18,24 +22,32 @@ import java.util.stream.Collectors;
*/ */
public class TransactionManager { public class TransactionManager {
private final ArrayList<Transaction> transactions = new ArrayList<>(); private final ConcurrentHashMap<UUID, Transaction> transactions = new ConcurrentHashMap<>();
private final HashMap<Player, UUID> prePurchaseHolding = new HashMap<>(); private final HashMap<Player, UUID> prePurchaseHolding = new HashMap<>();
public void addTransaction(Transaction transaction) { public void addTransaction(Transaction transaction) {
if (transaction == null) return; if (transaction == null) return;
this.transactions.add(transaction); this.transactions.put(transaction.getId(), transaction);
} }
public void removeTransaction(UUID uuid) { public void removeTransaction(UUID uuid) {
this.transactions.removeIf(item -> item.getId().equals(uuid)); this.transactions.remove(uuid);
} }
public Transaction getTransaction(UUID 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<Transaction> getTransactions() { public ConcurrentHashMap<UUID, Transaction> getTransactions() {
return Collections.unmodifiableList(this.transactions); 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) { public void addPrePurchase(Player player, UUID uuid) {
@ -69,9 +81,9 @@ public class TransactionManager {
public void saveTransactions(boolean useDatabase, boolean async) { public void saveTransactions(boolean useDatabase, boolean async) {
if (useDatabase) { if (useDatabase) {
AuctionHouse.getInstance().getDataManager().saveTransactions(getTransactions(), async); AuctionHouse.getInstance().getDataManager().saveTransactions(new ArrayList<>(getTransactions().values()), async);
} else { } 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(); AuctionHouse.getInstance().getData().save();
} }
} }

View File

@ -5,7 +5,7 @@ main: ca.tweetzy.auctionhouse.AuctionHouse
description: Auction House is a premium auction solution for your server. description: Auction House is a premium auction solution for your server.
website: https://tweetzy.ca/ website: https://tweetzy.ca/
authors: [Kiran Hart] authors: [Kiran Hart]
depend: [Vault] softdepend: [Vault, PlayerPoints]
commands: commands:
auctionhouse: auctionhouse: