Merge pull request #59 from Firepup6500/master

Add support for %NICKNAME%
This commit is contained in:
Chris 2024-01-16 16:42:17 -07:00 committed by GitHub
commit 6e5683b6b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 1 deletions

2
.gitignore vendored
View File

@ -1,7 +1,7 @@
/target/
/nbactions.xml
/dependency-reduced-pom.xml
/.vscode/
/.idea/
/*.iml

View File

@ -49,4 +49,14 @@ public class EssentialsHook {
return false;
}
public String getNickname(Player player) {
if (essentials != null) {
User user = essentials.getUser(player);
if (user != null) {
return user.getNickname();
}
}
return "";
}
}

View File

@ -1232,6 +1232,31 @@ public class PurpleIRC extends JavaPlugin {
return displayName;
}
/**
*
* @param player
* @return
*/
public String getNickname(String player) {
String nickname = "";
try {
UUID uuid = getPlayerUuid(player);
if (essentialsChatHook != null && uuid != null) {
Player user = getServer().getPlayer(uuid);
if (user != null) {
logDebug("getNickname: " + user.getName());
nickname = essentialsChatHook.getNickname(user);
}
}
} catch (Exception ex) {
logDebug("getNickname (" + player + "): " + ex.getMessage());
}
if (nickname == null) {
nickname = player;
}
return ChatColor.translateAlternateColorCodes('&', nickname);
}
/**
*
* @param player

View File

@ -941,11 +941,14 @@ public class ChatTokenizer {
public String playerTokenizer(Player player, String message) {
String pName;
String displayName;
String pNickname;
if (plugin.pingFixTemplate) {
pName = addZeroWidthSpace(player.getName());
pNickname = addZeroWidthSpace(plugin.getNickname(player.getName()));
displayName = player.getDisplayName().replace(player.getName(), pName);
} else {
pName = player.getName();
pNickname = plugin.getNickname(pName);
displayName = player.getDisplayName();
}
plugin.logDebug("Tokenizing " + pName + "(O: " + player.isOnline() + ")");
@ -968,6 +971,9 @@ public class ChatTokenizer {
String worldColor = "";
String jobShort = "";
String job = "";
if (pNickname == null) {
pNickname = "";
}
if (pSuffix == null) {
pSuffix = "";
}
@ -1007,6 +1013,7 @@ public class ChatTokenizer {
}
return message.replace("%DISPLAYNAME%", displayName)
.replace("%NICKNAME%", pNickname)
.replace("%UUID%", uuid.toString())
.replace("%JOBS%", job)
.replace("%JOBSSHORT%", jobShort)
@ -1051,6 +1058,7 @@ public class ChatTokenizer {
}
String displayName = plugin.getDisplayName(playerName);
String nickname = plugin.getNickname(playerName);
String uuid = "";
plugin.logDebug("playerTokenizer: 7 ");
String worldAlias = "";
@ -1099,6 +1107,7 @@ public class ChatTokenizer {
plugin.logDebug("[S]Raw message: " + message);
return message.replace("%DISPLAYNAME%", displayName)
.replace("%NICKNAME%", nickname)
.replace("%UUID%", uuid)
.replace("%JOBS%", job)
.replace("%JOBSSHORT%", jobShort)