Added EssentialsChat support for elements (#532)

Adds support for {ELEMENT} and {ELEMENTCOLOR} tags that can be used in
EssentialsChat formatting
This commit is contained in:
StrangeOne101 2016-08-10 12:34:48 +12:00 committed by OmniCypher
parent 382b90b3b8
commit bb383e584a

View file

@ -704,12 +704,20 @@ public class PKListener implements Listener {
public void onPlayerChat(AsyncPlayerChatEvent event) { public void onPlayerChat(AsyncPlayerChatEvent event) {
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} else if (!ConfigManager.languageConfig.get().getBoolean("Chat.Enable")) { }
return;
}
Player player = event.getPlayer(); Player player = event.getPlayer();
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
String e = bPlayer == null || bPlayer.getElements().size() == 0 ? "Nonbender" : (bPlayer.getElements().size() > 1 ? "Avatar" : bPlayer.getElements().get(0).getName());
String element = ConfigManager.languageConfig.get().getString("Chat.Prefixes." + e);
ChatColor c = bPlayer == null || bPlayer.getElements().size() == 0 ? ChatColor.WHITE : (bPlayer.getElements().size() > 1 ? Element.AVATAR.getColor() : bPlayer.getElements().get(0).getColor());
event.setFormat(event.getFormat().replace("{element}", c + element + ChatColor.RESET).replace("{ELEMENT}", c + element + ChatColor.RESET).replace("{elementcolor}", c + "").replace("{ELEMENTCOLOR}", c + ""));
if (!ConfigManager.languageConfig.get().getBoolean("Chat.Enable")) {
return;
}
ChatColor color = ChatColor.WHITE; ChatColor color = ChatColor.WHITE;
if (bPlayer == null) { if (bPlayer == null) {
@ -719,9 +727,9 @@ public class PKListener implements Listener {
if (player.hasPermission("bending.avatar") || bPlayer.getElements().size() > 1) { if (player.hasPermission("bending.avatar") || bPlayer.getElements().size() > 1) {
color = ChatColor.valueOf(ConfigManager.languageConfig.get().getString("Chat.Colors.Avatar")); color = ChatColor.valueOf(ConfigManager.languageConfig.get().getString("Chat.Colors.Avatar"));
} else { } else {
for (Element element : Element.getMainElements()) { for (Element element_ : Element.getMainElements()) {
if (bPlayer.hasElement(element)) { if (bPlayer.hasElement(element_)) {
color = element.getColor(); color = element_.getColor();
break; break;
} }
} }