How to set players Prefix/Suffix

Discussion in 'Plugin Development' started by Firerydragon2442, Jan 4, 2015.

Thread Status:
Not open for further replies.
  1. How do i set players prefix or suffix? (With the groupmanager API) i already tried but this gave me a NPE:

    Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "manuaddv " + player.getName() + " suffix" + " " + this.gm.getSuffix(player ) + " A 2nd suffix here");
     
  2. Well i tried but it seems to give me a NPE

    Main.chat.setPlayerSuffix(player, "TestSuffix");
     
  3. @Firerydragon2442 Errors (console errors?) - Is the player null? Is Vault not available so Chat is null? Are you making sure that you're using the .jar file inside the /plugins/ folder when you run the server (and you're using [depend] or [softdepend] to make sure that the API's are there?)
     
  4. Error = nullpointer
    How do i check if vault is available
    Yes
    Yes
     
  5. Offline

    haydenaa

    Would this work?
    Code:
    @EventHandler
    public void onChat(AsyncChatEvent e) {
    e.setFormat(yourPrefixHere + " " + e.getPlayer().getName() + " " + yourSuffixHere);
    }
    
    Also, you probably got a NPE before because i'm guessing your chat variable inside your Main class was null.
     
  6. im not doing a chat event. Im setting a tag (suffix) from a inventory
     
  7. Offline

    tytwining

    Then use the tag from the inventory to store the tag in a config, then onChat get the tag from the config?
     
  8. @Firerydragon2442 You can't just say there was a NullPointerException, was there no stacktrace?
     
  9. There was and it said it was a NPE at Main.chat.setPlayerSuffix(player, "TestSuffix");
     
  10. Offline

    mythbusterma

    @Firerydragon2442

    Then Main, chat, or player may be null. This is why you should actually use encapsulation and not just huruduurrrr static everything.
     
  11. And i can test this to use it in main class? So to make sure Main is not null?
     
  12. Offline

    mythbusterma

  13. Offline

    mythbusterma

  14. Offline

    MoseMister

    here is another way to do it, i think it is much simpler.
    Code:
    player.setDisplayName(prefex + " " + player.getName() + " " + suffix);
    this way works with default chat handlers and some plugin chat handlers.
     
  15. How di i
    make it not null?

    No >.< players already have a prefix and suffix i only want to add them ....
     
    Last edited by a moderator: Jan 5, 2015
  16. Offline

    1Rogue

    You should do this:

    Code:java
    1. e.setFormat(yourPrefix + "%s" + yourSuffix + ": %s"); //Can reset message color if wanted


    Where the first %s will be automatically replaced by the player name and the second %s is replaced by the message. It's the syntax for java.util.Formatter (and basically printf or anything of the sort in C), and should be used rather than manually replacing the values yourself.
     
    DJSkepter likes this.
Thread Status:
Not open for further replies.

Share This Page