mirror of
https://github.com/kiranhart/Auction-House.git
synced 2024-11-21 05:15:11 +01:00
✨ added new serialize version and itemstack columns to tables that require storing items, use nbtapi to serialize items from now on.
Took 59 minutes
This commit is contained in:
parent
a993ba5d97
commit
e0ef86ac0f
@ -22,6 +22,7 @@ import ca.tweetzy.auctionhouse.auction.AuctionedItem;
|
||||
import ca.tweetzy.auctionhouse.commands.*;
|
||||
import ca.tweetzy.auctionhouse.database.DataManager;
|
||||
import ca.tweetzy.auctionhouse.database.migrations.*;
|
||||
import ca.tweetzy.auctionhouse.database.migrations.v2.*;
|
||||
import ca.tweetzy.auctionhouse.helpers.UpdateChecker;
|
||||
import ca.tweetzy.auctionhouse.hooks.PlaceholderAPIHook;
|
||||
import ca.tweetzy.auctionhouse.listeners.*;
|
||||
@ -182,7 +183,9 @@ public class AuctionHouse extends TweetyPlugin {
|
||||
new _19_ServerAuctionMigration(),
|
||||
new _20_AuctionRequestsMigration(),
|
||||
new _21_RequestsDynAmtMigration(),
|
||||
new _22_BansV2Migration()
|
||||
new _22_BansV2Migration(),
|
||||
new _23_ItemToNBTSerializationMigration(),
|
||||
new _24_RemainingItemToNBTSerializationMigration()
|
||||
);
|
||||
|
||||
dataMigrationManager.runMigrations();
|
||||
|
@ -233,6 +233,16 @@ public class AuctionAPI {
|
||||
return config.getItemStack("i", null);
|
||||
}
|
||||
|
||||
public static ItemStack decodeItemTransaction(String string) {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
try {
|
||||
config.loadFromString(string);
|
||||
} catch (IllegalArgumentException | InvalidConfigurationException e) {
|
||||
return null;
|
||||
}
|
||||
return config.getItemStack("i", null);
|
||||
}
|
||||
|
||||
public static boolean tellMigrationStatus(CommandSender commandSender) {
|
||||
if (AuctionHouse.getInstance().isMigrating()) {
|
||||
AuctionHouse.getInstance().getLocale().newMessage("&cAuction House is currently migrating auction items, auction usage is disabled until it's finished").sendPrefixedMessage(commandSender);
|
||||
|
@ -28,9 +28,16 @@ import ca.tweetzy.auctionhouse.impl.AuctionBan;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.auctionhouse.transaction.Transaction;
|
||||
import ca.tweetzy.auctionhouse.transaction.TransactionViewFilter;
|
||||
import ca.tweetzy.flight.comp.enums.CompMaterial;
|
||||
import ca.tweetzy.flight.database.*;
|
||||
import ca.tweetzy.flight.nbtapi.NBT;
|
||||
import ca.tweetzy.flight.nbtapi.NbtApiException;
|
||||
import ca.tweetzy.flight.utils.Common;
|
||||
import ca.tweetzy.flight.utils.QuickItem;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -158,6 +165,10 @@ public class DataManager extends DataManagerAbstract {
|
||||
);
|
||||
}
|
||||
|
||||
//=================================================================================================//
|
||||
// WHITE LIST //
|
||||
//=================================================================================================//
|
||||
|
||||
public void saveFilterWhitelist(List<AuctionFilterItem> filterItems, boolean async) {
|
||||
String saveItems = "INSERT INTO " + this.getTablePrefix() + "filter_whitelist(data) VALUES(?)";
|
||||
String truncate = AuctionHouse.getDatabaseConnector() instanceof MySQLConnector ? "TRUNCATE TABLE " + this.getTablePrefix() + "filter_whitelist" : "DELETE FROM " + this.getTablePrefix() + "filter_whitelist";
|
||||
@ -214,6 +225,81 @@ public class DataManager extends DataManagerAbstract {
|
||||
}));
|
||||
}
|
||||
|
||||
//=================================================================================================//
|
||||
// AUCTION LISTINGS //
|
||||
//=================================================================================================//
|
||||
public void updateItemsAsync(Collection<AuctionedItem> items, UpdateCallback callback) {
|
||||
this.runAsync(() -> updateItems(items, callback));
|
||||
}
|
||||
|
||||
public void updateItems(Collection<AuctionedItem> items, UpdateCallback callback) {
|
||||
this.databaseConnector.connect(connection -> {
|
||||
connection.setAutoCommit(false);
|
||||
SQLException err = null;
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "auctions SET owner = ?, owner_name = ?, highest_bidder = ?, highest_bidder_name = ?, base_price = ?, bid_start_price = ?, bid_increment_price = ?, current_price = ?, expires_at = ?, expired = ?, item = ?, serialize_version = ?, itemstack = ? WHERE id = ?");
|
||||
for (AuctionedItem item : items) {
|
||||
try {
|
||||
statement.setString(1, item.getOwner().toString());
|
||||
statement.setString(2, item.getOwnerName());
|
||||
statement.setString(3, item.getHighestBidder().toString());
|
||||
statement.setString(4, item.getHighestBidderName());
|
||||
statement.setDouble(5, item.getBasePrice());
|
||||
statement.setDouble(6, item.getBidStartingPrice());
|
||||
statement.setDouble(7, item.getBidIncrementPrice());
|
||||
statement.setDouble(8, item.getCurrentPrice());
|
||||
statement.setLong(9, item.getExpiresAt());
|
||||
statement.setBoolean(10, item.isExpired());
|
||||
statement.setString(11, AuctionAPI.encodeItem(item.getItem()));
|
||||
|
||||
try {
|
||||
statement.setInt(12, 1);
|
||||
statement.setString(13, QuickItem.toString(item.getItem()));
|
||||
|
||||
} catch (NbtApiException e){
|
||||
statement.setInt(12, 0);
|
||||
statement.setString(13, null);
|
||||
}
|
||||
|
||||
statement.setString(14, item.getId().toString());
|
||||
statement.addBatch();
|
||||
} catch (SQLException e) {
|
||||
err = e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
statement.executeBatch();
|
||||
|
||||
if (err == null) {
|
||||
connection.commit();
|
||||
resolveUpdateCallback(callback, null);
|
||||
} else {
|
||||
connection.rollback();
|
||||
resolveUpdateCallback(callback, err);
|
||||
}
|
||||
|
||||
connection.setAutoCommit(true);
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteItems(Collection<UUID> items) {
|
||||
this.databaseConnector.connect(connection -> {
|
||||
connection.setAutoCommit(false);
|
||||
PreparedStatement statement = connection.prepareStatement("DELETE FROM " + this.getTablePrefix() + "auctions WHERE id = ?");
|
||||
for (UUID id : items) {
|
||||
statement.setString(1, id.toString());
|
||||
statement.addBatch();
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
connection.setAutoCommit(true);
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteItemsAsync(Collection<UUID> items) {
|
||||
this.runAsync(() -> deleteItems(items));
|
||||
}
|
||||
|
||||
public void getItems(Callback<ArrayList<AuctionedItem>> callback) {
|
||||
ArrayList<AuctionedItem> items = new ArrayList<>();
|
||||
this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
@ -222,12 +308,24 @@ public class DataManager extends DataManagerAbstract {
|
||||
final List<UUID> toRemove = new ArrayList<>();
|
||||
|
||||
while (resultSet.next()) {
|
||||
AuctionedItem item = extractAuctionedItem(resultSet);
|
||||
|
||||
if (item == null || item.getItem().getType() == CompMaterial.AIR.parseMaterial()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resultSet.getInt("serialize_version") == 0) {
|
||||
try (PreparedStatement updateStatement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "auctions SET serialize_version = 1, itemstack = ? WHERE id = ?")) {
|
||||
updateStatement.setString(1, QuickItem.toString(item.getItem()));
|
||||
updateStatement.setString(2, resultSet.getString("id"));
|
||||
updateStatement.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
if (resultSet.getBoolean("expired") && Settings.EXPIRATION_TIME_LIMIT_ENABLED.getBoolean() && Instant.ofEpochMilli(resultSet.getLong("expires_at")).isBefore(Instant.now().minus(Duration.ofHours(Settings.EXPIRATION_TIME_LIMIT.getInt())))) {
|
||||
toRemove.add(UUID.fromString(resultSet.getString("id")));
|
||||
} else {
|
||||
final AuctionedItem item = extractAuctionedItem(resultSet);
|
||||
if (item != null)
|
||||
items.add(item);
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,95 +337,9 @@ public class DataManager extends DataManagerAbstract {
|
||||
}));
|
||||
}
|
||||
|
||||
public void getAdminLogs(Callback<ArrayList<AuctionAdminLog>> callback) {
|
||||
ArrayList<AuctionAdminLog> logs = new ArrayList<>();
|
||||
this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "admin_logs")) {
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
logs.add(extractAdminLog(resultSet));
|
||||
}
|
||||
|
||||
callback.accept(null, logs);
|
||||
} catch (Exception e) {
|
||||
resolveCallback(callback, e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void getTransactions(Callback<ArrayList<Transaction>> callback) {
|
||||
ArrayList<Transaction> transactions = new ArrayList<>();
|
||||
this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "transactions")) {
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
final Transaction transaction = extractTransaction(resultSet);
|
||||
if (transaction != null)
|
||||
transactions.add(transaction);
|
||||
}
|
||||
|
||||
callback.accept(null, transactions);
|
||||
} catch (Exception e) {
|
||||
resolveCallback(callback, e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void insertTransaction(Transaction transaction, Callback<Transaction> callback) {
|
||||
this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + getTablePrefix() + "transactions (id, seller, seller_name, buyer, buyer_name, transaction_time, item, auction_sale_type, final_price) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
|
||||
PreparedStatement fetch = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "transactions WHERE id = ?");
|
||||
|
||||
fetch.setString(1, transaction.getId().toString());
|
||||
statement.setString(1, transaction.getId().toString());
|
||||
statement.setString(2, transaction.getSeller().toString());
|
||||
statement.setString(3, transaction.getSellerName());
|
||||
statement.setString(4, transaction.getBuyer().toString());
|
||||
statement.setString(5, transaction.getBuyerName());
|
||||
statement.setLong(6, transaction.getTransactionTime());
|
||||
statement.setString(7, AuctionAPI.encodeItem(transaction.getItem()));
|
||||
statement.setString(8, transaction.getAuctionSaleType().name());
|
||||
statement.setDouble(9, transaction.getFinalPrice());
|
||||
statement.executeUpdate();
|
||||
|
||||
if (callback != null) {
|
||||
ResultSet res = fetch.executeQuery();
|
||||
res.next();
|
||||
|
||||
final Transaction inserted = extractTransaction(res);
|
||||
if (inserted != null)
|
||||
callback.accept(null, inserted);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
resolveCallback(callback, e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void insertLog(AuctionAdminLog adminLog) {
|
||||
this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "admin_logs(admin, admin_name, target, target_name, item, item_id, action, time) VALUES(?, ?, ?, ?, ?, ?, ?, ?)")) {
|
||||
|
||||
statement.setString(1, adminLog.getAdmin().toString());
|
||||
statement.setString(2, adminLog.getAdminName());
|
||||
statement.setString(3, adminLog.getTarget().toString());
|
||||
statement.setString(4, adminLog.getTargetName());
|
||||
statement.setString(5, AuctionAPI.encodeItem(adminLog.getItem()));
|
||||
statement.setString(6, adminLog.getItemId().toString());
|
||||
statement.setString(7, adminLog.getAdminAction().name());
|
||||
statement.setLong(8, adminLog.getTime());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void insertAuction(AuctionedItem item, Callback<AuctionedItem> callback) {
|
||||
this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "auctions(id, owner, highest_bidder, owner_name, highest_bidder_name, category, base_price, bid_start_price, bid_increment_price, current_price, expired, expires_at, item_material, item_name, item_lore, item_enchants, item, listed_world, infinite, allow_partial_buys, server_auction, is_request, request_count) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
|
||||
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "auctions(id, owner, highest_bidder, owner_name, highest_bidder_name, category, base_price, bid_start_price, bid_increment_price, current_price, expired, expires_at, item_material, item_name, item_lore, item_enchants, item, listed_world, infinite, allow_partial_buys, server_auction, is_request, request_count, serialize_version, itemstack) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
|
||||
final AuctionAPI api = AuctionAPI.getInstance();
|
||||
PreparedStatement fetch = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "auctions WHERE id = ?");
|
||||
|
||||
@ -356,6 +368,14 @@ public class DataManager extends DataManagerAbstract {
|
||||
statement.setBoolean(22, item.isRequest());
|
||||
statement.setInt(23, item.getRequestAmount());
|
||||
|
||||
try {
|
||||
statement.setInt(24, 1);
|
||||
statement.setString(25, QuickItem.toString(item.getItem()));
|
||||
}catch (NbtApiException e) {
|
||||
statement.setInt(24, 0);
|
||||
statement.setString(25, null);
|
||||
}
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
if (callback != null) {
|
||||
@ -371,15 +391,202 @@ public class DataManager extends DataManagerAbstract {
|
||||
}));
|
||||
}
|
||||
|
||||
private AuctionedItem extractAuctionedItem(ResultSet resultSet) throws SQLException {
|
||||
final ItemStack item = resultSet.getInt("serialize_version") == 1 ? QuickItem.getItem(resultSet.getString("itemstack")) : AuctionAPI.decodeItem(resultSet.getString("item"));
|
||||
|
||||
if (item == null) {
|
||||
AuctionHouse.getInstance().getLogger().log(Level.WARNING, "Auction Item with id " + resultSet.getString("id") + " is using an unknown material, it is being skipped!");
|
||||
return null;
|
||||
}
|
||||
|
||||
AuctionedItem auctionItem = new AuctionedItem(
|
||||
UUID.fromString(resultSet.getString("id")),
|
||||
UUID.fromString(resultSet.getString("owner")),
|
||||
UUID.fromString(resultSet.getString("highest_bidder")),
|
||||
resultSet.getString("owner_name"),
|
||||
resultSet.getString("highest_bidder_name"),
|
||||
AuctionItemCategory.valueOf(resultSet.getString("category")),
|
||||
item,
|
||||
resultSet.getDouble("base_price"),
|
||||
resultSet.getDouble("bid_start_price"),
|
||||
resultSet.getDouble("bid_increment_price"),
|
||||
resultSet.getDouble("current_price"),
|
||||
resultSet.getDouble("bid_start_price") >= 1 || resultSet.getDouble("bid_increment_price") >= 1,
|
||||
resultSet.getBoolean("expired"),
|
||||
resultSet.getLong("expires_at")
|
||||
);
|
||||
|
||||
auctionItem.setListedWorld(resultSet.getString("listed_world"));
|
||||
auctionItem.setInfinite(hasColumn(resultSet, "infinite") && resultSet.getBoolean("infinite"));
|
||||
auctionItem.setAllowPartialBuy(hasColumn(resultSet, "allow_partial_buys") && resultSet.getBoolean("allow_partial_buys"));
|
||||
auctionItem.setServerItem(resultSet.getBoolean("server_auction"));
|
||||
auctionItem.setRequest(resultSet.getBoolean("is_request"));
|
||||
auctionItem.setRequestAmount(resultSet.getInt("request_count"));
|
||||
|
||||
return auctionItem;
|
||||
}
|
||||
|
||||
|
||||
//=================================================================================================//
|
||||
// AUCTION LOGS //
|
||||
//=================================================================================================//
|
||||
|
||||
public void getAdminLogs(Callback<ArrayList<AuctionAdminLog>> callback) {
|
||||
ArrayList<AuctionAdminLog> logs = new ArrayList<>();
|
||||
this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "admin_logs")) {
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
|
||||
final AuctionAdminLog log = extractAdminLog(resultSet);
|
||||
if (log == null || log.getItem() == null || log.getItem().getType() == CompMaterial.AIR.parseMaterial()) continue;
|
||||
|
||||
if (resultSet.getInt("serialize_version") == 0) {
|
||||
try (PreparedStatement updateStatement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "admin_logs SET serialize_version = 1, itemstack = ? WHERE id = ?")) {
|
||||
try {
|
||||
String possible = QuickItem.toString(log.getItem());
|
||||
updateStatement.setString(1, possible);
|
||||
updateStatement.setInt(2, resultSet.getInt("id"));
|
||||
updateStatement.executeUpdate();
|
||||
} catch (NbtApiException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logs.add(log);
|
||||
}
|
||||
|
||||
callback.accept(null, logs);
|
||||
} catch (Exception e) {
|
||||
resolveCallback(callback, e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void getTransactions(Callback<ArrayList<Transaction>> callback) {
|
||||
ArrayList<Transaction> transactions = new ArrayList<>();
|
||||
this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "transactions")) {
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
final Transaction transaction = extractTransaction(resultSet);
|
||||
|
||||
if (transaction == null || transaction.getItem().getType() == CompMaterial.AIR.parseMaterial()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resultSet.getInt("serialize_version") == 0) {
|
||||
try (PreparedStatement updateStatement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "transactions SET serialize_version = 1, itemstack = ? WHERE id = ?")) {
|
||||
try {
|
||||
String possible = QuickItem.toString(transaction.getItem());
|
||||
updateStatement.setString(1, possible);
|
||||
updateStatement.setString(2, resultSet.getString("id"));
|
||||
updateStatement.executeUpdate();
|
||||
} catch (NbtApiException e) {
|
||||
//todo idk do something
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
transactions.add(transaction);
|
||||
}
|
||||
|
||||
callback.accept(null, transactions);
|
||||
} catch (Exception e) {
|
||||
resolveCallback(callback, e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void insertTransaction(Transaction transaction, Callback<Transaction> callback) {
|
||||
this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + getTablePrefix() + "transactions (id, seller, seller_name, buyer, buyer_name, transaction_time, item, auction_sale_type, final_price, serialize_version, itemstack) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
|
||||
PreparedStatement fetch = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "transactions WHERE id = ?");
|
||||
|
||||
fetch.setString(1, transaction.getId().toString());
|
||||
statement.setString(1, transaction.getId().toString());
|
||||
statement.setString(2, transaction.getSeller().toString());
|
||||
statement.setString(3, transaction.getSellerName());
|
||||
statement.setString(4, transaction.getBuyer().toString());
|
||||
statement.setString(5, transaction.getBuyerName());
|
||||
statement.setLong(6, transaction.getTransactionTime());
|
||||
statement.setString(7, AuctionAPI.encodeItem(transaction.getItem()));
|
||||
statement.setString(8, transaction.getAuctionSaleType().name());
|
||||
statement.setDouble(9, transaction.getFinalPrice());
|
||||
|
||||
try {
|
||||
statement.setInt(10, 1);
|
||||
statement.setString(11, QuickItem.toString(transaction.getItem()));
|
||||
} catch (NbtApiException e) {
|
||||
statement.setInt(10, 0);
|
||||
statement.setString(11, null);
|
||||
}
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
if (callback != null) {
|
||||
ResultSet res = fetch.executeQuery();
|
||||
res.next();
|
||||
|
||||
final Transaction inserted = extractTransaction(res);
|
||||
if (inserted != null)
|
||||
callback.accept(null, inserted);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
resolveCallback(callback, e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void insertLog(AuctionAdminLog adminLog) {
|
||||
this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "admin_logs(admin, admin_name, target, target_name, item, item_id, action, time, serialize_version, itemstack) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
|
||||
|
||||
statement.setString(1, adminLog.getAdmin().toString());
|
||||
statement.setString(2, adminLog.getAdminName());
|
||||
statement.setString(3, adminLog.getTarget().toString());
|
||||
statement.setString(4, adminLog.getTargetName());
|
||||
statement.setString(5, AuctionAPI.encodeItem(adminLog.getItem()));
|
||||
statement.setString(6, adminLog.getItemId().toString());
|
||||
statement.setString(7, adminLog.getAdminAction().name());
|
||||
statement.setLong(8, adminLog.getTime());
|
||||
|
||||
try {
|
||||
statement.setInt(9, 1);
|
||||
statement.setString(10, QuickItem.toString(adminLog.getItem()));
|
||||
} catch (NbtApiException e) {
|
||||
statement.setInt(9, 0);
|
||||
statement.setString(10, null);
|
||||
}
|
||||
|
||||
statement.executeUpdate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void insertMinPrice(MinItemPrice item, Callback<MinItemPrice> callback) {
|
||||
this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "min_item_prices (id, item, price) VALUES(?, ?, ?)")) {
|
||||
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "min_item_prices (id, item, price, serialize_version, itemstack) VALUES(?, ?, ?, ?, ?)")) {
|
||||
PreparedStatement fetch = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "min_item_prices WHERE id = ?");
|
||||
|
||||
fetch.setString(1, item.getUuid().toString());
|
||||
statement.setString(1, item.getUuid().toString());
|
||||
statement.setString(2, AuctionAPI.encodeItem(item.getItemStack()));
|
||||
statement.setDouble(3, item.getPrice());
|
||||
|
||||
try {
|
||||
statement.setInt(4, 1);
|
||||
statement.setString(5, QuickItem.toString(item.getItemStack()));
|
||||
} catch (NbtApiException e) {
|
||||
statement.setInt(4, 0);
|
||||
statement.setString(5, null);
|
||||
}
|
||||
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
if (callback != null) {
|
||||
@ -401,7 +608,23 @@ public class DataManager extends DataManagerAbstract {
|
||||
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "min_item_prices")) {
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
minItemPrices.add(extractMinItemPrice(resultSet));
|
||||
|
||||
final MinItemPrice minItemPrice = extractMinItemPrice(resultSet);
|
||||
if (minItemPrice == null || minItemPrice.getItemStack() == null || minItemPrice.getItemStack().getType() == CompMaterial.AIR.parseMaterial()) continue;
|
||||
|
||||
if (resultSet.getInt("serialize_version") == 0) {
|
||||
try (PreparedStatement updateStatement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "min_item_prices SET serialize_version = 1, itemstack = ? WHERE id = ?")) {
|
||||
try {
|
||||
String possible = QuickItem.toString(minItemPrice.getItemStack());
|
||||
updateStatement.setString(1, possible);
|
||||
updateStatement.setString(2, resultSet.getString("id"));
|
||||
updateStatement.executeUpdate();
|
||||
} catch (NbtApiException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
minItemPrices.add(minItemPrice);
|
||||
}
|
||||
|
||||
callback.accept(null, minItemPrices);
|
||||
@ -480,102 +703,6 @@ public class DataManager extends DataManagerAbstract {
|
||||
}));
|
||||
}
|
||||
|
||||
public void updateItemsAsync(Collection<AuctionedItem> items, UpdateCallback callback) {
|
||||
this.runAsync(() -> updateItems(items, callback));
|
||||
}
|
||||
|
||||
public void updateItems(Collection<AuctionedItem> items, UpdateCallback callback) {
|
||||
this.databaseConnector.connect(connection -> {
|
||||
connection.setAutoCommit(false);
|
||||
SQLException err = null;
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "auctions SET owner = ?, owner_name = ?, highest_bidder = ?, highest_bidder_name = ?, base_price = ?, bid_start_price = ?, bid_increment_price = ?, current_price = ?, expires_at = ?, expired = ?, item = ? WHERE id = ?");
|
||||
for (AuctionedItem item : items) {
|
||||
try {
|
||||
statement.setString(1, item.getOwner().toString());
|
||||
statement.setString(2, item.getOwnerName());
|
||||
statement.setString(3, item.getHighestBidder().toString());
|
||||
statement.setString(4, item.getHighestBidderName());
|
||||
statement.setDouble(5, item.getBasePrice());
|
||||
statement.setDouble(6, item.getBidStartingPrice());
|
||||
statement.setDouble(7, item.getBidIncrementPrice());
|
||||
statement.setDouble(8, item.getCurrentPrice());
|
||||
statement.setLong(9, item.getExpiresAt());
|
||||
statement.setBoolean(10, item.isExpired());
|
||||
statement.setString(11, AuctionAPI.encodeItem(item.getItem()));
|
||||
statement.setString(12, item.getId().toString());
|
||||
statement.addBatch();
|
||||
} catch (SQLException e) {
|
||||
err = e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
statement.executeBatch();
|
||||
|
||||
if (err == null) {
|
||||
connection.commit();
|
||||
resolveUpdateCallback(callback, null);
|
||||
} else {
|
||||
connection.rollback();
|
||||
resolveUpdateCallback(callback, err);
|
||||
}
|
||||
|
||||
connection.setAutoCommit(true);
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteItems(Collection<UUID> items) {
|
||||
this.databaseConnector.connect(connection -> {
|
||||
connection.setAutoCommit(false);
|
||||
PreparedStatement statement = connection.prepareStatement("DELETE FROM " + this.getTablePrefix() + "auctions WHERE id = ?");
|
||||
for (UUID id : items) {
|
||||
statement.setString(1, id.toString());
|
||||
statement.addBatch();
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
connection.setAutoCommit(true);
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteItemsAsync(Collection<UUID> items) {
|
||||
this.runAsync(() -> deleteItems(items));
|
||||
}
|
||||
|
||||
public void deletePlayer(UUID uuid) {
|
||||
this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
PreparedStatement statement = connection.prepareStatement("DELETE FROM " + this.getTablePrefix() + "player WHERE uuid = ?");
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.execute();
|
||||
}));
|
||||
}
|
||||
|
||||
// public void insertAuctionPlayer(AuctionPlayer auctionPlayer, Callback<AuctionPlayer> callback) {
|
||||
// this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
// try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + getTablePrefix() + "player (uuid, filter_sale_type, filter_item_category, filter_sort_type, last_listed_item) VALUES (?, ?, ?, ?, ?)")) {
|
||||
// PreparedStatement fetch = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "player WHERE uuid = ?");
|
||||
//
|
||||
// fetch.setString(1, auctionPlayer.getUuid().toString());
|
||||
// statement.setString(1, auctionPlayer.getPlayer().getUniqueId().toString());
|
||||
// statement.setString(2, auctionPlayer.getSelectedSaleType().name());
|
||||
// statement.setString(3, auctionPlayer.getSelectedFilter().name());
|
||||
// statement.setString(4, auctionPlayer.getAuctionSortType().name());
|
||||
// statement.setLong(5, auctionPlayer.getLastListedItem());
|
||||
// statement.executeUpdate();
|
||||
//
|
||||
// if (callback != null) {
|
||||
// ResultSet res = fetch.executeQuery();
|
||||
// res.next();
|
||||
// callback.accept(null, extractAuctionPlayer(res));
|
||||
// }
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// resolveCallback(callback, e);
|
||||
// }
|
||||
// }));
|
||||
// }
|
||||
|
||||
public void insertAuctionPlayer(AuctionPlayer auctionPlayer, Callback<AuctionPlayer> callback) {
|
||||
this.runAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
try {
|
||||
@ -668,7 +795,24 @@ public class DataManager extends DataManagerAbstract {
|
||||
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "payments")) {
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
payments.add(extractAuctionPayment(resultSet));
|
||||
|
||||
final AuctionPayment payment = extractAuctionPayment(resultSet);
|
||||
if (payment == null || payment.getItem() == null || payment.getItem().getType() == CompMaterial.AIR.parseMaterial()) continue;
|
||||
|
||||
if (resultSet.getInt("serialize_version") == 0) {
|
||||
try (PreparedStatement updateStatement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "payments SET serialize_version = 1, itemstack = ? WHERE uuid = ? AND time = ?")) {
|
||||
try {
|
||||
String possible = QuickItem.toString(payment.getItem());
|
||||
updateStatement.setString(1, possible);
|
||||
updateStatement.setString(2, resultSet.getString("uuid"));
|
||||
updateStatement.setLong(3, resultSet.getLong("time"));
|
||||
updateStatement.executeUpdate();
|
||||
} catch (NbtApiException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
payments.add(payment);
|
||||
}
|
||||
|
||||
callback.accept(null, payments);
|
||||
@ -695,7 +839,7 @@ public class DataManager extends DataManagerAbstract {
|
||||
statement.executeUpdate();
|
||||
|
||||
// insert into storage
|
||||
AuctionHouse.getInstance().getPaymentsManager().add(auctionPayment);
|
||||
AuctionHouse.getPaymentsManager().add(auctionPayment);
|
||||
|
||||
if (callback != null) {
|
||||
ResultSet res = fetch.executeQuery();
|
||||
@ -724,10 +868,17 @@ public class DataManager extends DataManagerAbstract {
|
||||
}
|
||||
|
||||
private AuctionPayment extractAuctionPayment(ResultSet resultSet) throws SQLException {
|
||||
|
||||
String possibleItem = resultSet.getString("item");
|
||||
if (possibleItem.contains("Head Database"))
|
||||
possibleItem = possibleItem.replace("Head Database", "HeadDatabase");
|
||||
|
||||
ItemStack item = resultSet.getInt("serialize_version") == 1 ? QuickItem.getItem(resultSet.getString("itemstack")) : AuctionAPI.decodeItem(possibleItem);
|
||||
|
||||
return new AuctionPayment(
|
||||
UUID.fromString(resultSet.getString("uuid")),
|
||||
UUID.fromString(resultSet.getString("payment_for")),
|
||||
(resultSet.getString("item") == null || resultSet.getString("item").trim().isEmpty()) ? null : AuctionAPI.decodeItem(resultSet.getString("item")),
|
||||
item,
|
||||
(resultSet.getString("from_name") == null || resultSet.getString("from_name").trim().isEmpty()) ? null : resultSet.getString("from_name"),
|
||||
(resultSet.getString("reason") == null || resultSet.getString("reason").trim().isEmpty()) ? PaymentReason.ITEM_SOLD : PaymentReason.valueOf(resultSet.getString("reason")),
|
||||
resultSet.getDouble("amount"),
|
||||
@ -765,45 +916,17 @@ public class DataManager extends DataManagerAbstract {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private AuctionedItem extractAuctionedItem(ResultSet resultSet) throws SQLException {
|
||||
final ItemStack item = AuctionAPI.decodeItem(resultSet.getString("item"));
|
||||
if (item == null) {
|
||||
AuctionHouse.getInstance().getLogger().log(Level.WARNING, "Auction Item with id " + resultSet.getString("id") + " is using an unknown material, it is being skipped!");
|
||||
return null;
|
||||
}
|
||||
|
||||
AuctionedItem auctionItem = new AuctionedItem(
|
||||
UUID.fromString(resultSet.getString("id")),
|
||||
UUID.fromString(resultSet.getString("owner")),
|
||||
UUID.fromString(resultSet.getString("highest_bidder")),
|
||||
resultSet.getString("owner_name"),
|
||||
resultSet.getString("highest_bidder_name"),
|
||||
AuctionItemCategory.valueOf(resultSet.getString("category")),
|
||||
item,
|
||||
resultSet.getDouble("base_price"),
|
||||
resultSet.getDouble("bid_start_price"),
|
||||
resultSet.getDouble("bid_increment_price"),
|
||||
resultSet.getDouble("current_price"),
|
||||
resultSet.getDouble("bid_start_price") >= 1 || resultSet.getDouble("bid_increment_price") >= 1,
|
||||
resultSet.getBoolean("expired"),
|
||||
resultSet.getLong("expires_at")
|
||||
);
|
||||
|
||||
auctionItem.setListedWorld(resultSet.getString("listed_world"));
|
||||
auctionItem.setInfinite(hasColumn(resultSet, "infinite") && resultSet.getBoolean("infinite"));
|
||||
auctionItem.setAllowPartialBuy(hasColumn(resultSet, "allow_partial_buys") && resultSet.getBoolean("allow_partial_buys"));
|
||||
auctionItem.setServerItem(resultSet.getBoolean("server_auction"));
|
||||
auctionItem.setRequest(resultSet.getBoolean("is_request"));
|
||||
auctionItem.setRequestAmount(resultSet.getInt("request_count"));
|
||||
|
||||
return auctionItem;
|
||||
}
|
||||
|
||||
private MinItemPrice extractMinItemPrice(ResultSet resultSet) throws SQLException {
|
||||
|
||||
String possibleItem = resultSet.getString("item");
|
||||
if (possibleItem.contains("Head Database"))
|
||||
possibleItem = possibleItem.replace("Head Database", "HeadDatabase");
|
||||
|
||||
ItemStack item = resultSet.getInt("serialize_version") == 1 ? QuickItem.getItem(resultSet.getString("itemstack")) : AuctionAPI.decodeItem(possibleItem);
|
||||
|
||||
return new MinItemPrice(
|
||||
UUID.fromString(resultSet.getString("id")),
|
||||
AuctionAPI.decodeItem(resultSet.getString("item")),
|
||||
item,
|
||||
resultSet.getDouble("price")
|
||||
);
|
||||
}
|
||||
@ -813,6 +936,8 @@ public class DataManager extends DataManagerAbstract {
|
||||
if (possibleItem.contains("Head Database"))
|
||||
possibleItem = possibleItem.replace("Head Database", "HeadDatabase");
|
||||
|
||||
ItemStack item = resultSet.getInt("serialize_version") == 1 ? QuickItem.getItem(resultSet.getString("itemstack")) : AuctionAPI.decodeItemTransaction(possibleItem);
|
||||
|
||||
return new Transaction(
|
||||
UUID.fromString(resultSet.getString("id")),
|
||||
UUID.fromString(resultSet.getString("seller")),
|
||||
@ -820,19 +945,27 @@ public class DataManager extends DataManagerAbstract {
|
||||
resultSet.getString("seller_name"),
|
||||
resultSet.getString("buyer_name"),
|
||||
resultSet.getLong("transaction_time"),
|
||||
AuctionAPI.decodeItem(possibleItem),
|
||||
item,
|
||||
AuctionSaleType.valueOf(resultSet.getString("auction_sale_type")),
|
||||
resultSet.getDouble("final_price")
|
||||
);
|
||||
}
|
||||
|
||||
private AuctionAdminLog extractAdminLog(ResultSet resultSet) throws SQLException {
|
||||
|
||||
String possibleItem = resultSet.getString("item");
|
||||
if (possibleItem.contains("Head Database"))
|
||||
possibleItem = possibleItem.replace("Head Database", "HeadDatabase");
|
||||
|
||||
ItemStack item = resultSet.getInt("serialize_version") == 1 ? QuickItem.getItem(resultSet.getString("itemstack")) : AuctionAPI.decodeItem(possibleItem);
|
||||
|
||||
|
||||
return new AuctionAdminLog(
|
||||
UUID.fromString(resultSet.getString("admin")),
|
||||
resultSet.getString("admin_name"),
|
||||
UUID.fromString(resultSet.getString("target")),
|
||||
resultSet.getString("target_name"),
|
||||
AuctionAPI.decodeItem(resultSet.getString("item")),
|
||||
item,
|
||||
UUID.fromString(resultSet.getString("item_id")),
|
||||
AdminAction.valueOf(resultSet.getString("action").toUpperCase()),
|
||||
resultSet.getLong("time")
|
||||
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.database.migrations;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: February 09, 2024,
|
||||
* Time Created: 11:58 a.m.
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
|
||||
*/
|
||||
public class _23_ItemToNBTSerializationMigration extends DataMigration {
|
||||
|
||||
public _23_ItemToNBTSerializationMigration() {
|
||||
super(23);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate(Connection connection, String tablePrefix) throws SQLException {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.execute("ALTER TABLE " + tablePrefix + "transactions ADD itemstack TEXT NULL");
|
||||
statement.execute("ALTER TABLE " + tablePrefix + "transactions ADD serialize_version INTEGER DEFAULT 0");
|
||||
|
||||
statement.execute("ALTER TABLE " + tablePrefix + "auctions ADD itemstack TEXT NULL");
|
||||
statement.execute("ALTER TABLE " + tablePrefix + "auctions ADD serialize_version INTEGER DEFAULT 0");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public final class _24_RemainingItemToNBTSerializationMigration extends DataMigration {
|
||||
|
||||
public _24_RemainingItemToNBTSerializationMigration() {
|
||||
super(24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate(Connection connection, String tablePrefix) throws SQLException {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.execute("ALTER TABLE " + tablePrefix + "admin_logs ADD itemstack TEXT NULL");
|
||||
statement.execute("ALTER TABLE " + tablePrefix + "admin_logs ADD serialize_version INTEGER DEFAULT 0");
|
||||
|
||||
statement.execute("ALTER TABLE " + tablePrefix + "min_item_prices ADD itemstack TEXT NULL");
|
||||
statement.execute("ALTER TABLE " + tablePrefix + "min_item_prices ADD serialize_version INTEGER DEFAULT 0");
|
||||
|
||||
statement.execute("ALTER TABLE " + tablePrefix + "payments ADD itemstack TEXT NULL");
|
||||
statement.execute("ALTER TABLE " + tablePrefix + "payments ADD serialize_version INTEGER DEFAULT 0");
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.database.migrations;
|
||||
package ca.tweetzy.auctionhouse.database.migrations.v2;
|
||||
|
||||
import ca.tweetzy.flight.database.DataMigration;
|
||||
|
@ -447,7 +447,12 @@ public final class GUIAuctionHouse extends AuctionUpdatingPagedGUI<AuctionedItem
|
||||
}
|
||||
|
||||
if (Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_ENABLED.getBoolean()) {
|
||||
setButton(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_SLOT.getInt(), QuickItem.of(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_ITEM.getString()).name(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_NAME.getString()).lore(this.player, Replacer.replaceVariables(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_LORE.getStringList(), "total_items_bought", AuctionHouse.getInstance().getTransactionManager().getTotalItemsBought(auctionPlayer.getPlayer().getUniqueId()), "total_items_sold", AuctionHouse.getInstance().getTransactionManager().getTotalItemsSold(auctionPlayer.getPlayer().getUniqueId()))).make(), e -> {
|
||||
setButton(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_SLOT.getInt(), QuickItem.of(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_ITEM.getString())
|
||||
.name(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_NAME.getString())
|
||||
.lore(this.player, Replacer.replaceVariables(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_LORE.getStringList(),
|
||||
"total_items_bought", AuctionHouse.getTransactionManager().getTotalItemsBought(auctionPlayer.getPlayer().getUniqueId()),
|
||||
"total_items_sold", AuctionHouse.getTransactionManager().getTotalItemsSold(auctionPlayer.getPlayer().getUniqueId()))
|
||||
).make(), e -> {
|
||||
|
||||
cancelTask();
|
||||
if (Settings.RESTRICT_ALL_TRANSACTIONS_TO_PERM.getBoolean() && !e.player.hasPermission("auctionhouse.transactions.viewall")) {
|
||||
|
@ -78,26 +78,32 @@ public class PlaceholderAPIHook extends PlaceholderExpansion {
|
||||
|
||||
// legacy placeholders
|
||||
if (params.equalsIgnoreCase("total_money_earned"))
|
||||
return String.valueOf(AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.MONEY_EARNED));
|
||||
return String.valueOf(AuctionHouse.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.MONEY_EARNED));
|
||||
|
||||
if (params.equalsIgnoreCase("total_money_spent"))
|
||||
return String.valueOf(AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.MONEY_SPENT));
|
||||
return String.valueOf(AuctionHouse.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.MONEY_SPENT));
|
||||
|
||||
if (params.equalsIgnoreCase("total_items_bought"))
|
||||
return String.valueOf(AuctionHouse.getTransactionManager().getTotalItemsBought(player.getUniqueId()));
|
||||
|
||||
if (params.equalsIgnoreCase("total_items_sold"))
|
||||
return String.valueOf(AuctionHouse.getTransactionManager().getTotalItemsSold(player.getUniqueId()));
|
||||
|
||||
|
||||
if (params.equalsIgnoreCase("active_auctions")) {
|
||||
AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId());
|
||||
AuctionPlayer auctionPlayer = AuctionHouse.getAuctionPlayerManager().getPlayer(player.getUniqueId());
|
||||
if (auctionPlayer == null) return null;
|
||||
return String.valueOf(auctionPlayer.getItems(false).size());
|
||||
}
|
||||
|
||||
if (params.equalsIgnoreCase("expired_auctions")) {
|
||||
AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId());
|
||||
AuctionPlayer auctionPlayer = AuctionHouse.getAuctionPlayerManager().getPlayer(player.getUniqueId());
|
||||
if (auctionPlayer == null) return null;
|
||||
return String.valueOf(auctionPlayer.getItems(true).size());
|
||||
}
|
||||
|
||||
if (params.equalsIgnoreCase("server_active_auctions")) {
|
||||
return String.valueOf(AuctionHouse.getInstance().getAuctionItemManager().getItems().size());
|
||||
return String.valueOf(AuctionHouse.getAuctionItemManager().getItems().size());
|
||||
}
|
||||
|
||||
// cool statistic stuff
|
||||
@ -111,10 +117,10 @@ public class PlaceholderAPIHook extends PlaceholderExpansion {
|
||||
final int duration = Integer.parseInt(splitString(paramSplit[2])[0]);
|
||||
final ChronoUnit unit = getChronoUnitFromParam(splitString(paramSplit[2])[1]);
|
||||
|
||||
return String.valueOf(AuctionHouse.getInstance().getAuctionStatisticManager().getStatistic(auctionStatisticType, unit, duration));
|
||||
return String.valueOf(AuctionHouse.getAuctionStatisticManager().getStatistic(auctionStatisticType, unit, duration));
|
||||
}
|
||||
|
||||
return String.valueOf(AuctionHouse.getInstance().getAuctionStatisticManager().getStatistic(auctionStatisticType));
|
||||
return String.valueOf(AuctionHouse.getAuctionStatisticManager().getStatistic(auctionStatisticType));
|
||||
}
|
||||
|
||||
if (paramSplit[0].equalsIgnoreCase("pstat")) {
|
||||
@ -146,10 +152,10 @@ public class PlaceholderAPIHook extends PlaceholderExpansion {
|
||||
final int duration = Integer.parseInt(chronoSplit[0]);
|
||||
final ChronoUnit unit = getChronoUnitFromParam(chronoSplit[1]);
|
||||
|
||||
return String.valueOf(AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetUser.getUniqueId(), auctionStatisticType, unit, duration));
|
||||
return String.valueOf(AuctionHouse.getAuctionStatisticManager().getStatisticByPlayer(targetUser.getUniqueId(), auctionStatisticType, unit, duration));
|
||||
}
|
||||
|
||||
return String.valueOf(AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetUser.getUniqueId(), auctionStatisticType));
|
||||
return String.valueOf(AuctionHouse.getAuctionStatisticManager().getStatisticByPlayer(targetUser.getUniqueId(), auctionStatisticType));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -59,11 +59,13 @@ public class AuctionItemManager {
|
||||
|
||||
|
||||
public void start() {
|
||||
AuctionHouse.getInstance().getDataManager().getItems((error, results) -> {
|
||||
AuctionHouse.getDataManager().getItems((error, results) -> {
|
||||
if (error == null) {
|
||||
for (AuctionedItem item : results) {
|
||||
addAuctionItem(item);
|
||||
}
|
||||
} else {
|
||||
error.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -98,11 +98,13 @@ public class TransactionManager {
|
||||
}
|
||||
|
||||
public void loadTransactions() {
|
||||
AuctionHouse.getInstance().getDataManager().getTransactions((error, results) -> {
|
||||
AuctionHouse.getDataManager().getTransactions((error, results) -> {
|
||||
if (error == null) {
|
||||
for (Transaction transaction : results) {
|
||||
addTransaction(transaction);
|
||||
}
|
||||
} else {
|
||||
error.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user