Fix NPE on webhooks messages with show-webhook-messages enabled (#4452)

Co-authored-by: MD <1917406+mdcfe@users.noreply.github.com>

Fixes #4451.
This commit is contained in:
Josh Roy 2021-08-09 14:30:30 -07:00 committed by GitHub
parent 871e718f63
commit 36432c65e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View File

@ -48,10 +48,9 @@ public class DiscordListener extends ListenerAdapter {
final User user = event.getAuthor();
final Member member = event.getMember();
final String effectiveName = member == null ? event.getAuthor().getName() : member.getEffectiveName();
final Message message = event.getMessage();
assert member != null; // Member will never be null
if (plugin.getSettings().getDiscordFilter() != null && plugin.getSettings().getDiscordFilter().matcher(message.getContentDisplay()).find()) {
if (plugin.isDebug()) {
logger.log(Level.INFO, "Skipping message " + message.getId() + " with content, \"" + message.getContentDisplay() + "\" as it matched the filter!");
@ -73,7 +72,7 @@ public class DiscordListener extends ListenerAdapter {
.trim(), plugin.getSettings().getChatDiscordMaxLength());
// Apply or strip color formatting
final String finalMessage = DiscordUtil.hasRoles(member, plugin.getPlugin().getSettings().getPermittedFormattingRoles()) ?
final String finalMessage = member == null || DiscordUtil.hasRoles(member, plugin.getPlugin().getSettings().getPermittedFormattingRoles()) ?
FormatUtil.replaceFormat(strippedMessage) : FormatUtil.stripFormat(strippedMessage);
// Don't send blank messages
@ -86,7 +85,7 @@ public class DiscordListener extends ListenerAdapter {
final String formattedMessage = EmojiParser.parseToAliases(MessageUtil.formatMessage(plugin.getPlugin().getSettings().getDiscordToMcFormat(),
event.getChannel().getName(), user.getName(), user.getDiscriminator(), user.getAsTag(),
member.getEffectiveName(), DiscordUtil.getRoleColorFormat(member), finalMessage, DiscordUtil.getRoleFormat(member)), EmojiParser.FitzpatrickAction.REMOVE);
effectiveName, DiscordUtil.getRoleColorFormat(member), finalMessage, DiscordUtil.getRoleFormat(member)), EmojiParser.FitzpatrickAction.REMOVE);
for (final String group : keys) {
if (plugin.getSettings().getRelayToConsoleList().contains(group)) {

View File

@ -138,9 +138,9 @@ public final class DiscordUtil {
* @return The highest role or blank string.
*/
public static String getRoleFormat(Member member) {
final List<Role> roles = member.getRoles();
final List<Role> roles = member == null ? null : member.getRoles();
if (roles.isEmpty()) {
if (roles == null || roles.isEmpty()) {
return "";
}
@ -154,7 +154,7 @@ public final class DiscordUtil {
* @return The bukkit color code or blank string.
*/
public static String getRoleColorFormat(Member member) {
if (member.getColorRaw() == Role.DEFAULT_COLOR_RAW) {
if (member == null || member.getColorRaw() == Role.DEFAULT_COLOR_RAW) {
return "";
}
final int rawColor = 0xff000000 | member.getColorRaw();