Solved AsyncPlayerChatEvent - Changing specific words

Discussion in 'Plugin Development' started by Epicballzy, Jul 7, 2014.

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

    Epicballzy

    Hey, I'm playing around with AsyncPlayerChatEvent and I'm able to change specific words when said.

    Example:
    But my problem is that I still want to be able to make it look just like the regular player is sending it, instead of using broadcastMessage. I want the players name + prefix and/or suffix in the message like a regular message.

    This is what I got:
    Code:java
    1. @EventHandler
    2. public void playerChat(AsyncPlayerChatEvent chat) {
    3. String message = chat.getMessage();
    4. if(message.contains("hello")) {
    5. chat.setCancelled(true);
    6. Bukkit.getServer().broadcastMessage(chat.getPlayer().getDisplayName() + " " + message.replace("hello", "goodbye"));
    7. }
    8. }


    I'm using broadcastMessage because thats the only thing I know to use to send it like a regular message. But the getDisplayName() on shows the players name, and not prefix/suffix.

    Any suggestions?
     
  2. Offline

    JasonDL13

    Don't use broadcastMessage use a method like setFormet (I believe it's called) or setMessage
     
  3. Offline

    HungerCraftNL

    PHP:
    @EventHandler
    public void playerChat(AsyncPlayerChatEvent e) {
      
    Player p e.getPlayer();
      
    String m e.getMessage();
      if(
    m.contains("hello")) {
        
    e.setFormat(p.getDisplayName() + ": " m.replaceAll("Hello""Goodbye"));
      }
    }
     
  4. Offline

    Epicballzy

  5. Epicballzy
    You can do
    Code:java
    1. chat.setFormat(chat.getFormat().replace("something", "something else"))
     
  6. Offline

    Necrodoom

  7. Offline

    MrlolDestructo

    Instead of broadcasting the message, I believe you can do this:

    Code:java
    1. chat.setMessage(chat.getMessage().replaceAll("something", "new something"));
     
  8. Offline

    HungerCraftNL

  9. Offline

    Necrodoom

  10. Offline

    HungerCraftNL

    I he can do that, I only didn't add the displayname in my exemple. Added for you ;p
     
  11. Offline

    Necrodoom

Thread Status:
Not open for further replies.

Share This Page