Created
March 4, 2021 14:01
-
-
Save Muqsit/d0dca479cdcdbc48711ec42ee5a86e79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
/** | |
* @name InventoryTransactionEventTest | |
* @main muqsit\testing\InventoryTransactionEventTest | |
* @api 4.0.0 | |
* @version 0.0.1 | |
*/ | |
namespace muqsit\testing{ | |
use pocketmine\block\VanillaBlocks; | |
use pocketmine\command\Command; | |
use pocketmine\command\CommandSender; | |
use pocketmine\command\PluginCommand; | |
use pocketmine\event\inventory\InventoryTransactionEvent; | |
use pocketmine\event\Listener; | |
use pocketmine\player\Player; | |
use pocketmine\plugin\PluginBase; | |
final class InventoryTransactionEventTest extends PluginBase implements Listener{ | |
protected function onEnable() : void{ | |
$this->getServer()->getPluginManager()->registerEvents($this, $this); | |
$this->getServer()->getCommandMap()->register($this->getName(), new PluginCommand("itetest", $this, $this)); | |
} | |
public function handleInventoryTransaction(InventoryTransactionEvent $event) : void{ | |
$event->cancel(); | |
} | |
public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{ | |
if($sender instanceof Player){ | |
$sender->sendMessage("Placing chest at your location!"); | |
$pos = $sender->getPosition(); | |
$pos->getWorld()->setBlock($pos->floor(), VanillaBlocks::CHEST()); | |
$pos->getWorld()->getTile($pos->floor())->getInventory()->addItem(VanillaBlocks::BLACK_STAINED_GLASS_PANE()->asItem()); | |
} | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment