Chat

Discussion in 'Plugin Development' started by NoLiver92, May 24, 2013.

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

    NoLiver92

    I have made a plugin which requires a prefix to the player in chat. How would i go about coding this so that i can have a custom name infront of the players name (like essentials)
     
  2. Offline

    chasechocolate

    Example:
    Code:java
    1. player.setDisplayName(ChatColor.RED + "[Some-Prefix] " + ChatColor.BLUE + player.getName());
     
  3. Offline

    NoLiver92

    chasechocolate

    I tried this but it doesnt work when i type in chat i get <NoLiver92> message

    i put your code on player join but i cant get it to work
     
  4. Offline

    chasechocolate

    NoLiver92 are there any other plugins on the server that could interfere with yours? If not, try adding a line of debug to print out player.getDisplayName().
     
  5. Offline

    NoLiver92

    Ahh essentials was stopping it, how do i integrate it with essentials so it works?
     
  6. Offline

    lenis0012

    disable it in the config from essentials.
     
  7. Offline

    NoLiver92

    lenis0012 sorry i wasnt clear, i need to integrate it with something like pex and essentials but i dont know how to do this
     
  8. Offline

    Timatooth

    Have you considered using Vault to get a players group prefix?
     
  9. Offline

    NoLiver92

    Timatooth I have no idea where to start with this, is there a tutorial anywhere?
     
  10. Offline

    Timatooth

    Have a look at http://dev.bukkit.org/server-mods/vault/ under the "Linking Vault section"

    Basically you only want to deal with chat; so you only need the setupChat() method called from onEnable() which assigns a reference to a "chat"
    e.g
    Code:
    import org.bukkit.whatever
    import what.ever.packages.from.vault
     
    public class MyPlugin extends JavaPlugin{
      private Chat chat
     
      public void onEnable(){
        ...
        setupChat();
        ...
        //later on do whatever with chat methods
      }
    }

    Once you have the chat variable initialized, you can do all kinds of stuff like chat.getPlayerPrefix("Timatooth", "world") etc. JavaDocs for Vault's chat API here: http://mythcraft.dyndns.org/javadoc/vault/
     
  11. Offline

    lenis0012

    Did you make the MineLoad plugin?
     
  12. Offline

    Timatooth

    Yes, as my signature and plugins link suggests ;)
     
  13. Offline

    lenis0012

    You are one genius web designer.
    I wish i had soe of your talent, lol.
     
  14. Offline

    Lucariatias

    If you're using specifically Essentials and nothing else, I'd use Essentials to set someone's nickname. There's also the lazy method of executing a command from console to set someone's pEX prefix, but I'd advise against that (and using pEX in general).
    Using Essentials:
    Code:
    String prefix = "[SomePrefix]";
    String playerName = player.getName();
    Plugin essentialsPlugin = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
    if (essentialsPlugin != null) {
        if (essentialsPlugin instanceof Essentials) {
            Essentials essentials = (Essentials) essentialsPlugin;
            essentials.getUserMap().getUser(playerName).setNickname(prefix + " " + essentials.getUserMap().getUser(playerName).getNickname());
        }
    }
    (or at least that's how I used to do it, no guarantees.)
    Other than that, using Vault works too, especially if you plan for it to be run on servers that don't use Essentials for chat.
     
Thread Status:
Not open for further replies.

Share This Page