Skip to content

Commit

Permalink
Fixed bug with inventory glitching. (Probably #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Muqsit authored Feb 10, 2017
1 parent 1125289 commit 1fdb499
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/ChestShop/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

class EventListener implements Listener{

const DEFAULT_PRICE = 15000;
protected $plugin;

public function __construct(Main $plugin){
Expand Down Expand Up @@ -61,18 +62,19 @@ public function onTransaction(InventoryTransactionEvent $event){
$action = null;
foreach($transactions as $transaction){
if(($inv = $transaction->getInventory()) instanceof CustomChestInventory){
foreach($inv->getViewers() as $assumed)
if($assumed instanceof Player) {
foreach($inv->getViewers() as $assumed){
if($assumed instanceof Player){
$player = $assumed;
$chestinv = $inv;
$action = $transaction;
break;
}
}
}
$action = $transaction;
}

if($chestinv === null) return;
$event->setCancelled();

$item = $action->getTargetItem();

if(isset($item->getNamedTag()->turner)){
Expand All @@ -84,7 +86,7 @@ public function onTransaction(InventoryTransactionEvent $event){

$data = $item->getNamedTag()->ChestShop->getValue() ?? null;
if($data === null) return;
$price = $data[0] ?? 15000;
$price = $data[0] ?? self::DEFAULT_PRICE;
if(!isset($this->plugin->clicks[$player->getId()][$data[1]])){
$this->plugin->clicks[$player->getId()][$data[1]] = 1;
return;
Expand Down

0 comments on commit 1fdb499

Please sign in to comment.