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

How can I check if the player teleport to an another world? [FloatingText]

Comments in 'Plugin Development' started by cake23, Feb 18, 2016.

  1. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    How can I check if the player teleport to an another world?
    I add new FloatingTextParticle if the player joins the world. But how can I remove them, if the player teleports to an another world? Because the FloatingTextParticle are also in the another worlds.. :/ Can anyone help me?
    Thanks! :oops:
    Philipp likes this.
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    EntityLevelChangeEvent
    cake23, PocketKiller and Philipp like this.
  3. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Thanks! I will try it out :3
  4. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    Check out this hologram class that I use for my network:

    http://github.com/Samueljh1/Darkhammer-Open-Source-Classes/blob/master/Hologram/Hologram.php

    You can then do this:

    PHP:
    function onSwitchLevel(EntityTeleportEvent $event) {

        
    $player $event->getEntity();

        if(
    $player instanceof Player) {

            
    $from $event->getFrom();
            
    $to $event->getTo();

            
    //Workaround for holograms showing on other worlds
            
    if($from->getLevel() !== $to->getLevel()) {
        
                
    /** @var Hologram $hologram */
                
    foreach(Hologram::$holograms as $hologram) {

                    if (
    $hologram->getLevel() !== $to->getLevel()) {
                        
    $hologram->setInvisible(true$player);
                    } else {
                        
    $hologram->setInvisible(false$player);
                    }

                }

            }
        }
    }
    Philipp likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    StaticClass::$arrayProperty = bad practice
  6. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    How else could I store it? Within the plugin class?
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yep.
  8. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    How can I remove the FloatingTextParticle for only a player? So I mean not remove the FloatingTextParticle for all players. Only for one.
    Thanks!
  9. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    Look at my post above and add the hologram class. You can then do
    PHP:
    $hologram->setInvisible(true$player);
    cake23 likes this.
  10. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    I've made an big floatingtextmanager with @Samualjh's class:
    Here is the function "updateAllFloatingTexts", wich has to be run on LevelChange (You can also run it with NO parameters, to update them if you added an new
    PHP:
    public function updateAllFloatingTexts($playerLevelArray NULL){
            
    $this->hideAllFTPs();
            if(
    $playerLevelArray == NULL){
                
    $this->showAllFTPs();
            }else{
                foreach(
    $this->floatingTextConfig->getAll() as $configFT){
                    
    $configFT $configFT[0];
                    
    $this->FloatingTexts[$this->IndexFTC] = new FloatingText($this$this->getServer()->getLevelByName($configFT[0]), new Vector3($configFT[1], $configFT[2], $configFT[3]), $configFT[4]);
                    if(isset(
    $this->FloatingTexts)){
                        foreach(
    $this->getServer()->getOnlinePlayers() as $player){
                            foreach(
    $this->FloatingTexts as $FloatingTextObject){
                                if(!isset(
    $playerLevelArray[$player->getName()])){
                                    
    $playerLevel $player->getLevel()->getName();
                                }else{
                                    
    $playerLevel $playerLevelArray[$player->getName()];
                                }
                                
    $FloatingTextLevel $FloatingTextObject->getLevel()->getName();
                                if(
    $playerLevel == $FloatingTextLevel){
                                    
    $FloatingTextObject->update($player);
                                    
    //echo("Re-Created "."PlayerLevel: ".$playerLevel." FTPLevel: ".$FloatingTextLevel." ");
                                
    }
                            }
                        }
                    }
                    
    $this->IndexFTC++;
                }
            }
        }

        public function 
    hideAllFTPs(){
            if(isset(
    $this->FloatingTexts)){
                foreach(
    $this->FloatingTexts as $FloatingTextObject){
                    
    $FloatingTextObject->setInvisible(true);
                }
            }
            unset(
    $this->FloatingTexts);
            
    $this->IndexFTC 0;
        }

        public function 
    showAllFTPs(){
            foreach(
    $this->floatingTextConfig->getAll() as $configFT){
                
    $configFT $configFT[0];
                
    $this->FloatingTexts[$this->IndexFTC] = new FloatingText($this$this->getServer()->getLevelByName($configFT[0]), new Vector3($configFT[1], $configFT[2], $configFT[3]), $configFT[4]);
                if(isset(
    $this->FloatingTexts)){
                    foreach(
    $this->getServer()->getOnlinePlayers() as $player){
                        foreach(
    $this->FloatingTexts as $FloatingTextObject){
                            
    $playerLevel $player->getLevel()->getName();
                            
    $FloatingTextLevel $FloatingTextObject->getLevel()->getName();
                            if(
    $playerLevel == $FloatingTextLevel){
                                
    $FloatingTextObject->update($player);
                                
    //echo("Re-Created "."PlayerLevel: ".$playerLevel." FTPLevel: ".$FloatingTextLevel." ");
                            
    }
                        }
                    }
                }
                
    $this->IndexFTC++;
            }
        }
    The call code:
    PHP:
        public function LevelChangeEvent(EntityLevelChangeEvent $event){
            if(
    $event->getEntity() instanceof Player){
                
    $playerLevel[$event->getEntity()->getName()] = $event->getTarget();
                
    $this->updateAllFloatingTexts($playerLevel);
            }
    }
    Oh yeah, and the add code:
    PHP:
    [SPOILER]
                
    $parsedTFArray = array([$level$pos1$pos2$pos3"TEXT");
                
    $this->floatingTextConfig->set($this->IndexFTC$parsedTFArray);
                
    $this->floatingTextConfig->save();
                unset(
    $this->BlockFTP[$event->getPlayer()->getName()]);
                
    $this->IndexFTC++;
                
    $this->updateAllFloatingTexts();
    [/SPOILER]
    $this->FloatingTexts is an empty class property
    and $this->floatingTextConfig is an Config instance
  11. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Thanks, but it doesent work for me. :/

    If a player join the server, I add the FloatingTextParticle on my Spawn.
    PHP:
    public function onJoin(PlayerJoinEvent $event) {
    $particle = new FloatingTextParticle(new Vector3(127.57108.8), Color::WHITE."Teeeeeeeeest\n Test!"$this->anfang.Color::YELLOW."T".Color::GOLD."est".$this->anfang);
    $this->getServer()->getDefaultLevel()->addParticle($particle);
    }
    So now if the player teleports to an another world, the FloatingTextParticle should be invisible for the player. But all another players should see the FloatingTextParticle. If I add the FloatingTextParticle on the Default Level, all players can see the FloatingTextParticle in another worlds, too.
    (And if the players comes back to the spawn, the FloatingTextParticle are visible for the player)
    I already tried this:
    PHP:
    public function onLevelChange(EntityLevelChangeEvent $event) {
    $player $event->getEntity();
    if(
    $player instanceof Player) {
    $particle = new FloatingTextParticle(new Vector3(127.57108.8), Color::WHITE."Teeeeeeeeeeeeeest\n Test!"$this->anfang.Color::YELLOW."T".Color::GOLD."est".$this->anfang);
    $this->getServer()->getDefaultLevel()->addParticle($particle);
    $particle->setInvisible(true$player);
    }
    }
    But it doesnt work. I dont know what i make wrong...i am sorry. The FloatingTextParticle are visible after the Player change the level..
    Can anyone help me? Thanks! :oops:
  12. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    this is because you are spawning a new particle object. Define it in onEnable and then access it in onLevelChange.
  13. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Okay I will try it out, thanks!
  14. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    No one noticed my post lol
  15. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Where should I add the Code? :D In the EntityLevelChangeEvent function or showAllFTPs function? :oops:
  16. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    The first spoiler shows complete code, including the event
    The secound code you should call if you want to create a new FTP, and the call updateAllFloatingTexts() with no parameters
    You need to use @Samueljh1's class
  17. LCraftPE
    Offline

    LCraftPE New Member

    Joined:
    Nov 16, 2014
    Posts:
    30
    Minecraft User:
    LCraftPE
    It doesn't work...
  18. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    This is much better solution.
    idk FloatingTextParticle is bugged in 0.15
  19. LCraftPE
    Offline

    LCraftPE New Member

    Joined:
    Nov 16, 2014
    Posts:
    30
    Minecraft User:
    LCraftPE
    You know if they work with Genisys? Clear sky? PocketMine?
  20. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    PocketMine has that bug, but unofficially copies not

Share This Page

Advertisement