Is there a better way of registrating. PHP: this->getServer()->getPluginManager()->registerEvents(new CatEyes($this), $this); $this->getServer()->getPluginManager()->registerEvents(new Fireless($this), $this); $this->getServer()->getPluginManager()->registerEvents(new CutClean($this), $this); $this->getServer()->getPluginManager()->registerEvents(new Nofall($this), $this); Instead of putting all of them , PHP: public function onEnable() { @mkdir($this->getDataFolder()); $this->config = new Config($this->getDataFolder() . "/scenarios.yml", CONFIG::YAML, array( "cutclean" => true, "applerate" => true, "nofall" => true, "noenchant" => false, "noanvil" => false, "goldless" => false, "doubleores" => false, "diamondless" => false, "fastsmelt" => false, "fireless" => false, "cateyes" => true, ));$this->saveDefaultConfig();$this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getServer()->getNetwork()->registerPacket(BossEventPacket::NETWORK_ID, BossEventPacket::class); $this->getServer()->getScheduler()->scheduleRepeatingTask(new BossTask($this), $this->getConfig()->get("interval") * 20); $this->getServer()->getPluginManager()->registerEvents(new CatEyes($this), $this); $this->getServer()->getPluginManager()->registerEvents(new Fireless($this), $this); $this->getServer()->getPluginManager()->registerEvents(new CutClean($this), $this); $this->getServer()->getPluginManager()->registerEvents(new Nofall($this), $this); $this->getServer()->getPluginManager()->registerEvents(new Applerate($this), $this); $this->getServer()->getPluginManager()->registerEvents(new BloodDiamonds($this), $this); $this->getServer()->getPluginManager()->registerEvents(new Diamondless($this), $this); $this->getServer()->getPluginManager()->registerEvents(new NoEnchant($this), $this); $this->getServer()->getPluginManager()->registerEvents(new NoAnvil($this), $this); $this->getServer()->getPluginManager()->registerEvents(new Goldless($this), $this); $this->getServer()->getPluginManager()->registerEvents(new Diamondless($this), $this);$this->getServer()->getPluginManager()->registerEvents(new FastSmelt($this), $this); $this->getServer()->getPluginManager()->registerEvents(new DoubleOres($this), $this);$this->getLogger()->info("has been Enabled"); } public function onDisable(){ $this->getLogger()->info("has been Disabled"); } I have multiple files in the Scenarios Folder and how can I register them all at once?
PHP: $eventListeners = [new ClassName($args), new SecondClassName($args)];foreach($eventListeners as $event){ $this->getServer()->getPluginManager()->registerEvents($event, /*Main class*/):}
So PHP: eventListeners = [new ClassName($args), new SecondClassName($args)];foreach($eventListeners as $event){ $this->getServer()->getPluginManager()->registerEvents($event, Main);}
Example of one Scenarios File PHP: use UHCReload\Main;use pocketmine\event\block\BlockBreakEvent;use pocketmine\event\Listener;use pocketmine\item\Item;use pocketmine\utils\Config;use pocketmine\utils\TextFormat;use pocketmine\Player;class DoubleOres implements Listener { public $scenarios; private $plugin; public function __construct(Main $plugin){ $this->plugin = $plugin; $this->scenarios = new Config($this->plugin->getDataFolder() . "scenarios.yml"); } public function getPlugin(){ return $this->plugin; }
no no PHP: <?phpnamespace YourFileNameSpaceHere;use pocketmine\event\Listener;use pocketmine\plugin\PluginBase;class Main extends PluginBase implements Listener{ public function onEnable(){ $eventListeners = [new ClassName($args), new SecondClassName($args)]; foreach ($$eventListeners as $event) { $this->getServer()->getPluginManager()->registerEvents($event, $this); } }
Just import ALL classes and register like this: PHP: foreach (glob("MyNameSpace/Listeners*.php") as $file) { require_once $file; if (class_exists( basename($file, ".php"))) { $class = new $class; $this->getServer()->getPluginManager()->registerEvents($class, $this); }
What exactly do you want to do? If you want to register them all together, why don't you just put them all in the same file?
It appears they are different Listeners for a reason, he/she doesn't want them all active at the same time.
If you want to register all listener functions, putting them in the same listener class makes more sense. You would want to put listener functions in different classes only if you want to register them separately. But in that case, you shouldn't unconditionally register them all using a scandir.
by checking associated value in config is true /Somedir/ ScenarioNoFall.php ScenarioBarebones.php ScenarioCorrupted.php it would scan and check if in config "ScenarioCorrupted" is true meaning is enabled on the config only then register that class as listener unless you are not replying to me