Skip to content

Commit

Permalink
Separate nametag and display name
Browse files Browse the repository at this point in the history
  • Loading branch information
fromgate committed Dec 28, 2016
1 parent 5df5651 commit 4a0b7b9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/main/java/ru/nukkit/multichat/util/Cfg.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class Cfg extends SimpleConfig {
@Path("display-name.enable")
public boolean displayNameEnable = true;

@Path("display-name.format")
public String displayNameFormat = "&a%prefix%&6%player%";

@Path("display-name.strip-colors")
public boolean isDisplayNameNoColors = false;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ru/nukkit/multichat/util/ChatListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void onJoin(PlayerJoinEvent event) {
Message.debugMessage("setNameTag", Util.getNametag(event.getPlayer()));
}
if (MultiChat.getCfg().displayNameEnable) {
Util.setDisplayName(event.getPlayer(), Util.getNametag(player));
Util.setDisplayName(event.getPlayer(), Util.getDisplayName (player));
} else {
player.setDisplayName(player.getName());
}
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/ru/nukkit/multichat/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ private static String getCusomParam(Player player, boolean getFormat) {
return result;
}

private static String getCustomDisplayName(Player player) {
String result = MultiChat.getCfg().displayNameFormat;
String param = ".display-name";
ConfigSection section = MultiChat.getCfg().customGroups;
for (String key : section.getKeys(false)) {
if (isPlayerInGroup(player, key) && section.exists(key + param)) {
result = section.getString(key + param);
}
}
return result;
}

private static boolean isPlayerInGroup(Player player, String group) {
if (!MultiChat.getCfg().useSubGroup) return Multipass.isInGroup(player, group);
for (String g : Multipass.getGroups(player))
Expand Down Expand Up @@ -69,11 +81,18 @@ public static void setNameTag(Player player, String nameTag) {
player.setNameTagVisible(false);
} else {
player.isNameTagVisible();
player.setDisplayName(TextFormat.colorize(nameTag));
player.setNameTag(TextFormat.colorize(nameTag));
}
}

public static void setDisplayName(Player player, String nameTag) {
player.setDisplayName(MultiChat.getCfg().isDisplayNameNoColors ? TextFormat.clean(nameTag) : nameTag);
public static void setDisplayName(Player player, String displayName) {
player.setDisplayName(MultiChat.getCfg().isDisplayNameNoColors ? TextFormat.clean(displayName) : displayName);
}

public static String getDisplayName(Player player) {
return replacePlaceholders(player, getCustomDisplayName(player))
.replace("{%0}", player.getName()).replace("{%1}", "");
}


}
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ name-tag:
display-name:
# Enable display name (shown by TAB-key)
enable: true
format: '&2%prefix%a2%player%&e: %message%'
# Remove color codes from display name
strip-colors: false

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: MultiChat
main: ru.nukkit.multichat.MultiChat
version: "1.0.1"
version: "1.0.2"
author: fromgate, nukkit.ru
api: ["1.0.0"]
description: MultiChat - universal chat formater based on MultiPass plugin
Expand Down

0 comments on commit 4a0b7b9

Please sign in to comment.