From 3c9e38d7ade5acb5e7dfff5fd87c7a1c370ff584 Mon Sep 17 00:00:00 2001 From: GJ Date: Thu, 29 Mar 2012 10:05:04 -0400 Subject: [PATCH] Helps to include the new file. --- .../java/com/gmail/nossr50/api/PartyAPI.java | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/main/java/com/gmail/nossr50/api/PartyAPI.java diff --git a/src/main/java/com/gmail/nossr50/api/PartyAPI.java b/src/main/java/com/gmail/nossr50/api/PartyAPI.java new file mode 100644 index 000000000..1973d9bb1 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/api/PartyAPI.java @@ -0,0 +1,102 @@ +package com.gmail.nossr50.api; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.ArrayList; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import com.gmail.nossr50.Users; +import com.gmail.nossr50.datatypes.PlayerProfile; + +public class PartyAPI { + + /** + * Get the name of the party a player is in. + *
+ * This function is designed for API usage. + * + * @param player The player to check the party name of + * @return the name of the player's party + */ + public static String getPartyName(Player player) { + PlayerProfile PP = Users.getProfile(player); + return PP.getParty(); + } + + /** + * Checks if a player is in a party. + *
+ * This function is designed for API usage. + * + * @param player The player to check + * @return true if the player is in a party, false otherwise + */ + public static boolean inParty(Player player) { + PlayerProfile PP = Users.getProfile(player); + return PP.inParty(); + } + + /** + * Check if two players are in the same party. + *
+ * This function is designed for API usage. + * + * @param playera The first player to check + * @param playerb The second player to check + * @return true if the two players are in the same party, false otherwise + */ + public static boolean inSameParty(Player playera, Player playerb) { + if (Users.getProfile(playera).inParty() && Users.getProfile(playerb).inParty()) { + if (Users.getProfile(playera).getParty().equals(Users.getProfile(playerb).getParty())) { + return true; + } + else { + return false; + } + } + else { + return false; + } + } + + /** + * Get a list of all current party names. + *
+ * This function is designed for API usage. + * + * @return the list of parties. + */ + public static ArrayList getParties() { + String location = "plugins/mcMMO/mcmmo.users"; + ArrayList parties = new ArrayList(); + + try { + + //Open the users file + FileReader file = new FileReader(location); + BufferedReader in = new BufferedReader(file); + String line = ""; + + while((line = in.readLine()) != null) { + String[] character = line.split(":"); + String theparty = null; + + //Party + if (character.length > 3) { + theparty = character[3]; + } + + if (!parties.contains(theparty)) { + parties.add(theparty); + } + } + in.close(); + } + catch (Exception e) { + Bukkit.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString()); + } + return parties; + } +}