player chat event replacement?

Discussion in 'Plugin Development' started by djyee, Jun 16, 2014.

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

    djyee

    Hi
    Why is not it working? :
    Code:java
    1. @EventHandler
    2. public void onChat(AsyncPlayerChatEvent chat){
    3. chat.getMessage().replaceAll("Hey", ChatColor.DARK_RED + "[Chat] " + ChatColor.BOLD + "Hallo");
    4. chat.setMessage(chat.getMessage());
    5. }
    6.  
     
  2. Offline

    Lolmewn

    You replace on some string but do nothing with the result.
     
  3. Offline

    Onlineids

    Try this: djyee
     
  4. Offline

    techboy291

    And use replace() if you're not using regex.
     
  5. Offline

    djyee

    did not work :(
     
  6. Offline

    Onlineids

    djyee Switch to .replace(
     
  7. Offline

    Necrodoom

    djyee paste whole class + error.
     
  8. Offline

    djyee


    Code:java
    1. package com.nu._black;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.AsyncPlayerChatEvent;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9.  
    10.  
    11. public final class kufur extends JavaPlugin
    12.  
    13. implements Listener
    14.  
    15. {
    16. public void onEnable()
    17. {
    18.  
    19. getLogger().info("heyo!");
    20.  
    21.  
    22. }
    23.  
    24. public void onDisable() {
    25. getLogger().info("hey!");
    26. }
    27.  
    28. @EventHandler
    29. public void onChat(AsyncPlayerChatEvent chat){
    30. String s = chat.getMessage().replaceAll("Hey", ChatColor.DARK_RED + "[Chat] " + ChatColor.BOLD + "Hallo");
    31. chat.setMessage(s);
    32. }
    33.  
    34. }
    35.  
    36.  
    37.  
     
  9. Offline

    techboy291

    You have to register the Listener class in order for events to work. Add this to onEnable():

    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);
    2.  
     
    djyee likes this.
  10. Offline

    djyee

    Thanks !!!!!!!!!!!!!!!
     
Thread Status:
Not open for further replies.

Share This Page