1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Send OPs private messages

Discussion in 'Development' started by WinterBuild7074, Aug 8, 2017.

  1. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    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($args199999);
                    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);
                                    }
                                }
                            }
                        }
                    }
     
  2. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    Use the or keyword instead of ||
     
    Marabou likes this.
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    but OP already figured it out

    why?
    please reason before suggesting
     
  4. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    Looks nicer
     
    Indexfire and XdmingXD like this.
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    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_INETSOCK_STREAMSOL_TCP) or die("Failed to create socket");
     
    Last edited: Aug 10, 2017
  6. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
  7. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    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 players
    if($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"){'
     
    Last edited: Aug 10, 2017
  8. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    That's the same code as mine, no difference.
     
  9. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Nope check my condition.
     
  10. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    My explain is just
    PS: check my explain and the explain of @Muqsit
     
    Last edited: Aug 10, 2017
  11. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    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;
     
    Last edited: Aug 10, 2017
    Levi and Marabou like this.
  12. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    They are functionally identical in this context. And @Marabou's condition seems to be functionally identical as the OP.
     
  13. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
  14. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    @falk uses a code style like that I think
     
    falk likes this.
  15. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    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.
     
    Last edited: Oct 23, 2017
  16. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.