API NametagEdit API - Set prefixes and suffixes on nametags

Discussion in 'Resources' started by wacossusca34, May 8, 2013.

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



    NametagEdit makes use of scoreboard teams to give player's unique prefixes and suffixes on their nametags. While this has been a server plugin for some time, NametagEdit got an API when minecraft 1.5.2 rolled out.

    A popular use for this would to do something of the sort for nametags:

    [ELF] Notch - For a plugin that might have races, or special rankings outside of permissions plugins.
    [LV 42] Jarcode - For a leveling type plugin / server.

    You would originally have to create a whole new scoreboard team for each prefix / suffix you want to assign, but with NTE you can just assign them straight to the players. It's a lot nicer if you want to assign prefixes or suffixes that change often.

    NTE stores current nametags in a text file, and you can choose to set nametags that save to this file, or just update the nametag directly. This plugin also stores permission nodes assigned with prefixes and suffixes, which can be used by server owners to assign certain prefixes / suffixes to groups, and can be cancelled through the API. It's all up to how you want to use this.

    NametagEdit does a few fancy things:
    • It allows for ridiculously longer names. You can have 16 characters as a prefix, and 16 as a suffix in addition to your actual nametag. Developers wanting to add a prefix/suffix to player names without cutting off their names can do so (and they can toss out TagAPI and any other direct edits to the nametag).
    • It auto updates when a new, approved plugin release is available from dev.bukkit.org (it does not use any external sites to check and download updates).
    • Despite this using packets, this plugin is compatible with any bukkit server running 1.5 or higher.
    NametagEdit can be obtained from its bukkit page here: http://dev.bukkit.org/server-mods/nametagedit/

    Let's cut to the programming. There's two main things you can do with this API:

    You can listen for changes to the nametag!

    This only includes changes made within NTE, but you can see why, and how the nametag is being changed.

    1. @EventHandler
    2. public void onNametagChange(NametagChangeEvent event) {
    3. logger.info("Nametag for player " + event.getPlayerName() + " is being changed!");
    4. // Get the reason, or the source, for the change event.
    5. logger.info("Why? " + event.getReason());
    6. // Print the type of change (hard/soft)
    7. logger.info("How? " + event.getType());
    8. // And let's cancel the event, just because we can.
    9. event.setCancelled(true);
    10. }

    That's not all you can do with the event, you can get and set prefixes / suffixes that were going to be set to the player, as well as the current prefix / suffix for the player.

    You're probably wondering what I meant by a hard or soft nametag change type. Hard changes resets the whole nametag to the prefix and suffix that is about to be set. If they are null or empty, it simply removes that prefix / suffix. Soft changes are a little different, if they are null or empty, the prefix/suffix is ignored and replaced with the current one.

    There's a few different reasons for the nametag to change:

    • GROUP_NODE is the result of a player having a permission node with a prefix/suffix, and they just logged in or had their nametag reset. The most obvious use for this is to cancel it - only if you want your plugin to not have these default nametags.
    • SET_PREFIX and SET_SUFFIX is the result of the /ne command (NTE's built in command) to set a player's prefix/suffix. You can change this event to filter out certain things, or event cancel it.
    • CUSTOM is the result of another plugin using the API.
    You can set prefixes and suffixes yourself!

    NametagAPI is a class for setting nametags from any other plugin. It fires events when set, and can be canceled if the event is canceled.

    NametagAPI.setPrefix(), NametagAPI.setSuffix() can be used to set prefixes and suffixes for a player. They send soft nametag changes, and save their changes to the players.txt file in the plugin.

    NametagAPI.setNametagSoft(), NametagAPI.setNametagHard() can be used to reset or set nametags. I explained the difference between soft and hard changes above. These also save changes to the players.txt file in the plugin.

    NametagAPI.updateNametagSoft(), NametagAPI.updateNametagHard() can be used to directly set prefixes / suffixes without saving them to file. Use this if you're constantly updating player's nametags with information that would be redundant to save to file in NTE.

    NametagAPI.getSuffix(), NametagAPI.getPrefix() are pretty self explanatory

    NametagAPI.getNametag() returns the entire nametag of a player, with prefix, suffix, and the actual name.
    kicjow, Loogeh and HackintoshMan like this.
  2. Offline


    Thank you for making an API :D
  3. Offline


    It could be buggy. Let me know if you have any issues with it :)
  4. Offline


    I found a bug. If you just set a prefix it gets an error. I looked at the code on github and found it.
    In the PlayerLoader you should try if the prefix or suffix is null. You can't replace Strings that are null.
    But a VERY useful Plugin. The TagAPI should also implement that.
    Sorry for my bad english... I'm from Germany.
  5. wacossusca34 its working fine, but i'm getting some errors on it though, on PlayerLoader Class, line 97, you should perhaps fix that
  6. Offline


    I'll try to get around to it, lots of other work to do :'(
  7. ye, i understand but i hope you can fix it as possible as you can, as this is a nice API and it too bad to have this little issue, every time a player logs's in, a big stack trace
  8. Offline


    Wow! Im defiantly going to use this!
  9. Will this still work when I want to set the player health under the playername?
  10. Offline


    Getting this error when I get a prefix. It does actually set the prefix but it is an error none the less.
    05:16:46 [WARNING] [NametagEdit] Task #1282 for NametagEdit v1.8 generated an exception
            at ca.wacos.nametagedit.PlayerLoader.update(PlayerLoader.java:98)
            at ca.wacos.nametagedit.NametagAPI$1.run(NametagAPI.java:35)
            at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftTask.run(CraftTask.java:58)
            at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
            at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:518)
            at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:239)
            at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:481)
            at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:413)
            at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    05:16:47 [INFO] [PerformanceMonitor 1.7.0] Could not check for latest version: connect timed out
  11. Offline


    wacossusca34 Liked, definitely deserves more recognition on the forums. Love how you manage to keep the player's skin :D
  12. Offline


    I already posted this on the bukkit project page but since i agree with other people that this needs more attention im gonna post it here again:

    Well... There is 1 major issue with your API. Even tho you set the TabListDisabled to true the tablist still still updates and crashes your server once the player name passes 16 characters.
    I tried all your different methods and all of them change the tablist prefixes too.
    tried: setPrefix() updatePrefixSoft() setNameTagSoft()
    All of the hard ones didn't work either.
    Did i miss something in the API? Any way of preventing it from changing the tablist?
  13. Offline


    Does one use color codes like &f here or java color codes like ChatColor.WHITE?
  14. Offline


    Does anyone have the download link for this? :/
  15. Offline


  16. Offline


    I please you to change the [LIB] into [API]
  17. Offline


    Edited Tag. It indeed seems more appropriate.
Thread Status:
Not open for further replies.

Share This Page