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
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 }
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.