leave & join

This commit is contained in:
Olzie-12 committed 2022-12-19 19:07:53 +00:00
1 parent 46ba7512ac
commit f833290c70
6 files changed
+46 -16

No files matched your search

@@ -114,7 +114,7 @@ public final class BasicChatChannel implements ChatChannel {
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return ChannelPermissionResult.allowedIf(Component.empty(), () -> !player.leftChannels().contains(this));
return ChannelPermissionResult.allowedIf(Component.empty(), () -> !player.leftChannels().contains(this.key));
}
@Override
@@ -209,7 +209,7 @@ public final class ConfigChatChannel implements ChatChannel {
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return ChannelPermissionResult.allowedIf(empty(), () -> player.hasPermission(this.permission() + ".see") && !player.leftChannels().contains(this));
return ChannelPermissionResult.allowedIf(empty(), () -> player.hasPermission(this.permission() + ".see") && !player.leftChannels().contains(this.key));
}
@Override
@@ -77,25 +77,24 @@ public class JoinCommand extends CarbonCommand {
RichDescription.of(this.carbonMessages.commandWhisperArgumentMessage()))
.permission("carbon.join")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandIgnoreDescription())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandJoinDescription())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final @Nullable ChatChannel channel = ChannelUtils.locateChannel(handler.get("channel"));
if (channel == null) {
// send a message
this.carbonMessages.channelNotFound(sender);
return;
}
if (!channel.speechPermitted(sender).permitted()) {
// send a message
this.carbonMessages.channelNoPermission(sender);
return;
}
if (!sender.leftChannels().contains(channel.key())) {
// send a message
this.carbonMessages.channelNotLeft(sender);
return;
}
sender.joinChannel(channel);
// send a message
this.carbonMessages.channelJoined(sender);
})
.build();
@@ -77,26 +77,24 @@ public class LeaveCommand extends CarbonCommand {
RichDescription.of(this.carbonMessages.commandWhisperArgumentMessage()))
.permission("carbon.join")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandIgnoreDescription())
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandLeaveDescription())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final @Nullable ChatChannel channel = ChannelUtils.locateChannel(handler.get("channel"));
if (channel == null) {
// send a message
this.carbonMessages.channelNotFound(sender);
return;
}
if (!channel.speechPermitted(sender).permitted()) {
// send a message
this.carbonMessages.channelNoPermission(sender);
return;
}
if (sender.leftChannels().contains(channel.key())) {
// send a message
this.carbonMessages.channelAlreadyLeft(sender);
return;
}
sender.joinChannel(channel);
// send a message
sender.leaveChannel(channel);
this.carbonMessages.channelLeft(sender);
})
.build();
@@ -49,6 +49,24 @@ public interface CarbonMessages {
@Message("channel.radius.empty_recipients")
void emptyRecipients(final Audience audience);
@Message("channel.not_found")
void channelNotFound(final Audience audience);
@Message("channel.not_left")
void channelNotLeft(final Audience audience);
@Message("channel.already_left")
void channelAlreadyLeft(final Audience audience);
@Message("channel.no_permission")
void channelNoPermission(final Audience audience);
@Message("channel.left")
void channelLeft(final Audience audience);
@Message("channel.joined")
void channelJoined(final Audience audience);
/*
* =============================================================
* =========================== Mutes ===========================
@@ -275,6 +293,12 @@ public interface CarbonMessages {
@Message("command.ignore.description")
Component commandIgnoreDescription();
@Message("command.join.description")
Component commandJoinDescription();
@Message("command.leave.description")
Component commandLeaveDescription();
@Message("command.mute.argument.player")
Component commandMuteArgumentPlayer();
@@ -23,6 +23,8 @@ command.help.misc.showing_results_for_query=Showing search results for query
command.ignore.argument.player=The name of the player to ignore.
command.ignore.argument.uuid=The UUID of the player to ignore.
command.ignore.description=Hides all incoming messages from ignored players.
command.join.description=Join a channel you have previously left.
command.leave.description=Leave a channel that you currently have access to.
command.mute.argument.player=The name of the player to mute.
command.mute.argument.uuid=The UUID of the player to mute.
command.mute.description=Mutes players, preventing them from using chat or whispering other players.
@@ -95,3 +97,10 @@ whisper.ignored_by_target=<red><target> <red>is ignoring you
whisper.ignoring_target=<red>You are ignoring <target>
whisper.to=<gold>[<green>You</green>] -> [<green><recipient_display_name></green>] <message>
channel.radius.empty_recipients=<red>You're not close enough to anyone to send a message
channel.joined=<green>You have rejoined the channel</green>
channel.left=<red>You have left the channel</red>
channel.no_permission=<red>You do not have permission to use this channel</red>
channel.already_left=<red>You have already left this channel</red>
channel.not_left=<red>You have not left this channel</red>
channel.not_found=<red>Channel not found</red>