diff --git a/src/main/java/com/songoda/skyblock/command/commands/admin/ChatSpyCommand.java b/src/main/java/com/songoda/skyblock/command/commands/admin/ChatSpyCommand.java index a77f5521..6974a548 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/admin/ChatSpyCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/admin/ChatSpyCommand.java @@ -18,6 +18,7 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import java.io.File; +import java.util.Set; import java.util.UUID; public class ChatSpyCommand extends SubCommand { @@ -45,39 +46,57 @@ public class ChatSpyCommand extends SubCommand { case "global": if(!playerData.isGlobalChatSpy()){ playerData.enableGlobalChatSpy(); - messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.Bank.ByConsole.Message")); + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.GlobalEnabled.Message")); } else { - messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.Bank.ByConsole.Message")); + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.GlobalAlreadyEnabled.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1f, 1f); } break; case "add": if(args.length > 2){ - Island island = islandManager.getIslandByPlayer(new OfflinePlayer(UUID.fromString(args[1])).getBukkitOfflinePlayer()); + OfflinePlayer offlinePlayer = new OfflinePlayer(args[1]); + Island island = islandManager.getIslandByPlayer(offlinePlayer.getBukkitOfflinePlayer()); if(island != null) { playerData.addChatSpyIsland(island); + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.Add.Message")); + } else { + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.NullIsland.Message")); } } else { - messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.Bank.Unexpected.Message")); + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.InvalidArgNumber.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1f, 1f); } break; case "remove": if(args.length > 2){ - Island island = islandManager.getIslandByPlayer(new OfflinePlayer(UUID.fromString(args[1])).getBukkitOfflinePlayer()); + OfflinePlayer offlinePlayer = new OfflinePlayer(args[1]); + Island island = islandManager.getIslandByPlayer(offlinePlayer.getBukkitOfflinePlayer()); if(island != null) { playerData.removeChatSpyIsland(island); + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.Remove.Message")); + } else { + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.NullIsland.Message")); } } else { - messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.Bank.Unexpected.Message")); + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.InvalidArgNumber.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1f, 1f); } break; case "list": - + Set uuidSet = playerData.getChatSpyIslands(); + if(!uuidSet.isEmpty()){ + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.List.Start.Message")); + for(UUID uuid : uuidSet) { + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.List.List.Message") + .replace("%owner", new OfflinePlayer(uuid).getName())); + } + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.List.End.Message")); + } else { + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.List.Empty.Message")); + } break; default: - messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.Bank.Unexpected.Message")); + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.InvalidArgNumber.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1f, 1f); break; } @@ -118,6 +137,6 @@ public class ChatSpyCommand extends SubCommand { @Override public String[] getArguments() { - return new String[0]; + return new String[]{"toggle", "global", "add", "remove", "list"}; } } diff --git a/src/main/java/com/songoda/skyblock/playerdata/PlayerData.java b/src/main/java/com/songoda/skyblock/playerdata/PlayerData.java index 291e033d..c878f9cf 100644 --- a/src/main/java/com/songoda/skyblock/playerdata/PlayerData.java +++ b/src/main/java/com/songoda/skyblock/playerdata/PlayerData.java @@ -350,6 +350,10 @@ public class PlayerData { Bukkit.getScheduler().runTaskAsynchronously(skyblock, this::save); } + public Set getChatSpyIslands() { + return new HashSet<>(spiedIslands); + } + public void addChatSpyIsland(Island island) { this.addChatSpyIsland(island.getOwnerUUID()); } diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 6812a057..3c40d9cc 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -183,6 +183,27 @@ Command: Message: '&bSkyBlock &8| &aInfo&8: &eChat spy enabled.' Disabled: Message: '&bSkyBlock &8| &aInfo&8: &eChat spy disabled.' + GlobalEnabled: + Message: '&bSkyBlock &8| &aInfo&8: &eEnabled global chat spy.' + GlobalAlreadyEnabled: + Message: '&bSkyBlock &8| &cError&8: &eGlobal chat spy already enabled.' + Add: + Message: '&bSkyBlock &8| &aInfo&8: &eAdded %owner''s island to chat spy.' + Remove: + Message: '&bSkyBlock &8| &aInfo&8: &eRemoved %owner''s island to chat spy.' + NullIsland: + Message: '&bSkyBlock &8| &cError&8: &ePlayer does not have an island.' + InvalidArgNumber: + Message: '&bSkyBlock &8| &cError&8: &eInvalid arguments number.' + List: + Start: + Message: '&bSkyBlock &8| &aInfo&8: &eCurrently spied island''s chats:' + List: + Message: '&a- &e%owner' + End: + Message: '&a---------' + Empty: + Message: '&bSkyBlock &8| &aInfo&8: &eYou are not spying on any island''s chat. Global mode is enabled.' Reload: Info: Message: '&f&oReload all loaded files.'