I want OPs to see all private messages sent by the players, but my code isn't working. I have no idea why, I don't get any errors or info in console. PHP: case "tell": case "msg": case "m": case "whisper": $to_player = $this->getServer()->getPlayer($args[0]); $msg = array_splice($args, 1, 99999); if($to_player) { $players = $this->getServer()->getOnlinePlayers(); foreach($players as $player) { if($player->isOp() || $player->hasPermission("pmsee")) { if($sender->getName() === $player->getName() || $to_player->getName() === $player->getName()) { } else { $player->sendMessage("§e[" . $sender->getDisplayName() . " -> " . $to_player->getDisplayName() . "]§f " . $msg); } } } } }
That only looks nicer to you. This is no sufficient reason to recommend it to others. As a side note, many code styles (citation needed: which?) even discourage the use of `and` and `or`, because they should be used only for convenient failure, e.g. PHP: $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Failed to create socket");
Easy, your condition is false for what they have permission without being op Look good the op is what have the permission but that they are not op it can not receive it PS: You must review the operators http://php.net/manual/en/language.operators.php PHP: foreach($this->getServer()->getOnlinePlayers() as $p){//get All playersif($p->isOp() or $p->hasPermission("pmsee")){//check all players have the permission or op$p->sendMessage("{$sender->getDisplayName()} -> {$p->getDisplayName()} ".$msg);//message}//your problem it's the 'if($p->isOp || $p->hasPermission("pmsee"){'
They aren't the same. "||" would work more normal than "or" PHP: /** @var Item $item */$bool1 = $item->getId() === Item::APPLE || $item->getId() !== Item::APPLE;$bool2 = $item->getId() === Item::APPLE or $item->getId() !== Item::APPLE; $bool1 will always output true while $bool2 will output true only of $item->getId() === Item::APPLE. The or $item->getId() !== Item::APPLE doesn't even matter. It's totally ignored. $bool1 is true if either $item->getId() is Item::APPLE or $item->getId() is not Item::APPLE (which means it's true every time). $bool2 is true if $item->getId() is Item::APPLE. The "or" function is not used to provide a second criteria but is a delimiter. It breaks the whole statement into two parts, including the variable that had been assigned. You can rewrite the above snippet as: PHP: /** @var Item $item */$bool1 = $item->getId() === Item::APPLE || $item->getId() !== Item::APPLE;$bool2 = $item->getId() === Item::APPLE; OR: PHP: /** @var Item $item */$bool1 = ($item->getId() === Item::APPLE || $item->getId() !== Item::APPLE);($bool2 = $item->getId() === Item::APPLE) || true;
They are functionally identical in this context. And @Marabou's condition seems to be functionally identical as the OP.
It looks like that the whole code in case isn't working. It's because there're already /tell, /msg, commands, etc. How to fix? I'm trying to run some more code when I run a command.