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();