Im not a good plugin maker because of lack php skills regarding pocketmine, can i ask for help where i can disable certain command at spawn area? thank you. here is the code so far basing at wiess peaceful spawn. PHP: case "command": /////disable spawn command//// if (!isset($issuer->iusername)) return false; $c = $this->api->entity->get($issuer->iusername); if (!isset($c)) return false; $t = new Vector3($c->x, $c->y, $c->z); $s = new Vector3($this->server->spawn->x, $this->server->spawn->y, $this->server->spawn->z); $distance = $t->distance($s); if ($distance <= $this->server->api->getProperty("spawn-protection")) { return ("You cant use this command at spawn."); } else {bla blah blahhh blahhahah } break; /////////////////////////////// thanks
API 12: PHP: public function init(){ ServerAPI::request()->addHandler("console.command", array($this, "onCmd"));}public function onCmd($c, $a, $p){ if(!($p instanceof Player))return; if($this->isAtSpawn($p->entity))return false;}public function isAtSpawn(Position $pos){ // your definition of spawn: $pos->x, $pos->y, $pos->z, $pos->level->getName() ...} New API: PHP: <?phpnamespace PEMapModder\NoCmdAtSpawn;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\level\Position as Pos;class MainPlugin extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); } /** * @param PlayerCommandPreproccessEvent $event * @priority NORMAL * @ignoreCancelled true */ public function onCommand($event){ if($this->isAtSpawn($event->getPlayer()->entity)) $event->setCancelled(true); } public function isAtSpawn(Pos $pos){ // your method ($pos->x, $pos->y, $pos->z, $pos->level->getName()) }}
Please anyone who knows the API help me check the above. I am not very sure about the event thing. (I am terrible at RegExp)
can u pls explain this a little further? thanks Code: public function isAtSpawn(Position $pos){ // your definition of spawn: $pos->x, $pos->y, $pos->z, $pos->level->getName() ... }
Any functions as the definition of "at spawn area": e.g. PHP: public function isAtSpawn(pocketmine\level\Position $pos){ return $pos->level->getSafeSpawn()->distance($pos)<=10;}
what you mean? i get errors with it.... Error: array ( 'type' => 'E_RECOVERABLE_ERROR', 'message' => 'Argument 1 passed to pluginPVP::isAtSpawn() must be an instance of Position, null given, called in ..,blahblahblah...
i made it work now but how to fix this: A E_WARNING error happened: "strtolower() expects parameter 1 to be string, array given ....
Here is it: PHP: <?phpnamespace PEMapModder\NoCmdAtSpawn;use pocketmine\level\Position;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\player\PlayerCommandPreprocessEvent;class MainPlugin extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); } /** * @param PlayerCommandPreproccessEvent $event * @priority NORMAL * @ignoreCancelled true */ public function onPlayerPreCommand(PlayerCommandPreprocessEvent $event){ if($this->isAtSpawn($event->getPlayer()->entity)) $event->setCancelled(true); } public function isAtSpawn(Position $pos) { $spawn = $this->getServer()->getDefaultLevel()->getSpawn(); $radius = $this->getServer()->getSpawnRadius(); if($spawn->x <= $pos->x && $pos->x <= $spawn->x + $radius) { if($spawn->y <= $pos->y && $pos->y <= $spawn->y + $radius) { if($spawn->z <= $pos->z && $pos->z <= $spawn->z + $radius) { if($spawn->level === $pos->level) return true; } } } return false; }}
Why not PHP: return $this->getServer()->getDefaultLevel()->getSpawn()->distance($pos) <= $this->getServer()->getSpawnRadius();
Try this function: PHP: public function checkInside($x, $z){ $radius = 10; //Count blocks from spawn $spawn = $this->getServer()->getDefaultLevel()->getSpawn(); $t = new Vector2($x, $z); $s = new Vector2($spawn->x, $spawn->z); if($t->distance($s) =< $radius){ return true; }else{ return false; } } And in command: PHP: case "command": if($this->checkInside($sender->getX(), $sender->getZ())){ $sender->sendMessage("You cant use this command at spawn."); }break;