Skip to content

Commit 87f31f2

Browse files
authored
Merge branch 'main' into resolve-228
2 parents 3f520bf + f766397 commit 87f31f2

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

plugin/src/main/java/at/helpch/chatchat/listener/ChatListener.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public void onChat(final AsyncPlayerChatEvent event) {
7373

7474
final var consoleFormat = plugin.configManager().formats().consoleFormat();
7575

76+
final var oldChannel = user.channel();
77+
78+
// We switch the user to the channel here so that the console can parse the correct channel prefix
79+
user.channel(channel);
80+
7681
event.setMessage(LegacyComponentSerializer.legacySection().serialize(
7782
MessageProcessor.processMessage(plugin, user, ConsoleUser.INSTANCE, message)
7883
));
@@ -97,6 +102,7 @@ public void onChat(final AsyncPlayerChatEvent event) {
97102
// Cancel the event if the message doesn't end up being sent
98103
// This only happens if the message contains illegal characters or if the ChatChatEvent is canceled.
99104
event.setCancelled(!MessageProcessor.process(plugin, user, channel, message, event.isAsynchronous()));
105+
user.channel(oldChannel);
100106
}
101107

102108
private static String cleanseMessage(@NotNull final String message) {

plugin/src/main/java/at/helpch/chatchat/util/ChannelUtils.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import at.helpch.chatchat.api.user.User;
66
import at.helpch.chatchat.channel.ChatChannel;
77
import org.bukkit.Location;
8+
import org.bukkit.World;
89
import org.jetbrains.annotations.NotNull;
910

1011
import java.util.List;
@@ -53,10 +54,15 @@ public static boolean isTargetWithinRadius(
5354
}
5455

5556
if (radius != -1 && source instanceof ChatUser) {
56-
final Location sourceLocation = ((ChatUser) source).player().getLocation();
5757
final Location targetLocation = targetChatUser.player().getLocation();
58-
final int relativeX = targetLocation.getBlockX() - sourceLocation.getBlockX();
59-
final int relativeZ = targetLocation.getBlockZ() - sourceLocation.getBlockZ();
58+
final Location targetLocation = ((ChatUser) target).player().getLocation();
59+
60+
final World sourceWorld = sourceLocation.getWorld();
61+
final World targetWorld = targetLocation.getWorld();
62+
63+
if(sourceWorld != null && targetWorld != null && !sourceWorld.getUID().equals(targetWorld.getUID())) {
64+
return false;
65+
}
6066

6167
return relativeX*relativeX + relativeZ*relativeZ <= radius*radius;
6268
}

plugin/src/main/java/at/helpch/chatchat/util/MessageProcessor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ private MessageProcessor() {
5959
throw new AssertionError("Util classes are not to be instantiated!");
6060
}
6161

62+
/**
63+
* Process a message for a user and send it to the recipients.
64+
* @param plugin The plugin instance.
65+
* @param user The user sending the message.
66+
* @param channel The channel the user is sending the message to.
67+
* @param message The message to send.
68+
* @param async Whether to process the message asynchronously.
69+
*
70+
* @return Whether the message was sent successfully.
71+
*/
6272
public static boolean process(
6373
@NotNull final ChatChatPlugin plugin,
6474
@NotNull final ChatUser user,

0 commit comments

Comments
 (0)