Skip to content

Commit

Permalink
Add radius spying
Browse files Browse the repository at this point in the history
  • Loading branch information
Draycia committed May 24, 2024
1 parent 4c96b88 commit f154ce5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package net.draycia.carbon.common.listeners;

import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.api.event.events.CarbonChatEvent;
import net.draycia.carbon.api.users.CarbonPlayer;
Expand All @@ -46,14 +48,22 @@ public RadiusListener(
return;
}

final List<CarbonPlayer> spyingPlayers = new ArrayList<>();

if (radius == 0) {
event.recipients().removeIf(audience -> {
if (audience.equals(event.sender())) {
return false;
}

if (audience instanceof CarbonPlayer carbonPlayer) {
return !carbonPlayer.sameWorldAs(event.sender());
final boolean sameWorld = carbonPlayer.sameWorldAs(event.sender());

if (!sameWorld && carbonPlayer.spying()) {
spyingPlayers.add(carbonPlayer);
}

return !sameWorld;
}

return false;
Expand All @@ -66,18 +76,32 @@ public RadiusListener(

if (audience instanceof CarbonPlayer carbonPlayer) {
if (!event.sender().sameWorldAs(carbonPlayer)) {
if (carbonPlayer.spying()) {
spyingPlayers.add(carbonPlayer);
}
return true;
}

final double distance = carbonPlayer.distanceSquaredFrom(event.sender());
return distance > (radius * radius);
final boolean outOfRange = distance > (radius * radius);

if (outOfRange && carbonPlayer.spying()) {
spyingPlayers.add(carbonPlayer);
}

return outOfRange;
}

return false;
});
}
if (event.recipients().size() <= 2 && event.chatChannel().emptyRadiusRecipientsMessage()) { // the player and cosole
carbonMessages.emptyRecipients(event.sender());
return;
}

for (final CarbonPlayer player : spyingPlayers) {
carbonMessages.radiusSpy(player, event.message());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public interface CarbonMessages {
@Message("channel.radius.empty_recipients")
void emptyRecipients(final Audience audience);

@Message("channel.radius.spy")
void radiusSpy(Audience audience, Component message);

@Message("channel.not_found")
void channelNotFound(final Audience audience);

Expand Down

0 comments on commit f154ce5

Please sign in to comment.