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

How to send only ops a message?

Discussion in 'Facepalm' started by xXSirButterXx, Jun 24, 2017.

  1. xXSirButterXx

    xXSirButterXx Witch

    Messages:
    52
    GitHub:
    xxsirbutterxx
    I want it so ops or any player with a certain permision to get a secret message on join in my plugin. How can i do this and what do i have to use?
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    try this: you create a onjoin handler, when on join try get all config, foreach if has permission for value, send message config get value with permission
    like this example, DO NOT COPY, this is only meant to be an example
    Code:
    function onJoin(){
        foreach $config->getall as perm
            if playerhasperm(perm) player->tell(config->get(perm))
    }
     
    so your config would be perm as keys and messages as value
     
  3. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    PHP:
    public functiom onJoin(PlayerJoinEvent $event) {
        
    $players $this->getServer()->getOnlinePlayers();
        foreach(
    $players as $player) {
            if(
    $player->hasPermission("anything") || $player->isOp()) {
                
    $player->tell("Anything");
            }
        }
    }
     
  4. xXSirButterXx

    xXSirButterXx Witch

    Messages:
    52
    GitHub:
    xxsirbutterxx
  5. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    this wont be a good idea as you will be spammed when others join
    also a bad idea if you want to edit things
     
  6. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    But that's what he asked for.
     
  7. xXSirButterXx

    xXSirButterXx Witch

    Messages:
    52
    GitHub:
    xxsirbutterxx
    Well i just needed an example actually. So i could add it for different things. it was very helpful actually
     
  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.