Skip to content

Commit

Permalink
Add ignore player methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaFox161 committed Jul 30, 2016
1 parent cbe3824 commit 811d75a
Showing 1 changed file with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -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 <code>true</code> if ignored, else <code>false</code>.
*/
public static boolean isIgnoringPlayer(Player player, Player playerIgnored) {
return getIgnoredPlayers(player).contains(playerIgnored.getUniqueId());
}

//Getters
/**
* Gets the player's chat color (Default White).
Expand All @@ -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<UUID> getIgnoredPlayers(Player player) {
ArrayList<UUID> 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.
Expand Down Expand Up @@ -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 <code>true</code> if successful, else <code>false</code>.
*/
public static Boolean ignorePlayer(Player player, Player playerToIgnore) {
YamlConfiguration playerData = getPlayerDataYml(player);
List<String> 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 <code>true</code> if successful, else <code>false</code>.
*/
public static Boolean unignorePlayer(Player player, Player toStopIgnoring) {
YamlConfiguration playerData = getPlayerDataYml(player);
List<String> 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;
}
}

0 comments on commit 811d75a

Please sign in to comment.