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..e48be6d 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->pop(); + $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