More small bug and config fixes

This commit is contained in:
Draycia committed 2020-07-02 07:45:05 -07:00
1 parent 30793f1c72
commit 58477c0b6a
8 files changed
+88 -25

No files matched your search

@@ -102,6 +102,8 @@ public abstract class ChatChannel {
return false; return false;
} }
public abstract boolean firstMatchingGroup();
/** /**
* @return If the player can use this channel. * @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 setShouldForwardFormatting(boolean forwardFormatting);
public abstract ChatChannel.Builder setShouldBungee(boolean shouldBungee); public abstract ChatChannel.Builder setShouldBungee(boolean shouldBungee);
public abstract ChatChannel.Builder setFilterEnabled(boolean filterEnabled); public abstract ChatChannel.Builder setFilterEnabled(boolean filterEnabled);
public abstract ChatChannel.Builder setFirstMatchingGroup(boolean firstMatchingGroup);
} }
} }
@@ -11,8 +11,8 @@ import java.util.Map;
public class AllianceChatChannel extends SimpleChatChannel { public class AllianceChatChannel extends SimpleChatChannel {
AllianceChatChannel(TextColor color, long id, Map<String, String> 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) { AllianceChatChannel(TextColor color, long id, Map<String, String> 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, simpleChat); super(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
} }
@Override @Override
@@ -12,8 +12,8 @@ import java.util.Map;
public class NationChatChannel extends SimpleChatChannel { public class NationChatChannel extends SimpleChatChannel {
NationChatChannel(TextColor color, long id, Map<String, String> 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) { NationChatChannel(TextColor color, long id, Map<String, String> 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, simpleChat); super(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
} }
@Override @Override
@@ -9,8 +9,8 @@ import java.util.Map;
public class PartyChatChannel extends SimpleChatChannel { public class PartyChatChannel extends SimpleChatChannel {
PartyChatChannel(TextColor color, long id, Map<String, String> 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) { PartyChatChannel(TextColor color, long id, Map<String, String> 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, simpleChat); super(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
} }
@Override @Override
@@ -41,6 +41,7 @@ public class SimpleChatChannel extends ChatChannel {
private boolean forwardFormatting; private boolean forwardFormatting;
private boolean shouldBungee; private boolean shouldBungee;
private boolean filterEnabled; private boolean filterEnabled;
private boolean firstMatchingGroup;
private DiscordWebhook discordWebhook = null; private DiscordWebhook discordWebhook = null;
@@ -50,7 +51,7 @@ public class SimpleChatChannel extends ChatChannel {
private SimpleChatChannel() { } private SimpleChatChannel() { }
SimpleChatChannel(TextColor color, long id, Map<String, String> 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<String, String> 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.color = color;
this.id = id; this.id = id;
this.formats = formats; this.formats = formats;
@@ -65,6 +66,7 @@ public class SimpleChatChannel extends ChatChannel {
this.forwardFormatting = forwardFormatting; this.forwardFormatting = forwardFormatting;
this.shouldBungee = shouldBungee; this.shouldBungee = shouldBungee;
this.filterEnabled = filterEnabled; this.filterEnabled = filterEnabled;
this.firstMatchingGroup = firstMatchingGroup;
this.simpleChat = simpleChat; this.simpleChat = simpleChat;
@@ -142,7 +144,7 @@ public class SimpleChatChannel extends ChatChannel {
@Override @Override
public void sendMessage(ChatUser user, String message, boolean fromBungee) { public void sendMessage(ChatUser user, String message, boolean fromBungee) {
// Get player's formatting // Get player's formatting
String messageFormat = getFormat(getGroup(user)); String messageFormat = getFormat(user);
// Call custom chat event // Call custom chat event
ChatFormatEvent formatEvent = new ChatFormatEvent(user, this, messageFormat, message); ChatFormatEvent formatEvent = new ChatFormatEvent(user, this, messageFormat, message);
@@ -220,18 +222,39 @@ public class SimpleChatChannel extends ChatChannel {
simpleChat.getPluginMessageManager().sendMessage(this, player, message); simpleChat.getPluginMessageManager().sendMessage(this, player, message);
} }
private String getGroup(ChatUser user) { private String getFormat(ChatUser user) {
String group = "default";
if (!firstMatchingGroup()) {
if (user.isOnline()) { if (user.isOnline()) {
return simpleChat.getPermission().getPrimaryGroup(user.asPlayer()); group = simpleChat.getPermission().getPrimaryGroup(user.asPlayer());
} else { } else {
return simpleChat.getPermission().getPrimaryGroup(null, user.asOfflinePlayer()); group = simpleChat.getPermission().getPrimaryGroup(null, user.asOfflinePlayer());
} }
} else {
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) { public boolean canPlayerSee(ChatUser sender, ChatUser target) {
Player targetPlayer = target.asPlayer(); Player targetPlayer = target.asPlayer();
if (!targetPlayer.hasPermission("simplechat." + getName().toLowerCase() + ".see")) { if (!targetPlayer.hasPermission("simplechat.channels." + getName() + ".see")) {
return false; return false;
} }
@@ -328,6 +351,11 @@ public class SimpleChatChannel extends ChatChannel {
return filterEnabled; return filterEnabled;
} }
@Override
public boolean firstMatchingGroup() {
return firstMatchingGroup;
}
@Override @Override
public List<Pattern> getItemLinkPatterns() { public List<Pattern> getItemLinkPatterns() {
return itemPatterns; return itemPatterns;
@@ -353,6 +381,7 @@ public class SimpleChatChannel extends ChatChannel {
private boolean forwardFormatting = true; private boolean forwardFormatting = true;
private boolean shouldBungee = false; private boolean shouldBungee = false;
private boolean filterEnabled = true; private boolean filterEnabled = true;
private boolean firstMatchingGroup = false;
private Builder() { } private Builder() { }
@@ -362,7 +391,7 @@ public class SimpleChatChannel extends ChatChannel {
@Override @Override
public SimpleChatChannel build(SimpleChat simpleChat) { 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 @Override
@@ -467,6 +496,13 @@ public class SimpleChatChannel extends ChatChannel {
return this; return this;
} }
@Override
public Builder setFirstMatchingGroup(boolean firstMatchingGroup) {
this.firstMatchingGroup = firstMatchingGroup;
return this;
}
} }
} }
@@ -11,8 +11,8 @@ import java.util.Map;
public class TownChatChannel extends SimpleChatChannel { public class TownChatChannel extends SimpleChatChannel {
TownChatChannel(TextColor color, long id, Map<String, String> 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) { TownChatChannel(TextColor color, long id, Map<String, String> 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, simpleChat); super(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
} }
@Override @Override
@@ -126,6 +126,18 @@ public class ChannelManager {
builder.setShouldBungee(defaults.getBoolean("should-bungee")); 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); ChatChannel channel = builder.build(simpleChat);
if (channel.isTownChat() || channel.isNationChat() || channel.isAllianceChat()) { if (channel.isTownChat() || channel.isNationChat() || channel.isAllianceChat()) {
@@ -173,5 +185,4 @@ public class ChannelManager {
} }
} }
} }
+22 -9
View File
@@ -12,22 +12,35 @@ default:
toggle-on-message: '<gray>You can now see <color><channel> <gray>chat!' toggle-on-message: '<gray>You can now see <color><channel> <gray>chat!'
toggle-off-message: '<gray>You can no longer see <color><channel> <gray>chat!' toggle-off-message: '<gray>You can no longer see <color><channel> <gray>chat!'
formats: formats:
discord-to-mc: '<gray>[<blue>Discord<gray>] <username><white>: <pre><message>' # Placeholders: username, displayname, channel, server, message, primaryrole # Placeholders: username, displayname, channel, server, message, primaryrole
# Also supports PlaceholderAPI
discord-to-mc: '<gray>[<blue>Discord<gray>] <username><white>: <pre><message>'
staff: '<gray>{[%vault_prefix%<gray>]} %player_displayname% <gray>» <white><pre><message>' staff: '<gray>{[%vault_prefix%<gray>]} %player_displayname% <gray>» <white><pre><message>'
default: '<gray>[%vault_prefix%<gray>] %player_displayname%<gray>: <white><pre><message>' default: '<gray>[%vault_prefix%<gray>] %player_displayname%<gray>: <white><pre><message>'
color: '#FFFFFF' # Removing this option defaults to '#FFFFFF' color: '#FFFFFF'
ignorable: true # Removing this option defaults to 'true' # Can players /toggle this channel and hide its messages?
distance: -1 # Set to -1, comment out, or remove to disable distance checking ignorable: true
forward-format: true # Removing this option defaults to 'true'. Forces all other servers to use this server's formatting for this channel. # Set to -1, comment out, or remove to disable distance checking
should-bungee: true # Removing this option defaults to 'false'. Enables/disables cross server chat for this channel. 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: channels:
global: global:
name: 'Global' name: 'Global'
aliases: 'global|g' aliases: 'global|g'
id: '' # Comment out / remove to disable channel bridge # Discord channel ID for bridging
webhook: '' # Comment out / remove to disable webhook id: -1
default: true # Removing this option defaults to 'false' # Webhook URL for bridging
webhook: ''
# If this channel is the default channel
default: true
announcements: announcements:
name: 'Announcements' name: 'Announcements'
formats: formats: