Merge pull request #223 from Olzie-12/emptyRecipients

This commit is contained in:
Josua Parks authored and GitHub committed 2022-12-16 14:25:27 -08:00
commit 107ee990c8
6 files changed
+35 -2

No files matched your search

@@ -131,6 +131,14 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
*/ */
double radius(); double radius();
/**
* If the empty receipt message should be sent to the sender.
*
* @return Returns true if the channel should display a message when a player is out of range.
* @since 2.1.0
*/
boolean emptyRadiusRecipientsMessage();
/** /**
* Represents the result of a channel permission check. * Represents the result of a channel permission check.
* *
@@ -103,6 +103,11 @@ public final class BasicChatChannel implements ChatChannel {
return -1; return -1;
} }
@Override
public boolean emptyRadiusRecipientsMessage() {
return true;
}
@Override @Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer carbonPlayer) { public ChannelPermissionResult speechPermitted(final CarbonPlayer carbonPlayer) {
return ChannelPermissionResult.allowed(); return ChannelPermissionResult.allowed();
@@ -110,6 +110,12 @@ public final class ConfigChatChannel implements ChatChannel {
""") """)
private int radius = -1; private int radius = -1;
@Comment("""
If true, players will be able to see if they're not sending messages to anyone
because they're out of range from the radius.
""")
private boolean emptyRadiusRecipientsMessage = true;
private transient @Nullable ConfigChannelMessages messageService = null; private transient @Nullable ConfigChannelMessages messageService = null;
@Override @Override
@@ -290,6 +296,11 @@ public final class ConfigChatChannel implements ChatChannel {
return this.radius; return this.radius;
} }
@Override
public boolean emptyRadiusRecipientsMessage() {
return this.emptyRadiusRecipientsMessage;
}
@Override @Override
public boolean equals(final Object other) { public boolean equals(final Object other) {
if (!(other instanceof BasicChatChannel otherChannel)) { if (!(other instanceof BasicChatChannel otherChannel)) {
@@ -23,6 +23,7 @@ import com.google.inject.Inject;
import net.draycia.carbon.api.CarbonChat; import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.events.CarbonChatEvent; import net.draycia.carbon.api.events.CarbonChatEvent;
import net.draycia.carbon.api.users.CarbonPlayer; import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.messages.CarbonMessages;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier; import org.checkerframework.framework.qual.DefaultQualifier;
@@ -31,10 +32,11 @@ public class RadiusListener {
@Inject @Inject
public RadiusListener( public RadiusListener(
final CarbonChat carbonChat final CarbonChat carbonChat,
final CarbonMessages carbonMessages
) { ) {
carbonChat.eventHandler().subscribe(CarbonChatEvent.class, 0, false, event -> { carbonChat.eventHandler().subscribe(CarbonChatEvent.class, 0, false, event -> {
if (event.chatChannel() == null) { if (event.chatChannel() == null || event.previewing()) {
return; return;
} }
@@ -74,6 +76,9 @@ public class RadiusListener {
return false; return false;
}); });
} }
if (event.recipients().size() <= 2 && event.chatChannel().emptyRadiusRecipientsMessage()) { // the player and cosole
carbonMessages.emptyRecipients(event.sender());
}
}); });
} }
@@ -50,6 +50,9 @@ public interface CarbonMessages {
@Message("channel.change") @Message("channel.change")
void changedChannels(final Audience audience, final String channel); void changedChannels(final Audience audience, final String channel);
@Message("channel.radius.empty_recipients")
void emptyRecipients(final Audience audience);
/* /*
* ============================================================= * =============================================================
* =========================== Mutes =========================== * =========================== Mutes ===========================
@@ -94,3 +94,4 @@ whisper.from=<gold>[<green><sender_display_name></green>] -> [<green>You</green>
whisper.ignored_by_target=<red><target> <red>is ignoring you whisper.ignored_by_target=<red><target> <red>is ignoring you
whisper.ignoring_target=<red>You are ignoring <target> whisper.ignoring_target=<red>You are ignoring <target>
whisper.to=<gold>[<green>You</green>] -> [<green><recipient_display_name></green>] <message> 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