So, I've been working on fixing up an outdated TurfWars plugin, and I've gotten this far and am now stuck with This error: Code: Cannot instantiate abstract class pocketmine\scheduler\Task The files are at https://github.com/LegoFan48737/TurfWars/tree/master/src/TurfWars Main.php (From the beginning to the problematic line) PHP: <?phpnamespace TurfWars;use pocketmine\Player;use pocketmine\Server;use pocketmine\event\Listener;use pocketmine\plugin\PluginBase;use pocketmine\event\player\PlayerChatEvent;use pocketmine\event\player\PlayerMoveEvent;use pocketmine\event\player\PlayerQuitEvent;use pocketmine\event\player\PlayerKickEvent;use pocketmine\event\player\PlayerDeathEvent;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\event\player\PlayerDropItemEvent;use pocketmine\event\block\BlockBreakEvent;use pocketmine\event\entity\EntityDamageEvent;use pocketmine\event\entity\ProjectileLaunchEvent;use pocketmine\event\entity\ProjectileHitEvent;use pocketmine\event\entity\EntityDamageByEntityEvent;use pocketmine\event\block\SignChangeEvent;use pocketmine\tile\Sign;use pocketmine\level\Position;use pocketmine\utils\Config;use pocketmine\item\Item;use pocketmine\block\Block;use pocketmine\entity\Arrow;use pocketmine\entity\Entity;use pocketmine\scheduler\Task;use pocketmine\scheduler\TaskScheduler;use pocketmine\nbt\tag\IntTag;use pocketmine\nbt\tag\CompoundTag;use pocketmine\math\Vector3;class Main extends PluginBase implements Listener{public $MAX = 2;public $PREFIX = "§d[§9TW§d]§b ";public $REDSPAWN;public $BLUESPAWN;public $config;public $sign;public $games = ["Game1" => ["Arena" => "TW-1", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game2" => ["Arena" => "TW-2", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game3" => ["Arena" => "TW-3", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game4" => ["Arena" => "TW-4", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game5" => ["Arena" => "TW-5", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game6" => ["Arena" => "TW-6", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game7" => ["Arena" => "TW-7", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game8" => ["Arena" => "TW-8", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game9" => ["Arena" => "TW-9", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game10" => ["Arena" => "TW-10", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0]];public function onEnable(){$this->getServer()->getPluginManager()->registerEvents($this, $this);$this->getScheduler()->scheduleRepeatingTask(new Task($this), 20); Tasks.php: PHP: <?phpnamespace TurfWars;use pocketmine\scheduler\Task;use pocketmine\Player;use pocketmine\Server;class Tasks extends Task { public function __construct(Main $plugin, Player $player){ $this->plugin = $plugin; } public function onRun($currentTick){ $this->plugin->Second(); }} Anyone know what this error is, and how to fix it? I've looked at a few other threads, but haven't found any clear solution.
when you are trying to repeat the task the plugin is repeating pocketmine\scheduler\Task instead of TrufWars\Tasks
here's the fixed code PHP: <?phpnamespace TurfWars;use pocketmine\Player;use pocketmine\Server;use pocketmine\event\Listener;use pocketmine\plugin\PluginBase;use pocketmine\event\player\PlayerChatEvent;use pocketmine\event\player\PlayerMoveEvent;use pocketmine\event\player\PlayerQuitEvent;use pocketmine\event\player\PlayerKickEvent;use pocketmine\event\player\PlayerDeathEvent;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\event\player\PlayerDropItemEvent;use pocketmine\event\block\BlockBreakEvent;use pocketmine\event\entity\EntityDamageEvent;use pocketmine\event\entity\ProjectileLaunchEvent;use pocketmine\event\entity\ProjectileHitEvent;use pocketmine\event\entity\EntityDamageByEntityEvent;use pocketmine\event\block\SignChangeEvent;use pocketmine\tile\Sign;use pocketmine\level\Position;use pocketmine\utils\Config;use pocketmine\item\Item;use pocketmine\block\Block;use pocketmine\entity\Arrow;use pocketmine\entity\Entity;use pocketmine\scheduler\Task;use pocketmine\scheduler\TaskScheduler;use pocketmine\nbt\tag\IntTag;use pocketmine\nbt\tag\CompoundTag;use pocketmine\math\Vector3;use TrufWars\Tasks as GameTask;class Main extends PluginBase implements Listener{public $MAX = 2;public $PREFIX = "§d[§9TW§d]§b ";public $REDSPAWN;public $BLUESPAWN;public $config;public $sign;public $games = ["Game1" => ["Arena" => "TW-1", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game2" => ["Arena" => "TW-2", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game3" => ["Arena" => "TW-3", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game4" => ["Arena" => "TW-4", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game5" => ["Arena" => "TW-5", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game6" => ["Arena" => "TW-6", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game7" => ["Arena" => "TW-7", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game8" => ["Arena" => "TW-8", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game9" => ["Arena" => "TW-9", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0], "Game10" => ["Arena" => "TW-10", "Status" => "JOINABLE", "RedScore" => 0, "BlueScore" => 0]];public function onEnable(){$this->getServer()->getPluginManager()->registerEvents($this, $this);$this->getScheduler()->scheduleRepeatingTask(new GameTask($this), 20);
What do you mean with "not work"? You could at least describe the issue / error occuring more detailed.
[Server thread/CRITICAL]: Error: "Cannot instantiate abstract class pocketmine\scheduler\Task" (EXCEPTION) in "plugins/TurfWars.phar/src/TurfWars/Main" at line 62 [13:32:02] [Server thread/DEBUG]: #0 src/pocketmine/plugin/PluginBase(120): TurfWars\Main->onEnable() [13:32:02] [Server thread/DEBUG]: #1 src/pocketmine/plugin/PluginManager(597): pocketmine\plugin\PluginBase->setEnabled(boolean 1) [13:32:02] [Server thread/DEBUG]: #2 src/pocketmine/Server(2035): pocketmine\plugin\PluginManager->enablePlugin(object TurfWars\Main) [13:32:02] [Server thread/DEBUG]: #3 src/pocketmine/Server(2019): pocketmine\Server->enablePlugin(object TurfWars\Main) [13:32:02] [Server thread/DEBUG]: #4 src/pocketmine/Server(1809): pocketmine\Server->enablePlugins(integer 1) [13:32:02] [Server thread/DEBUG]: #5 src/pocketmine/PocketMine(274): pocketmine\Server->__construct(object BaseClassLoader, object pocketmine\utils\MainLogger, string[16] /home/container/, string[24] /home/container/plugins/) [13:32:02] [Server thread/DEBUG]: #6 src/pocketmine/PocketMine(297): pocketmine\server() [13:32:02] [Server thread/DEBUG]: #7 (1): require(string[71] phar:///home/container/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
That's because you are creating an instance of the task class, which is the base class for all synchronous tasks and abstract, means you cannot create an instance of it. What you probably wanna do is create an Object of your task, which is "Tasks", not "Task".
you're calling pocketmine abstract task class to be scheduled. just change the name of the classes like what i said above already.