diff --git a/CarbonChat/src/main/java/net/draycia/carbon/channels/ChatChannel.java b/CarbonChat/src/main/java/net/draycia/carbon/channels/ChatChannel.java index 5eb10fcc..3aacecf2 100644 --- a/CarbonChat/src/main/java/net/draycia/carbon/channels/ChatChannel.java +++ b/CarbonChat/src/main/java/net/draycia/carbon/channels/ChatChannel.java @@ -79,10 +79,14 @@ public abstract class ChatChannel implements ForwardingAudience { public abstract Boolean honorsRecipientList(); + public abstract Boolean permissionGroupMatching(); + public abstract boolean testContext(ChatUser sender, ChatUser target); public abstract Object getContext(String key); + public abstract List getGroupOverrides(); + /** * @return If the player can use this channel. */ diff --git a/CarbonChat/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java b/CarbonChat/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java index eea3c506..ee32738b 100644 --- a/CarbonChat/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java +++ b/CarbonChat/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java @@ -175,6 +175,16 @@ public class CarbonChatChannel extends ChatChannel { } public String getFormat(ChatUser user) { + for (String group : this.getGroupOverrides()) { + if (userHasGroup(user, group)) { + String format = getFormat(group); + + if (format != null) { + return format; + } + } + } + if (primaryGroupOnly()) { return getPrimaryGroupFormat(user); } else { @@ -182,6 +192,24 @@ public class CarbonChatChannel extends ChatChannel { } } + private boolean userHasGroup(ChatUser user, String group) { + if (user.isOnline()) { + if (carbonChat.getPermission().playerInGroup(user.asPlayer(), group)) { + return true; + } + } else { + if (carbonChat.getPermission().playerInGroup(null, user.asOfflinePlayer(), group)) { + return true; + } + } + + if (user.isOnline() && this.permissionGroupMatching()) { + return user.asPlayer().hasPermission("carbonchat.group." + group); + } + + return false; + } + private String getFirstFoundUserFormat(ChatUser user) { String[] playerGroups; @@ -337,6 +365,16 @@ public class CarbonChatChannel extends ChatChannel { return getBoolean("honors-recipient-list"); } + @Override + public Boolean permissionGroupMatching() { + return getBoolean("permission-group-matching"); + } + + @Override + public List getGroupOverrides() { + return getStringList("group-overrides"); + } + @Override public String getName() { String name = getString("name"); @@ -451,6 +489,20 @@ public class CarbonChatChannel extends ChatChannel { return null; } + private List getStringList(String key) { + if (config != null && config.contains(key)) { + return config.getStringList(key); + } + + ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default"); + + if (defaultSection != null && defaultSection.contains(key)) { + return defaultSection.getStringList(key); + } + + return Collections.emptyList(); + } + private boolean getBoolean(String key) { if (config != null && config.contains(key)) { return config.getBoolean(key); diff --git a/CarbonChat/src/main/resources/config.yml b/CarbonChat/src/main/resources/config.yml index d29f9f6e..6bd06c2c 100644 --- a/CarbonChat/src/main/resources/config.yml +++ b/CarbonChat/src/main/resources/config.yml @@ -18,6 +18,17 @@ default: # Also supports PlaceholderAPI staff: '{[%vault_prefix%]} %player_displayname% ยป ' default: '[%vault_prefix%] %player_displayname%: ' + # The plugin will look for matching group in here when choosing which group to use for formatting + # If there are no matches, the plugin will fall back to the primary-group-only option. + # It's advised to set this option to [] if you don't want to use this. + format-groups: + - Owner + - Admin + - Moderator + - VIP + # If set to true, players with the permission carbonchat.group.groupname will count has having + # The group with the name groupname (carbonchat.group.owner will count has having the group owner) + permission-group-matching: false contexts: # -1 to disable, 0 to set to world, 1+ to fully enable distance: -1