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

help?

Comments in 'Plugin Development' started by TryoneLegendZzz, Oct 15, 2015.

  1. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    why isnt this working?
    PHP:
      public function onChat(PlayerChatEvent $ev){
        
    $p $ev->getPlayer();
        
    $badwords = array("bad""words");
        
    $list = array("can i be op?","can i be op");
        
    $msg explode(" ",$ev->getMessage());
        foreach(
    $msg as $word){
        foreach(
    $badwords as $m){
        if(
    strtolower($word) === $m){
        
    $ev->setCancelled();
        
    $p->sendMessage("You can't say that youngster!");
      
        }
        }
        }
        
    //below is the part that does not work
        
    foreach($list as $w){
        foreach(
    $msg as $word){
        if(
    strtolower($word) === $w){
            
    $ev->setCancelled();
        
    $p->sendMessage("Please do not ask that question!");
        }
        }
        }
      
        }
    Last edited by a moderator: Oct 15, 2015
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Don't use a foreach for the array, use in_array($array, $word)
    TryoneLegendZzz likes this.
  3. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    still not workin :/
  4. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    1) It's hard to help when you're code is as messy as this. Use tabs and spaces.
    2) You say it's not working while we're not even sure what it's supposed to do. What's the point of this code? Was there an error? What is the problem?
    PEMapModder likes this.
  5. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    ayeeeee boioioioi no errors just dosent work
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Send the code from now.
  7. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Meanwhile I still don't know what you're trying to do.
  8. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    trying to stop the player from asking questions in the array of $list
  9. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    If you want to block specific sentences, like the most popular "can I have op", something like this should work:
    PHP:
    $msg "please can i have op";
    $blacklisted = [
    [
    "have""op"],
    [
    "have""creative"]
    ];
    $isBlocked true;
    foreach(
    $blacklisted as $blacklistitem){
       foreach(
    $blacklistitem as $word){
          if(
    strpos($msg$word) === false){
             
    $isBlocked false;
          }
       }
    }
    For blocking bad words, something like this:
    PHP:
    $msg "i hate this server";
    $blacklisted = ["hate"];
    $isBlocked false;
    foreach(
    $blacklisted as $blacklistedword){
       if(
    str_replace(['4''0'], ['a''o', ], preg_replace("/[^ \w]+/",""strtolower($msg))) == $blacklistedword){ // first converts the string to a string without symbols and spaces and then replaces some numbers with letters so you can write things like h4te
          
    $isBlocked true;
       }
    }
    Of course there are probably much better swear filters out there. I just made this as an example.
  10. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    nvm i figurird it out lul
  11. CavinMiana
    Offline

    CavinMiana Active Member

    Joined:
    Aug 26, 2015
    Posts:
    101
    Minecraft User:
    CavinMiana
    I do something like this
    PHP:
    $msg $event->getMessage;
    $op "can I be op";

    if(
    strpos($msg$op) !==false) {
    $event->sendMessage("DONT SAY THAT");
    // Idk this is what I use. But I think your way is better
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use stripos, then you don't need to strtolower :)

Share This Page

Advertisement