Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menus Simplified #9

Merged
merged 17 commits into from
Apr 1, 2020
Merged
6 changes: 3 additions & 3 deletions src/DaPigGuy/PiggyAuctions/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public function onDataPacketReceive(DataPacketReceiveEvent $event): void
$player = $event->getPlayer();
$packet = $event->getPacket();
if ($packet instanceof ContainerClosePacket) {
if (isset(Menu::$displayQueue[$player->getName()])) {
Menu::$displayQueue[$player->getName()]->send($player);
unset(Menu::$displayQueue[$player->getName()]);
if (isset(Menu::$awaitingInventoryClose[$player->getName()])) {
Menu::$awaitingInventoryClose[$player->getName()]->send($player);
unset(Menu::$awaitingInventoryClose[$player->getName()]);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DaPigGuy/PiggyAuctions/auction/Auction.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function getUnclaimedBids(): array
*/
public function getUnclaimedBidsHeldBy(string $player): array
{
return array_filter($this->getUnclaimedBids(), function (AuctionBid $bid) use ($player): bool {
return array_filter($this->getUnclaimedBids(), static function (AuctionBid $bid) use ($player): bool {
return $bid->getBidder() === $player;
});
}
Expand Down
16 changes: 8 additions & 8 deletions src/DaPigGuy/PiggyAuctions/auction/AuctionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function init(): void
$row["startdate"],
$row["enddate"],
(bool)$row["claimed"],
array_map(function (array $bidData) use ($row) {
array_map(static function (array $bidData) use ($row) {
return new AuctionBid($row["id"], $bidData["bidder"], $bidData["bidamount"], $bidData["timestamp"]);
}, json_decode($row["claimed_bids"], true)),
$row["starting_bid"],
array_map(function (array $bidData) use ($row) {
array_map(static function (array $bidData) use ($row) {
return new AuctionBid($row["id"], $bidData["bidder"], $bidData["bidamount"], $bidData["timestamp"]);
}, json_decode($row["bids"], true))
);
Expand Down Expand Up @@ -75,7 +75,7 @@ public function getAuction(int $id): ?Auction
public function getAuctionsHeldBy($player): array
{
if ($player instanceof Player) $player = $player->getName();
return array_filter($this->auctions, function (Auction $auction) use ($player): bool {
return array_filter($this->auctions, static function (Auction $auction) use ($player): bool {
return strtolower($auction->getAuctioneer()) === strtolower($player);
});
}
Expand All @@ -87,14 +87,14 @@ public function getAuctionsHeldBy($player): array
public function getActiveAuctionsHeldBy($player): array
{
if ($player instanceof Player) $player = $player->getName();
return array_filter($this->auctions, function (Auction $auction) use ($player): bool {
return array_filter($this->auctions, static function (Auction $auction) use ($player): bool {
return strtolower($auction->getAuctioneer()) === strtolower($player) && !$auction->hasExpired();
});
}

public function getActiveAuctions(): array
{
return array_filter($this->auctions, function (Auction $auction): bool {
return array_filter($this->auctions, static function (Auction $auction): bool {
return !$auction->hasExpired();
});
}
Expand All @@ -116,7 +116,7 @@ public function getBids(): array
public function getBidsBy($player): array
{
if ($player instanceof Player) $player = $player->getName();
return array_filter($this->getBids(), function (AuctionBid $bid) use ($player): bool {
return array_filter($this->getBids(), static function (AuctionBid $bid) use ($player): bool {
return strtolower($bid->getBidder()) === strtolower($player);
});
}
Expand All @@ -143,10 +143,10 @@ public function updateAuction(Auction $auction): void
$this->plugin->getDatabase()->executeChange("piggyauctions.update", [
"id" => $auction->getId(),
"claimed" => (int)$auction->isClaimed(),
"claimed_bids" => json_encode(array_map(function (AuctionBid $bid) {
"claimed_bids" => json_encode(array_map(static function (AuctionBid $bid) {
return ["bidder" => $bid->getBidder(), "bidamount" => $bid->getBidAmount(), "timestamp" => $bid->getTimestamp()];
}, $auction->getclaimedBids())),
"bids" => json_encode(array_map(function (AuctionBid $bid) {
"bids" => json_encode(array_map(static function (AuctionBid $bid) {
return ["bidder" => $bid->getBidder(), "bidamount" => $bid->getBidAmount(), "timestamp" => $bid->getTimestamp()];
}, $auction->getBids()))
]);
Expand Down
7 changes: 4 additions & 3 deletions src/DaPigGuy/PiggyAuctions/commands/AuctionHouseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
use CortexPE\Commando\args\RawStringArgument;
use CortexPE\Commando\BaseCommand;
use CortexPE\Commando\exception\ArgumentOrderException;
use DaPigGuy\PiggyAuctions\menu\Menu;
use DaPigGuy\PiggyAuctions\menu\pages\AuctioneerMenu;
use DaPigGuy\PiggyAuctions\menu\pages\MainMenu;
use DaPigGuy\PiggyAuctions\PiggyAuctions;
use pocketmine\command\CommandSender;
use pocketmine\Player;
Expand Down Expand Up @@ -43,10 +44,10 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo
$sender->sendMessage(PiggyAuctions::getInstance()->getMessage("commands.no-active-auctions", ["{PLAYER}" => $args["player"]]));
return;
}
Menu::displayAuctioneerPage($sender, $args["player"]);
new AuctioneerMenu($sender, $args["player"]);
return;
}
Menu::displayMainMenu($sender);
new MainMenu($sender);
}

/**
Expand Down
Loading