From 0041d970df4159cefd42ab8a256b98f31fd4d567 Mon Sep 17 00:00:00 2001 From: Shock95x Date: Wed, 27 Oct 2021 02:05:12 -0400 Subject: [PATCH] Updates Bug fixes, closes #89, #90, #94 --- plugin.yml | 2 +- .../commands/subcommand/SellCommand.php | 6 +++--- src/shock95x/auctionhouse/menu/type/AHMenu.php | 15 +++++---------- src/shock95x/auctionhouse/utils/Utils.php | 3 ++- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/plugin.yml b/plugin.yml index c0a0408..b89eebd 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: AuctionHouse main: shock95x\auctionhouse\AuctionHouse version: 1.3.2 -api: 3.21.0 +api: 3.24.0 author: Shock95x softdepend: [EconomyAPI, InvCrashFix] virions: ["InvMenu", "libasynql", "await-generator", "UpdateNotifier", "Commando"] diff --git a/src/shock95x/auctionhouse/commands/subcommand/SellCommand.php b/src/shock95x/auctionhouse/commands/subcommand/SellCommand.php index 6e6587a..357ef3c 100644 --- a/src/shock95x/auctionhouse/commands/subcommand/SellCommand.php +++ b/src/shock95x/auctionhouse/commands/subcommand/SellCommand.php @@ -77,10 +77,10 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo $event->call(); if(!$event->isCancelled()) { if($listingPrice != 0) $this->getEconomy()->subtractMoney($sender, $listingPrice); - $count = $item->getCount(); + $oldItem = clone $item; Utils::removeItem($sender, $item); - $listing = DataHolder::addListing($sender, $item, (int) $price); - $sender->sendMessage(str_replace(["@player", "@item", "@price", "@amount"], [$sender->getName(), $item->getName(), $listing->getPrice(true, Settings::formatPrice()), $count], Locale::getMessage($sender, "item-listed", true))); + $listing = DataHolder::addListing($sender, $oldItem, (int) $price); + $sender->sendMessage(str_replace(["@player", "@item", "@price", "@amount"], [$sender->getName(), $oldItem->getName(), $listing->getPrice(true, Settings::formatPrice()), $oldItem->getCount()], Locale::getMessage($sender, "item-listed", true))); } } diff --git a/src/shock95x/auctionhouse/menu/type/AHMenu.php b/src/shock95x/auctionhouse/menu/type/AHMenu.php index a0ba8f4..7f7a1a0 100644 --- a/src/shock95x/auctionhouse/menu/type/AHMenu.php +++ b/src/shock95x/auctionhouse/menu/type/AHMenu.php @@ -29,7 +29,7 @@ abstract class AHMenu extends InvMenu { protected bool $newMenu = false; protected bool $returnMain = false; - /** @var InvMenuInventory */ + /** @var ?InvMenuInventory */ protected $inventory; protected static string $inventoryType = InvMenu::TYPE_DOUBLE_CHEST; @@ -46,8 +46,9 @@ public function __construct(Player $player, bool $returnMain = false) { private function initialize(): void { // workaround for recursive menus & menu bug - if(!is_null($plManager = PlayerManager::get($this->getPlayer()))) { - $menu = $plManager->getCurrentMenu(); + $manager = PlayerManager::get($this->getPlayer()); + if($manager !== null) { + $menu = $manager->getCurrentMenu(); if($menu instanceof AHMenu) { if($menu->newMenu) { $this->getPlayer()->removeWindow($menu->getInventory()); @@ -59,8 +60,7 @@ private function initialize(): void { } } } - if($this->inventory == null) - $this->inventory = $this->type->createInventory(); + $this->inventory ??= $this->type->createInventory(); $this->setMenuListener($this); } @@ -83,7 +83,6 @@ private function setMenuListener(self $menu) { public function handle(Player $player, Item $itemClicked, Inventory $inventory, int $slot): bool { if($itemClicked->getNamedTag()->hasTag("return")) { new ShopMenu($player); - return true; } return true; } @@ -115,8 +114,4 @@ protected function checkPurchase(int $slot, Item $itemClicked): bool { public function getPlayer(): Player { return $this->player; } - - public function getInventory(): InvMenuInventory { - return $this->inventory; - } } \ No newline at end of file diff --git a/src/shock95x/auctionhouse/utils/Utils.php b/src/shock95x/auctionhouse/utils/Utils.php index a761f94..582ec49 100644 --- a/src/shock95x/auctionhouse/utils/Utils.php +++ b/src/shock95x/auctionhouse/utils/Utils.php @@ -5,6 +5,7 @@ use pocketmine\inventory\Inventory; use pocketmine\item\Item; +use pocketmine\item\ItemFactory; use pocketmine\Player; use pocketmine\plugin\Plugin; use pocketmine\scheduler\ClosureTask; @@ -52,7 +53,7 @@ public static function getMaxListings(Player $player): int { } public static function getButtonItem(Player $player, string $itemKey, string $messageKey, array $searchArgs = [], array $replaceArgs = []): Item { - $item = Item::fromString(Settings::getButtons()[$itemKey]); + $item = ItemFactory::fromStringSingle(Settings::getButtons()[$itemKey]); $message = Locale::getMessage($player, $messageKey); $item->setCustomName(TextFormat::RESET . str_replace($searchArgs, $replaceArgs, $message["name"]));