🔨 fixed some transaction serialization issues, update flight to use lenient skull texture, insertPlayer adjustments

Took 33 minutes
This commit is contained in:
Kiran Hart 2024-07-10 12:39:41 -04:00
parent f7e79760d7
commit 2713eb0651
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
5 changed files with 148 additions and 93 deletions

View File

@ -205,6 +205,7 @@ public class AuctionAPI {
* @return Serialized data.
*/
public byte[] serializeItem(ItemStack item) {
try (ByteArrayOutputStream stream = new ByteArrayOutputStream(); BukkitObjectOutputStream bukkitStream = new BukkitObjectOutputStream(stream)) {
bukkitStream.writeObject(item);
return stream.toByteArray();
@ -580,7 +581,7 @@ public class AuctionAPI {
Objects.requireNonNull(items, "Cannot create a bundled item with no items");
ItemStack item = QuickItem
.of(Settings.ITEM_BUNDLE_ITEM.getString())
.name(Replacer.replaceVariables(Settings.ITEM_BUNDLE_NAME.getString(),"item_name", getItemName(baseItem)))
.name(Replacer.replaceVariables(Settings.ITEM_BUNDLE_NAME.getString(), "item_name", getItemName(baseItem)))
.lore(Replacer.replaceVariables(Settings.ITEM_BUNDLE_LORE.getStringList(), "item_name", getItemName(baseItem)))
.make();
@ -853,70 +854,77 @@ public class AuctionAPI {
return meets;
}
private String enchantmentName(String arg) {
switch (Enchantment.getByName(arg).getName()) {
case "ARROW_DAMAGE":
return "Power";
case "ARROW_FIRE":
return "Flame";
case "ARROW_INFINITE":
return "Infinity";
case "ARROW_KNOCKBACK":
return "Punch";
case "BINDING_CURSE":
return "Curse of Binding";
case "DAMAGE_ALL":
return "Sharpness";
case "DAMAGE_ARTHROPODS":
return "Bane of Arthropods";
case "DAMAGE_UNDEAD":
return "Smite";
case "DEPTH_STRIDER":
return "Depth Strider";
case "DIG_SPEED":
return "Efficiency";
case "DURABILITY":
return "Unbreaking";
case "FIRE_ASPECT":
return "Fire Aspect";
case "FROST_WALKER":
return "Frost Walker";
case "KNOCKBACK":
return "Knockback";
case "LOOT_BONUS_BLOCKS":
return "Fortune";
case "LOOT_BONUS_MOBS":
return "Looting";
case "LUCK":
return "Luck of the Sea";
case "LURE":
return "Lure";
case "MENDING":
return "Mending";
case "OXYGEN":
return "Respiration";
case "PROTECTION_ENVIRONMENTAL":
return "Protection";
case "PROTECTION_EXPLOSIONS":
return "Blast Protection";
case "PROTECTION_FALL":
return "Feather Falling";
case "PROTECTION_FIRE":
return "Fire Protection";
case "PROTECTION_PROJECTILE":
return "Projectile Protection";
case "SILK_TOUCH":
return "Silk Touch";
case "SWEEPING_EDGE":
return "Sweeping Edge";
case "THORNS":
return "Thorns";
case "VANISHING_CURSE":
return "Cure of Vanishing";
case "WATER_WORKER":
return "Aqua Affinity";
default:
return "Unknown";
public String enchantmentName(String arg) {
try {
final Enchantment enchantment = Enchantment.getByName(arg);
if (enchantment == null) return "Unknown";
switch (enchantment.getName()) {
case "ARROW_DAMAGE":
return "Power";
case "ARROW_FIRE":
return "Flame";
case "ARROW_INFINITE":
return "Infinity";
case "ARROW_KNOCKBACK":
return "Punch";
case "BINDING_CURSE":
return "Curse of Binding";
case "DAMAGE_ALL":
return "Sharpness";
case "DAMAGE_ARTHROPODS":
return "Bane of Arthropods";
case "DAMAGE_UNDEAD":
return "Smite";
case "DEPTH_STRIDER":
return "Depth Strider";
case "DIG_SPEED":
return "Efficiency";
case "DURABILITY":
return "Unbreaking";
case "FIRE_ASPECT":
return "Fire Aspect";
case "FROST_WALKER":
return "Frost Walker";
case "KNOCKBACK":
return "Knockback";
case "LOOT_BONUS_BLOCKS":
return "Fortune";
case "LOOT_BONUS_MOBS":
return "Looting";
case "LUCK":
return "Luck of the Sea";
case "LURE":
return "Lure";
case "MENDING":
return "Mending";
case "OXYGEN":
return "Respiration";
case "PROTECTION_ENVIRONMENTAL":
return "Protection";
case "PROTECTION_EXPLOSIONS":
return "Blast Protection";
case "PROTECTION_FALL":
return "Feather Falling";
case "PROTECTION_FIRE":
return "Fire Protection";
case "PROTECTION_PROJECTILE":
return "Projectile Protection";
case "SILK_TOUCH":
return "Silk Touch";
case "SWEEPING_EDGE":
return "Sweeping Edge";
case "THORNS":
return "Thorns";
case "VANISHING_CURSE":
return "Cure of Vanishing";
case "WATER_WORKER":
return "Aqua Affinity";
default:
return "Unknown";
}
} catch (NullPointerException e) {
return "Unknown";
}
}
}

View File

@ -390,7 +390,7 @@ public final class CommandSell extends AbstractCommand {
AuctionHouse.getInstance().getAuctionPlayerManager().processSell(player);
if (listingResult != ListingResult.SUCCESS) {
PlayerUtils.giveItem(player, auction.getCleanItem());
// PlayerUtils.giveItem(player, auction.getCleanItem());
auctionPlayer.setItemBeingListed(null);
return;
}

View File

@ -28,12 +28,9 @@ 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 lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
@ -45,8 +42,6 @@ import java.time.Instant;
import java.util.*;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* The current file has been created by Kiran Hart
@ -266,9 +261,9 @@ public class DataManager extends DataManagerAbstract {
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "transactions")) {
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
transactions.add(extractTransaction(resultSet));
final Transaction transaction = extractTransaction(resultSet);
if (transaction != null)
transactions.add(transaction);
}
callback.accept(null, transactions);
@ -300,8 +295,8 @@ public class DataManager extends DataManagerAbstract {
res.next();
final Transaction inserted = extractTransaction(res);
callback.accept(null, inserted);
if (inserted != null)
callback.accept(null, inserted);
}
} catch (Exception e) {
@ -555,27 +550,77 @@ public class DataManager extends DataManagerAbstract {
}));
}
// 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 (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 = ?");
try {
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();
String insertQuery = "INSERT OR IGNORE INTO " + getTablePrefix() + "player " +
"(uuid, filter_sale_type, filter_item_category, filter_sort_type, last_listed_item) " +
"VALUES (?, ?, ?, ?, ?)";
if (callback != null) {
if (AuctionHouse.getInstance().getDatabaseConnector() instanceof MySQLConnector) {
insertQuery = "INSERT INTO " + getTablePrefix() + "player " +
"(uuid, filter_sale_type, filter_item_category, filter_sort_type, last_listed_item) " +
"VALUES (?, ?, ?, ?, ?) " +
"ON DUPLICATE KEY UPDATE " +
"filter_sale_type = VALUES(filter_sale_type), " +
"filter_item_category = VALUES(filter_item_category), " +
"filter_sort_type = VALUES(filter_sort_type), " +
"last_listed_item = VALUES(last_listed_item)";
}
// Attempt to insert the new auction player
try (PreparedStatement statement = connection.prepareStatement(insertQuery)) {
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();
}
// Fetch the auction player (whether newly inserted or already existing)
try (PreparedStatement fetch = connection.prepareStatement(
"SELECT * FROM " + this.getTablePrefix() + "player WHERE uuid = ?")) {
fetch.setString(1, auctionPlayer.getUuid().toString());
ResultSet res = fetch.executeQuery();
res.next();
callback.accept(null, extractAuctionPlayer(res));
if (callback != null) {
if (res.next()) {
callback.accept(null, extractAuctionPlayer(res));
} else {
callback.accept(null, auctionPlayer); // Should not reach here
}
}
}
} catch (Exception e) {
e.printStackTrace();
resolveCallback(callback, e);
}
}));
@ -764,6 +809,10 @@ public class DataManager extends DataManagerAbstract {
}
private Transaction extractTransaction(ResultSet resultSet) throws SQLException {
String possibleItem = resultSet.getString("item");
if (possibleItem.contains("Head Database"))
possibleItem = possibleItem.replace("Head Database", "HeadDatabase");
return new Transaction(
UUID.fromString(resultSet.getString("id")),
UUID.fromString(resultSet.getString("seller")),
@ -771,7 +820,7 @@ public class DataManager extends DataManagerAbstract {
resultSet.getString("seller_name"),
resultSet.getString("buyer_name"),
resultSet.getLong("transaction_time"),
AuctionAPI.decodeItem(resultSet.getString("item")),
AuctionAPI.decodeItem(possibleItem),
AuctionSaleType.valueOf(resultSet.getString("auction_sale_type")),
resultSet.getDouble("final_price")
);

View File

@ -190,7 +190,7 @@ public final class AuctionCreator {
if (seller != null) {
instance.getLocale().getMessage("general.something_went_wrong_while_listing").sendPrefixedMessage(seller);
ItemStack originalCopy = auctionItem.getItem().clone();
ItemStack originalCopy = auctionItem.getCleanItem().clone();
int totalOriginal = BundleUtil.isBundledItem(originalCopy) ? AuctionAPI.getInstance().getItemCountInPlayerInventory(seller, originalCopy) : originalCopy.getAmount();
if (!auctionItem.isRequest()) {

View File

@ -149,8 +149,6 @@ public class PlayerListeners implements Listener {
instance.getAuctionPlayerManager().getSellHolding().remove(player.getUniqueId());
instance.getLogger().info("Removing sell holding instance for user: " + player.getName());
instance.getDataManager().deletePlayer(player.getUniqueId());
}
@EventHandler