Replacing a string in chat formatting

Discussion in 'Plugin Development' started by ron975, Aug 28, 2012.

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

    ron975

    Say for example, I put a string like "[a]" in the chat formatting through a plugin like mChat, iChat, EssentialsChat, etc.

    I want to replace that [a] with something like, "test"

    This is my current code, but it's not working.

    Also, e.getFormat() returns the default format as well (<%1$s> %2$s) even though I've changed it in the config (I'm using iChat for testing)
    Code:java
    1.  
    2. @EventHandler(priority = EventPriority.MONITOR)
    3. public void ChatEvent(AsyncPlayerChatEvent e){
    4. String str = e.getFormat();
    5. str.replace("[a]", "testing");
    6. e.setFormat(str);
    7. }
    8.  
     
  2. Offline

    sternmin8or

    Strings are immutable. use the line:
    e.setFormat(str.replace("[a]", "testing");

    That being said, DONT CHANGE THINGS ON THE MONTOR LEVEL IT MAKES ORPHANS CRY:'(
     
  3. Offline

    ron975

    Code:java
    1.  
    2.  
    3. @EventHandler(priority = EventPriority.HIGHEST)
    4. public void ChatEvent(AsyncPlayerChatEvent e){
    5. String str = e.getFormat();
    6. str.replace("[a]", "testing");
    7. e.setFormat(str.replace("[a]", "testing"));
    8. }
    9.  



    Nope.
    I have the format set to
    Code:
    [[a] +displayname]
    
    And when ingame, I still get
    "[[a] ron975]: message"
    rather than
    '[test ron975]: message"

    This is more difficult than I thought it would be..

    And using
    Code:
    e.setMessage(str);
    to debug, the message is set as
    "[[a] ron975]: <%1$s> %2$s"


    It seems like simply replacing the string in the chat format isn't working..

    I don't usually bump threads this early, but I really need to figure this out, does anyone see why it's not working?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  4. Offline

    Firefly

    Registered your event?
     
  5. Offline

    ron975

    Code:java
    1.  
    2. public void onEnable(){
    3. Bukkit.getServer().getLogger().info("Enabled");
    4. this.getServer().getPluginManager().registerEvents(this, this);
    5. }
    6.  
     
  6. Offline

    Taco

    Not really relevant, but It drives me insane when people use their main class as a Listener. Also, try setting the priority to Lowest?
     
  7. Offline

    ron975

    Taco
    I get the same result, the tag is shown, but what I replaced it with is not.

    As said before, I really need to figure this out.. Such a simple thing is supppsed to be simple D:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
Thread Status:
Not open for further replies.

Share This Page