From eb84659e5bed8b0ef6b8c9a8a93b4f49e72f0b44 Mon Sep 17 00:00:00 2001 From: nickreesdev Date: Fri, 19 Feb 2021 23:38:16 -0600 Subject: [PATCH] Added a /find command. --- .../themcgamer/core/server/ServerManager.java | 1 + .../core/server/command/FindCommand.java | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 core/src/main/java/zone/themcgamer/core/server/command/FindCommand.java 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