From 811d75a7ff84e67a8bd2f803d5ba65369ebed082 Mon Sep 17 00:00:00 2001 From: NovaFox161 Date: Sat, 30 Jul 2016 15:52:16 -0500 Subject: [PATCH] Add ignore player methods. --- .../data/PlayerDataManager.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/main/java/com/cloudcraftgaming/perworldchatplus/data/PlayerDataManager.java b/src/main/java/com/cloudcraftgaming/perworldchatplus/data/PlayerDataManager.java index b1d8831..4d68174 100644 --- a/src/main/java/com/cloudcraftgaming/perworldchatplus/data/PlayerDataManager.java +++ b/src/main/java/com/cloudcraftgaming/perworldchatplus/data/PlayerDataManager.java @@ -7,6 +7,7 @@ import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -166,6 +167,16 @@ public static boolean hasChatMuted(Player player) { return PlayerDataManager.getPlayerDataYml(player).getString("ChatMute").equalsIgnoreCase("True"); } + /** + * Checks if the specified player is ignoring the other player. + * @param player The player who to check. + * @param playerIgnored The player that may be ignored. + * @return true if ignored, else false. + */ + public static boolean isIgnoringPlayer(Player player, Player playerIgnored) { + return getIgnoredPlayers(player).contains(playerIgnored.getUniqueId()); + } + //Getters /** * Gets the player's chat color (Default White). @@ -176,6 +187,21 @@ public static ChatColor getChatColor(Player player) { return ChatColor.valueOf(getPlayerDataYml(player).getString("ChatColor")); } + /** + * Gets a list of all players that are being ignored by the specified player. + * @param player The player to get. + * @return An ArrayList of UUIDs of ignored players. + */ + public static ArrayList getIgnoredPlayers(Player player) { + ArrayList ignored = new ArrayList<>(); + if (getPlayerDataYml(player).contains("Ignored")) { + for (String uuidString : getPlayerDataYml(player).getStringList("Ignored")) { + ignored.add(UUID.fromString(uuidString)); + } + } + return ignored; + } + //Setters /** * Sets the player's chat mute status. If true, they will not see any chat messages. False if they should see chat messages. @@ -248,4 +274,40 @@ public static void setChatColor(Player player, ChatColor color) { data.set("ChatColor", color.name()); savePlayerData(data, getPlayerDataFile(player)); } + + /** + * Ignores the specified player. + * @param player The player who wants to ignore someone. + * @param playerToIgnore The player to ignore. + * @return true if successful, else false. + */ + public static Boolean ignorePlayer(Player player, Player playerToIgnore) { + YamlConfiguration playerData = getPlayerDataYml(player); + List ignoredPlayers = playerData.getStringList("Ignored"); + if (!ignoredPlayers.contains(playerToIgnore.getUniqueId().toString())) { + ignoredPlayers.add(playerToIgnore.getUniqueId().toString()); + playerData.set("Ignored", ignoredPlayers); + savePlayerData(playerData, getPlayerDataFile(player)); + return true; + } + return false; + } + + /** + * Stops ignoring the specified player. + * @param player The player who wants to stop ignoring someone. + * @param toStopIgnoring The player to stop ignoring. + * @return true if successful, else false. + */ + public static Boolean unignorePlayer(Player player, Player toStopIgnoring) { + YamlConfiguration playerData = getPlayerDataYml(player); + List ignoredPlayers = playerData.getStringList("Ignored"); + if (ignoredPlayers.contains(toStopIgnoring.getUniqueId().toString())) { + ignoredPlayers.remove(toStopIgnoring.getUniqueId().toString()); + playerData.set("Ignored", ignoredPlayers); + savePlayerData(playerData, getPlayerDataFile(player)); + return true; + } + return false; + } } \ No newline at end of file