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

What is wrong with this code?

Comments in 'Plugin Development' started by Hittmana, Apr 17, 2016.

  1. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    I have been working on a plugin and it doesn't work (obviously). I have tried to fix it several times but to no avail. Here is the code:
    PHP:
    <?php

    namespace Hittmana\VipGate;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerMoveEvent;

    class 
    MainClass extends PluginBase implements Listener
    {
      public function 
    onEnable()
            {
            
    $this->getLogger()->info("VipGate enabled v1.0.0");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            }
        public function 
    onDisable()
            {
            
    $this->getLogger()->info("VipGate disabled v1.0.0");
            }  
        public function 
    onMove(PlayerMoveEvent $event)
            {
            
    $player $event->getPlayer();
            
    $block $player->getLevel()->getBlock($player->floor()->subtract(01));
            if (
    $block == "activator_rail" or $block == "126")
                {
                    
    $event->getPlayer()->teleport($this->getServer()->getLevelByName()->getSafeSpawn());
                }
            }
        }   
    And here is the error:
    Code:
    Could not pass event 'pocketmine\event\player\PlayerMoveEvent' to 'VipGate v1.0.0': Method pocketmine\block\ActivatorRail::__toString() must return a string value on Hittmana\VipGate\MainClass
    2016-04-17 [08:40:30] [Server thread/NOTICE]: RuntimeException: "Method pocketmine\block\ActivatorRail::__toString() must return a string value" (E_RECOVERABLE_ERROR) in "/VipGate_v1.0.0.phar/src/HittmanA/VipGate/MainClass" at line 26
    Please help!
  2. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    applqpak and Primus like this.
  3. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
  4. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    I changed it to
    PHP:
    $block $player->getLevel()->getId($player->floor()->subtract(01));
    And now it does nothing, it doesn't even send anything to the console.
    Last edited: Apr 18, 2016
  5. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Anyone?
  6. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    Block->getId()
  7. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Where?
  8. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    First, you need to get the block first:
    PHP:
    $block $player->getLevel()->getBlock(new Vector3($player->getFloorX(), $player->getFloorY() - 1$player->getFloorZ()));
    Then, check if id = 126:
    PHP:
    $block $player->getLevel()->getBlock(new Vector3($player->getFloorX(), $player->getFloorY() - 1$player->getFloorZ()));
    if(
    $block->getId() == 126){

    }
    Last, tp player to level:
    PHP:
    $block $player->getLevel()->getBlock(new Vector3($player->getFloorX(), $player->getFloorY() - 1$player->getFloorZ()));
    if(
    $block->getId() == 126){
         
    $player->teleport($this->getServer()->getLevelByName("Name")->getSafeSpawn());
    }
    You have to use /pocketmine/math/Vector3
    Primus and Vaivez66 like this.
  9. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Ohhh Ok thanks!

Share This Page

Advertisement