How do i say "If chat text contains"

Discussion in 'Plugin Development' started by isleepzzz, Jul 24, 2012.

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

    isleepzzz

    (notice: im suuuper new to coding plugins)

    How do i make it say "if chat contains any of these" then:
    do not send the chat text. and send the play a message?
     
  2. Offline

    RazorFlint

  3. Offline

    r0306

    isleepzzz
    I recommend you use the Bukkit configuration API to store the strings as a list. Then all you would have to do would be:

    Code:
    for (String s : getConfig().getStringList("Blocked-Words")
    {
      if (event.getMessage().contains(s)
        event.setCancelled(true);
    }
    Otherwise, you would have to loop through the text file with a Buffered Reader which is slightly more complicated than this but not so much.
     
    RazorFlint likes this.
  4. Offline

    RazorFlint

    Or that xD
     
  5. Offline

    isleepzzz

    ehh my script doesnt recognize what even is sooo what should i do? It wont let me import it and idk if its an integer or string or boolean or what?:/ im new:/
     
  6. Offline

    pzxc

    event needs to be inside a PlayerChatEvent function

    @EventHandler
    function onPlayerChat(PlayerChatEvent event) {
    ... code in here...
    }

    Then it will know what "event" is. But you still have to register the event with the plugin so it knows to fire it when chat occurs.
     
  7. Offline

    RazorFlint

Thread Status:
Not open for further replies.

Share This Page