diff --git a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/AliasedChannelCommand.java b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/AliasedChannelCommand.java index 596b1367..dd6a30e0 100644 --- a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/AliasedChannelCommand.java +++ b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/AliasedChannelCommand.java @@ -48,22 +48,20 @@ public class AliasedChannelCommand { private void channel(final @NonNull CommandContext context) { final PlayerUser user = (PlayerUser) context.getSender(); - if (user.channelSettings(this.chatChannel()).ignored()) { - user.sendMessage(Identity.nil(), this.carbonChat.messageProcessor().processMessage(this.chatChannel().cannotUseMessage(), - "color", "<" + this.chatChannel().channelColor(user).toString() + ">", - "channel", this.chatChannel().name())); - - return; - } + if (!this.canUse(user)) return; user.selectedChannel(this.chatChannel()); } private void sendMessage(final @NonNull CommandContext context) { + final PlayerUser user = (PlayerUser) context.getSender(); + + if (!this.canUse(user)) return; + context.getOptional("message").ifPresent(message -> { this.chatChannel().sendComponentsAndLog( context.getSender().identity(), - this.chatChannel().parseMessage((PlayerUser) context.getSender(), message, false)); + this.chatChannel().parseMessage(user, message, false)); }); } @@ -74,4 +72,15 @@ public class AliasedChannelCommand { public @NonNull String commandName() { return this.commandName; } + + private boolean canUse(final PlayerUser user) { + if (user.channelSettings(this.chatChannel()).ignored() || !this.chatChannel().canPlayerUse(user)) { + user.sendMessage(Identity.nil(), this.carbonChat.messageProcessor().processMessage(this.chatChannel().cannotUseMessage(), + "color", "<" + this.chatChannel().channelColor(user).toString() + ">", + "channel", this.chatChannel().name())); + + return false; + } + return true; + } } diff --git a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/ChannelCommand.java b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/ChannelCommand.java index a468dc82..e5e1816e 100644 --- a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/ChannelCommand.java +++ b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/ChannelCommand.java @@ -54,23 +54,31 @@ public class ChannelCommand { final PlayerUser user = (PlayerUser) context.getSender(); final TextChannel channel = context.get("channel"); - if (user.channelSettings(channel).ignored()) { - user.sendMessage(Identity.nil(), this.carbonChat.messageProcessor().processMessage(channel.cannotUseMessage(), - "color", "<" + channel.channelColor(user).toString() + ">", - "channel", channel.name())); - - return; - } + if (!this.canUse(user, channel)) return; user.selectedChannel(channel); } private void sendMessage(final @NonNull CommandContext context) { + final PlayerUser user = (PlayerUser) context.getSender(); final ChatChannel channel = context.get("channel"); final String message = context.get("message"); - channel.sendComponentsAndLog(context.getSender().identity(), channel.parseMessage((PlayerUser) context.getSender(), + if (!this.canUse(user, channel)) return; + + channel.sendComponentsAndLog(context.getSender().identity(), channel.parseMessage(user, message, false)); } + private boolean canUse(final PlayerUser user, final ChatChannel channel) { + if (user.channelSettings(channel).ignored() || !channel.canPlayerUse(user)) { + user.sendMessage(Identity.nil(), this.carbonChat.messageProcessor().processMessage(channel.cannotUseMessage(), + "color", "<" + channel.channelColor(user).toString() + ">", + "channel", channel.name())); + + return false; + } + return true; + } + }