this is actualy my first plugin i want to do a plugin any effect you set in config when players join they will get that effect but im stuck with the join event (im just trying to get better in php so please do not judge me ) PHP: public function onJoin(PlayerJoinEvent $event) { $cfg = $this->getConfig(); $p = $event->getPlayer(); $this->getServer()= new receiveEffect() == $p; //This the ligne 56 } i does get a erreur on console on line 56 PHP: Fatal error: Can't use method return value in write context in C:\Users\PC\Downloads\Minecraft\Genisys Server\plugins\JoinEffect-master\src\YoungRichNigger9\Main.php on line 56
$this->getServer() is a final function in PluginBase. PHP: = new receiveEffect() == $p; I do not get the point? Altough, "Genisys Server"...
I don't know what that line is supposed to do. It is total nonsense. Try explaining in english what you want to do...
Im french so my englesh is kinda bad what im trying to do is when the playerà join it will get the effect that is set in the config and give it to the player
add this after namespace: PHP: use pocketmine\entity\Effect; and this(Player Join event): PHP: public function onJoin(PlayerJoinEvent $event) { $player = $event->getPlayer(); $player->addEffect(Effect::getEffect(1)->setDuration(1200)->setAmplifier(1)); //Effect::getEffect() is getting The Effect with id 1(speed) //setDuration() is setting duration of the effect(in ticks), 1200 ticks = 1 minute //setAmplifier() is setting the Amplifier of the effect }
create a config with array onEnable: PHP: $config = new Config($this->getDataFolder() . "config.yml", Config::YAML, array ( "Effect-id" => 1, "Effect-Duration" => 2400, "Amplifier" => 0, "Particles" => true )); And change onJoin to: PHP: public function onJoin(PlayerJoinEvent $event) { $id = $config->get("Effect-id"); $ticks = $config->get("Effect-Duration"); $amplifier = $config->get("Amplifier"); $particle = $config->get("Particles"); $player = $event->getPlayer(); $player->addEffect(Effect::getEffect($id)->setDuration($ticks)->setAmplifier($amplifier)->setVisible($particle); }
What? Is more easy create a folder called "resources" with a config.yml and then you put all the info PHP: $config = $this->getConfig(); Some people use that, works but isn't the good way to do it PHP: $config = new Config($this->getDataFolder()."config.yml", Config::YAML)
PluginBase::getConfig() is a good way to do that. If it is really a config file. If you abuse the Config class to save data rather than making a config file, maybe no. The main advantage is that it reduces the amount of code you write (putting them in resource files instead). Usually, verbose content such as config format declaration, config default values, etc., should be placed in external files rather than in code directly.