Hello again people of PocketMine, I'm creating a plugin that only allows players with a 'Builder' or 'Owner' rank to place/break blocks. Here is the code so far... PHP: public function onBlockPlace(BlockPlaceEvent $event){ $player = $event->getPlayer(); if ($this->getRank($player) !== "Builder" || "Owner") { $event->setCancelled(); $player->sendMessage("[CR] Only [Builders] can place blocks!"); } } public function onBlockBreak(BlockBreakEvent $event){ $player = $event->getPlayer(); if ($this->getRank($player) !== "Builder" || "Owner") { $event->setCancelled(); $player->sendMessage("[CR] Only [Builders] can break blocks!"); } } So I thought this would work, and it does but it applies to everyone even Builders and Owners How can I make it so only the ranks that are not Builders or Owners have this function applied to them. -Calrizer
This wouldn't work because you are writing PHP (which is a computer language and not a natural human language). The compute will evaluate your expression by first looking at $this->getRank($player) !== "Builder" and come with a boolean, and then evaluate "Owner" which evaluates to a boolean true. Then it does the "||" which takes whatever was on the left with the true from the "Owner", which always results in true. What you want is: PHP: if ($this->getRank($player) !== "Builder" && $this->getRank($player) !== "Owner") {
Yeah it was a simple mistake || is the logical operator for 'OR' when in fact I needed to use the 'AND' operator which is && in PHP. Cheers for all the help!