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

Solved Underfined property line180

Discussion in 'Development' started by romainbizet46, Oct 15, 2017.

  1. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Error with plugin task


    PHP:
    <?php

    namespace GunGame;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\Player;
    use 
    pocketmine\lang\BaseLang;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\item\enchantment\Enchantment;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\entity\Entity;
    use 
    pocketmine\entity\PrimedTNT;
    use 
    pocketmine\event\entity\EntityExplodeEvent;
    use 
    pocketmine\nbt\tag\CompoundTag;
    use 
    pocketmine\nbt\tag\DoubleTag;
    use 
    pocketmine\nbt\tag\FloatTag;
    use 
    pocketmine\nbt\tag\ListTag;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\event\block\{BlockBreakEventBlockPlaceEvent};
    use 
    pocketmine\event\player\{PlayerInteractEventPlayerMoveEventPlayerDropItemEventPlayerQuitEventPlayerJoinEventPlayerExhaustEvent};
    use 
    pocketmine\event\entity\{EntityDamageByEntityEventEntityDamageEventEntityLevelChangeEvent};

    class 
    GunGame extends PluginBase implements Listener{
       
        public 
    $tntCooldown = [ ];
        public 
    $tntCooldownTime = [ ];
       
        public function 
    onEnable() {
            
    $lang $this->getConfig()->get("language"BaseLang::FALLBACK_LANGUAGE);
            
    $this->prefix $this->getConfig()->get("Prefix")." ";
           
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->saveDefaultConfig();
            
    $this->getLogger()->info($this->prefix "by §6ArmTheDev§7!");
            
    $this->baseLang = new BaseLang($lang$this->getFile() . "resources/");
            
    $this->getLogger()->info($this->prefix "Language: ".$lang);
            
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new CooldownTask($this), 20);
        }
       
        public function 
    getLanguage() : BaseLang {
            return 
    $this->baseLang;
        }
       
        public function 
    onBreak(BlockBreakEvent $event){
            
    $event->setCancelled();
        }
       
        public function 
    onPlace(BlockPlaceEvent $event){
            
    $event->setCancelled();
        }
       
        public function 
    onDrop(PlayerDropItemEvent $event){
            
    $event->setCancelled();
        }
       
        public function 
    onExhaust(PlayerExhaustEvent $event){
            
    $event->setCancelled();
        }
       
        public function 
    onJoin(PlayerJoinEvent $event){
            
    $spawn $this->getServer()->getDefaultLevel()->getSafeSpawn();
            
    $player $event->getPlayer();
            
    $item Item::get(369);
            
    $item3 Item::get(280);
           
            
    $player->teleport($spawn );
            
    $player->sendMessage$this->prefix .$this->getLanguage()->get("player.join"));
            
    $player->getInventory()->clearAll();
            
    $player->setGamemode(0);
            
    $item->addEnchantment(new Enchantment(-1"unknown"000));
            
    $item->setCustomName("§bGunTest");
            
    $player->getInventory()->setItem(4$item);
            
    $item2->addEnchantment(new Enchantment(-1"unknown"000));
            
    $item2->setCustomName("§bGunTest");
            
    $player->getInventory()->setitem2(5$item2);
        }
       
        public function 
    onQuit(PlayerQuitEvent $event){
        }
       
        public function 
    PlayerRespawn(Player $player){
        }
       
        public function 
    onIneract(PlayerInteractEvent $event){
            
    $player $event->getPlayer();
           
            
    #TNT
            
    if($player->getInventory()->getItemInHand()->getId() === Item::BLAZE_ROD){
                if(!isset(
    $this->tntCooldown[$player->getName()])){
                    
    $nbt = new CompoundTag("", [
                    
    "Pos" => new ListTag("Pos", [
                    new 
    DoubleTag(""$player->x),
                    new 
    DoubleTag(""$player->$player->getEyeHeight()),
                    new 
    DoubleTag(""$player->z)
                    ]),
                    
    "Motion" => new ListTag("Motion", [
                    new 
    DoubleTag("", -sin($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI)),
                    new 
    DoubleTag("", -sin($player->pitch 180 M_PI)),
                    new 
    DoubleTag(""cos($player->yaw 180 M_PI) * cos($player->pitch 180 M_PI))
                    ]),
                    
    "Rotation" => new ListTag("Rotation", [
                    new 
    FloatTag(""$player->yaw),
                    new 
    FloatTag(""$player->pitch)
                    ]),
                    ]);
                    
    $tnt Entity::createEntity("PrimedTNT"$player->getLevel(), $nbt);
                    
    $tnt->setMotion($tnt->getMotion()->multiply(2));
                    
    $tnt->spawnTo($player);
                    
    $this->tntCooldown[$player->getName()] = $player->getName();
                    
    $time "1";
                    
    $this->tntCooldownTime[$player->getName()] = $time;
                    }else{
                        
    $player->sendMessage("§cYou can't use your gun for another ".$this->tntCooldownTime[$player->getName()]." seconds.");
                }
            }
            if(
    $player->getInventory()->getItemInHand()->getId() === Item::STICK){
                if(!isset(
    $this->snowballCooldown[$player->getName()])){
                    
    $nbt = new CompoundTag"", [
                    
    "Pos" => new ListTag(
                    
    "Pos", [
                    new 
    DoubleTag(""$player->x),
                    new 
    DoubleTag(""$player->y+$player->getEyeHeight()),
                    new 
    DoubleTag(""$player->z)
                    ]),
                    
    "Motion" => new ListTag("Motion", [
                    new 
    DoubleTag("", -\sin ($player->yaw 180 M_PI) *\cos ($player->pitch 180 M_PI)),
                    new 
    DoubleTag ("", -\sin ($player->pitch 180 M_PI)),
                    new 
    DoubleTag("",\cos ($player->yaw 180 M_PI) *\cos $player->pitch 180 M_PI))
                    ] ),
                    
    "Rotation" => new ListTag("Rotation", [
                    new 
    FloatTag(""$player->yaw),
                    new 
    FloatTag(""$player->pitch)
                    ] )
                    ] );
                    
    $snowball Entity::createEntity("Snowball"$player->getlevel(), $nbt);
                    
    $snowball->setMotion($snowball->getMotion()->multiply(2));
                    
    $snowball->spawnToAll();
                    
    $this->snowballCooldown[$player->getName()] = $player->getName();
                    
    $time "1";
                    
    $this->snowballCooldownTime[$player->getName()] = $time;
                    }else{
                        
    $player->sendMessage("§cYou can't use your gun for another ".$this->tntCooldownTime[$player->getName()]." seconds.");
                }
            }
        }
       
        public function 
    onEntityExplode(EntityExplodeEvent $event){
            
    $entity $event->getEntity();
           
            if(
    $entity instanceof PrimedTNT){
                
    $event->setCancelled();
            }
        }
    }

    class 
    CooldownTask extends PluginTask{
       
        public function 
    __construct($plugin){
            
    $this->plugin $plugin;
            
    parent::__construct($plugin);
        }
       
        public function 
    onRun($currentTick){
            
    #TNT-TIME
            
    foreach($this->plugin->tntCooldown as $player){
                if(
    $this->plugin->tntCooldownTime[$player] <= 0){
                    unset(
    $this->plugin->tntCooldown[$player]);
                    unset(
    $this->plugin->tntCooldownTime[$player]);
                    }else{
                        
    $this->plugin->tntCooldownTime[$player]--;
                }
            }
       
        
    #SNOWBALL-TIME
        
    foreach($this->plugin->snowballCooldown as $player){
                if(
    $this->plugin->snowballCooldownTime[$player] <= 0){
                    unset(
    $this->plugin->snowballCooldown[$player]);
                    unset(
    $this->plugin->snowballCooldownTime[$player]);
                    }else{
                        
    $this->plugin->snowballCooldownTime[$player]--;
                }
            }
        }
    }
       
           
           
           
           
           
           

     
  2. DayKoala

    DayKoala Silverfish

    Messages:
    22
    GitHub:
    daykoala
    Is your construct

    Erro:

    PHP:
    public function __construct($plugin){
    Right:

    PHP:
    public function __construct(GunGame $plugin){
     
    romainbizet46 likes this.
  3. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    That doesnt fix °=°
     
  4. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    try to make an other function/task with snowball and test
     
  5. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    You forgot to define $this->snowballCooldown and $this->plugin, define it like this:
    PHP:
    // Line 28
    class GunGame extends PluginBase implements Listener{
       
        public 
    $snowballCooldownTime = [ ];
        public 
    $tntCooldown = [ ];
        public 
    $tntCooldownTime = [ ];


    // Line 161
    class CooldownTask extends PluginTask{
        private 
    $plugin;
        
        public function 
    __construct($plugin){
            
    $this->plugin $plugin;
            
    parent::__construct($plugin);
        }
     
    Last edited: Oct 16, 2017
  6. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    What is the error given?
     
    romainbizet46 likes this.
  7. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    PHP:
    [16:35:56] [Server thread/CRITICAL]: Could not execute task GunGame\CooldownTaskUndefined propertyGunGame\GunGame::$snowballCooldown
    [16:35:56] [Server thread/CRITICAL]: ErrorException"Undefined property: GunGame\GunGame::$snowballCooldown(EXCEPTIONin "gungamev1/src/GunGame/GunGame" at line 180
     
  8. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
     
    jasonwynn10 and romainbizet46 like this.
  9. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Yep thank to you
    Now this issu is solved THX A LOT !
     
  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.