Ranks

Discussion in 'Plugin Development' started by djmaster329, Feb 28, 2012.

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

    djmaster329

    Hi.

    I tried to build a new plugin.
    It is supposed to show the rank of a player when talking:
    Like:
    [OWNER]<name> Message

    But the way I tried it it goes like:
    <name>[OWNER] Message.

    Code:
    Code:
    if(event.getPlayer().isOp()){
                        String message;
                        message = event.getMessage();
                        event.setMessage("[" +ChatColor.YELLOW + "OPERATOR" +ChatColor.GRAY + "] " + message.toString());
                       
                    }
    Is there a way to do it right?

    Thanks :)
     
  2. Offline

    Neodork

    Yes, please use:

    //this to cancel the original text and catch the text
    public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    }

    Then use Broadcast to tell your message's to the server


    Small example:

    PHP:
    public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    String message event.getMessage();
    Player player event.getPlayer()
    if(
    player.getname.equals("MrOwner")){
    event.setCancelled(true);
    //do your new broadcast
     
    }
     
  3. Offline

    killjoy64

    instead of:
    event.setMessage("[" +ChatColor.YELLOW + "OPERATOR" +ChatColor.GRAY + "] " + message.toString());

    Should Be:
    event.setFormat("[" + ChatColor.YELLOW + "OPERATOR" + ChatColor.GRAY + "]" + player.getDisplayName() + ": " + message.toString());


    and of course called in the onPlayerChat method inside a listener.
     
Thread Status:
Not open for further replies.

Share This Page