diff --git a/core/src/main/java/zone/themcgamer/core/server/ServerManager.java b/core/src/main/java/zone/themcgamer/core/server/ServerManager.java index 3832eeb..7bb0d1e 100644 --- a/core/src/main/java/zone/themcgamer/core/server/ServerManager.java +++ b/core/src/main/java/zone/themcgamer/core/server/ServerManager.java @@ -33,6 +33,7 @@ public class ServerManager extends Module { registerCommand(new HubCommand(traveler)); registerCommand(new RestartCommand(this, serverGroupRepository, minecraftServerRepository)); registerCommand(new StopCommand(this)); + registerCommand(new FindCommand()); // Handle server restarting JedisCommandHandler.getInstance().addListener(jedisCommand -> { diff --git a/core/src/main/java/zone/themcgamer/core/server/command/FindCommand.java b/core/src/main/java/zone/themcgamer/core/server/command/FindCommand.java new file mode 100644 index 0000000..c7a91c9 --- /dev/null +++ b/core/src/main/java/zone/themcgamer/core/server/command/FindCommand.java @@ -0,0 +1,40 @@ +package zone.themcgamer.core.server.command; + +import org.bukkit.command.CommandSender; +import zone.themcgamer.core.command.Command; +import zone.themcgamer.core.command.CommandProvider; +import zone.themcgamer.core.common.Style; +import zone.themcgamer.data.Rank; +import zone.themcgamer.data.jedis.cache.CacheRepository; +import zone.themcgamer.data.jedis.cache.ICacheItem; +import zone.themcgamer.data.jedis.cache.ItemCacheType; +import zone.themcgamer.data.jedis.cache.impl.PlayerStatusCache; +import zone.themcgamer.data.jedis.repository.RedisRepository; + +import java.util.List; + +/** + * @author Nicholas + */ +public class FindCommand { + @Command(name = "find", aliases = {"locate", "where"}, description = "Find a player on the network", ranks = Rank.HELPER) + public void onCommand(CommandProvider command) { + CommandSender sender = command.getSender(); + String[] args = command.getArgs(); + if (args.length < 1) { + sender.sendMessage(Style.main("Find", "Usage: /" + command.getLabel() + " ")); + return; + } + CacheRepository cacheRepository = RedisRepository.getRepository(CacheRepository.class).orElse(null); + if (cacheRepository == null) + return; + List> playerStatuses = cacheRepository + .filter(iCacheItem -> iCacheItem.getType() == ItemCacheType.PLAYER_STATUS && ((PlayerStatusCache) iCacheItem).getPlayerName().equalsIgnoreCase(args[0])); + if (playerStatuses.isEmpty()) { + sender.sendMessage(Style.error("Find", "§b" + args[0] + " §7was not found.")); + return; + } + PlayerStatusCache playerStatusCacheOptional = (PlayerStatusCache) playerStatuses.get(0); + sender.sendMessage(Style.main("Find", "§b" + playerStatusCacheOptional.getPlayerName() + " §7is online on §b" + playerStatusCacheOptional.getServer() + "§7.")); + } +} \ No newline at end of file