I've recently added __constuct so command aliases can be added and command description can be changed. But it got an error: Code: Fatal error: Declaration of Kygekraqmak\KygekRulesUI\Main::__construct($name, pocketmine\plugin\Plugin $plugin) must be compatible with pocketmine\plugin\Plugin::__construct(pocketmine\plugin\PluginLoader $loader, pocketmine\Server $server, pocketmine\plugin\PluginDescription $description, string $dataFolder, string $file) in src/Kygekraqmak/KygekRulesUI/Main.php on line 33 [Error] -> PHPStan (255) - Unable to parse. I guess the error is around here, but I don't know how to fix it. This is just a part of the code. PHP: use pocketmine\Server;use pocketmine\Player;use pocketmine\plugin\Plugin;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\utils\TextFormat;use pocketmine\utils\Config;use pocketmine\command\{Command, CommandSender, CommandExecutor, ConsoleCommandSender, PluginIdentifiableCommand};use jojoe77777\FormAPI;use jojoe77777\FormAPI\SimpleForm;class Main extends PluginBase implements Listener { public $plugin; public function __construct($name, Plugin $plugin) { $this->plugin = $plugin; parent::__construct("rules"); $this->setDescription($this->getConfig()->get("command-description")); $this->setPermission("rules.command"); $this->setAliases($this->getConfig()->get("command-aliases")); } So what should I add/change/remove? Any help would be appreciated. Project: https://github.com/Kygekraqmak/KygekRulesUI
Use this code on Main file PHP: use Kygekraqmak\KygekRulesUI\command\RulesCMD;//use in function onEnable$this->getServer()->getCommandMap()->regsiter("rules", new RulesCMD($this)); Create new Folder command and Create File RulesCMD Code PHP: <?phpnamespace Kygekraqmak\KygekRulesUI;use pocketmine\command\{Command, CommandSender};use jojoe77777\FormAPI;use jojoe77777\FormAPI\SimpleForm;use pocketmine\Server;use pocketmine\Player;use Kygekraqmak\KygekRulesUI\Main;class RulesCMD extends Command{public function __construct($name, Main $plugin) { $this->main = $plugin; $config = $this->main->getConfig(); parent::__construct("rules"); $this->setDescription($config->get("command-description")); $this->setAliases($config->get("command-aliases")); } public function execute(CommandSender $p, string $currentAlias, array $agrs){ if($p instanceof Player){ $this->main->kygekRulesUI($p); } }}
First, why $this->setPermission("rules.command"); not used? Second, should I move the onCommand() function in Main.php to command\RulesCMD.php?
1. mybe you are op?! 2. learn php 3. use public function excute(CommandSender $player,string $label, array $args) { :L }
I'm not talking about OP. I'm talking about adding permission using that with the default set to true. I'm learning.
You can use it if you want, the person probably just forgot to include the permission setting. Actually, instead of onCommand, like in PluginBase, the Command class uses a function called execute, so there is no need for onCommand: https://github.com/pmmp/PocketMine-MP/blob/stable/src/pocketmine/command/Command.php#L91
but you can register cmd and perm for cmd in plugin .yml and then write new class cmd or you can use cmd fucn in class Main
also you can write your cmd function in a new class and use : PHP: public function __cunstruct(Main $plugin) {$this->godweedzao = $plugin;//im using my name in my examples, you can change it.}
or you can write it in another files and then use that class in your main. also you can use OOP for doing this
This is not a chat. Stop with the spam and if you truly want to contribute to solution of the issue, without being annoying, use the edit button.