Hi, I was wondering if anyone could point out a fix for this potential plugin that alerts players when someone is killing in creative (and changes them to survival). PHP: class StopCreativeKilling implements Plugin{ private $api; public function __construct(ServerAPI $api, $server = false){ $this->api = $api; $this->server = ServerAPI::request();} public function init(){ $this->api->addHandler("player.death", array($this, "handler"), 5); } public function __destruct(){} public function eventHandler($data, $event){ switch($event){ case "player.death": $player = $this->api->entity->get($data["cause"]); if($player->Gamemode === CREATIVE){ $broadcast = "$player is in creative mode.\n"; $this->api->chat->broadcast($broadcast); $this -> api -> console -> run("gamemode 0 $player"); } break;} } } For the record, every single line below is from another plugin (even if its just an online plugin generator) or the pocketmine files on the server, and I am happy to list sources (or multiple sources) for each line item. I am not a coder, but also not looking to claim that I am. So for example, the if($player->Gamemode === CREATIVE){ is from KsyMC's Essentials plugin. However, that is the only line borrowed from that plugin. It may not be the right code for what I am trying to do, but it looks like it logically should be. RuinPVP and InfoEssentials have also been helpful. I want to be upfront about that because I don't know what is considered ok for borrowing or imitating when coding vs. being accused of stealing. Jag
No it doesn't. It seems to be something with the If function, as it broadcasts $player is in creative mode, whether they are in it or not.
Based on https://github.com/PocketMine/Pocke...cf82cdfb292f02dc1ee7fe3f26b7a3/src/Player.php at line 1030, something like this should work: PHP: <?php/*__PocketMine Plugin__name=NoKillCreativeversion=1.0description=No killing in creative.author=Lamboclass=nokillcapiversion=12*/class nokillc implements Plugin{ private $api; public function __construct(ServerAPI $api, $server = false){ $this->api = $api; } public function __destruct(){} public function init(){ $this->api->addHandler("player.interact", array($this,"onHit")); } public function onHit($d){ if($d["entity"]->player->getGamemode()=="creative" and $d["targetentity"]->player->getGamemode()=="survival"){ $d["entity"]->player->setGamemode(0); $d["entity"]->player->sendChat("You cannot kill in creative!"); return false; }} I'm not quite sure if this would work, and if it doesn't, PM me and I will try to fix it.
Line 1030 is this... https://github.com/PocketMine/Pocke...fb292f02dc1ee7fe3f26b7a3/src/Player.php#L1030
I tested is a couple of times and it worked great after I added another } at the end. The only thing that would be better is if instead of send chat to send the message, it was broadcast to all. Because the game mode switch logs the offending player out, you don't have time to see the message. At least if it was broadcast they could find out why their game mode was switched when they returned. Thanks a lot for putting this together, as it will help me with not only with this, but also I would like to use similar code to create a map that prevents creative players from building on it. The idea being a server that has a creative and a survival section, with protections in place to prevent players using creative in the survival sections (even if they are teleported there). Of course with the API update coming soon, it won't work for very long. Jag
I don't really understand the first paragraph: you want it to broadcast in the chat that you cannot kill in creative? And about the other plugins, PM me and I will see what I can do.