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

Sign Interact?

Comments in 'Plugin Development' started by Legoboy0215, Jul 1, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    This code does not work. No errors while interacting too...
    PHP:
        public function onTouch(PlayerInteractEvent $event){
            
    $sign $event->getBlock();
            
    $player $event->getPlayer();
            
    $playern $event->getPlayer()->getName();
            if(
    $sign instanceof Sign){
            
    $signtile $event->getPlayer()->getLevel()->getTile($event->getBlock());
                
    $text $signtile->getText();
                if(
    $text[0] === '[Parkour]'){
                    if(
    $signtile->getLevel()->getName() == "parkour") {
                    
    $this->getServer()->broadcastMessage(TextFormat::RED $playern " won the parkour!!! He earned 1000$...");
                    
    $this->api->addMoney($player1000);
                }
            }
        }
    }
    onEnable is here:
    PHP:
        public function onEnable(){
                
    $this->getServer()->getPluginManager()->registerEvents($this$this);
                
    $this->getLogger()->info("XXXXXXXXXX");
            
    $this->api EconomyAPI::getInstance();
              if (!
    $this->api) {
                
    $this->getLogger()->info(TextFormat::RED."Unable to find EconomyAPI.");
                return 
    true;
        }
    }
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Signtile should be instanceof Sign
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Ok...
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    PHP:
        public function onTouch(PlayerInteractEvent $event){
            
    $signtile $event->getPlayer()->getLevel()->getTile($event->getBlock());
            
    $player $event->getPlayer();
            
    $playern $event->getPlayer()->getName();
            if(
    $signtile instanceof Sign){
                
    $text $signtile->getText();
                if(
    $text[0] === '[Parkour]'){
                    if(
    $signtile->getLevel()->getName() == "parkour") {
                    
    $this->getServer()->broadcastMessage(TextFormat::RED $playern " won the parkour!!! He earned 1000$...");
                    
    $this->api->addMoney($player1000);
                }
            }
        }
    }
    ???
  5. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Try this
    PHP:
    public function onInteract(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) {
                
    $signtext $sign->getText();
                if(
    $signtext[0] === "[Parkour]") {
                    if(
    $sign->getLevel()->getName() === "parkour") {
                        
    $this->getServer()->broadcastMessage(TextFormat::RED $event->getPlayer()->getName() . " won the parkour!!! They earned $1000...");
                        
    $this->api->addMoney($player1000);
                    }
                }
            }
        }
    }

    and make sure the world's name is parkour with no capital letters.
    Last edited: Jul 1, 2015
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I think it should be $signtext[0]
  7. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    yah, oops :p
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Why do you check whether it's a sign twice? Also, a placed sign cannot be an Item. And yes, it's $signtext[0]
    Legoboy0215 likes this.
  9. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    It's just the way I've always done it, remove the item from the if statement.
  10. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    If it makes u happy
    PHP:
    public function onInteract(PlayerInteractEvent $event) {
        if(
    $event->getBlock()->getId() == 63 || $event->getBlock()->getId() == 68) {
            
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
            
    $signtext $sign->getText();
            if(
    $signtext[0] === "[Parkour]") {
                if(
    $sign->getLevel()->getName() === "parkour") {
                    
    $this->getServer()->broadcastMessage(TextFormat::RED $event->getPlayer()->getName() . " won the parkour!!! They earned $1000...");
                    
    $this->api->addMoney($player1000);
                }
            }
        }
    }

  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You have to ensure $sign is an instance of \pocketmine\tile\Sign.
    The first check optimizes performance by only trying to retrieve the tile object if the block is a sign block. The second check makes sure that the tile for that sign has been initialized.
    CrazedMiner likes this.
  12. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I knew I did the double check for a reason :p
  13. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You told me once that I don't need the check with the IDs.
  14. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    The check with ID's just eliminates things that aren't tiles and in theory speeds up the process of checking the Sign, I'm guessing.
    PEMapModder likes this.
  15. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Oh... So the process is to check id, the check is the tile blahblahed?
  16. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Checking the ID only leaves signs and signs are tiles so when instanceof Sign is called there's only one type of tile.
    Legoboy0215 likes this.
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    First check: whether that block is a sign block
    Second check: whether that block is associated with a sign tile.
    Andrey Nazarchuk and CrazedMiner like this.

Share This Page

Advertisement