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

Solved code request

Comments in 'Plugin Development' started by AvivShopenCraft, Dec 9, 2015.

  1. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    hello! I need to make a plugin, which protect the chat, like if player swears, the PlayerChatEvent set to cancelled and the server send to the player message "DONT SWEAR!" so I started with this code:
    PHP:
    <?php


    namespace AvivShopen\ChatProtect;


    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\event\player\PlayerChatEvent;

    class 
    MainClass extends PluginBase implements Listener{

      

    function 
    onLoad(){

          
                    
    $this->getLogger()->info(TextFormat::WHITE "I've been loaded!");
        }
      
      
         function 
    onEnable(){

                    
    $this->getServer()->getPluginManager()->registerEvents($this$this);

          
            
    $this->getLogger()->info(TextFormat::DARK_GREEN "I've been enabled!");
    }  


        function 
    onDisable(){


            
    $this->getLogger()->info(TextFormat::DARK_RED "I've been disabled!");
        }

         
                
    function 
    onChat(PlayerChatEvent $event) {

            
    $player $event->getPlayer();

            
    $message $event->getMessage();

    if (
    $message == "word") {

    $player->sendMessage(TextFormat::RED "Dont say word!!!!");

    $event->setCancelled(true);}
    }
    }

    the "word" and the message is just for example,
    so I got a problem, player can say EVERYTHING except "word" like "wordy" "wordi" "I love words"
    is there a code to fix it?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  3. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
  4. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    oh i got it, thx!
  5. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    [CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerChatEvent' to 'ChatProtect v1.0.0': stripos() expects at most 3 parameters, 6 given on AvivShopen\ChatProtect\MainClass

    [15:40:29] [WARNING]: RuntimeException: "stripos() expects at most 3 parameters, 6 given" (E_WARNING) in "/ChatProtect/src/AvivShopen/ChatProtect/MainClass" at line 50
    idk why that's happening, i tried all:/
  6. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Post your code.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Seriously, this is a forum not a chatroom. Nobody cares if you go online or offline...
  9. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    but if I wont answear their questions, they will leave and they may never help me:(
  10. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    PHP:
    <?php


    namespace AvivShopen\ChatProtect;


    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\event\Listener;

    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\event\player\PlayerChatEvent;

    class 
    MainClass extends PluginBase implements Listener{

       

       
       
         function 
    onEnable(){

                    
    $this->getServer()->getPluginManager()->registerEvents($this$this);

           
            
    $this->getLogger()->info("enabled!");
    }   


        function 
    onDisable(){


            
    $this->getLogger()->info("disabled!");
        }

          
                 
    function 
    onChat(PlayerChatEvent $event) {

            
    $player $event->getPlayer();


            
    $message $event->getMessage();
    if(
    stripos($message"word" or $message"word1" or $message"word2" or  $message"word3" or  $message"word4") === 0){

    $player->sendMessage(TextFormat::RED "Dont swear!!!!");

    $event->setCancelled(true);}
    }
    }

  11. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Lol, stripos() expects at most 3 parameters, but u give it more than 3
    PocketKiller likes this.
  12. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    i know, I fixed it already:p but its still not working:(
    [CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerChatEvent' to 'ChatProtect v1.0.0': stripos() expects parameter 3 to be long, string given on AvivShopen\ChatProtect\MainClass

    [09:12:32] [WARNING]: InvalidArgumentException: "stripos() expects parameter 3 to be long, string given" (E_WARNING) in "/ChatProtect/src/AvivShopen/ChatProtect/MainClass" at line 45

    but answear me just if you have time, I don't want to annoy you:(
    (I just gived the original swears)
    btw, right now I'm going to codeacademy to learn PHP and don't be a noob! so PLEASE don't tell me that I don't know php cuz I know it and you know it lol
  13. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    ok fixed it by myself:) thx for helping!
    (I'm in lesson 42)
    Vaivez66 likes this.

Share This Page

Advertisement