added config option and fixed issues. should be ready to merge

This commit is contained in:
Olzie-12 committed 2022-12-15 22:38:03 +00:00
1 parent 90ef438ea9
commit 15c445ee91
5 files changed
+28 -4

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)) return false; if (!(other instanceof BasicChatChannel otherChannel)) return false;
@@ -36,7 +36,7 @@ public class RadiusListener {
final CarbonMessages carbonMessages 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;
} }
@@ -76,9 +76,9 @@ public class RadiusListener {
return false; return false;
}); });
} }
if (event.recipients().size() > 1) return; if (event.recipients().size() <= 2 && event.chatChannel().emptyRadiusRecipientsMessage()) { // the player and cosole
carbonMessages.emptyRecipients(event.sender()); carbonMessages.emptyRecipients(event.sender());
}
}); });
} }
@@ -94,4 +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>No players found within <radius> blocks of <sender> channel.radius.empty_recipients=<red>You're not close enough to anyone to send a message