Feel free to update and expand upon this.
- ProtocolLib
package your.package.here;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Collections;
import java.util.UUID;
public class Nametag {
PacketContainer packet;
public Nametag(Player player) {
this.packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_TEAM);
String name = UUID.randomUUID().toString().replace("-", "").substring(0, 12);
this.packet.getIntegers().write(1, 0);
this.packet.getStrings().write(0, name);
this.packet.getChatComponents().write(0, WrappedChatComponent.fromText(player.toString()));
this.packet.getSpecificModifier(Collection.class).write(0, Collections.singletonList(player.getName()));
}
public Nametag setPrefix(String prefix) {
this.packet.getChatComponents().write(1, WrappedChatComponent.fromText(ChatColor.translateAlternateColorCodes('&', prefix) + " "));
return this;
}
public Nametag setSuffix(String suffix) {
this.packet.getChatComponents().write(2, WrappedChatComponent.fromText(" " + ChatColor.translateAlternateColorCodes('&', suffix)));
return this;
}
public void build() {
for (Player p : Bukkit.getOnlinePlayers()) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
} catch (InvocationTargetException e) {
throw new RuntimeException("Cannot send packet " + packet, e);
}
}
}
}
new Nametag(player).setPrefix("&6Test").setSuffix("&aTest").build();
// 1.13+
new Nametag(player).setPrefix("&6Testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt").setSuffix("&aTestttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt").build();
is there a way to organize the priority of the ranks? i assume I would have to set the name to "0-name" to get that type of effect.