1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

send BossBar

Discussion in 'Development' started by freakingdev, Apr 30, 2017.

  1. freakingdev

    freakingdev Spider Jockey

    Messages:
    33
    GitHub:
    imjayl
    What is the format for this?
     
  2. WreckagePE / ZAYD

    WreckagePE / ZAYD Slime

    Messages:
    82
    You must use a custom API for this.
    PocketEssential have created an API, which you can find here: https://github.com/PocketEssential/BossBarAPI

    PHP:
    // First you"ll need this
    use PocketEssential\BossBarAPI\BossBarAPI;

    // You can also do:

    $BossBarAPI BossBarAPI::getInstance();
    Sending bossbar
    PHP:
    $message "This is a BossBar message";

    $BossBarAPI->setBarMessage($message);

    /*
     Player should an instance of a PLAYER, Just foreach loop all the online players; etc
     */

    $BossBarAPI->sendBossBar($player);
     
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    Or you can make a libary based off that instead of hard depending on other plugins
     
    Irish, corytortoise and Sandertv like this.
  4. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    Nop you can send packets manually too
     
    corytortoise likes this.
  5. freakingdev

    freakingdev Spider Jockey

    Messages:
    33
    GitHub:
    imjayl
    How to that?
     
  6. freakingdev

    freakingdev Spider Jockey

    Messages:
    33
    GitHub:
    imjayl

    Thanks ill try it
     
    WreckagePE / ZAYD likes this.
  7. Lowkey

    Lowkey Slime

    Messages:
    94
    It is possible to send packets, but I think he was trying to give OP a faster way.

    For anyone that wanted to know how to do this manually and create an API themself, here's how.

    PHP:
    use pocketmine\item\Item;
    use 
    pocketmine\network\protocol\AddPlayerPacket;
    use 
    sys\jordan\utils\BossEventPacket;
    use 
    pocketmine\network\protocol\MovePlayerPacket;
    use 
    pocketmine\network\protocol\SetEntityDataPacket;
    use 
    pocketmine\Player;
    use 
    pocketmine\network\protocol\RemoveEntityPacket;
    use 
    pocketmine\Server;
    use 
    pocketmine\network\protocol\AddEntityPacket;
    use 
    pocketmine\entity\Entity;
    use 
    pocketmine\utils\UUID;

    class 
    BossBar {

        private 
    $plugin;

        public function 
    __construct(Main $plugin){
            
    $this->plugin $plugin;
        }

        public function 
    addBar(array $players null){
            if(empty(
    $players)){
                
    $players $this->plugin->getPlayers();
            }
            
    $eid Entity::$entityCount++;
            
    $aepkt = new AddEntityPacket();
            
    $aepkt->metadata = [Entity::DATA_LEAD_HOLDER => [Entity::DATA_TYPE_LONG, -1], Entity::DATA_FLAG_SILENT => [Entity::DATA_TYPE_BYTE1], Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT0],
                
    Entity::DATA_BOUNDING_BOX_WIDTH => [Entity::DATA_TYPE_FLOAT0], Entity::DATA_BOUNDING_BOX_HEIGHT => [Entity::DATA_TYPE_FLOAT0]];
            
    $aepkt->eid Entity::$entityCount++;
            
    $aepkt->type 52;
            
    $aepkt->yaw 0;
            
    $aepkt->pitch 0;
            foreach(
    $players as $player){
                
    $ppkt = clone $aepkt;
                
    $ppkt->$player->x;
                
    $ppkt->$player->y;
                
    $ppkt->$player->z;
                
    $player->dataPacket($ppkt);
            }
            
    $pk = new BossEventPacket();
            
    $pk->state 0;
            
    $pk->eid Entity::$entityCount++;
            
    Server::getInstance()->broadcastPacket($players$pk);
            return 
    $eid;
        }


        public function 
    setTitle(int $eidstring $string){
            
    $players $this->plugin->getServer()->getOnlinePlayers();
            
    $pk = new SetEntityDataPacket();
            
    $pk->metadata = [Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING$string]];
            
    $pk->eid $eid;
            
    Server::getInstance()->broadcastPacket($players$pk);
            
    $pkt = new BossEventPacket();
            
    $pkt->eid $eid;
            
    $pkt->state 500;
            
    Server::getInstance()->broadcastPacket($players$pkt);

        }
    }
    // You should probably use a task also. I will post this in the resources forum later.
    [/SPOILER]
     
  8. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    But nobody else can use this method, because they don't have a BossEventPacket class. Also, your class paths aren't compatible with the current master branch of PMMP.
     
  9. Lowkey

    Lowkey Slime

    Messages:
    94
    I really should've thought about that. Silly me, editing now and I will include BossEventPacket. Why isn't it compatible though?
     
  10. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    There were some changes in PMMP that involves packets. The correct path for AddPlayerPacket, for example, would be: pocketmine\network\mcpe\protocol\AddPlayerPacket.
     
  11. Lowkey

    Lowkey Slime

    Messages:
    94
    Wow... any reasons why they changed the path?
     
  12. Lowkey

    Lowkey Slime

    Messages:
    94
    I've made a thread on resources. Currently awaiting approval from a moderator
     
  13. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I assume it was because the former was a mess. This way network classes can be separated, since there are network classes for mcpe protocol, and for the raklib/etc. stuff. It's neater now, but there may be other reasons for the change I don't know about.
     
    Lowkey likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.