diff --git a/src/main/java/net/draycia/simplechat/channels/ChatChannel.java b/src/main/java/net/draycia/simplechat/channels/ChatChannel.java index 19d0bd3c..94b0c826 100644 --- a/src/main/java/net/draycia/simplechat/channels/ChatChannel.java +++ b/src/main/java/net/draycia/simplechat/channels/ChatChannel.java @@ -102,6 +102,8 @@ public abstract class ChatChannel { return false; } + public abstract boolean firstMatchingGroup(); + /** * @return If the player can use this channel. */ @@ -148,6 +150,7 @@ public abstract class ChatChannel { public abstract ChatChannel.Builder setShouldForwardFormatting(boolean forwardFormatting); public abstract ChatChannel.Builder setShouldBungee(boolean shouldBungee); public abstract ChatChannel.Builder setFilterEnabled(boolean filterEnabled); + public abstract ChatChannel.Builder setFirstMatchingGroup(boolean firstMatchingGroup); } } diff --git a/src/main/java/net/draycia/simplechat/channels/impls/AllianceChatChannel.java b/src/main/java/net/draycia/simplechat/channels/impls/AllianceChatChannel.java index 9e22d7eb..3f9ed3c3 100644 --- a/src/main/java/net/draycia/simplechat/channels/impls/AllianceChatChannel.java +++ b/src/main/java/net/draycia/simplechat/channels/impls/AllianceChatChannel.java @@ -11,8 +11,8 @@ import java.util.Map; public class AllianceChatChannel extends SimpleChatChannel { - AllianceChatChannel(TextColor color, long id, Map formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, SimpleChat simpleChat) { - super(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, simpleChat); + AllianceChatChannel(TextColor color, long id, Map formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) { + super(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat); } @Override diff --git a/src/main/java/net/draycia/simplechat/channels/impls/NationChatChannel.java b/src/main/java/net/draycia/simplechat/channels/impls/NationChatChannel.java index f901b6d9..29ef2b89 100644 --- a/src/main/java/net/draycia/simplechat/channels/impls/NationChatChannel.java +++ b/src/main/java/net/draycia/simplechat/channels/impls/NationChatChannel.java @@ -12,8 +12,8 @@ import java.util.Map; public class NationChatChannel extends SimpleChatChannel { - NationChatChannel(TextColor color, long id, Map formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, SimpleChat simpleChat) { - super(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, simpleChat); + NationChatChannel(TextColor color, long id, Map formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) { + super(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat); } @Override diff --git a/src/main/java/net/draycia/simplechat/channels/impls/PartyChatChannel.java b/src/main/java/net/draycia/simplechat/channels/impls/PartyChatChannel.java index ddf763bf..d7f3ade7 100644 --- a/src/main/java/net/draycia/simplechat/channels/impls/PartyChatChannel.java +++ b/src/main/java/net/draycia/simplechat/channels/impls/PartyChatChannel.java @@ -9,8 +9,8 @@ import java.util.Map; public class PartyChatChannel extends SimpleChatChannel { - PartyChatChannel(TextColor color, long id, Map formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, SimpleChat simpleChat) { - super(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, simpleChat); + PartyChatChannel(TextColor color, long id, Map formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) { + super(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat); } @Override diff --git a/src/main/java/net/draycia/simplechat/channels/impls/SimpleChatChannel.java b/src/main/java/net/draycia/simplechat/channels/impls/SimpleChatChannel.java index 8747aaac..6ce583f3 100644 --- a/src/main/java/net/draycia/simplechat/channels/impls/SimpleChatChannel.java +++ b/src/main/java/net/draycia/simplechat/channels/impls/SimpleChatChannel.java @@ -41,6 +41,7 @@ public class SimpleChatChannel extends ChatChannel { private boolean forwardFormatting; private boolean shouldBungee; private boolean filterEnabled; + private boolean firstMatchingGroup; private DiscordWebhook discordWebhook = null; @@ -50,7 +51,7 @@ public class SimpleChatChannel extends ChatChannel { private SimpleChatChannel() { } - SimpleChatChannel(TextColor color, long id, Map formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, SimpleChat simpleChat) { + SimpleChatChannel(TextColor color, long id, Map formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) { this.color = color; this.id = id; this.formats = formats; @@ -65,6 +66,7 @@ public class SimpleChatChannel extends ChatChannel { this.forwardFormatting = forwardFormatting; this.shouldBungee = shouldBungee; this.filterEnabled = filterEnabled; + this.firstMatchingGroup = firstMatchingGroup; this.simpleChat = simpleChat; @@ -142,7 +144,7 @@ public class SimpleChatChannel extends ChatChannel { @Override public void sendMessage(ChatUser user, String message, boolean fromBungee) { // Get player's formatting - String messageFormat = getFormat(getGroup(user)); + String messageFormat = getFormat(user); // Call custom chat event ChatFormatEvent formatEvent = new ChatFormatEvent(user, this, messageFormat, message); @@ -220,18 +222,39 @@ public class SimpleChatChannel extends ChatChannel { simpleChat.getPluginMessageManager().sendMessage(this, player, message); } - private String getGroup(ChatUser user) { - if (user.isOnline()) { - return simpleChat.getPermission().getPrimaryGroup(user.asPlayer()); + private String getFormat(ChatUser user) { + String group = "default"; + + if (!firstMatchingGroup()) { + if (user.isOnline()) { + group = simpleChat.getPermission().getPrimaryGroup(user.asPlayer()); + } else { + group = simpleChat.getPermission().getPrimaryGroup(null, user.asOfflinePlayer()); + } } else { - return simpleChat.getPermission().getPrimaryGroup(null, user.asOfflinePlayer()); + String[] groups; + + if (user.isOnline()) { + groups = simpleChat.getPermission().getPlayerGroups(user.asPlayer()); + } else { + groups = simpleChat.getPermission().getPlayerGroups(null, user.asOfflinePlayer()); + } + + for (String entry : groups) { + if (formats.containsKey(entry.toLowerCase())) { + group = entry; + break; + } + } } + + return getFormat(group); } public boolean canPlayerSee(ChatUser sender, ChatUser target) { Player targetPlayer = target.asPlayer(); - if (!targetPlayer.hasPermission("simplechat." + getName().toLowerCase() + ".see")) { + if (!targetPlayer.hasPermission("simplechat.channels." + getName() + ".see")) { return false; } @@ -328,6 +351,11 @@ public class SimpleChatChannel extends ChatChannel { return filterEnabled; } + @Override + public boolean firstMatchingGroup() { + return firstMatchingGroup; + } + @Override public List getItemLinkPatterns() { return itemPatterns; @@ -353,6 +381,7 @@ public class SimpleChatChannel extends ChatChannel { private boolean forwardFormatting = true; private boolean shouldBungee = false; private boolean filterEnabled = true; + private boolean firstMatchingGroup = false; private Builder() { } @@ -362,7 +391,7 @@ public class SimpleChatChannel extends ChatChannel { @Override public SimpleChatChannel build(SimpleChat simpleChat) { - return new SimpleChatChannel(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, simpleChat); + return new SimpleChatChannel(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat); } @Override @@ -467,6 +496,13 @@ public class SimpleChatChannel extends ChatChannel { return this; } + + @Override + public Builder setFirstMatchingGroup(boolean firstMatchingGroup) { + this.firstMatchingGroup = firstMatchingGroup; + + return this; + } } } diff --git a/src/main/java/net/draycia/simplechat/channels/impls/TownChatChannel.java b/src/main/java/net/draycia/simplechat/channels/impls/TownChatChannel.java index 42a9c848..c21da2f2 100644 --- a/src/main/java/net/draycia/simplechat/channels/impls/TownChatChannel.java +++ b/src/main/java/net/draycia/simplechat/channels/impls/TownChatChannel.java @@ -11,8 +11,8 @@ import java.util.Map; public class TownChatChannel extends SimpleChatChannel { - TownChatChannel(TextColor color, long id, Map formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, SimpleChat simpleChat) { - super(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, simpleChat); + TownChatChannel(TextColor color, long id, Map formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) { + super(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat); } @Override diff --git a/src/main/java/net/draycia/simplechat/managers/ChannelManager.java b/src/main/java/net/draycia/simplechat/managers/ChannelManager.java index 735f6897..73b2a217 100644 --- a/src/main/java/net/draycia/simplechat/managers/ChannelManager.java +++ b/src/main/java/net/draycia/simplechat/managers/ChannelManager.java @@ -126,6 +126,18 @@ public class ChannelManager { builder.setShouldBungee(defaults.getBoolean("should-bungee")); } + if (section.contains("filter-enabled")) { + builder.setFilterEnabled(section.getBoolean("filter-enabled")); + } else if (defaults != null && defaults.contains("filter-enabled")) { + builder.setFilterEnabled(defaults.getBoolean("filter-enabled")); + } + + if (section.contains("first-matching-group")) { + builder.setFirstMatchingGroup(section.getBoolean("first-matching-group")); + } else if (defaults != null && defaults.contains("first-matching-group")) { + builder.setFirstMatchingGroup(defaults.getBoolean("first-matching-group")); + } + ChatChannel channel = builder.build(simpleChat); if (channel.isTownChat() || channel.isNationChat() || channel.isAllianceChat()) { @@ -173,5 +185,4 @@ public class ChannelManager { } } - } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 89e69b7e..2dd7b93c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -12,22 +12,35 @@ default: toggle-on-message: 'You can now see chat!' toggle-off-message: 'You can no longer see chat!' formats: - discord-to-mc: '[Discord] :
' # Placeholders: username, displayname, channel, server, message, primaryrole
+    # Placeholders: username, displayname, channel, server, message, primaryrole
+    # Also supports PlaceholderAPI
+    discord-to-mc: '[Discord] : 
'
     staff: '{[%vault_prefix%]} %player_displayname% ยป 
'
     default: '[%vault_prefix%] %player_displayname%: 
'
-  color: '#FFFFFF' # Removing this option defaults to '#FFFFFF'
-  ignorable: true # Removing this option defaults to 'true'
-  distance: -1 # Set to -1, comment out, or remove to disable distance checking
-  forward-format: true # Removing this option defaults to 'true'. Forces all other servers to use this server's formatting for this channel.
-  should-bungee: true # Removing this option defaults to 'false'. Enables/disables cross server chat for this channel.
+  color: '#FFFFFF'
+  # Can players /toggle this channel and hide its messages?
+  ignorable: true
+  # Set to -1, comment out, or remove to disable distance checking
+  distance: -1
+  # Forces all other servers to use this server's formatting for this channel
+  forward-format: true
+  # Enables/disables cross server chat for this channel
+  should-bungee: true
+  # Determines if this channel should use the highest matching vault group found for formatting
+  first-matching-group: false
+  # Determines if the chat filter is enabled for this channel
+  filter-enabled: true
 
 channels:
   global:
     name: 'Global'
     aliases: 'global|g'
-    id: '' # Comment out / remove to disable channel bridge
-    webhook: '' # Comment out / remove to disable webhook
-    default: true # Removing this option defaults to 'false'
+    # Discord channel ID for bridging
+    id: -1
+    # Webhook URL for bridging
+    webhook: ''
+    # If this channel is the default channel
+    default: true
   announcements:
     name: 'Announcements'
     formats: