Skip to content

Commit

Permalink
Do not resolve pm target when player can't see it
Browse files Browse the repository at this point in the history
  • Loading branch information
Brikster committed Jun 30, 2024
1 parent f2417c1 commit 73baee5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void execute(@NotNull CommandContext<CommandSender> commandContext) {
CommandSender sender = commandContext.getSender();

String targetName = commandContext.get("target");
PmMessageTarget target = pmMessageService.resolveTarget(targetName, true);
PmMessageTarget target = pmMessageService.resolveTarget(sender, targetName, true);
if (target == null) {
audiences.sender(sender).sendMessage(messagesConfig.getPmPlayerNotFound());
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,20 @@ public class PmMessageService {
.expireAfterAccess(Duration.ofMinutes(10))
.build();

public @Nullable PmMessageTarget resolveTarget(String targetName, boolean allowConsole) {
public @Nullable PmMessageTarget resolveTarget(CommandSender sender,
String targetName,
boolean allowConsole) {
PmMessageTarget target = null;
if (allowConsole && pmConfig.isAllowConsole() && targetName.equalsIgnoreCase("Console")) {
target = new CommandSenderPmMessageTarget(Bukkit.getConsoleSender());
} else {
Player targetPlayer = Bukkit.getPlayer(targetName);
if (targetPlayer != null) {
// return null if target is vanished
if (sender instanceof Player
&& !((Player) sender).canSee(targetPlayer)) {
return null;
}
target = new CommandSenderPmMessageTarget(targetPlayer);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void execute(@NotNull CommandContext<CommandSender> commandContext) {

UUID targetUuid;

PmMessageTarget target = pmMessageService.resolveTarget(targetName, false);
PmMessageTarget target = pmMessageService.resolveTarget(sender, targetName, false);
if (target == null) {
targetUuid = repository.getCachedUuid(targetName);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void execute(@NotNull CommandContext<CommandSender> commandContext) {

UUID targetUuid;

PmMessageTarget target = pmMessageService.resolveTarget(targetName, false);
PmMessageTarget target = pmMessageService.resolveTarget(sender, targetName, false);
if (target == null) {
targetUuid = repository.getCachedUuid(targetName);
} else {
Expand Down

0 comments on commit 73baee5

Please sign in to comment.