From afd95fd0843bd29c692d08015276afa1775ba8e7 Mon Sep 17 00:00:00 2001 From: Len <40720638+destro174@users.noreply.github.com> Date: Mon, 6 Apr 2026 14:41:34 +0200 Subject: [PATCH] Add RelogCheckCommand --- .../com/alttd/afkdectector/AFKDetector.java | 2 + .../command/RelogCheckCommand.java | 65 +++++++++++++++++++ .../alttd/afkdectector/config/Messages.java | 3 + src/main/resources/plugin.yml | 5 ++ 4 files changed, 75 insertions(+) create mode 100755 src/main/java/com/alttd/afkdectector/command/RelogCheckCommand.java diff --git a/src/main/java/com/alttd/afkdectector/AFKDetector.java b/src/main/java/com/alttd/afkdectector/AFKDetector.java index ec49600..ccb8a7e 100755 --- a/src/main/java/com/alttd/afkdectector/AFKDetector.java +++ b/src/main/java/com/alttd/afkdectector/AFKDetector.java @@ -4,6 +4,7 @@ import com.alttd.afkdectector.afkplayer.AFKPlayer; import com.alttd.afkdectector.command.AFKCheckCommand; import com.alttd.afkdectector.command.AFKListCommand; import com.alttd.afkdectector.command.ReloadCommand; +import com.alttd.afkdectector.command.RelogCheckCommand; import com.alttd.afkdectector.config.Config; import com.alttd.afkdectector.config.Messages; import com.alttd.afkdectector.config.MessagesConfig; @@ -55,6 +56,7 @@ public class AFKDetector extends JavaPlugin implements Listener { //getCommand("afk").setExecutor(new AFKCommand(this)); getCommand("afklist").setExecutor(new AFKListCommand(this)); getCommand("afkcheck").setExecutor(new AFKCheckCommand(this)); + getCommand("relogcheck").setExecutor(new RelogCheckCommand(this)); getCommand("reloadafkdetector").setExecutor(new ReloadCommand(this)); new AFKCheckTimer(this).init(); myPetEnabled = getServer().getPluginManager().isPluginEnabled("MyPet"); diff --git a/src/main/java/com/alttd/afkdectector/command/RelogCheckCommand.java b/src/main/java/com/alttd/afkdectector/command/RelogCheckCommand.java new file mode 100755 index 0000000..7dec96f --- /dev/null +++ b/src/main/java/com/alttd/afkdectector/command/RelogCheckCommand.java @@ -0,0 +1,65 @@ +package com.alttd.afkdectector.command; + +import com.alttd.afkdectector.AFKDetector; +import com.alttd.afkdectector.afkplayer.AFKPlayer; +import com.alttd.afkdectector.config.Messages; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.title.Title; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +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 org.bukkit.util.StringUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class RelogCheckCommand implements CommandExecutor, TabCompleter { + + private final AFKDetector plugin; + + public RelogCheckCommand(AFKDetector plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + if (!(args.length > 0)) { + sender.sendMessage(Component.text(command.getUsage(), NamedTextColor.RED)); + return true; + } + Player target = Bukkit.getPlayer(args[0]); + if (target == null) { + sender.sendMessage(Component.text(command.getUsage(), NamedTextColor.RED)); + return true; + } + MiniMessage miniMessage = AFKDetector.miniMessage; + target.showTitle(Title.title(miniMessage.deserialize(Messages.RELOG_CHECK_TITLE.getMessage()), + miniMessage.deserialize(Messages.RELOG_CHECK_SUBTITLE.getMessage()))); + if (sender instanceof Player player) { + String cmd = "msg " + args[0] + " " + Messages.RELOG_CHECK_MESSAGE.getMessage(); + PlayerCommandPreprocessEvent commandEvent = new PlayerCommandPreprocessEvent(player, "/" + cmd); + Bukkit.getPluginManager().callEvent(commandEvent); + player.performCommand(cmd); + } else { + Bukkit.dispatchCommand(sender, "msg " + args[0] + " " + Messages.RELOG_CHECK_MESSAGE.getMessage()); + } + return true; + } + + @Override + public List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, String[] strings) { + List completions = new ArrayList<>(); + if (strings.length == 1) { + StringUtil.copyPartialMatches(strings[0], plugin.players.values().stream().filter(AFKPlayer::isAFK).map(AFKPlayer::getPlayerName).collect(Collectors.toList()), completions); + } + return null; + } +} \ No newline at end of file diff --git a/src/main/java/com/alttd/afkdectector/config/Messages.java b/src/main/java/com/alttd/afkdectector/config/Messages.java index 6ce7890..ed929d1 100644 --- a/src/main/java/com/alttd/afkdectector/config/Messages.java +++ b/src/main/java/com/alttd/afkdectector/config/Messages.java @@ -19,6 +19,9 @@ public enum Messages { AFK_CHECK_TITLE("afkcheck-title", "AFK CHECK"), AFK_CHECK_SUBTITLE("afkcheck-subtitle", "Please respond to the dm from staff!"), AFK_CHECK_MESSAGE("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."), + RELOG_CHECK_TITLE("relogcheck-title", "AFK CHECK"), + RELOG_CHECK_SUBTITLE("relogcheck-subtitle", "Please respond to the dm from staff!"), + RELOG_CHECK_MESSAGE("relogcheck-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."), AFK_KICK_STAFF_MESSAGE("afkkick-staff-messsge", " got afk kicked after being afk for minutes."), SUSPICIOUS_KICK_COUNT("afkkick-suspicious-message", " has had suspicious AFK kicks since last reboot."), AFK_SOON_BOSS_BAR("afk-soon-boss-bar", "Time until AFK."), diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 745b028..da1bba8 100755 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -19,6 +19,11 @@ commands: permission: afkdetector.afkcheck permission-message: You do not have permission! usage: /afkcheck + relogcheck: + description: Sends and relogcheck message to the target + permission: afkdetector.relogcheck + permission-message: You do not have permission! + usage: /relogcheck reloadafkdetector: description: Reloads the plugin config permission: afkdetector.reload