-
-
Notifications
You must be signed in to change notification settings - Fork 43
Registering your own nickname provider
LOOHP edited this page Dec 31, 2021
·
2 revisions
InteractiveChat allows registering your own nickname providers so to display the player name tooltip on them as well. It is done by hooking into InteractiveChat from another plugin.
Here is an example of registering CMI nicknames using the CMIAPI.
package com.loohp.interactivechatcminicknamebridge;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
import com.Zrips.CMI.CMI;
import com.Zrips.CMI.Containers.CMIUser;
import com.loohp.interactivechat.api.InteractiveChatAPI;
public class InteractiveChatCMINicknameBridge extends JavaPlugin {
@Override
public void onEnable() {
InteractiveChatAPI.registerNicknameProvider(this, uuid -> { //The Function provides a player's uuid to us from InteractiveChat,
List<String> nicknames = new ArrayList<>(); //which we will need to return a list of this player's nicknames
CMIUser user = CMI.getInstance().getPlayerManager().getUser(uuid); //Keep in mind that if bungeecord is enabled, the uuid might be of a player on another server!!!
if (user != null) {
String nickname = user.getNickName(); //Here we've retrieved the nickname of the player provided by CMI
if (nickname != null) {
nicknames.add(nickname);
}
}
return nicknames; //Return the list of nicknames to InteractiveChat
});
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[InteractiveChatCMINicknameBridge] Registered CMI nicknames into InteractiveChat!"); //A friendly message to tell us that the plugin worked!
}
}Make sure to add InteractiveChat and the plugin that supplies your nicknames into the dependency list in your plugin.yml!