From 7b5e4c93f0818e7cd8d34344737701913c3ea3c8 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Mon, 11 Sep 2023 19:18:55 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=88=82=EF=B8=8F=20server=20listing=20migr?= =?UTF-8?q?ation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 2 minutes Took 12 seconds --- .../ca/tweetzy/auctionhouse/AuctionHouse.java | 3 +- .../auctionhouse/auction/AuctionedItem.java | 2 + .../auctionhouse/commands/CommandSell.java | 38 +++++++-------- .../_19_ServerAuctionMigration.java | 46 +++++++++++++++++++ .../helpers/ConfigurationItemHelper.java | 2 +- 5 files changed, 70 insertions(+), 21 deletions(-) create mode 100644 src/main/java/ca/tweetzy/auctionhouse/database/migrations/_19_ServerAuctionMigration.java diff --git a/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java index bf5c8fa..bf933ac 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java @@ -221,7 +221,8 @@ public class AuctionHouse extends TweetyPlugin { new _15_AuctionPlayerMigration(), new _16_StatisticVersionTwoMigration(), new _17_PaymentsMigration(), - new _18_PaymentsItemMigration() + new _18_PaymentsItemMigration(), + new _19_ServerAuctionMigration() ); dataMigrationManager.runMigrations(); diff --git a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionedItem.java b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionedItem.java index 15a3133..228b481 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionedItem.java +++ b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionedItem.java @@ -70,6 +70,7 @@ public class AuctionedItem { private String listedWorld = null; private boolean infinite = false; private boolean allowPartialBuy = false; + private boolean serverItem = false; public AuctionedItem() { } @@ -104,6 +105,7 @@ public class AuctionedItem { this.isBidItem = isBidItem; this.expired = expired; this.expiresAt = expiresAt; + this.serverItem = false; } public ItemStack getBidStack() { diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java index cf3a7ee..b3e94c6 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java @@ -379,27 +379,27 @@ public final class CommandSell extends AbstractCommand { })); } else { // Bukkit.getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> { - if (auctionPlayer.getPlayer() == null || !auctionPlayer.getPlayer().isOnline()) { - return ReturnType.FAILURE; + if (auctionPlayer.getPlayer() == null || !auctionPlayer.getPlayer().isOnline()) { + return ReturnType.FAILURE; + } + + player.getInventory().setItemInHand(XMaterial.AIR.parseItem()); + + AuctionCreator.create(auctionPlayer, auctionedItem, (auction, listingResult) -> { + AuctionHouse.getInstance().getAuctionPlayerManager().processSell(player); + + if (listingResult != ListingResult.SUCCESS) { + PlayerUtils.giveItem(player, auction.getItem()); + auctionPlayer.setItemBeingListed(null); + return; } - player.getInventory().setItemInHand(XMaterial.AIR.parseItem()); - - AuctionCreator.create(auctionPlayer, auctionedItem, (auction, listingResult) -> { - AuctionHouse.getInstance().getAuctionPlayerManager().processSell(player); - - if (listingResult != ListingResult.SUCCESS) { - PlayerUtils.giveItem(player, auction.getItem()); - auctionPlayer.setItemBeingListed(null); - return; - } - - if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) { - player.removeMetadata("AuctionHouseConfirmListing", AuctionHouse.getInstance()); - instance.getGuiManager().showGUI(player, new GUIAuctionHouse(auctionPlayer)); - } else - AuctionHouse.newChain().sync(player::closeInventory).execute(); - }); + if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) { + player.removeMetadata("AuctionHouseConfirmListing", AuctionHouse.getInstance()); + instance.getGuiManager().showGUI(player, new GUIAuctionHouse(auctionPlayer)); + } else + AuctionHouse.newChain().sync(player::closeInventory).execute(); + }); // }, Settings.INTERNAL_CREATE_DELAY.getInt()); diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_19_ServerAuctionMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_19_ServerAuctionMigration.java new file mode 100644 index 0000000..d8d3bf1 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_19_ServerAuctionMigration.java @@ -0,0 +1,46 @@ +/* + * 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 . + */ + +package ca.tweetzy.auctionhouse.database.migrations; + +import ca.tweetzy.core.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: August 12 2021 + * Time Created: 11:58 a.m. + * Usage of any code found within this class is prohibited unless given explicit permission otherwise + */ +public class _19_ServerAuctionMigration extends DataMigration { + + public _19_ServerAuctionMigration() { + super(19); + } + + @Override + public void migrate(Connection connection, String tablePrefix) throws SQLException { + try (Statement statement = connection.createStatement()) { + statement.execute("ALTER TABLE " + tablePrefix + "auctions ADD server_auction BOOLEAN NOT NULL DEFAULT 0"); + + } + } +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java b/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java index 0c820fe..05e396b 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java +++ b/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java @@ -23,8 +23,8 @@ import ca.tweetzy.core.compatibility.XMaterial; import ca.tweetzy.core.utils.NumberUtils; import ca.tweetzy.core.utils.TextUtils; import ca.tweetzy.flight.comp.enums.ServerVersion; -import ca.tweetzy.flight.utils.QuickItem; import ca.tweetzy.flight.nbtapi.NBT; +import ca.tweetzy.flight.utils.QuickItem; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack;