[Tut] Custom prefix/suffix/formats etc. to Chat messages

Discussion in 'Plugin Development' started by ChipDev, Jul 3, 2014.

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

    ChipDev

    Hey guys. Today is a very simple tutorial on how to change chat messages to make new formats, names, words, prefixes, suffixes, etc.

    This breaks all other plugins that add prefixes/colors. (Overrides them!)

    How to do it?

    First, get the event, (AsyncPlayerChatEvent)
    Code:Java
    1. public void onPlayerChat{AsyncPlayerChatEvent e) {
    2. //Leh code!
    3. }


    Second, set the format!
    Code:Java
    1. public void onPlayerChat{AsyncPlayerChatEvent e) {
    2. e.setFormat(ChatColor.BLUE + "" + ChatColor.BOLD + ">>" + " " + ChatColor.RED + "" + ChatColor.BOLD + e.getPlayer().getName() + ChatColor.RESET + "" + ChatColor.BOLD + " " + e.getMessage());
    3. }

    What this does:​
    Code:java
    1. e.setFormat(ChatColor.BLUE + "" + ChatColor.BOLD + ">>" + " " + ChatColor.RED + "" + ChatColor.BOLD + e.getPlayer().getName() + ChatColor.RESET + "" + ChatColor.BOLD + " " + e.getMessage());

    It will turn out:

    ">> Kanss Message"

    Message in white.
    Great for the 4th!
    Thats all guys, So thanks for reading! Hopefully this helped you in some sort.
    -Chip
     
  2. Offline

    chasechocolate

    ChipDev and sgtcaze like this.
  3. Offline

    macguy8

    chasechocolate You'd want to use a variable for the player's name as well, as it's replaced with the player's display name, which can be (although unlikely) changed in the chat event.
     
  4. Offline

    ChipDev

    chasechocolate macguy8
    Examples.
    Message could be a variable as
    Code:java
    1. String message = e.getMessage();

    Yes, correct. formats etc, But for more customization of the colors, etc.
    for example: Kanss - Testing, testing.
     
  5. Offline

    mythbusterma

    ChipDev
    There are quite a few things wrong with this, first and foremost, you break every single chat plugin ever made, completely ignore other plugins attempts at prefixes or suffixes, ruin private chat channels for anything else, and prevent the displaying of colored names for operators properly.

    Second, Bukkit.getServer().broadcastMessage(String) is not a thread safe operation, and you completely ignore that fact, creating a buggy plugin that is difficult to debug.

    TL;DR nodody do this, ever.
     
  6. Offline

    ChipDev

    Some people (Like me) Don't use any other plugins.. other than themselves.

    Great idea.
    While typing my brain blew up.
    sorry :p Edit..
    [​IMG]

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  7. Offline

    Xyplo

    Can a mod move this to the correct forum please?
     
  8. Offline

    AoH_Ruthless

    Xyplo
    A resource implies that it offers some help to plugin developers. As mythbusterma refuted, this resource is basically an explanation of why this tutorial is bad. While I am not a mod and hold no sway in the decision to move the thread, I believe that the OP doesn't even explain his stance well; just says that because he "doesn't use any other plugins", this tutorial is good. Doesn't even think from the perspective of most developers, which for public uses, is to provide server admins with quality plugins that don't break their chat formatting plugins that they already might like.

    However, mythbusterma, I don't see any mention of Bukkit.broadcastMessage(String) in this thread?
     
  9. Offline

    ChipDev

    What forum would this go in?

    Iroh
    Please delete this thread. Did bad work on it :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  10. Offline

    mythbusterma

    xTigerRebornx likes this.
  11. Offline

    Xyplo

    It's still a resource for developers. It's a tutorial, it's kind of obvious.
     
    Phasesaber likes this.
  12. Offline

    chasechocolate

    Yeah, I believe that's "%1$s"
     
  13. Offline

    Rocoty

    You are kinda bound to have to use the literal format parameters. Because without them, if a player typer a % you are in for an error or misformatted message.
     
    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page