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

How to check?

Comments in 'Plugin Development' started by CraftYourBukkit, Oct 4, 2015.

Thread Status:
Not open for further replies.
  1. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    In PlayerChatEvent, how can I check if one word is in an array?
    Using this would be to long and unclear
    PianoPlayer38 likes this.
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Maybe use implode() and then foreach() and in_array()
    jojoe77777 likes this.
  3. AppPhil
    Offline

    AppPhil Active Member

    Joined:
    Oct 3, 2015
    Posts:
    54
    Do you want to check if the message which was sent by the player is in an array?
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Do you have an example code? I tried using implode() on $event->getMessage() but it didn't work
    PianoPlayer38 likes this.
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    No, I want to check whether one word of the array is in the message
    PianoPlayer38 likes this.
  6. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Try
    PHP:
    $wordArray = ["word""anotherword""more""words"]
    $words explode(" "$event->getMessage());
    foreach(
    $words as $word){
        if(
    in_array($word$wordArray){
            
    // whatever you want to do
        
    }
    }
    CraftYourBukkit and AppPhil like this.
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Thanks, works, but you have some syntax errors in your code
    PianoPlayer38 likes this.
Thread Status:
Not open for further replies.

Share This Page

Advertisement