1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved TypeError

Discussion in 'Development' started by SJames, May 2, 2019.

  1. SJames

    SJames Spider Jockey

    Messages:
    35
    GitHub:
    sjamese
    Hello,
    I made a plugin that should should work like that... so i type the command /up (y) and i should get teleported to that y coordination and the plugin should place a glass block under my feet. I am getting some errors.. Please look over the whole main file and tell me what I am doing wrong.
    PHP:
    <?php
    namespace SJames\UpCommand;

    use 
    pocketmine\Blocks;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Server;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\utils\TextFormat as c;use pocketmine\Vector3;

    class 
    Main extends PluginBase {
        public function 
    onEnable(){
        }
        public function 
    onCommand(CommandSender $playerCommand $cmdString $label, array $args) :bool {
            switch(
    $cmd->getName()){
                case 
    "up" ;
                    if(!(
    $player instanceof Player)){
                      
    $sender->sendMessage("Please run this command in-game.");
                    }else{
                      
    $x $player->getX();
                      
    $z $player->getZ();
                      
    $level $player->getLevel();
                      
    $y $args[0];
                      if(
    is_numeric($y)) {
                       
    $player->teleport(new Position($x$y$z));
                       
    $level->setBlock(new Position($x$y-1$z), new Glass(), false);
                       } else {
                        
    $sender->sendMessage("Usage: /up {y-coordinates}");
                        return 
    true;
    }
    }
    }
    }
    }
     
  2. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    PHP:
    [/COLOR][/SIZE][/LEFT]
    [SIZE=4][COLOR=rgb(20, 20, 20)][LEFT]<?php
    namespace SJames\UpCommand;

    use 
    pocketmine\Blocks;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Server;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\utils\TextFormat as c;use pocketmine\Vector3;

    class 
    Main extends PluginBase {
        public function 
    onEnable(){
        }
        public function 
    onCommand(CommandSender $playerCommand $cmdString $label, array $args) :bool {
            switch(
    $cmd->getName()){
                case 
    "up" ;
                    if(!(
    $player instanceof Player)){
                      
    $sender->sendMessage("Please run this command in-game.");
                    }else{
                      
    $x $player->getX();
                      
    $z $player->getZ();
                      
    $level $player->getLevel();
                      
    $y $args[0];
                      if(
    is_numeric($y)) {
                       
    $player->teleport(new Position($x$y 1$z));
                       
    $level->setBlock(new Position($x, (int)$y$z), Block::get(Block::GLASS), false);
                       } else {
                        
    $sender->sendMessage("Usage: /up {y-coordinates}");
                        return 
    true;
    }
    }
    }
    }
    }




    block should be placed where value specified, to avoid bounds glitching, you teleport the player one block above the given value

    you should use Block::get() to get instances of blocks
     
  3. SJames

    SJames Spider Jockey

    Messages:
    35
    GitHub:
    sjamese
    Thanks. But is isn't working still. I do not understand.. the error says that the pocketmine\Block is missing but I have it "use pocketmine\blocks", "use pocketmine\block" doesn't work eather
    Error: "Class 'pocketmine\Block' not found" (EXCEPTION) in "plugins/UpCommand/src/SJames/UpCommand/Main" at line 29
     
  4. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    add this:
    Code:
    use pocketmine\block\Block;
    EDIT: Also remove 'pocketmine\Blocks'
     
    SJames likes this.
  5. SJames

    SJames Spider Jockey

    Messages:
    35
    GitHub:
    sjamese
    Thanks
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.