Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Help with onChat

Comments in 'Plugin Development' started by asyven, Aug 7, 2015.

  1. asyven
    Offline

    asyven New Member

    Joined:
    Jan 17, 2015
    Posts:
    29
    Minecraft User:
    asyven
    PHP:
    <?php


                    $player 
    $event->getPlayer()->getDisplayName();
                    
    $msg $event->getMessage();
                if (
    $msg == "op me please") {
                
    $event->setCancelled(true);
                
    $event->getPlayer()->sendMessage(TextFormat::RED "go out!");
            }
            else{
                
    $event->setCancelled(false);
            }
     
    }
    How i can delete messages with: op me please
    examples (need canceled):
    - Admin, op me please
    - 12jshjs1vg op me please kdjhaskdjhas
    - 11 op me please maaan
    and so on

    ps: sry 4 my eng
    Last edited: Aug 8, 2015
  2. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Try

    PHP:
    if(stristr($msg"op me")){
    }
    Instead of
    PHP:
    if($msg == "op me"){
    }
    asyven, PixelGuy75 and BalAnce like this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Don't uncancel the event on else. You break other plugins by doing that.
    asyven, basprohop and Legoboy0215 like this.
  4. asyven
    Offline

    asyven New Member

    Joined:
    Jan 17, 2015
    Posts:
    29
    Minecraft User:
    asyven
    i got it, thx
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    public function onChat(PlayerCommandPreprocessEvent $event){
    $player $event->getPlayer();
    $msg $event->getMessage();
    if(
    strpos($msg'op me') != false){
    $event->setCancelled(true);
    $player->sendMessage('No :P');
    }
    }
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That doesn't work. You MUST use !== instead of !=, because strpos (actually stripos is better) returns false, 0 or any positive integer. False and 0 are considered to be the same thing. 0 != false actually returns false, i.e. (0 == false) is true. Learn PHP.
    Xenturio likes this.

Share This Page

Advertisement