Solved .setFormat usage

Discussion in 'Spigot Plugin Help' started by _Joseph_, Jun 7, 2018.

Thread Status:
Not open for further replies.
  1. Apologies if this is a dupe thread

    I'm using an onChat event handler for a part of my plugin and I'm having issues working with other plugin's prefixes and suffixes and general chat formatting. I found .setFormat which I believe would be what I had to do (of which it worked on my private server with little plugins e.g. groupmanager and essentials) and it was displaying tags from group manager fine. It gets installed on a server with skyblock level tags in chat and it breaks them. If I'm using this wrong please let me know what I should be doing instead, many thanks in advance!

    Code (Text):

    event.setFormat(player.getDisplayName() + ": " + event.getMessage());
    .....
    player.sendMessage(format);
     
     
  2. delete this
    Code (Text):
    player.sendMessage(format);
     
    • Agree Agree x 1
  3. What do I use instead then? It's in a for loop for players in a certain radius and using event.setCancelled(false); does not work
     
  4. event.getMessage();
    And send this to the player who is in the loop
     
  5. electronicboy

    IRC Staff

    Don't put the message that the player sends into the format, Don't cancel the event to send the message yourself.

    The event exposes a set of players which are going to receive the message, that list is pretty much always mutable (i.e. you can modify the contents) and remove players from the list;

    When the event sends a message, it shoves everything through a String#format, to put the message and player name and stuff into the string, you'll want to use the proper formatting tokens to specify to put the message into there, otherwise, it's going to break when somebody sends a % in chat
     
  6. Thank you very much this clears everything up!
     
Thread Status:
Not open for further replies.