Skip to content

Provides a easier utility to send PlaySoundPackets

License

Notifications You must be signed in to change notification settings

presentkim-pm/play-sound-utils

Repository files navigation

Poggit CI Stars License


Logo

play-sound-utils

Provides utils for send `PlaySoundPacket` shorter and easier!

View in Poggit · Report a bug · Request a feature

About The Project

This virion was developed to streamline the boilerplate code required to send sounds by their string names using PlaySoundPacket. It supports implementations of the Sound interface that can be used with World::addSound(), and also provides utility methods for sending packets directly.


How to use?

1. Create PlaySound object for World::addSound()

use pocketmine\math\Vector3;
use pocketmine\world\World;
use kim\present\utils\playsound\PlaySound;

function sendLevelUpSound(World $world, Vector3 $vec) : void{
    $world->addSound($vec, new PlaySound("random.levelup"));
}

2. Create PlaySoundPacket object for Player::sendDataPacket()

use pocketmine\math\Vector3;
use pocketmine\player\Player;
use kim\present\utils\playsound\PlaySound;

function sendLevelUpSound(Player $player, Vector3 $vec) : void{
    $player->getNetworkSession()->sendDataPacket(
        PlaySound::createPacket($vec, "random.levelup")
    );
}

3. Send PlaySoundPacket via static util method

use pocketmine\math\Vector3;
use pocketmine\player\Player;
use kim\present\utils\playsound\PlaySound;

function sendLevelUpSound(Player $player, Vector3 $vec) : void{
    PlaySound::sendTo($player, "random.levelup");
}

4. Using VanillaPlaySounds for World::addSound()

use pocketmine\math\Vector3;
use pocketmine\world\World;
use kim\present\utils\playsound\VanillaPlaySounds;

function sendLevelUpSound(World $world, Vector3 $vec) : void{
    $world->addSound($vec, VanillaPlaySounds::LEVELUP());
}

Installation

See Official Poggit Virion Documentation


License

Distributed under the MIT. See LICENSE for more information

About

Provides a easier utility to send PlaySoundPackets

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages