From 6b548bc8d68c441e3787ef90fbcdb10a3da347be Mon Sep 17 00:00:00 2001 From: len <40720638+destro174@users.noreply.github.com> Date: Thu, 8 Apr 2021 18:13:47 +0200 Subject: [PATCH] Fix afkcheck not being picked up by spy --- src/main/java/com/alttd/afkdectector/Lang.java | 2 +- .../alttd/afkdectector/command/AFKCheckCommand.java | 10 +++++++++- .../com/alttd/afkdectector/command/AFKListCommand.java | 6 +++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/alttd/afkdectector/Lang.java b/src/main/java/com/alttd/afkdectector/Lang.java index 1405003..c19891a 100755 --- a/src/main/java/com/alttd/afkdectector/Lang.java +++ b/src/main/java/com/alttd/afkdectector/Lang.java @@ -18,7 +18,7 @@ public enum Lang { AFK_PREFIX("afk-prefix", "[AFK]"), AFKCHECKTITLE("afkcheck-title", "AFK CHECK"), AFKCHECKSUBTITLE("afkcheck-subtitle", "Please respond to the dm from staff!"), - AFKCHECKCMESSAGE("afkcheck-message", "Hey, since you're near a farm and not moving I'm making sure you aren't afk. Please respond to me if you're not AFK."); + AFKCHECKCMESSAGE("afkcheck-message", "Hey, since you're near a farm and not moving. I'm making sure you aren't afk. Please respond to me if you're not AFK."); private String path; diff --git a/src/main/java/com/alttd/afkdectector/command/AFKCheckCommand.java b/src/main/java/com/alttd/afkdectector/command/AFKCheckCommand.java index 4623e63..7c10be4 100755 --- a/src/main/java/com/alttd/afkdectector/command/AFKCheckCommand.java +++ b/src/main/java/com/alttd/afkdectector/command/AFKCheckCommand.java @@ -12,6 +12,7 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; import java.util.List; @@ -40,7 +41,14 @@ public class AFKCheckCommand implements CommandExecutor, TabCompleter { } target.showTitle(Title.title(Component.text(Lang.AFKCHECKTITLE.toString(), NamedTextColor.RED), Component.text(Lang.AFKCHECKSUBTITLE.toString(), NamedTextColor.RED))); - Bukkit.dispatchCommand(sender, "msg " + args[0] + " " + Lang.AFKCHECKCMESSAGE.toString()); + if(sender instanceof Player) { + Player player = (Player) sender; + PlayerCommandPreprocessEvent commandEvent = new PlayerCommandPreprocessEvent(player, "/" + "msg " + args[0] + " " + Lang.AFKCHECKCMESSAGE.toString()); + Bukkit.getPluginManager().callEvent(commandEvent); + player.performCommand("msg " + args[0] + " " + Lang.AFKCHECKCMESSAGE.toString()); + } else { + Bukkit.dispatchCommand(sender, "msg " + args[0] + " " + Lang.AFKCHECKCMESSAGE.toString()); + } return true; } diff --git a/src/main/java/com/alttd/afkdectector/command/AFKListCommand.java b/src/main/java/com/alttd/afkdectector/command/AFKListCommand.java index d13fb33..48b18ad 100755 --- a/src/main/java/com/alttd/afkdectector/command/AFKListCommand.java +++ b/src/main/java/com/alttd/afkdectector/command/AFKListCommand.java @@ -30,14 +30,14 @@ public class AFKListCommand implements CommandExecutor, TabCompleter { if(System.currentTimeMillis() - standingTime > plugin.toggletime * 60 * 1000) { afkplayers += 1; message = message.append(Component.newline()); - Component userinfo = Component.text(afkplayer.getPlayerName(), NamedTextColor.DARK_PURPLE) - .append(Component.text(" has been afk for " + (System.currentTimeMillis() - standingTime) / 1000 + " seconds.")) + Component userinfo = Component.text(afkplayer.getPlayerName(), NamedTextColor.GOLD) + .append(Component.text(" has been afk for " + (System.currentTimeMillis() - standingTime) / 1000 + " seconds.", NamedTextColor.WHITE)) .hoverEvent(Component.text("Click here to send an afkcheck to " + afkplayer.getPlayerName() + "!" , NamedTextColor.GRAY).asHoverEvent()) .clickEvent(net.kyori.adventure.text.event.ClickEvent.runCommand("/afkcheck " + afkplayer.getPlayerName())); message = message.append(userinfo); } } - Component component = Component.text(Lang.AFK_LIST.toString().replaceAll("%afkplayers%", Integer.toString(afkplayers)), NamedTextColor.YELLOW, TextDecoration.BOLD); + Component component = Component.text(Lang.AFK_LIST.toString().replaceAll("%afkplayers%", Integer.toString(afkplayers)), NamedTextColor.YELLOW); sender.sendMessage(component.append(message)); return true; }