Add more group formatting options

This commit is contained in:
Draycia committed 2020-08-18 04:11:07 -07:00
1 parent 34f138a96b
commit 90fed17d86
3 files changed
+67

No files matched your search

@@ -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<String> getGroupOverrides();
/**
* @return If the player can use this channel.
*/
@@ -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<String> 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<String> 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);
+11
View File
@@ -18,6 +18,17 @@ default:
# Also supports PlaceholderAPI
staff: '<gray>{[%vault_prefix%<gray>]} %player_displayname% <reset><gray>» <color><message>'
default: '<gray>[%vault_prefix%<gray>] %player_displayname%<reset><gray>: <color><message>'
# 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