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

Illegal offset type in isset or empty in phar

Discussion in 'Development' started by InspectorGadget, May 6, 2017.

  1. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Hi! I'm fixing and changing stuffs on this WorldBorder plugin, i need help with the config..

    Thanks


    PHP:
    <?php

    namespace WorldBorder;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\math\Vector3 as Vector3;
    use 
    pocketmine\math\Vector2 as Vector2;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;

    class 
    WorldBorder extends PluginBase implements Listener{
       
        public 
    $config;
        public 
    $spawn;
       
        public function 
    onEnable(){
            @
    mkdir($this->getDataFolder());

            
    $this->config = new Config($this->getDataFolder() . "config.yml"Config::YAML, [
            
    "message" => "This is end of world"
            
    ]);
       
            
    $this->getLogger()->info(TextFormat::DARK_GREEN."WorldBorder Loaded!");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
       
        public function 
    onDisable(){
            
    $this->getLogger()->info(TextFormat::DARK_RED."WorldBorder Unloaded!");
        }
           
            public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){ 
               
                switch (
    strtolower($command->getName())) {
                   
                    case 
    "worldborder":
                       
                        if (
    $sender->hasPermission("worldborder.command.worldborder")) {
                           
                            if (isset(
    $args[0])) {
                               
                                switch (
    strtolower($args[0])) {
                                   
                                    case 
    "add":
                                       
                                        if (isset(
    $args[1]) && isset($args[2])) {
                                           
                                            if (
    $this->getServer()->isLevelLoaded($args[1])) {
                                                
    $worlds $this->config->get("worlds");
                                                
    //if ($args[2] > 199) {
                                                    
    $this->config->set($args[1], ['blocks' => $args[2]]); 
                                                    
    $this->config->save();
                                                    
    $sender->sendMessage("[WorldBorder] You border world: ".$args[1]." in: ".$args[2]." blocks.");
                                                
    //} else {
                                                    //$sender->sendMessage("[WorldBorder] Your block should be more than 200 to prevent lag!");
                                                //}
                                               
                                            
    }
                                           
                                        }
                                       
                                        return 
    true;
                                    break;
                                   
                                }
                                 
                            } else {
                                
    $sender->sendMessage("[WorldBorder] /worldborder add [world] [blocks]");
                            }
                             
                        }
                       
                        return 
    true;
                    break;
                     
                }
                 
            }

        public function 
    checkBorder($player$e$p) {
               
                
    $level $this->getServer()->getLevelByName($player["level"]);
                
    $t = new Vector2($player["x"], $player["z"]);
                
    $s = new Vector2($level->getSpawnLocation()->getX(), $level->getSpawnLocation()->getZ());
                           
                            if (
    $this->config->get($level) === true) {
                                echo 
    "Yep";
                                
    $cfg $this->config->getAll();
                                return 
    $cfg[$level];
                            } else {
                                echo 
    "Not found";
                            }
                                 
        }

        public function 
    onPlayerMove(PlayerMoveEvent $event){
            
    $player $event->getPlayer();
                    
    $p $event->getPlayer();
            if(
    $player instanceof Player){
                
    $border $this->checkBorder(array("level" => $player->getLevel()->getName(), "x" => round($player->getX()), "z" => round($player->getZ())), $event$p);
                if(
    $border && !$player->hasPermission("worldborder.event.worldborder")){
                    
    $event->setCancelled(true);
                    
    $player->sendMessage("[WorldBorder] ".$this->config->get("message"));
                }
            }
        }

        public function 
    onBlockPlace(BlockPlaceEvent $event){
            
    $block $event->getBlock();
                    
    $p $event->getPlayer();
            if(
    $block instanceof Block){
                
    $border $this->checkBorder(array("level" => $block->getLevel()->getName(), "x" => round($block->getX()), "z" => round($block->getZ())), $event$p);
                if(
    $border && !$event->getPlayer()->hasPermission("worldborder.event.worldborder")){
                    
    $event->setCancelled(true);
                    
    $event->getPlayer()->sendMessage("[WorldBorder] ".$this->config->get("message"));
                }
            }
        }

        public function 
    onBlockBreak(BlockBreakEvent $event){
            
    $block $event->getBlock();
                    
    $p $event->getPlayer();                
            if(
    $block instanceof Block){
                
    $border $this->checkBorder(array("level" => $block->getLevel()->getName(), "x" => round($block->getX()), "z" => round($block->getZ())), $event$p);
                if(
    $border && !$event->getPlayer()->hasPermission("worldborder.event.worldborder")){
                    
    $event->setCancelled(true);
                    
    $event->getPlayer()->sendMessage("[WorldBorder] ".$this->config->get("message"));
                }
            }
        }
       
    }
    Error:

    Code:
    Illegal offset type in isset or empty in phar://C:/Users/RTG/Desktop/TesterUnit/PocketMine-MP.phar/src/pocketmine/utils/Config.php on line 383
    Not found
    
     
  2. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Can you explicitly show line 383 of that file?
     
  3. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    • I appreciate your ability of prediction.
    what are you doing?!?!? , use this
    PHP:
    $this->saveDefaultConfig();
     
  4. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    WTF? Seems like you don't understand PocketMine configs yet.
    Also this is in wrong section, should be in the facepalm section.
     
  5. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I believe the problem lies in you trying to Config->get a Level object in your checkBorder method. How can a Config file store an object? You probably meant to Config->get the Level's name, not the Level object. It's a simple fix, just use $player["level"] in your Config search instead of $this->getServer()->getLevelByName($player["level"])..
     
    falk likes this.
  6. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    PocketMine though,
    phar://C:/Users/RTG/Desktop/TesterUnit/PocketMine-MP.phar/src/pocketmine/utils/Config.php on line 383
     
  7. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    doesn't make any difference.
     
  8. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Hi, sorry. I don't get you... Can you provide sample code?
     
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    Please tell us where the error occurred in which line
    and please tell us everything so we dont need to go through the ask and respond sequence when you could have just provided it
     
  10. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    That's the error. I've provided it
     
  11. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    sorry then, it's a illegal array accessing
    say $array = [1=>1,2=>2]; i do $array[3] that should cause the error
    try using isset before accessing it like is set $array[3] before actually accessing it
     
  12. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    You simply mean
    PHP:
    $this->config->set($args[1], ['blocks' => $args[2]]); 
    is causing it?
     
  13. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    The error tells you that you are not passing the correct arguments to a pocketmine function. As Corytortoise says, the $level in $this->config->get($level) is an object returned by getLevelByName(), whereas you need to pass the level name to config->get() as a string. There might be other errors too, I haven't checked, but that needs fixing first!
     
  14. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    also in border check player is an instance of vector 3 there's no need to re construct it...
     
    Awzaw likes this.
  15. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    There's no need to pass that $player array at all since you pass the Player object which contains all the data you need in checkBorder. As for calling that array $player... that's a terrible name for what is essentially a Position.
     
  16. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Honest question: Why? Why should he use it? How is it better?

    OP, I think Awzaw explained what I meant pretty well, but if you still need an example, I would be glad to provide one. While this might not cause errors, I discourage passing an Event object to your checkBorder method unnecessarily.
     
  17. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    does cloning the event object do better?
     
  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.