Skip to content

Commit

Permalink
Index out of range fix (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shock95 committed Aug 24, 2020
1 parent 0fe364a commit c998927
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 51 deletions.
5 changes: 4 additions & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: AuctionHouse
main: shock95x\auctionhouse\AuctionHouse
version: 1.2.0
version: 1.2.1
api: 3.0.0
author: Shock95x
softdepend: [EconomyAPI, InvCrashFix]
Expand All @@ -23,6 +23,9 @@ permissions:
auctionhouse.command.listings:
default: true
description: Allows player to view listings.
auctionhouse.command.expired:
default: true
description: Allows player to view expired listings.
auctionhouse.command.admin:
default: op
description: Opens the AuctionHouse admin menu.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class ReloadCommand extends BaseSubCommand {

protected function prepare(): void {
$this->setPermission("auctionhouse.command.update");
$this->setPermission("auctionhouse.command.reload");
}

public function onRun(CommandSender $sender, string $aliasUsed, array $args): void {
Expand Down
21 changes: 16 additions & 5 deletions src/shock95x/auctionhouse/menu/AHMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use muqsit\invmenu\inventory\InvMenuInventory;
use muqsit\invmenu\InvMenu;
use muqsit\invmenu\InvMenuHandler;
use muqsit\invmenu\metadata\MenuMetadata;
use muqsit\invmenu\session\PlayerManager;
use pocketmine\inventory\transaction\action\SlotChangeAction;
use pocketmine\item\Item;
Expand Down Expand Up @@ -37,12 +38,17 @@ public function __construct(Player $player, bool $returnMain = false, bool $pagi
// workaround for recursive menus
if(PlayerManager::get($player)->getCurrentMenu() != null && !$this->newMenu) {
$menu = PlayerManager::get($player)->getCurrentMenu();
$menu->getInventory()->clearAll();
$this->inventory = $menu->getInventory();
$menu->setListener([$this, "handle"]);
// workaround for inventory bug
if($menu->getInventory()->getSize() < $type->getSize()) {
$player->removeWindow($menu->getInventory());
$this->createNewInventory($type);
} else {
$menu->getInventory()->clearAll();
$this->inventory = $menu->getInventory();
$menu->setListener([$this, "handle"]);
}
} else {
$this->inventory = $type->createInventory();
$this->setListener([$this, "handle"]);
$this->createNewInventory($type);
}
$this->player = $player;

Expand All @@ -54,6 +60,11 @@ public function __construct(Player $player, bool $returnMain = false, bool $pagi

abstract function renderItems();

public function createNewInventory(MenuMetadata $type) {
$this->inventory = $type->createInventory();
$this->setListener([$this, "handle"]);
}

public function handle(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action): bool {
if($itemClicked->getNamedTag()->hasTag("pagination")) {
$this->handlePagination($itemClicked->getNamedTag()->getInt("pagination"));
Expand Down
1 change: 0 additions & 1 deletion src/shock95x/auctionhouse/menu/ExpiredMenu.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace shock95x\auctionhouse\menu;

use pocketmine\inventory\Inventory;
use pocketmine\inventory\transaction\action\SlotChangeAction;
use pocketmine\item\Item;
use pocketmine\nbt\tag\ByteTag;
Expand Down
18 changes: 15 additions & 3 deletions src/shock95x/auctionhouse/menu/MainMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace shock95x\auctionhouse\menu;

use DateTime;
use pocketmine\inventory\Inventory;
use pocketmine\inventory\transaction\action\SlotChangeAction;
use pocketmine\item\Item;
use pocketmine\nbt\NBT;
Expand All @@ -11,11 +10,11 @@
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\Player;
use pocketmine\scheduler\Task;
use pocketmine\utils\TextFormat;
use shock95x\auctionhouse\AuctionHouse;
use shock95x\auctionhouse\database\DataHolder;
use shock95x\auctionhouse\menu\admin\AdminMenu;
use shock95x\auctionhouse\task\MenuDelayTask;
use shock95x\auctionhouse\utils\Locale;
use shock95x\auctionhouse\utils\Settings;
use shock95x\auctionhouse\utils\Utils;
Expand Down Expand Up @@ -105,7 +104,20 @@ public function handle(Player $player, Item $itemClicked, Item $itemClickedWith,
return false;
}
if($action->getSlot() <= 44 && $itemClicked->getNamedTag()->hasTag("marketId")) {
AuctionHouse::getInstance()->getScheduler()->scheduleDelayedTask(new MenuDelayTask($player, new ConfirmPurchaseMenu($this->getPlayer(), clone $itemClicked)), 10);
$player->removeWindow($action->getInventory());
AuctionHouse::getInstance()->getScheduler()->scheduleDelayedTask(new class($player, clone $itemClicked) extends Task{
private $player;
private $item;

public function __construct(Player $player, Item $item) {
$this->player = $player;
$this->item = $item;
}

public function onRun(int $currentTick) {
new ConfirmPurchaseMenu($this->player, $this->item);
}
}, 10);
}
return parent::handle($player, $itemClicked, $itemClickedWith, $action);
}
Expand Down
18 changes: 16 additions & 2 deletions src/shock95x/auctionhouse/menu/admin/AdminMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\Player;
use pocketmine\scheduler\Task;
use pocketmine\utils\TextFormat;
use shock95x\auctionhouse\auction\Listing;
use shock95x\auctionhouse\AuctionHouse;
use shock95x\auctionhouse\database\DataHolder;
use shock95x\auctionhouse\menu\AHMenu;
use shock95x\auctionhouse\task\MenuDelayTask;
use shock95x\auctionhouse\utils\Locale;
use shock95x\auctionhouse\utils\Settings;
use shock95x\auctionhouse\utils\Utils;
Expand Down Expand Up @@ -78,7 +79,20 @@ public function handle(Player $player, Item $itemClicked, Item $itemClickedWith,
Locale::getMessage($player, "listing-gone");
return false;
}
AuctionHouse::getInstance()->getScheduler()->scheduleDelayedTask(new MenuDelayTask($player, new ManageListingMenu($player, $listing)), 10);
$player->removeWindow($action->getInventory());
AuctionHouse::getInstance()->getScheduler()->scheduleDelayedTask(new class($player, $listing) extends Task{
private $player;
private $listing;

public function __construct(Player $player, Listing $listing) {
$this->player = $player;
$this->listing = $listing;
}

public function onRun(int $currentTick) {
new ManageListingMenu($this->player, $this->listing);
}
}, 10);
}
return parent::handle($player, $itemClicked, $itemClickedWith, $action);
}
Expand Down
17 changes: 15 additions & 2 deletions src/shock95x/auctionhouse/menu/player/PlayerListingMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
use pocketmine\item\Item;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\Player;
use pocketmine\scheduler\Task;
use pocketmine\utils\TextFormat;
use shock95x\auctionhouse\AuctionHouse;
use shock95x\auctionhouse\database\DataHolder;
use shock95x\auctionhouse\menu\AHMenu;
use shock95x\auctionhouse\menu\ConfirmPurchaseMenu;
use shock95x\auctionhouse\task\MenuDelayTask;
use shock95x\auctionhouse\utils\Locale;
use shock95x\auctionhouse\utils\Settings;
use shock95x\auctionhouse\utils\Utils;
Expand Down Expand Up @@ -69,7 +69,20 @@ public function renderItems() {

public function handle(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : bool {
if($action->getSlot() <= 44 && $itemClicked->getNamedTag()->hasTag("marketId")) {
AuctionHouse::getInstance()->getScheduler()->scheduleDelayedTask(new MenuDelayTask($player, new ConfirmPurchaseMenu($this->getPlayer(), clone $itemClicked)), 10);
$player->removeWindow($action->getInventory());
AuctionHouse::getInstance()->getScheduler()->scheduleDelayedTask(new class($player, clone $itemClicked) extends Task{
private $player;
private $item;

public function __construct(Player $player, Item $item) {
$this->player = $player;
$this->item = $item;
}

public function onRun(int $currentTick) {
new ConfirmPurchaseMenu($this->player, $this->item);
}
}, 10);
}
return parent::handle($player, $itemClicked, $itemClickedWith, $action);
}
Expand Down
36 changes: 0 additions & 36 deletions src/shock95x/auctionhouse/task/MenuDelayTask.php

This file was deleted.

0 comments on commit c998927

Please sign in to comment.