Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Deleting FloatingTextParticle don't works

Comments in 'Plugin Development' started by sero583, May 9, 2016.

  1. sero583
    Offline

    sero583 New Member

    Joined:
    May 6, 2016
    Posts:
    6
    Minecraft User:
    sero583
    Hey guys, i know that such threads already exsist, but none of them are helpful anyways.
    So i were trying to use on a FloatingTextParticle Object setInvisible(true); but nothing happend. No errors came, but the FloatingTextParticle didn't gone too. Please help ASAP anyone, thanks for any help!

    Im running on ClearSky version 1.1 "Sunrise" (API 1.13.1), Build 427

    My not working code:

    PHP:
    <?php

    namespace sero583\FloatingTextParticleTest;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\level\particle\FloatingTextParticle;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\TextFormat;

    class 
    main extends PluginBase implements Listener {
        public 
    $holos = [];

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getLogger()->info(TextFormat::DARK_GREEN "FloatingParticleTest loaded!");
        }

        public function 
    onJoin(PlayerJoinEvent $event){
            
    $player $event->getPlayer();

            
    $holo = new FloatingTextParticle($this->getServer()->getDefaultLevel()->getSafeSpawn(), TextFormat::GREEN "WOOORKK!!!!"TextFormat::BLUE "FINNALLLY!!!!");
            
    $player->getLevel()->addParticle($holo, [$player]);
            
    $this->holos[$player->getName()] = $holo;
        }

        public function 
    onDie(PlayerDeathEvent $event){
            
    $player $event->getEntity();
           
            
    $this->holos[$player->getName()]->setInvisible(true);
            unset(
    $this->holos[$player->getName()]);
        }
    }
    ?>
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You are not PocketMine user.

    Anyway, shouldn't it be setVisible(false). Well it's basic english after all :p
    sero583 likes this.
  3. sero583
    Offline

    sero583 New Member

    Joined:
    May 6, 2016
    Posts:
    6
    Minecraft User:
    sero583
    @Primus Well, if the PocketMine App would run on PHP 7.0 i would surely use it, but it does not... :/
  4. sero583
    Offline

    sero583 New Member

    Joined:
    May 6, 2016
    Posts:
    6
    Minecraft User:
    sero583
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Was that challenge for me to update it? o_O Ok, ok, I know it wasn't but it's good idea anyway :D

    Back on topic. Create new Text particle class yourself which would implement functions you need.

    Edit: Try calling FloatingTextParticle::encode() after setting invisibility to true.
    PHP:
    $particle->setInvisible(true);
    $particle->encode();
    Last edited: May 9, 2016
    sero583 likes this.
  6. sero583
    Offline

    sero583 New Member

    Joined:
    May 6, 2016
    Posts:
    6
    Minecraft User:
    sero583
    @Primus So i've tried it with that FloatingTextParticle::encode(); but still the same problem. Nothing happens.

    Edit: The Challenge, if you would do it, it would be really cool from you! :)
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I'll see what I can after I finish school ;)

    I figured it out. FloatingTextParticle::encode() returns an array containing DataPackets you need to broadcast them.
    PHP:
    $particle->setInvisible(true);
    foreach(
    $particle->encode() as $pk){
        
    $this->getServer()->broadcastPacket($this->getServer()->getOnlinePlayers(), $pk); // Fixed @sero583 
        // or $player->dataPacket($pk);
    }
    Last edited: May 9, 2016
    sero583 likes this.
  8. sero583
    Offline

    sero583 New Member

    Joined:
    May 6, 2016
    Posts:
    6
    Minecraft User:
    sero583
    @Primus Thanks alot, it works fine!!! :D
    Thanks for your help! :)

    For anyone who had the same problem and landed here, if you do FloatingTextParticle::setText(); or other things you'll need to send again a packet to the player, to update it.

    You can send the packet with @Primus solution, but don't forget, in:
    PHP:
     Sever::broadcastPacket($player$packet);
    to give the player/-s object/-s, who will recieve the packet, if you want that everyone should recieve it, then do:
    PHP:
     $this->getServer()->broadcastPacket($this->getServer()->getOnlinePlayers(), $pk);


    @Primus forgot to do it in his solution, so i wanted to show attention for it :p
    Primus likes this.

Share This Page

Advertisement