Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
Bug fixes, closes #89, #90, #94
  • Loading branch information
Shock95 committed Oct 27, 2021
1 parent 6b06f6b commit 0041d97
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions src/shock95x/auctionhouse/commands/subcommand/SellCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}

Expand Down
15 changes: 5 additions & 10 deletions src/shock95x/auctionhouse/menu/type/AHMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
3 changes: 2 additions & 1 deletion src/shock95x/auctionhouse/utils/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"]));
Expand Down

0 comments on commit 0041d97

Please sign in to comment.