mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 22:16:22 +00:00
Add more group formatting options
This commit is contained in:
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);
|
||||
|
||||
Reference in new issue
Block a user