Skip to content

Commit

Permalink
ChestShop v3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Muqsit authored Apr 11, 2017
1 parent 936a201 commit 63fa9fa
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 40 deletions.
6 changes: 4 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name: ChestShop
main: ChestShop\Main
api: [2.0.0, 3.0.0, 3.0.0-ALPHA4]
version: 2.0
api: [2.0.0, 3.0.0, 3.0.0-ALPHA4, 3.0.0-ALPHA5, 3.0.0-ALPHA6]
version: 3.0
depend: [EconomyAPI]
commands:
chestshop:
aliases: ["cs", "cshop"]
permissions:
chestshop.command.opcmd:
default: op
chestshop.command.add:
default: op
chestshop.command.remove:
Expand Down
32 changes: 29 additions & 3 deletions src/ChestShop/Chest/CustomChest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,42 @@
use pocketmine\block\Block;
use pocketmine\level\Level;
use pocketmine\nbt\tag\{CompoundTag, IntTag};
use pocketmine\Player;

class CustomChest extends \pocketmine\tile\Chest{

private $replacement = [0, 0];

public function __construct(Level $level, CompoundTag $nbt){
parent::__construct($level, $nbt);
$this->inventory = new CustomChestInventory($this);
$this->replacement = [$this->getBlock()->getId(), $this->getBlock()->getDamage()];
}

public function getInventory() : CustomChestInventory{
return $this->inventory;
}

private function getReplacement() : Block{
return Block::get(...$this->replacement);
}

public function sendReplacement(Player $player){
$block = $this->getReplacement();
$block->x = floor($this->x);
$block->y = floor($this->y);
$block->z = floor($this->z);
$block->level = $this->getLevel();
if($block->level !== null){
$block->level->sendBlocks([$player], [$block]);
}
}

public function spawnTo(Player $player){
//needless
}

public function getReplacement() : Block{
$replace = $this->namedtag->replace->getValue() ?? [0, 0];
return Block::get($replace[0], $replace[1]);
public function spawnToAll(){
//needless
}
}
8 changes: 1 addition & 7 deletions src/ChestShop/Chest/CustomChestInventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ public function onOpen(Player $who){
}

public function onClose(Player $who){
$pos = $this->holder;//not really "pos".. but our usage definitely makes it a pos.
$block = $pos->getReplacement();
$block->x = floor($pos->x);
$block->y = floor($pos->y);
$block->z = floor($pos->z);
$block->level = $pos->getLevel();
if($who instanceof Player) $block->level->sendBlocks([$who], [$block]);
$this->holder->sendReplacement($who);
parent::onClose($who);
unset(\ChestShop\Main::getInstance()->clicks[$who->getId()]);
$this->holder->close();
Expand Down
18 changes: 14 additions & 4 deletions src/ChestShop/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use ChestShop\Chest\{CustomChest, CustomChestInventory};
use onebone\economyapi\EconomyAPI;

use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\inventory\InventoryTransactionEvent;
use pocketmine\event\Listener;
Expand Down Expand Up @@ -72,23 +73,32 @@ public function onTransaction(InventoryTransactionEvent $event){
}
}

if(($player ?? $chestinv ?? $action) === null){
return;
}

/*
* $player => Player interacting with the GUI.
* $chestinv => The chest's inventory.
* $action => BaseTransaction|Transaction|SimpleTransactionGroup
*/
$event->setCancelled();
$item = ($item = $action->getTargetItem())->getId() === 0 ? $action->getSourceItem() : $item;
$item = $action->getSourceItem();
if($item->getId() === Item::AIR){
return;
}

if(isset($item->getNamedTag()->turner)){
$action = $item->getNamedTag()->turner->getValue();
$page = $action[0] === 0 ? --$action[1] : ++$action[1];
$pagedata = $item->getNamedTag()->turner->getValue();
$page = $pagedata[0] === 0 ? --$pagedata[1] : ++$pagedata[1];
$this->plugin->fillInventoryWithShop($chestinv, $page);
return;
}

$data = isset($item->getNamedTag()->ChestShop) ? $item->getNamedTag()->ChestShop->getValue() : null;
if($data === null) return;
if($data === null){
return;
}

$price = $data[0] ?? $this->plugin->defaultprice;
if(!isset($this->plugin->clicks[$player->getId()][$data[1]])){
Expand Down
Loading

0 comments on commit 63fa9fa

Please sign in to comment.