From 8d9cbcf2ecf7d23b687d4740fa6a46c9b8766dc8 Mon Sep 17 00:00:00 2001 From: "Taylor.R" Date: Sun, 28 May 2023 20:02:37 +0700 Subject: [PATCH 1/2] PM5 Support --- plugin.yml | 2 +- src/Vecnavium/LaunchableTNT/LaunchableTNT.php | 50 ++++--------------- 2 files changed, 10 insertions(+), 42 deletions(-) diff --git a/plugin.yml b/plugin.yml index c621b99..3a80214 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: LaunchableTNT -api: 4.0.0 +api: 5.0.0 main: Vecnavium\LaunchableTNT\LaunchableTNT version: 1.0.2 author: Vecnavium diff --git a/src/Vecnavium/LaunchableTNT/LaunchableTNT.php b/src/Vecnavium/LaunchableTNT/LaunchableTNT.php index a256f03..d24d259 100644 --- a/src/Vecnavium/LaunchableTNT/LaunchableTNT.php +++ b/src/Vecnavium/LaunchableTNT/LaunchableTNT.php @@ -2,19 +2,12 @@ namespace Vecnavium\LaunchableTNT; +use pocketmine\block\TNT; +use pocketmine\entity\Location; use pocketmine\plugin\PluginBase; use pocketmine\event\player\PlayerItemUseEvent; -use pocketmine\entity\Entity; -use pocketmine\item\ItemIds; -use pocketmine\math\Vector3; use pocketmine\event\Listener; -use pocketmine\event\entity\EntityExplodeEvent; use pocketmine\entity\object\PrimedTNT; -use pocketmine\nbt\tag\CompoundTag; -use pocketmine\nbt\tag\DoubleTag; -use pocketmine\nbt\tag\FloatTag; -use pocketmine\nbt\tag\ListTag; -use pocketmine\world\Position; class LaunchableTNT extends PluginBase implements Listener{ @@ -28,43 +21,18 @@ public function checkUpdate(bool $isRetry = false): void { $this->getServer()->getAsyncPool()->submitTask(new CheckUpdateTask($this->getDescription()->getName(), $this->getDescription()->getVersion())); } - - public function onExplode(EntityExplodeEvent $event): void - { - foreach ($event->getBlockList() as $block) { - if ($block->isSolid()) { - $nbt = self::createBaseNBT($block->getPosition()); - $nbt->setInt("TileID", $block->getId()); - $nbt->setByte("Data", $block->getMeta()); - } - } - } - public function onClick(PlayerItemUseEvent $event): void { $player = $event->getPlayer(); - if ($player->getInventory()->getItemInHand()->getId() === ItemIds::TNT) { - $entity = new PrimedTNT($player->getLocation(), self::createBaseNBT($player->getPosition())); + $item = $player->getInventory()->getItemInHand(); + if ($item->getBlock() instanceof TNT) { + if ($player->isSurvival()) { + $item->setCount($item->getCount() - 1); + $player->getInventory()->setItemInHand($item); + } + $entity = new PrimedTNT(Location::fromObject($player->getPosition()->asVector3(), $player->getWorld())); $entity->setMotion($player->getDirectionVector()->normalize()->multiply(2)); $entity->spawnToAll(); } } - - private static function createBaseNBT(Position $pos, ?Vector3 $motion = null, float $yaw = 0.0, float $pitch = 0.0): CompoundTag { - return CompoundTag::create() - ->setTag("Pos", new ListTag([ - new DoubleTag($pos->x), - new DoubleTag($pos->y), - new DoubleTag($pos->z) - ])) - ->setTag("Motion", new ListTag([ - new DoubleTag($motion !== null ? $motion->x : 0.0), - new DoubleTag($motion !== null ? $motion->y : 0.0), - new DoubleTag($motion !== null ? $motion->z : 0.0) - ])) - ->setTag("Rotation", new ListTag([ - new FloatTag($yaw), - new FloatTag($pitch) - ])); - } } \ No newline at end of file From 5e283b8ffcbcf93da085b40b77ae6120f24713c7 Mon Sep 17 00:00:00 2001 From: "Taylor.R" Date: Fri, 2 Jun 2023 07:48:38 +0700 Subject: [PATCH 2/2] Clean Code --- src/Vecnavium/LaunchableTNT/LaunchableTNT.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Vecnavium/LaunchableTNT/LaunchableTNT.php b/src/Vecnavium/LaunchableTNT/LaunchableTNT.php index d24d259..e48be6d 100644 --- a/src/Vecnavium/LaunchableTNT/LaunchableTNT.php +++ b/src/Vecnavium/LaunchableTNT/LaunchableTNT.php @@ -27,7 +27,7 @@ public function onClick(PlayerItemUseEvent $event): void $item = $player->getInventory()->getItemInHand(); if ($item->getBlock() instanceof TNT) { if ($player->isSurvival()) { - $item->setCount($item->getCount() - 1); + $item->pop(); $player->getInventory()->setItemInHand($item); } $entity = new PrimedTNT(Location::fromObject($player->getPosition()->asVector3(), $player->getWorld()));