ChatReplace + Colors

Discussion in 'Plugin Development' started by tschagg, Jan 23, 2013.

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


    Hey guy, i want to make a chat plugin for prefixes and suffixes.

    @EventHandler (priority = EventPriority.LOW)
    public void onPlayerChat(AsyncPlayerChatEvent event) {
        Player player = event.getPlayer();
        PermissionUser user = PermissionsEx.getUser(player);
        String[] msg = event.getMessage().split(" ");
        String suffix = user.getSuffix();
        String prefix = user.getPrefix();
        //player.setPlayerListName(suffix + player.getName());
        //String eventMessage = event.getMessage();
        player.sendMessage("My Suffix is: " + suffix +  player.getName());
        String newmsg = "";
        for (int i = 0; i < msg.length; i++) {
            newmsg = newmsg + msg[i];
            newmsg = newmsg + " ";
        event.setMessage(prefix + newmsg);
    i've 2 problems with this:

    1: the "suffix" give me out the color code in minecraft like &4 or something, i want to have to color in minecraft of this...
    2: when im writing, my name is still here like: <MyName>: "prefix" text, i want to remove the <MyName>

    thank you!
  2. Offline


    oh look, another prefix suffix plugin :|

    I'll still help you, for the &4 thing use Chatcolor.TransformsomethinghereIforgot(text, "&")
    for the <name>:, check the event.setFormat()
    tschagg likes this.
  3. Offline


    oh hey zach! i use your plugin right now :) its very good!

    thank you for the help! i'll try it

    thank you so much! it worked!

    both problems fixed with:
    event.setFormat((ChatColor.translateAlternateColorCodes('&',  prefix + player.getName()) + ChatColor.WHITE + ": " + ChatColor.WHITE + event.getMessage()));
    - SOLVED -

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


    Use the getdisplayname instead of getname. GetName is for keeping track of a player, display is for showing to other people.

    There are plugins that modify the displayname so you can have a nick name for example.
  5. Offline


    aah ok thanks!
Thread Status:
Not open for further replies.

Share This Page