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

Undefined offset 1

Discussion in 'Development' started by ZackyVN, Jan 14, 2019.

  1. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    so i have this code
    PHP:
                        case "green":
                            if(!
    $sender->hasPermission("green.wing")){
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Bạn không có quyền dùng Wing §aGreen");
                            return 
    true;
                        }
                            if(
    $args[1] == "on"){
                            
    $greenwing[$sender->getName()] = $sender;
                            
    $task = new GreenWing($sender);
                            
    $this->tasks[$sender->getId()] = $task;
                            
    $this->getScheduler()->scheduleRepeatingTask($task10);
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§a Đã bật Wing Green");
                            }
                                if(
    $args[1] == "off"){
                                        if(isset(
    $task)){
                                            
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Bạn có bật wing green đâu?");
                                        }else{
                                        
    $task $this->tasks[$sender->getId()];
                                        unset(
    $this->tasks[$sender->getId()]);
                                        
    $task->getHandler()->cancel();
                                        
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Đã tắt Wing §aGreen");
                                    }
                                }
                        break;
    when i executed the command, it crashed. I have no idea about this
    Console sent this
    Code:
    2019-01-14 [11:48:06] [Server thread/CRITICAL]: ErrorException: "Undefined offset: 1" (EXCEPTION) in "plugins/Wings/src/Wings/Main" at line 53
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #0 plugins/Wings/src/Wings/Main(53): pocketmine\utils\Utils::errorExceptionHandler(integer 8, string Undefined offset: 1, string C:\Users\Administrator\Desktop\Minecraft\HeroMC 1vs1\plugins\Wings\src\Wings\Main.php, integer 53, array Array())
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #1 src/pocketmine/command/PluginCommand(58): Wings\Main->onCommand(pocketmine\Player object, pocketmine\command\PluginCommand object, string wing, array Array())
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #2 src/pocketmine/command/SimpleCommandMap(261): pocketmine\command\PluginCommand->execute(pocketmine\Player object, string wing, array Array())
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #3 src/pocketmine/Server(2028): pocketmine\command\SimpleCommandMap->dispatch(pocketmine\Player object, string wing green off)
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #4 src/pocketmine/Player(2209): pocketmine\Server->dispatchCommand(pocketmine\Player object, string wing green off)
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #5 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(238): pocketmine\Player->chat(string /wing green off)
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #6 src/pocketmine/network/mcpe/protocol/CommandRequestPacket(54): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleCommandRequest(pocketmine\network\mcpe\protocol\CommandRequestPacket object)
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #7 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(108): pocketmine\network\mcpe\protocol\CommandRequestPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #8 src/pocketmine/network/mcpe/protocol/BatchPacket(119): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\CommandRequestPacket object)
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #9 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(108): pocketmine\network\mcpe\protocol\BatchPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #10 src/pocketmine/Player(3097): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #11 src/pocketmine/network/mcpe/RakLibInterface(170): pocketmine\Player->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #12 vendor/pocketmine/raklib/src/server/ServerHandler(99): pocketmine\network\mcpe\RakLibInterface->handleEncapsulated(string 192.168.1.7 57868, raklib\protocol\EncapsulatedPacket object, integer 0)
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #13 src/pocketmine/network/mcpe/RakLibInterface(110): raklib\server\ServerHandler->handlePacket()
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #14 src/pocketmine/network/mcpe/RakLibInterface(100): pocketmine\network\mcpe\RakLibInterface->process()
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #15 vendor/pocketmine/snooze/src/SleeperHandler(123): pocketmine\network\mcpe\RakLibInterface->pocketmine\network\mcpe\{closure}()
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #16 vendor/pocketmine/snooze/src/SleeperHandler(85): pocketmine\snooze\SleeperHandler->processNotifications()
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #17 src/pocketmine/Server(2347): pocketmine\snooze\SleeperHandler->sleepUntil(double 1547441286.919)
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #18 src/pocketmine/Server(2207): pocketmine\Server->tickProcessor()
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #19 src/pocketmine/Server(1783): pocketmine\Server->start()
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #20 src/pocketmine/PocketMine(249): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string C:\Users\Administrator\Desktop\Minecraft\HeroMC 1vs1\, string C:\Users\Administrator\Desktop\Minecraft\HeroMC 1vs1\plugins\)
    2019-01-14 [11:48:06] [Server thread/DEBUG]: #21 (1): require(string phar://C:/Users/Administrator/Desktop/Minecraft/HeroMC 1vs1/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
    
     
  2. Erkam

    Erkam Spider

    Messages:
    13
    GitHub:
    erkamkahriman
    insert isset in our code
     
  3. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    ???
     
  4. Erkam

    Erkam Spider

    Messages:
    13
    GitHub:
    erkamkahriman
    PHP:
    if(isset($args[1]){
    ....
     
  5. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    My full code
    PHP:
    <?php

    namespace Wings;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    Wings\Tasks\{GreenWingHeartWingRedCircleYellowCircleBlueCircleGreenCircle};
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerQuitEvent;

    class 
    Main extends PluginBase implements Listener{

        public 
    $tasks = [];
        public 
    $winggreen = array("GreenWing");

        public function 
    onEnable () : void{
            
    $this->getServer()->getLogger()->info("§l§aHero§bMC§e>§r§a Wings Enable");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }

        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool{
            if (
    $cmd == "wing"){
                if(empty(
    $args[0]) || empty($args[1])){
                    
    $sender->sendMessage("§9•§4 Circle Red. §e/wing circlered <on|off>");
                    
    $sender->sendMessage("§9•§e Circle Yellow. §e/wing circleyellow <on|off>");
                    
    $sender->sendMessage("§9•§b Circle Blue. §e/wing circleblue <on|off>");
                    
    $sender->sendMessage("§9•§a Circle Green. §e/wing circlegreen <on|off>");
                    
    $sender->sendMessage("§9•§a Wing Green §e/wing green <on|off>");
                    
    $sender->sendMessage("§9•§c Wing Heart. §e/wing heart <on|off>");
                return 
    true;
            }
                if(!empty(
    $args[0])){
                    switch(
    $args[0]){
                        case 
    "green":
                            if(!
    $sender->hasPermission("green.wing")){
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Bạn không có quyền dùng Wing §aGreen");
                            return 
    true;
                        }
                            if(
    $args[1] == "on"){
                            
    $greenwing[$sender->getName()] = $sender;
                            
    $task = new GreenWing($sender);
                            
    $this->tasks[$sender->getId()] = $task;
                            
    $this->getScheduler()->scheduleRepeatingTask($task10);
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§a Đã bật Wing Green");
                            }
                                if(
    $args[1] == "off"){
                                        if(isset(
    $task)){
                                            
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Bạn có bật wing green đâu?");
                                        }else{
                                        
    $task $this->tasks[$sender->getId()];
                                        unset(
    $this->tasks[$sender->getId()]);
                                        
    $task->getHandler()->cancel();
                                        
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Đã tắt Wing §aGreen");
                                    }
                                }
                        break;
                        case 
    "circlered":
                            if(!
    $sender->hasPermission("red.circle")){
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Bạn không có quyền dùng Circle §4Red");
                            return 
    true;
                        }
                            if(
    $args[1] == "on"){
                            
    $task = new RedCircle($sender);
                            
    $this->tasks[$sender->getId()] = $task;
                            
    $this->getScheduler()->scheduleRepeatingTask($task10);
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§a Đã bật Circle §4Red");
                            }
                                if(
    $args[1] == "off"){
                                    
    $task $this->tasks[$sender->getId()];
                                    unset(
    $this->tasks[$sender->getId()]);
                                    
    $task->getHandler()->cancel();
                                    
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Đã tắt Circle §4Red");
                                }
                        break;
                        case 
    "circleyellow":
                            if(!
    $sender->hasPermission("yellow.circle")){
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Bạn không có quyền dùng Circle §eYellow");
                            return 
    true;
                        }
                            if(
    $args[1] == "on"){
                            
    $task = new YellowCircle($sender);
                            
    $this->tasks[$sender->getId()] = $task;
                            
    $this->getScheduler()->scheduleRepeatingTask($task10);
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§a Đã bật Circle §eYellow");
                            }
                                if(
    $args[1] == "off"){
                                    
    $task $this->tasks[$sender->getId()];
                                    unset(
    $this->tasks[$sender->getId()]);
                                    
    $task->getHandler()->cancel();
                                    
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Đã tắt Circle §eYellow");
                                }
                        break;
                        case 
    "circleblue":
                            if(!
    $sender->hasPermission("blue.circle")){
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Bạn không có quyền dùng Circle §bBlue");
                            return 
    true;
                        }
                            if(
    $args[1] == "on"){
                            
    $task = new BlueCircle($sender);
                            
    $this->tasks[$sender->getId()] = $task;
                            
    $this->getScheduler()->scheduleRepeatingTask($task10);
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§a Đã bật Circle §bBlue");
                            }
                                if(
    $args[1] == "off"){
                                    
    $task $this->tasks[$sender->getId()];
                                    unset(
    $this->tasks[$sender->getId()]);
                                    
    $task->getHandler()->cancel();
                                    
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Đã tắt Circle §bBlue");
                                    unset(
    $this->tasks[$sender->getId()]);
                                    
    $task->getHandler()->cancel();
                                    
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Đã tắt Circle §bBlue");
                                    }
                        break;
                        case 
    "circlegreen":
                            if(!
    $sender->hasPermission("green.circle")){
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Bạn không có quyền dùng Circle §aGreen");
                            return 
    true;
                        }
                            if(
    $args[1] == "on"){
                            
    $task = new GreenCircle($sender);
                            
    $this->tasks[$sender->getId()] = $task;
                            
    $this->getScheduler()->scheduleRepeatingTask($task10);
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§a Đã bật Circle §aGreen");
                            }
                                if(
    $args[1] == "off"){
                                    
    $task $this->tasks[$sender->getId()];
                                    unset(
    $this->tasks[$sender->getId()]);
                                    
    $task->getHandler()->cancel();
                                    
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Đã tắt Circle §aGreen");
                                        }
                        break;
                        case 
    "heart":
                            if(!
    $sender->hasPermission("heart.wing")){
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Bạn không có quyền dùng Wing §cHeart");
                            return 
    true;
                        }
                            if(
    $args[1] == "on"){
                            
    $task = new HeartWing($sender);
                            
    $this->tasks[$sender->getId()] = $task;
                            
    $this->getScheduler()->scheduleRepeatingTask($task10);
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§a Đã bật Wing §cHeart");
                            }
                                if(
    $args[1] == "off"){
                                    
    $task $this->tasks[$sender->getId()];
                                    unset(
    $this->tasks[$sender->getId()]);
                                    
    $task->getHandler()->cancel();
                                    
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Đã tắt Wing §cHeart");
                                        }
                        break;
                        default:
                    
    $sender->sendMessage("§9•§4 Circle Red. §e/wing circlered <on|off>");
                    
    $sender->sendMessage("§9•§e Circle Yellow. §e/wing circleyellow <on|off>");
                    
    $sender->sendMessage("§9•§b Circle Blue. §e/wing circleblue <on|off>");
                    
    $sender->sendMessage("§9•§a Circle Green. §e/wing circlegreen <on|off>");
                    
    $sender->sendMessage("§9•§a Wing Green §e/wing green <on|off>");
                    
    $sender->sendMessage("§9•§c Wing Heart. §e/wing heart <on|off>");
                            break;
                    }
                }
            }
            return 
    true;
        }
       
        public function 
    onQuit(PlayerQuitEvent $e) {
            
    $player $e->getPlayer();
            
    $name $player->getName();
            
    $task $this->tasks[$player->getId()];
                if(isset(
    $task)){
                    unset(
    $this->tasks[$player->getId()]);
                    
    $task->getHandler()->cancel();
                }else{
                    
    $this->getServer()->getLogger()->info("§l§aHero§bMC§e>§r§a $name không dùng wing nên không tắt~");
                }
            }
    }
     
  6. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    what exactly is line 53
     
  7. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    PHP:
                                        if(isset($task)){
                                            
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Bạn có bật wing green đâu?");
                                        }else{
                                        
    $task $this->tasks[$sender->getId()];
                                        unset(
    $this->tasks[$sender->getId()]);
                                        
    $task->getHandler()->cancel();
                                        
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Đã tắt Wing §aGreen");
                                    }
                                }
    Line 53
    PHP:
    $task $this->tasks[$sender->getId()];
     
  8. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    Well the issue is the Player/Sender id isn't set in the array so from the look of your code you must either: run a certain command first so that the Player/Sender id is SET in the array or provide BETTER checks to see if the Player/Sender id is set in the array.
     
  9. VincBros

    VincBros Silverfish

    Messages:
    19
    GitHub:
    vincbros
    How exactly am I doing that?
     
  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.