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

Best way to check sign text?

Comments in 'Plugin Development' started by CrazedMiner, May 22, 2015.

  1. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I was wondering what the best way was to check the text on a sign (I'm pretty sure there's multiple ways :p) as I want as few lines of code as possible. I'm currently using this :
    PHP:
    public function onInteract(PlayerInteractEvent $event) {
            
    $signtext $event->getPlayer()->getLevel()->getTile($this->main->getBlock())->getText();
           
            if(
    $event->getBlock()->getId() == 68) {
                if(
    $signtext[0] == "-join-") {
                    if(
    $signtext[1] == "small") {
                        
    $event->getPlayer()->teleport(new Vector3(1411133));
                    }
                    elseif(
    $signtext[1] == "medium") {
                        
    $event->getPlayer()->teleport(new Vector3(1841128));
                    }
                    elseif(
    $signtext[1] == "large") {
                        
    $event->getPlayer()->teleport(new Vector3(13111, -18));
                    }
                    elseif(
    $signtext[1] == "skyisland") {
                        
    $event->getPlayer()->teleport(new Vector3(207274));
                    }
                    elseif(
    $signtext[1] == "wasteland") {
                        
    $event->getPlayer()->teleport(new Vector3(-47106));
                    }
                    elseif(
    $signtext[1] == "end") {
                        
    $event->getPlayer()->teleport(new Vector3(-628165));
                    }
                    elseif(
    $signtext[1] == "village") {
                        
    $event->getPlayer()->teleport(new Vector3(-1205164));
                    }
                    elseif(
    $signtext[1] == "nether") {
                        
    $event->getPlayer()->teleport(new Vector3(-6813103));
                    }
                }
            }
        }
     
    Thanks :)
  2. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    PHP:
    use pocketmine\tile\Sign;
    use 
    pocketmine\tile\Tile;
        
           if(
    $event->getBlock()->getID() == 323 || $event->getBlock()->getID() == 63 || $event->getBlock()->getID() == 68)
           {
             
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
            
             if(!(
    $sign instanceof Sign))
             {
               return;
             }
          }
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    He asked for checking Sign Text, not just a sign.
  4. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    yes... but checking is after
    PHP:
      if(!($sign instanceof Sign)) { return; }
    there u can check the lines
    PHP:
            $sign $sign->getText();
             
    $i $sign[1];
             
    $i2 $sign[2];
             
    $i3 $sign[3];
    Jon likes this.
  5. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    You forgot $sign[0]
    Jon likes this.
  6. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    -.- i didnt xD

    PHP:
        public function tileupdate(SignChangeEvent $event)
        {

                if(
    $event->getBlock()->getID() == 323 || $event->getBlock()->getID() == 63 || $event->getBlock()->getID() == 68)
                {
                    
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
                      
                    if(!(
    $sign instanceof Sign))
                    {
                        return 
    true;
                    }
                    
    $sign $event->getLines();
                      
                    if(
    $sign[0]=='[Bettkampf]')
                    {
                        if(!
    $event->getPlayer()->isOp())
                        {
                            
    $event->setLine(0,"[Nichtig]");
                            return 
    false;
                        }
                    }
                }
                return 
    true;
          
        }
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
  8. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    I would use switch and case like so
    PHP:
    $lines$sign->getText();
    $ln1 $lines[0];
    switch(
    $ln1) {
    case 
    "Word":

    break;
    case 
    "DiffWord":

    break;
    }
    of course you can change it to do any line on the sign you may like
    Last edited: May 23, 2015
    Xenturio likes this.
  9. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    I am using this code:

    PHP:
    public function playerBlockTouch(PlayerInteractEvent $event){
      if(
    $event->getBlock()->getID() == 323 || $event->getBlock()->getID() == 63 || $event->getBlock()->getID() == 68){
      
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
      if(!(
    $sign instanceof Sign)){
      return;
      }
      
    $sign $sign->getText();
      
    $this->getServer()->loadLevel("PVP");
      if(
    $sign[0]=='[PVP]'){
      if(
    Server::getInstance()->loadLevel("PVP") != false){
      
    $event->getPlayer()->sendMessage("[server] teleporting you to arena...");
      
    $event->getPlayer()->teleport(new Position($x$y$z$this->getServer()->getLevelByName("PVP")));
    }
    }
    Works perfectly for me.
    CrazedMiner likes this.
  10. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Thanks for all your input :)

    I found this code works fastest
    PHP:
    public function onInteract(PlayerInteractEvent $event) {
            
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
            if(
    $event->getBlock()->getId() == 323 || $event->getBlock()->getId() == 63 || $event->getBlock()->getId() == 68) {
                if(
    $sign instanceof Sign) {
                    
    $signtext $sign->getText();
                    if(
    $signtext[0] === "Tap to Join") {
                        if(
    $signtext[1] === "Small PvP") {
                            
    $event->getPlayer()->teleport(new Vector3(1411133));
                            
    $event->getPlayer()->sendMessage("Teleporting you to Small PvP.");
                        }
                        elseif(
    $signtext[1] === "Medium PvP") {
                            
    $event->getPlayer()->teleport(new Vector3(1841128));
                            
    $event->getPlayer()->sendMessage("Teleported you to Medium PvP.");
                        }
                        elseif(
    $signtext[1] === "Large PvP") {
                            
    $event->getPlayer()->teleport(new Vector3(13911, -18));
                            
    $event->getPlayer()->sendMessage("Teleported you to Large PvP.");
                        }
                        elseif(
    $signtext[1] === "Sky Land") {
                            
    $event->getPlayer()->teleport(new Vector3(107274));
                            
    $event->getPlayer()->sendMessage("Teleported you to Sky Islands PvP.");
                        }
                        elseif(
    $signtext[1] === "Nether PvP") {
                            
    $event->getPlayer()->teleport(new Vector3(-6813103));
                            
    $event->getPlayer()->sendMessage("Teleported you to Nether PvP.");
                        }
                        elseif(
    $signtext[1] === "End PvP") {
                            
    $event->getPlayer()->teleport(new Vector3(-628165));
                            
    $event->getPlayer()->sendMessage("Teleported you to End PvP.");
                        }
                        elseif(
    $signtext[1] === "Wasteland PvP") {
                            
    $event->getPlayer()->teleport(new Vector3(-47186));
                            
    $event->getPlayer()->sendMessage("Teleported you to Wasteland PvP.");
                        }
                        elseif(
    $signtext[1] === "Small Village") {
                            
    $event->getPlayer()->teleport(new Vector3(-1205164));
                            
    $event->getPlayer()->sendMessage("Teleported you to Small Village PvP.");
                        }
                    }
                }
            }
        }

Share This Page

Advertisement