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

Check player message

Comments in 'Plugin Development' started by Artide, Sep 10, 2015.

  1. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    How to check if player chat message = something?
  2. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    PHP:
    public function onChat(PlayerChatEvent $ev){
    $p $ev->getPlayer();
    $msg $ev->getMessage();
    if(
    $msg == "spam spam spam"){
    $p->sendMessage("No spamming!");
    }
    }
  3. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    OK let me test this.
  4. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Ok, I'm not at home so I can't test it but I think it should work... :oops:
  5. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    It doesn't work. I tried the strpos function too but doesn't work either, help @PEMapModder ?
  6. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Remember to register events..?
  7. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Have you implemented Listener?
    Used the directory?

    PHP:
    use pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerChatEvent;

    class 
    Plugin extends PluginBase implements Listener{
    }
  8. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Maybe ur using strpos wrong.

    Try this:
    PHP:
    public function onChat(PlayerChatEvent $ev) {
    $p $ev->getPlayer();
    $msg $ev->getMessage();
    if(
    strpos($msg"spam spam spam")) {
    $p->sendMessage("No spamming!");
    }
    }
    Although i recommend using stripos();
    Last edited: Sep 10, 2015
  9. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    PHP:
    $p $ev->getPlayer();$msg $ev->getMessage();
    isn't good syntax :p
  10. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    i just copy and pasted @jojoe77777's code. Things dont always paste the way u want. I also fixed this before u even pointed it out :p
    HotFireyDeath likes this.
  11. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Did I do something wrong?
  12. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    No, I messed up the syntax when copy and pasting.
  13. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Ok :D
  14. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Oops, I forgot to use some things... This works as a script plugin:
    PHP:
    <?php
    /**
     * Detect chat
     *
     * @name ChatTest
     * @main jojoe\chat\Main
     * @version 1.0.0
     * @api 1.12.0
     * @description Chat away!
     * @author jojoe77777
     */

    namespace jojoe\chat{
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\event\Event;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    class 
    Main extends PluginBase implements Listener{

    public function 
    onEnable(){
      
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    }

    public function 
    onChat(PlayerChatEvent $event){
    $p $event->getPlayer();
    $message $event->getMessage();
    if(
    $message == "Hi"){
    $p->kick();
    }
    }
    }
    }
  15. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    namespace jojoe\chat{
    Should be:
    PHP:
    namespace jojoe\chat;
  16. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    It's a script plugin. It works fine.
  17. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Ah
  18. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    And I installed a PM server on this laptop and tested it.
  19. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    But on a server, you would want to use strtolower
    PHP:
    public function onChat(PlayerChatEvent $event){
    $p $event->getPlayer();
    $message $event->getMessage();
    if(
    strtolower($message) == "Hi"){
    $p->kick();
    }
    }
  20. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Done my plugin. I forgot to register events.
    HotFireyDeath likes this.

Share This Page

Advertisement