Error with plugin task PHP: <?phpnamespace 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\{BlockBreakEvent, BlockPlaceEvent};use pocketmine\event\player\{PlayerInteractEvent, PlayerMoveEvent, PlayerDropItemEvent, PlayerQuitEvent, PlayerJoinEvent, PlayerExhaustEvent};use pocketmine\event\entity\{EntityDamageByEntityEvent, EntityDamageEvent, EntityLevelChangeEvent};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", 0, 0, 0)); $item->setCustomName("§bGunTest"); $player->getInventory()->setItem(4, $item); $item2->addEnchantment(new Enchantment(-1, "unknown", 0, 0, 0)); $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->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) ]), ]); $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]--; } } }}
Is your construct Erro: PHP: public function __construct($plugin){ Right: PHP: public function __construct(GunGame $plugin){
You forgot to define $this->snowballCooldown and $this->plugin, define it like this: PHP: // Line 28class GunGame extends PluginBase implements Listener{ public $snowballCooldownTime = [ ]; public $tntCooldown = [ ]; public $tntCooldownTime = [ ];// Line 161class CooldownTask extends PluginTask{ private $plugin; public function __construct($plugin){ $this->plugin = $plugin; parent::__construct($plugin); }
PHP: [16:35:56] [Server thread/CRITICAL]: Could not execute task GunGame\CooldownTask: Undefined property: GunGame\GunGame::$snowballCooldown[16:35:56] [Server thread/CRITICAL]: ErrorException: "Undefined property: GunGame\GunGame::$snowballCooldown" (EXCEPTION) in "gungamev1/src/GunGame/GunGame" at line 180