2012-01-09 20:00:13 +01:00
|
|
|
package com.gmail.nossr50.party;
|
|
|
|
|
2012-04-22 21:36:48 +02:00
|
|
|
import java.io.BufferedReader;
|
2012-01-09 20:00:13 +01:00
|
|
|
import java.io.EOFException;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileOutputStream;
|
2012-04-22 21:36:48 +02:00
|
|
|
import java.io.FileReader;
|
2012-01-09 20:00:13 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.ObjectInputStream;
|
|
|
|
import java.io.ObjectOutputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
2012-04-27 08:17:02 +02:00
|
|
|
import java.util.Map;
|
|
|
|
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2012-03-21 03:33:58 +01:00
|
|
|
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-03-21 03:33:58 +01:00
|
|
|
public class Party {
|
2012-04-21 20:05:39 +02:00
|
|
|
public static String pluginPath;
|
|
|
|
public static String partyPlayersFile;
|
|
|
|
public static String partyLocksFile;
|
|
|
|
public static String partyPasswordsFile;
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
HashMap<String, HashMap<String, Boolean>> partyPlayers = new HashMap<String, HashMap<String, Boolean>>();
|
|
|
|
HashMap<String, Boolean> partyLocks = new HashMap<String, Boolean>();
|
|
|
|
HashMap<String, String> partyPasswords = new HashMap<String, String>();
|
|
|
|
|
|
|
|
private static mcMMO plugin;
|
|
|
|
private static volatile Party instance;
|
|
|
|
|
2012-04-27 07:11:13 +02:00
|
|
|
private Party() {
|
|
|
|
plugin = mcMMO.p;
|
2012-04-21 20:05:39 +02:00
|
|
|
pluginPath = plugin.getDataFolder().getPath();
|
|
|
|
partyPlayersFile = pluginPath + File.separator + "FlatFileStuff" + File.separator + "partyPlayers";
|
|
|
|
partyLocksFile = pluginPath + File.separator + "FlatFileStuff" + File.separator + "partyLocks";
|
|
|
|
partyPasswordsFile = pluginPath + File.separator + "FlatFileStuff" + File.separator + "partyPasswords";
|
|
|
|
new File(pluginPath + File.separator + "FlatFileStuff").mkdir();
|
2012-04-27 07:11:13 +02:00
|
|
|
loadParties();
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
public static Party getInstance() {
|
|
|
|
if (instance == null) {
|
2012-04-27 07:11:13 +02:00
|
|
|
instance = new Party();
|
2012-04-03 06:06:30 +02:00
|
|
|
}
|
|
|
|
return instance;
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if two players are in the same party.
|
|
|
|
*
|
|
|
|
* @param playera The first player
|
|
|
|
* @param playerb The second player
|
|
|
|
* @return true if they are in the same party, false otherwise
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
public boolean inSameParty(Player playera, Player playerb){
|
2012-04-03 06:06:30 +02:00
|
|
|
PlayerProfile PPa = Users.getProfile(playera);
|
|
|
|
PlayerProfile PPb = Users.getProfile(playerb);
|
|
|
|
|
|
|
|
if ((PPa.inParty() && PPb.inParty()) && (PPa.getParty().equals(PPb.getParty()))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of players in this player's party.
|
|
|
|
*
|
|
|
|
* @param player The player to check
|
2012-06-05 15:57:10 +02:00
|
|
|
* @param players A list of players to
|
2012-04-03 06:06:30 +02:00
|
|
|
* @return the number of players in this player's party
|
|
|
|
*/
|
|
|
|
public int partyCount(Player player) {
|
2012-04-22 21:36:48 +02:00
|
|
|
if (player != null) {
|
|
|
|
return getAllMembers(player).size();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
private void informPartyMembers(Player player) {
|
|
|
|
String playerName = player.getName();
|
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
if (player != null) {
|
|
|
|
for (Player p : getOnlineMembers(player)) {
|
2012-04-22 21:36:48 +02:00
|
|
|
if (p.getName() != playerName) {
|
2012-04-27 11:47:11 +02:00
|
|
|
p.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", new Object[] {playerName}));
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all online players in this player's party.
|
|
|
|
*
|
|
|
|
* @param player The player to check
|
|
|
|
* @return all online players in the player's party
|
|
|
|
*/
|
|
|
|
public ArrayList<Player> getOnlineMembers(Player player) {
|
|
|
|
ArrayList<Player> players = new ArrayList<Player>();
|
|
|
|
|
2012-04-22 21:36:48 +02:00
|
|
|
if (player != null) {
|
|
|
|
for (Player p : plugin.getServer().getOnlinePlayers()) {
|
|
|
|
if (inSameParty(player, p)) {
|
|
|
|
players.add(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return players;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all online players in this party.
|
|
|
|
*
|
|
|
|
* @param partyName The party to check
|
|
|
|
* @return all online players in this party
|
|
|
|
*/
|
|
|
|
public ArrayList<Player> getOnlineMembers(String partyName) {
|
|
|
|
ArrayList<Player> players = new ArrayList<Player>();
|
|
|
|
|
2012-04-21 00:09:50 +02:00
|
|
|
for (Player p : plugin.getServer().getOnlinePlayers()) {
|
2012-04-22 21:36:48 +02:00
|
|
|
PlayerProfile PP = Users.getProfile(p);
|
|
|
|
|
|
|
|
if (PP.inParty()) {
|
|
|
|
if (PP.getParty().equalsIgnoreCase(partyName)) {
|
2012-04-22 08:55:58 +02:00
|
|
|
players.add(p);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
|
|
|
|
return players;
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all players in this player's party.
|
|
|
|
*
|
|
|
|
* @param player The player to check
|
|
|
|
* @return all the players in the player's party
|
|
|
|
*/
|
2012-04-22 08:55:58 +02:00
|
|
|
public ArrayList<Player> getAllMembers(Player player) {
|
2012-04-03 06:06:30 +02:00
|
|
|
ArrayList<Player> players = new ArrayList<Player>();
|
2012-04-22 08:55:58 +02:00
|
|
|
HashMap<String, PlayerProfile> profiles = Users.getProfiles();
|
2012-04-03 06:06:30 +02:00
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
if (player != null) {
|
|
|
|
for (String name : profiles.keySet()) {
|
2012-05-04 11:04:05 +02:00
|
|
|
Player otherPlayer = profiles.get(name).getPlayer();
|
|
|
|
|
|
|
|
if (otherPlayer != null && inSameParty(otherPlayer, player)) {
|
|
|
|
players.add(otherPlayer);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2012-04-03 06:06:30 +02:00
|
|
|
return players;
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
2012-04-22 21:36:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all current party names.
|
|
|
|
*
|
|
|
|
* @return the list of parties.
|
|
|
|
*/
|
|
|
|
public ArrayList<String> getParties() {
|
2012-05-05 19:51:54 +02:00
|
|
|
String location = plugin.usersFile;
|
2012-04-22 21:36:48 +02:00
|
|
|
ArrayList<String> parties = new ArrayList<String>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
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) {
|
2012-05-05 19:51:54 +02:00
|
|
|
plugin.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
|
|
|
return parties;
|
|
|
|
}
|
|
|
|
|
2012-04-03 06:06:30 +02:00
|
|
|
/**
|
|
|
|
* Notify party members when the party owner changes.
|
|
|
|
*
|
|
|
|
* @param newOwnerName The name of the new party owner
|
|
|
|
*/
|
|
|
|
private void informPartyMembersOwnerChange(String newOwnerName) {
|
|
|
|
Player newOwner = plugin.getServer().getPlayer(newOwnerName);
|
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
if (newOwner != null) {
|
|
|
|
for (Player p : getOnlineMembers(newOwner)) {
|
2012-04-22 21:36:48 +02:00
|
|
|
if (p.getName() != newOwnerName) {
|
|
|
|
p.sendMessage(newOwnerName + " is the new party owner."); //TODO: Needs more locale
|
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify party members when the a party member quits.
|
|
|
|
*
|
|
|
|
* @param player The player that quit
|
|
|
|
*/
|
|
|
|
private void informPartyMembersQuit(Player player) {
|
|
|
|
String playerName = player.getName();
|
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
if (player != null) {
|
|
|
|
for (Player p : getOnlineMembers(player)) {
|
2012-04-22 21:36:48 +02:00
|
|
|
if (p.getName() != playerName) {
|
2012-04-27 11:47:11 +02:00
|
|
|
p.sendMessage(LocaleLoader.getString("Party.InformedOnQuit", new Object[] {playerName}));
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a player from a party.
|
|
|
|
*
|
|
|
|
* @param player The player to remove
|
|
|
|
* @param PP The profile of the player to remove
|
|
|
|
*/
|
|
|
|
public void removeFromParty(Player player, PlayerProfile PP) {
|
|
|
|
String party = PP.getParty();
|
|
|
|
String playerName = player.getName();
|
|
|
|
|
|
|
|
//Stop NPE... hopefully
|
|
|
|
if (!isParty(party) || !isInParty(player, PP)) {
|
|
|
|
addToParty(player, PP, party, false, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
informPartyMembersQuit(player);
|
|
|
|
|
|
|
|
if (isPartyLeader(playerName, party)) {
|
|
|
|
if (isPartyLocked(party)) {
|
|
|
|
unlockParty(party);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
partyPlayers.get(party).remove(playerName);
|
|
|
|
|
|
|
|
if (isPartyEmpty(party)) {
|
|
|
|
deleteParty(party);
|
|
|
|
}
|
|
|
|
|
|
|
|
PP.removeParty();
|
|
|
|
savePartyFile(partyPlayersFile, partyPlayers);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 06:06:30 +02:00
|
|
|
/**
|
|
|
|
* Add a player to a party.
|
|
|
|
*
|
|
|
|
* @param player The player to add to the party
|
|
|
|
* @param PP The profile of the player to add to the party
|
|
|
|
* @param newParty The party to add the player to
|
|
|
|
* @param invite true if the player was invited to this party, false otherwise
|
|
|
|
* @param password the password for this party, null if there was no password
|
|
|
|
*/
|
|
|
|
public void addToParty(Player player, PlayerProfile PP, String newParty, Boolean invite, String password) {
|
|
|
|
String playerName = player.getName();
|
|
|
|
|
|
|
|
//Fix for FFS
|
|
|
|
newParty = newParty.replace(":", ".");
|
|
|
|
|
|
|
|
//Don't care about passwords on invites
|
|
|
|
if (!invite) {
|
|
|
|
|
|
|
|
//Don't care about passwords if it isn't locked
|
|
|
|
if (isPartyLocked(newParty)) {
|
|
|
|
if (isPartyPasswordProtected(newParty)) {
|
|
|
|
if (password == null) {
|
|
|
|
player.sendMessage("This party requires a password. Use /party <party> <password> to join it."); //TODO: Needs more locale.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(!password.equalsIgnoreCase(getPartyPassword(newParty))) {
|
|
|
|
player.sendMessage("Party password incorrect."); //TODO: Needs more locale.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage("Party is locked."); //TODO: Needs more locale.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PP.acceptInvite();
|
|
|
|
}
|
|
|
|
|
|
|
|
//New party?
|
|
|
|
if (!isParty(newParty)) {
|
|
|
|
putNestedEntry(partyPlayers, newParty, playerName, true);
|
|
|
|
|
|
|
|
//Get default locking behavior from config?
|
|
|
|
partyLocks.put(newParty, false);
|
|
|
|
partyPasswords.put(newParty, null);
|
|
|
|
saveParties();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
putNestedEntry(partyPlayers, newParty, playerName, false);
|
|
|
|
savePartyFile(partyPlayersFile, partyPlayers);
|
|
|
|
}
|
|
|
|
|
|
|
|
PP.setParty(newParty);
|
|
|
|
informPartyMembers(player);
|
|
|
|
|
|
|
|
if (!invite) {
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", new Object[]{ newParty }));
|
2012-04-03 06:06:30 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Invite.Accepted", new Object[]{ PP.getParty() }));
|
2012-04-03 06:06:30 +02:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
private static <U,V,W> W putNestedEntry(HashMap<U, HashMap<V, W>> nest, U nestKey, V nestedKey, W nestedValue) {
|
2012-01-09 20:00:13 +01:00
|
|
|
HashMap<V,W> nested = nest.get(nestKey);
|
|
|
|
|
|
|
|
if (nested == null) {
|
|
|
|
nested = new HashMap<V,W>();
|
|
|
|
nest.put(nestKey, nested);
|
|
|
|
}
|
|
|
|
|
2012-04-03 06:06:30 +02:00
|
|
|
return nested.put(nestedKey, nestedValue);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lock a party.
|
|
|
|
*
|
|
|
|
* @param partyName The party to lock
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
public void lockParty(String partyName) {
|
2012-04-03 06:06:30 +02:00
|
|
|
partyLocks.put(partyName, true);
|
|
|
|
savePartyFile(partyLocksFile, partyLocks);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unlock a party.
|
|
|
|
*
|
|
|
|
* @param partyName The party to unlock
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
public void unlockParty(String partyName) {
|
2012-04-03 06:06:30 +02:00
|
|
|
partyLocks.put(partyName, false);
|
|
|
|
savePartyFile(partyLocksFile, partyLocks);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a party.
|
|
|
|
*
|
|
|
|
* @param partyName The party to delete
|
|
|
|
*/
|
2012-03-27 21:57:37 +02:00
|
|
|
private void deleteParty(String partyName) {
|
2012-04-03 06:06:30 +02:00
|
|
|
partyPlayers.remove(partyName);
|
|
|
|
partyLocks.remove(partyName);
|
|
|
|
partyPasswords.remove(partyName);
|
|
|
|
saveParties();
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the password for a party.
|
|
|
|
*
|
|
|
|
* @param partyName The party name
|
|
|
|
* @param password The new party password
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
public void setPartyPassword(String partyName, String password) {
|
2012-04-03 06:06:30 +02:00
|
|
|
if (password.equalsIgnoreCase("\"\"")) { //What's with that password string?
|
|
|
|
password = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
partyPasswords.put(partyName, password);
|
|
|
|
savePartyFile(partyPasswordsFile, partyPasswords);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
/**
|
|
|
|
* Get the leader of a party.
|
|
|
|
*
|
|
|
|
* @param partyName The party name
|
|
|
|
* @return the leader of the party
|
|
|
|
*/
|
|
|
|
public Player getPartyLeader(String partyName) {
|
|
|
|
Player leader = null;
|
|
|
|
|
|
|
|
for (String name : partyPlayers.get(partyName).keySet()) {
|
|
|
|
if (partyPlayers.get(partyName).get(name)) {
|
|
|
|
leader = plugin.getServer().getPlayer(name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return leader;
|
|
|
|
}
|
|
|
|
|
2012-04-03 06:06:30 +02:00
|
|
|
/**
|
|
|
|
* Set the leader of a party.
|
|
|
|
*
|
|
|
|
* @param partyName The party name
|
|
|
|
* @param playerName The name of the player to set as leader
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
public void setPartyLeader(String partyName, String playerName) {
|
2012-04-03 06:06:30 +02:00
|
|
|
for (String name : partyPlayers.get(partyName).keySet()) {
|
|
|
|
if (name.equalsIgnoreCase(playerName)) {
|
|
|
|
partyPlayers.get(partyName).put(playerName, true);
|
|
|
|
informPartyMembersOwnerChange(playerName);
|
|
|
|
plugin.getServer().getPlayer(playerName).sendMessage("You are now the party owner."); //TODO: Needs more locale.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (partyPlayers.get(partyName).get(name)) {
|
|
|
|
plugin.getServer().getPlayer(name).sendMessage("You are no longer party owner."); //TODO: Needs more locale.
|
|
|
|
partyPlayers.get(partyName).put(name, false);
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the password of a party.
|
|
|
|
*
|
|
|
|
* @param partyName The party name
|
|
|
|
* @return The password of this party
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
public String getPartyPassword(String partyName) {
|
2012-04-03 06:06:30 +02:00
|
|
|
return partyPasswords.get(partyName);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a player can invite others to their party.
|
|
|
|
*
|
|
|
|
* @param player The player to check
|
|
|
|
* @param PP The profile of the given player
|
|
|
|
* @return true if the player can invite, false otherwise
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
public boolean canInvite(Player player, PlayerProfile PP) {
|
2012-04-03 06:06:30 +02:00
|
|
|
String party = PP.getParty();
|
|
|
|
|
|
|
|
if (isPartyLocked(party) && !isPartyLeader(player.getName(), party)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a string is a valid party name.
|
|
|
|
*
|
|
|
|
* @param partyName The party name to check
|
|
|
|
* @return true if this is a valid party, false otherwise
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
public boolean isParty(String partyName) {
|
2012-04-03 06:06:30 +02:00
|
|
|
return partyPlayers.containsKey(partyName);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 06:06:30 +02:00
|
|
|
/**
|
|
|
|
* Check if a party is empty.
|
|
|
|
*
|
|
|
|
* @param partyName The party to check
|
|
|
|
* @return true if this party is empty, false otherwise
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
public boolean isPartyEmpty(String partyName) {
|
2012-04-03 06:06:30 +02:00
|
|
|
return partyPlayers.get(partyName).isEmpty();
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a player is the party leader.
|
|
|
|
*
|
|
|
|
* @param playerName The player name to check
|
|
|
|
* @param partyName The party name to check
|
|
|
|
* @return true if the player is the party leader, false otherwise
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
public boolean isPartyLeader(String playerName, String partyName) {
|
2012-04-03 06:06:30 +02:00
|
|
|
HashMap<String, Boolean> partyMembers = partyPlayers.get(partyName);
|
|
|
|
|
|
|
|
if (partyMembers != null) {
|
|
|
|
Boolean isLeader = partyMembers.get(playerName);
|
|
|
|
|
|
|
|
if (isLeader == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return isLeader;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if this party is locked.
|
|
|
|
*
|
|
|
|
* @param partyName The party to check
|
|
|
|
* @return true if this party is locked, false otherwise
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
public boolean isPartyLocked(String partyName) {
|
2012-04-03 06:06:30 +02:00
|
|
|
Boolean isLocked = partyLocks.get(partyName);
|
|
|
|
|
|
|
|
if (isLocked == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return isLocked;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if this party is password protected.
|
|
|
|
*
|
|
|
|
* @param partyName The party to check
|
|
|
|
* @return true if this party is password protected, false otherwise
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
public boolean isPartyPasswordProtected(String partyName) {
|
2012-04-03 06:06:30 +02:00
|
|
|
String password = partyPasswords.get(partyName);
|
|
|
|
|
|
|
|
if (password == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a player is in the party reflected by their profile.
|
|
|
|
*
|
|
|
|
* @param player The player to check
|
|
|
|
* @param PP The profile of the player
|
|
|
|
* @return true if this player is in the right party, false otherwise
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
public boolean isInParty(Player player, PlayerProfile PP) {
|
2012-04-27 08:17:02 +02:00
|
|
|
Map<String, Boolean> party = partyPlayers.get(PP.getParty());
|
|
|
|
|
|
|
|
if (party != null && party.containsKey(player.getName())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load all party related files.
|
|
|
|
*/
|
2012-01-09 20:00:13 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2012-04-03 06:06:30 +02:00
|
|
|
public void loadParties() {
|
|
|
|
if (new File(partyPlayersFile).exists()) {
|
|
|
|
try {
|
|
|
|
ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyPlayersFile));
|
|
|
|
partyPlayers = (HashMap<String, HashMap<String, Boolean>>) obj.readObject();
|
|
|
|
}
|
|
|
|
catch (FileNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
catch (EOFException e) {
|
2012-04-21 00:09:50 +02:00
|
|
|
plugin.getLogger().info("partyPlayersFile empty.");
|
2012-04-03 06:06:30 +02:00
|
|
|
}
|
|
|
|
catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
catch (ClassNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new File(partyLocksFile).exists()) {
|
|
|
|
try {
|
|
|
|
ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyLocksFile));
|
|
|
|
partyLocks = (HashMap<String, Boolean>) obj.readObject();
|
|
|
|
}
|
|
|
|
catch (FileNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
catch (EOFException e) {
|
2012-04-21 00:09:50 +02:00
|
|
|
plugin.getLogger().info("partyLocksFile empty.");
|
2012-04-03 06:06:30 +02:00
|
|
|
}
|
|
|
|
catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
catch (ClassNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new File(partyPasswordsFile).exists()) {
|
|
|
|
try {
|
|
|
|
ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyPasswordsFile));
|
|
|
|
this.partyPasswords = (HashMap<String, String>) obj.readObject();
|
|
|
|
}
|
|
|
|
catch (FileNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
catch (EOFException e) {
|
2012-04-21 00:09:50 +02:00
|
|
|
plugin.getLogger().info("partyPasswordsFile empty.");
|
2012-04-03 06:06:30 +02:00
|
|
|
}
|
|
|
|
catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
catch (ClassNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Save all party-related files.
|
|
|
|
*/
|
|
|
|
private void saveParties() {
|
|
|
|
savePartyFile(partyPlayersFile, partyPlayers);
|
|
|
|
savePartyFile(partyLocksFile, partyLocks);
|
|
|
|
savePartyFile(partyPasswordsFile, partyPasswords);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-04-03 06:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Save a party-related file.
|
|
|
|
*
|
|
|
|
* @param fileName The filename to save as
|
|
|
|
* @param partyData The Hashmap with the party data
|
|
|
|
*/
|
|
|
|
private void savePartyFile(String fileName, Object partyData) {
|
|
|
|
try {
|
|
|
|
new File(fileName).createNewFile();
|
|
|
|
ObjectOutputStream obj = new ObjectOutputStream(new FileOutputStream(fileName));
|
|
|
|
obj.writeObject(partyData);
|
|
|
|
obj.close();
|
|
|
|
}
|
|
|
|
catch (FileNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
}
|