To use the NametagEdit API, you have 2 choices: reference NametagEdit in your libraries, or use Maven.
Add the following repository to your POM.xml:
<repository>
<id>upstream</id>
<url>https://ci.nametagedit.com/plugin/repository/everything/</url>
</repository>Then add the dependency:
<dependency>
<groupId>com.nametagedit</groupId>
<artifactId>nametagedit</artifactId>
<version>4.4.16</version>
</dependency>You can choose to listen to the NametagEvent. This event fires BEFORE a nametag is changed.
There are 5 available parameters. The player, value, change type, change reason and storage type.
Example Usage:
@EventHandler
public void onNametagEvent(NametagEvent event) {
if (event.getChangeReason() == NametagEvent.ChangeReason.PLUGIN) {
if (event.getChangeType() == NametagEvent.ChangeType.PREFIX) {
Player player = Bukkit.getPlayerExact(event.getPlayer());
player.sendMessage("The value was: " + event.getValue());
}
}
} @EventHandler
public void onNametagFirstLoadedEvent(NametagFirstLoadedEvent event) {
// This event is fired when a player joins the server and their nametag is determined
// This is useful for custom join messages. For general nametag changes, listen to NametagEvent
INametag tag = event.getNametag();
Player player = event.getPlayer();
String prefix = tag.getPrefix();
String suffix = tag.getSuffix();
int sortPriority = tag.getSortPriority();
boolean isPlayerTag = tag.isPlayerTag();
}There are various methods available through the API. You can access these methods via NametagEdit.getApi()
Example Usage:
public void something(Player player) {
NametagEdit.getApi().setPrefix(player, "&c");
}If you use or develop a plugin that utilizes scoreboards, there can be issues when displaying the correct nametag for a player. Your client could also crash.
To get around this, simply use:
FakeTeam team = NametagEdit.getApi().getFakeTeam(String player); String name = team.getName();
And reuse the name for the new scoreboard. Credit to @Maximvdw for the workaround, which can be found at Adding Compatibility