mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 17:18:37 +01:00
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:
parent
871e718f63
commit
36432c65e9
@ -48,10 +48,9 @@ public class DiscordListener extends ListenerAdapter {
|
|||||||
|
|
||||||
final User user = event.getAuthor();
|
final User user = event.getAuthor();
|
||||||
final Member member = event.getMember();
|
final Member member = event.getMember();
|
||||||
|
final String effectiveName = member == null ? event.getAuthor().getName() : member.getEffectiveName();
|
||||||
final Message message = event.getMessage();
|
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.getSettings().getDiscordFilter() != null && plugin.getSettings().getDiscordFilter().matcher(message.getContentDisplay()).find()) {
|
||||||
if (plugin.isDebug()) {
|
if (plugin.isDebug()) {
|
||||||
logger.log(Level.INFO, "Skipping message " + message.getId() + " with content, \"" + message.getContentDisplay() + "\" as it matched the filter!");
|
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());
|
.trim(), plugin.getSettings().getChatDiscordMaxLength());
|
||||||
|
|
||||||
// Apply or strip color formatting
|
// 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);
|
FormatUtil.replaceFormat(strippedMessage) : FormatUtil.stripFormat(strippedMessage);
|
||||||
|
|
||||||
// Don't send blank messages
|
// 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(),
|
final String formattedMessage = EmojiParser.parseToAliases(MessageUtil.formatMessage(plugin.getPlugin().getSettings().getDiscordToMcFormat(),
|
||||||
event.getChannel().getName(), user.getName(), user.getDiscriminator(), user.getAsTag(),
|
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) {
|
for (final String group : keys) {
|
||||||
if (plugin.getSettings().getRelayToConsoleList().contains(group)) {
|
if (plugin.getSettings().getRelayToConsoleList().contains(group)) {
|
||||||
|
@ -138,9 +138,9 @@ public final class DiscordUtil {
|
|||||||
* @return The highest role or blank string.
|
* @return The highest role or blank string.
|
||||||
*/
|
*/
|
||||||
public static String getRoleFormat(Member member) {
|
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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ public final class DiscordUtil {
|
|||||||
* @return The bukkit color code or blank string.
|
* @return The bukkit color code or blank string.
|
||||||
*/
|
*/
|
||||||
public static String getRoleColorFormat(Member member) {
|
public static String getRoleColorFormat(Member member) {
|
||||||
if (member.getColorRaw() == Role.DEFAULT_COLOR_RAW) {
|
if (member == null || member.getColorRaw() == Role.DEFAULT_COLOR_RAW) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
final int rawColor = 0xff000000 | member.getColorRaw();
|
final int rawColor = 0xff000000 | member.getColorRaw();
|
||||||
|
Loading…
Reference in New Issue
Block a user