*CLEANUP* - Party.java

This commit is contained in:
GJ 2012-04-03 00:06:30 -04:00
parent 24a50346db
commit b70e868b5c
4 changed files with 524 additions and 356 deletions

View File

@ -100,5 +100,26 @@ public class PartyAPI {
return Party.getInstance().getPartyMembers(player); return Party.getInstance().getPartyMembers(player);
} }
/**
* Add a player to a party.
* </br>
* This function is designed for API usage.
*
* @param player The player to add to the party
* @param partyName The party to add the player to
*/
public void addToParty(Player player, String partyName) {
Party.getInstance().addToParty(player, Users.getProfile(player), partyName, false, null);
}
/**
* Remove a player from a party.
* </br>
* This function is designed for API usage.
*
* @param player The player to remove
*/
public void removeFromParty(Player player) {
Party.getInstance().removeFromParty(player, Users.getProfile(player));
}
} }

View File

@ -54,7 +54,7 @@ public class AcceptCommand implements CommandExecutor {
} }
} }
PP.acceptInvite(); PP.acceptInvite();
Pinstance.addToParty(player, PP, PP.getParty(), true); Pinstance.addToParty(player, PP, PP.getParty(), true, null);
} else { } else {
player.sendMessage(mcLocale.getString("mcPlayerListener.NoInvites")); player.sendMessage(mcLocale.getString("mcPlayerListener.NoInvites"));

View File

@ -35,7 +35,7 @@ public class PartyCommand implements CommandExecutor {
Party Pinstance = Party.getInstance(); Party Pinstance = Party.getInstance();
if (PP.inParty() && (!Pinstance.isParty(PP.getParty()) || !Pinstance.isInParty(player, PP))) { if (PP.inParty() && (!Pinstance.isParty(PP.getParty()) || !Pinstance.isInParty(player, PP))) {
Pinstance.addToParty(player, PP, PP.getParty(), false); Pinstance.addToParty(player, PP, PP.getParty(), false, null);
} }
if (args.length == 0 && !PP.inParty()) { if (args.length == 0 && !PP.inParty()) {
@ -48,7 +48,7 @@ public class PartyCommand implements CommandExecutor {
int x = 0; int x = 0;
for (Player p : Bukkit.getServer().getOnlinePlayers()) { for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (PP.getParty().equals(Users.getProfile(p).getParty())) { if (PP.getParty().equals(Users.getProfile(p).getParty())) {
if (p != null && x + 1 >= Pinstance.partyCount(player, Bukkit.getServer().getOnlinePlayers())) { if (p != null && x + 1 >= Pinstance.partyCount(player)) {
if (Pinstance.isPartyLeader(p.getName(), PP.getParty())) { if (Pinstance.isPartyLeader(p.getName(), PP.getParty())) {
tempList += ChatColor.GOLD + p.getName(); tempList += ChatColor.GOLD + p.getName();
x++; x++;
@ -57,7 +57,7 @@ public class PartyCommand implements CommandExecutor {
x++; x++;
} }
} }
if (p != null && x < Pinstance.partyCount(player, Bukkit.getServer().getOnlinePlayers())) { if (p != null && x < Pinstance.partyCount(player)) {
if (Pinstance.isPartyLeader(p.getName(), PP.getParty())) { if (Pinstance.isPartyLeader(p.getName(), PP.getParty())) {
tempList += ChatColor.GOLD + p.getName() + ", "; tempList += ChatColor.GOLD + p.getName() + ", ";
x++; x++;
@ -175,7 +175,7 @@ public class PartyCommand implements CommandExecutor {
return true; return true;
} }
} }
Pinstance.addToParty(player, PP, args[0], false); Pinstance.addToParty(player, PP, args[0], false, null);
return true; return true;
} }
} else if (args.length == 2 && PP.inParty()) { } else if (args.length == 2 && PP.inParty()) {

View File

@ -20,7 +20,6 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
public class Party { public class Party {
/* /*
* This file is part of mmoMinecraft (http://code.google.com/p/mmo-minecraft/). * This file is part of mmoMinecraft (http://code.google.com/p/mmo-minecraft/).
@ -48,80 +47,85 @@ public class Party {
HashMap<String, String> partyPasswords = new HashMap<String, String>(); HashMap<String, String> partyPasswords = new HashMap<String, String>();
private static mcMMO plugin; private static mcMMO plugin;
private static volatile Party instance;
public Party(mcMMO instance) { public Party(mcMMO instance) {
new File(mcMMO.maindirectory + File.separator + "FlatFileStuff").mkdir(); new File(mcMMO.maindirectory + File.separator + "FlatFileStuff").mkdir();
plugin = instance; plugin = instance;
} }
private static volatile Party instance;
public static Party getInstance() public static Party getInstance() {
{
if (instance == null) { if (instance == null) {
instance = new Party(plugin); instance = new Party(plugin);
} }
return instance; return instance;
} }
/**
* 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
*/
public boolean inSameParty(Player playera, Player playerb){ public boolean inSameParty(Player playera, Player playerb){
if(Users.getProfile(playera).inParty() && Users.getProfile(playerb).inParty()) PlayerProfile PPa = Users.getProfile(playera);
{ PlayerProfile PPb = Users.getProfile(playerb);
if(Users.getProfile(playera).getParty().equals(Users.getProfile(playerb).getParty()))
{ if ((PPa.inParty() && PPb.inParty()) && (PPa.getParty().equals(PPb.getParty()))) {
return true; return true;
} else
{
return false;
} }
} else else {
{
return false; return false;
} }
} }
public int partyCount(Player player, Player[] players) /**
{ * Get the number of players in this player's party.
int x = 0; *
for(Player hurrdurr : players) * @param player The player to check
{ * @param players A list of players to
if(player != null && hurrdurr != null) * @return the number of players in this player's party
{ */
if(Users.getProfile(player).getParty().equals(Users.getProfile(hurrdurr).getParty())) public int partyCount(Player player) {
x++; PlayerProfile PP = Users.getProfile(player);
int partyMembers = 0;
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (player != null && p != null) { //Is this even possible?
if (PP.getParty().equals(Users.getProfile(p).getParty())) {
partyMembers++;
} }
} }
return x;
} }
public void informPartyMembers(Player player) return partyMembers;
{
informPartyMembers(player, Bukkit.getServer().getOnlinePlayers());
} }
private void informPartyMembers(Player player) {
String playerName = player.getName();
public void informPartyMembers(Player player, Player[] players) for (Player p : Bukkit.getServer().getOnlinePlayers()) {
{ if (player != null && p != null) {
for(Player p : players) if (inSameParty(player, p) && !p.getName().equals(playerName)) {
{ p.sendMessage(mcLocale.getString("Party.InformedOnJoin", new Object[] {playerName}));
if(player != null && p != null)
{
if(inSameParty(player, p) && !p.getName().equals(player.getName()))
{
p.sendMessage(mcLocale.getString("Party.InformedOnJoin", new Object[] {player.getName()}));
} }
} }
} }
} }
public ArrayList<Player> getPartyMembers(Player player) /**
{ * 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
*/
public ArrayList<Player> getPartyMembers(Player player) {
ArrayList<Player> players = new ArrayList<Player>(); ArrayList<Player> players = new ArrayList<Player>();
for(Player p : Bukkit.getServer().getOnlinePlayers()) for (Player p : Bukkit.getServer().getOnlinePlayers()) {
{ if (p.isOnline() && player != null && p != null) {
if(p.isOnline() && player != null && p != null) if (inSameParty(player, p) && !p.getName().equals(player.getName())) {
{
if(inSameParty(player, p) && !p.getName().equals(player.getName()))
{
players.add(p); players.add(p);
} }
} }
@ -129,131 +133,139 @@ public class Party {
return players; return players;
} }
public void informPartyMembersOwnerChange(String newOwner) { /**
Player newOwnerPlayer = plugin.getServer().getPlayer(newOwner); * Notify party members when the party owner changes.
informPartyMembersOwnerChange(newOwnerPlayer, Bukkit.getServer().getOnlinePlayers()); *
} * @param newOwnerName The name of the new party owner
*/
private void informPartyMembersOwnerChange(String newOwnerName) {
Player newOwner = plugin.getServer().getPlayer(newOwnerName);
public void informPartyMembersOwnerChange(Player newOwner, Player[] players) { for (Player p : Bukkit.getServer().getOnlinePlayers()){
for(Player p : players){
if (newOwner != null && p != null) { if (newOwner != null && p != null) {
if(inSameParty(newOwner, p)) if (inSameParty(newOwner, p)) {
{ p.sendMessage(newOwnerName + " is the new party owner."); //TODO: Needs more locale
p.sendMessage(newOwner.getName()+" is the new party owner."); //TODO: Needs more locale
} }
} }
} }
} }
public void informPartyMembersQuit(Player player) /**
{ * Notify party members when the a party member quits.
informPartyMembersQuit(player, Bukkit.getServer().getOnlinePlayers()); *
} * @param player The player that quit
*/
private void informPartyMembersQuit(Player player) {
String playerName = player.getName();
public void informPartyMembersQuit(Player player, Player[] players) for (Player p : Bukkit.getServer().getOnlinePlayers()){
{
for(Player p : players){
if (player != null && p != null){ if (player != null && p != null){
if(inSameParty(player, p) && !p.getName().equals(player.getName())) if (inSameParty(player, p) && !p.getName().equals(playerName)) {
{ p.sendMessage(mcLocale.getString("Party.InformedOnQuit", new Object[] {playerName}));
p.sendMessage(mcLocale.getString("Party.InformedOnQuit", new Object[] {player.getName()}));
} }
} }
} }
} }
public void removeFromParty(Player player, PlayerProfile PP) /**
{ * 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 //Stop NPE... hopefully
if(!isParty(PP.getParty()) || !isInParty(player, PP)) if (!isParty(party) || !isInParty(player, PP)) {
addToParty(player, PP, PP.getParty(), false); addToParty(player, PP, party, false, null);
}
informPartyMembersQuit(player); informPartyMembersQuit(player);
String party = PP.getParty();
if(isPartyLeader(player.getName(), party)) if (isPartyLeader(playerName, party)) {
{
if (isPartyLocked(party)) { if (isPartyLocked(party)) {
unlockParty(party); unlockParty(party);
} }
} }
this.partyPlayers.get(party).remove(player.getName()); partyPlayers.get(party).remove(playerName);
if(isPartyEmpty(party)) deleteParty(party);
if (isPartyEmpty(party)) {
deleteParty(party);
}
PP.removeParty(); PP.removeParty();
savePartyPlayers(); savePartyFile(partyPlayersFile, partyPlayers);
} }
public void addToParty(Player player, PlayerProfile PP, String newParty, Boolean invite) { /**
newParty = newParty.replace(":", "."); * Add a player to a party.
addToParty(player, PP, newParty, invite, null); *
} * @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();
public void addToParty(Player player, PlayerProfile PP, String newParty, Boolean invite, String password)
{
//Fix for FFS //Fix for FFS
newParty = newParty.replace(":", "."); newParty = newParty.replace(":", ".");
//Don't care about passwords on invites //Don't care about passwords on invites
if(!invite) if (!invite) {
{
//Don't care about passwords if it isn't locked //Don't care about passwords if it isn't locked
if(isPartyLocked(newParty)) if (isPartyLocked(newParty)) {
{ if (isPartyPasswordProtected(newParty)) {
if(isPartyPasswordProtected(newParty)) if (password == null) {
{
if(password == null)
{
player.sendMessage("This party requires a password. Use /party <party> <password> to join it."); //TODO: Needs more locale. player.sendMessage("This party requires a password. Use /party <party> <password> to join it."); //TODO: Needs more locale.
return; return;
} else if(!password.equalsIgnoreCase(getPartyPassword(newParty))) }
{ else if(!password.equalsIgnoreCase(getPartyPassword(newParty))) {
player.sendMessage("Party password incorrect."); //TODO: Needs more locale. player.sendMessage("Party password incorrect."); //TODO: Needs more locale.
return; return;
} }
} else }
{ else {
player.sendMessage("Party is locked."); //TODO: Needs more locale. player.sendMessage("Party is locked."); //TODO: Needs more locale.
return; return;
} }
} }
} else }
{ else {
PP.acceptInvite(); PP.acceptInvite();
} }
//New party? //New party?
if(!isParty(newParty)) if (!isParty(newParty)) {
{ putNestedEntry(partyPlayers, newParty, playerName, true);
putNestedEntry(this.partyPlayers, newParty, player.getName(), true);
//Get default locking behavior from config? //Get default locking behavior from config?
this.partyLocks.put(newParty, false); partyLocks.put(newParty, false);
this.partyPasswords.put(newParty, null); partyPasswords.put(newParty, null);
saveParties(); saveParties();
} else
{
putNestedEntry(this.partyPlayers, newParty, player.getName(), false);
savePartyPlayers();
} }
else {
putNestedEntry(partyPlayers, newParty, playerName, false);
savePartyFile(partyPlayersFile, partyPlayers);
}
PP.setParty(newParty); PP.setParty(newParty);
informPartyMembers(player); informPartyMembers(player);
if(!invite) if (!invite) {
{
player.sendMessage(mcLocale.getString("mcPlayerListener.JoinedParty", new Object[]{ newParty })); player.sendMessage(mcLocale.getString("mcPlayerListener.JoinedParty", new Object[]{ newParty }));
} else }
{ else {
player.sendMessage(mcLocale.getString("mcPlayerListener.InviteAccepted", new Object[]{ PP.getParty() })); player.sendMessage(mcLocale.getString("mcPlayerListener.InviteAccepted", new Object[]{ PP.getParty() }));
} }
} }
private static <U,V,W> W putNestedEntry( private static <U,V,W> W putNestedEntry(HashMap<U, HashMap<V, W>> nest, U nestKey, V nestedKey, W nestedValue) {
HashMap<U,HashMap<V,W>> nest,
U nestKey,
V nestedKey,
W nestedValue)
{
HashMap<V,W> nested = nest.get(nestKey); HashMap<V,W> nested = nest.get(nestKey);
if (nested == null) { if (nested == null) {
@ -264,7 +276,10 @@ public class Party {
return nested.put(nestedKey, nestedValue); return nested.put(nestedKey, nestedValue);
} }
public void dump(Player player) { /*
* Any reason why we need to keep this function around?
*/
private void dump(Player player) {
player.sendMessage(partyPlayers.toString()); player.sendMessage(partyPlayers.toString());
player.sendMessage(partyLocks.toString()); player.sendMessage(partyLocks.toString());
player.sendMessage(partyPasswords.toString()); player.sendMessage(partyPasswords.toString());
@ -285,151 +300,283 @@ public class Party {
} }
} }
/**
* Lock a party.
*
* @param partyName The party to lock
*/
public void lockParty(String partyName) { public void lockParty(String partyName) {
this.partyLocks.put(partyName, true); partyLocks.put(partyName, true);
savePartyLocks(); savePartyFile(partyLocksFile, partyLocks);
} }
/**
* Unlock a party.
*
* @param partyName The party to unlock
*/
public void unlockParty(String partyName) { public void unlockParty(String partyName) {
this.partyLocks.put(partyName, false); partyLocks.put(partyName, false);
savePartyLocks(); savePartyFile(partyLocksFile, partyLocks);
} }
/**
* Delete a party.
*
* @param partyName The party to delete
*/
private void deleteParty(String partyName) { private void deleteParty(String partyName) {
this.partyPlayers.remove(partyName); partyPlayers.remove(partyName);
this.partyLocks.remove(partyName); partyLocks.remove(partyName);
this.partyPasswords.remove(partyName); partyPasswords.remove(partyName);
saveParties(); saveParties();
} }
/**
* Set the password for a party.
*
* @param partyName The party name
* @param password The new party password
*/
public void setPartyPassword(String partyName, String password) { public void setPartyPassword(String partyName, String password) {
if(password.equalsIgnoreCase("\"\"")) password = null; if (password.equalsIgnoreCase("\"\"")) { //What's with that password string?
this.partyPasswords.put(partyName, password); password = null;
savePartyPasswords();
} }
partyPasswords.put(partyName, password);
savePartyFile(partyPasswordsFile, partyPasswords);
}
/**
* Set the leader of a party.
*
* @param partyName The party name
* @param playerName The name of the player to set as leader
*/
public void setPartyLeader(String partyName, String playerName) { public void setPartyLeader(String partyName, String playerName) {
Iterator<String> i = partyPlayers.get(partyName).keySet().iterator(); for (String name : partyPlayers.get(partyName).keySet()) {
while(i.hasNext()) { if (name.equalsIgnoreCase(playerName)) {
String playerKey = i.next();
if(playerKey.equalsIgnoreCase(playerName)) {
partyPlayers.get(partyName).put(playerName, true); partyPlayers.get(partyName).put(playerName, true);
informPartyMembersOwnerChange(playerName); informPartyMembersOwnerChange(playerName);
plugin.getServer().getPlayer(playerName).sendMessage("You are now the party owner."); //TODO: Needs more locale. plugin.getServer().getPlayer(playerName).sendMessage("You are now the party owner."); //TODO: Needs more locale.
continue; continue;
} }
if(partyPlayers.get(partyName).get(playerKey)) {
plugin.getServer().getPlayer(playerKey).sendMessage("You are no longer party owner."); //TODO: Needs more locale. if (partyPlayers.get(partyName).get(name)) {
partyPlayers.get(partyName).put(playerKey, false); plugin.getServer().getPlayer(name).sendMessage("You are no longer party owner."); //TODO: Needs more locale.
partyPlayers.get(partyName).put(name, false);
} }
} }
} }
/**
* Get the password of a party.
*
* @param partyName The party name
* @return The password of this party
*/
public String getPartyPassword(String partyName) { public String getPartyPassword(String partyName) {
return this.partyPasswords.get(partyName); return partyPasswords.get(partyName);
} }
/**
* 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
*/
public boolean canInvite(Player player, PlayerProfile PP) { public boolean canInvite(Player player, PlayerProfile PP) {
return (isPartyLocked(PP.getParty()) && !isPartyLeader(player.getName(), PP.getParty())) ? false : true; String party = PP.getParty();
}
public boolean isParty(String partyName) { if (isPartyLocked(party) && !isPartyLeader(player.getName(), party)) {
return this.partyPlayers.containsKey(partyName);
}
public boolean isPartyEmpty(String partyName) {
return this.partyPlayers.get(partyName).isEmpty();
}
public boolean isPartyLeader(String playerName, String partyName) {
if(this.partyPlayers.get(partyName) != null)
{
if(this.partyPlayers.get(partyName).get(playerName) == null) return false;
return this.partyPlayers.get(partyName).get(playerName);
}
else
return false; return false;
} }
else {
return true;
}
}
/**
* 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
*/
public boolean isParty(String partyName) {
return partyPlayers.containsKey(partyName);
}
/**
* Check if a party is empty.
*
* @param partyName The party to check
* @return true if this party is empty, false otherwise
*/
public boolean isPartyEmpty(String partyName) {
return partyPlayers.get(partyName).isEmpty();
}
/**
* 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
*/
public boolean isPartyLeader(String playerName, String partyName) {
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;
}
}
/**
* Check if this party is locked.
*
* @param partyName The party to check
* @return true if this party is locked, false otherwise
*/
public boolean isPartyLocked(String partyName) { public boolean isPartyLocked(String partyName) {
if(this.partyLocks.get(partyName) == null) return false; Boolean isLocked = partyLocks.get(partyName);
return this.partyLocks.get(partyName);
if (isLocked == null) {
return false;
}
else {
return isLocked;
}
} }
/**
* Check if this party is password protected.
*
* @param partyName The party to check
* @return true if this party is password protected, false otherwise
*/
public boolean isPartyPasswordProtected(String partyName) { public boolean isPartyPasswordProtected(String partyName) {
return !(this.partyPasswords.get(partyName) == null); String password = partyPasswords.get(partyName);
if (password == null) {
return false;
}
else {
return true;
}
} }
/**
* 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
*/
public boolean isInParty(Player player, PlayerProfile PP) { public boolean isInParty(Player player, PlayerProfile PP) {
return partyPlayers.get(PP.getParty()).containsKey(player.getName()); return partyPlayers.get(PP.getParty()).containsKey(player.getName());
} }
/**
* Load all party related files.
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void loadParties() { public void loadParties() {
if (new File(partyPlayersFile).exists()) { if (new File(partyPlayersFile).exists()) {
try { try {
ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyPlayersFile)); ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyPlayersFile));
this.partyPlayers = (HashMap<String, HashMap<String, Boolean>>)obj.readObject(); partyPlayers = (HashMap<String, HashMap<String, Boolean>>) obj.readObject();
} catch (FileNotFoundException e) { e.printStackTrace(); }
} catch (EOFException e) { Bukkit.getLogger().info("partyPlayersFile empty."); catch (FileNotFoundException e) {
} catch (IOException e) { e.printStackTrace(); e.printStackTrace();
} catch (ClassNotFoundException e) { e.printStackTrace(); } }
catch (EOFException e) {
Bukkit.getLogger().info("partyPlayersFile empty.");
}
catch (IOException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
} }
if (new File(partyLocksFile).exists()) { if (new File(partyLocksFile).exists()) {
try { try {
ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyLocksFile)); ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyLocksFile));
this.partyLocks = (HashMap<String, Boolean>)obj.readObject(); partyLocks = (HashMap<String, Boolean>) obj.readObject();
} catch (FileNotFoundException e) { e.printStackTrace(); }
} catch (EOFException e) { Bukkit.getLogger().info("partyLocksFile empty."); catch (FileNotFoundException e) {
} catch (IOException e) { e.printStackTrace(); e.printStackTrace();
} catch (ClassNotFoundException e) { e.printStackTrace(); } }
catch (EOFException e) {
Bukkit.getLogger().info("partyLocksFile empty.");
}
catch (IOException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
} }
if (new File(partyPasswordsFile).exists()) { if (new File(partyPasswordsFile).exists()) {
try { try {
ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyPasswordsFile)); ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyPasswordsFile));
this.partyPasswords = (HashMap<String, String>) obj.readObject(); this.partyPasswords = (HashMap<String, String>) obj.readObject();
} catch (FileNotFoundException e) { e.printStackTrace(); }
} catch (EOFException e) { Bukkit.getLogger().info("partyPasswordsFile empty."); catch (FileNotFoundException e) {
} catch (IOException e) { e.printStackTrace(); e.printStackTrace();
} catch (ClassNotFoundException e) { e.printStackTrace(); } }
catch (EOFException e) {
Bukkit.getLogger().info("partyPasswordsFile empty.");
}
catch (IOException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
} }
} }
public void saveParties() { /**
savePartyPlayers(); * Save all party-related files.
savePartyLocks(); */
savePartyPasswords(); private void saveParties() {
savePartyFile(partyPlayersFile, partyPlayers);
savePartyFile(partyLocksFile, partyLocks);
savePartyFile(partyPasswordsFile, partyPasswords);
} }
public void savePartyPlayers() { /**
* 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 { try {
new File(partyPlayersFile).createNewFile(); new File(fileName).createNewFile();
ObjectOutputStream obj = new ObjectOutputStream(new FileOutputStream(partyPlayersFile)); ObjectOutputStream obj = new ObjectOutputStream(new FileOutputStream(fileName));
obj.writeObject(this.partyPlayers); obj.writeObject(partyData);
obj.close(); obj.close();
} catch (FileNotFoundException e) { e.printStackTrace();
} catch (IOException e) { e.printStackTrace(); }
} }
catch (FileNotFoundException e) {
public void savePartyLocks() { e.printStackTrace();
try { }
new File(partyLocksFile).createNewFile(); catch (IOException e) {
ObjectOutputStream obj = new ObjectOutputStream(new FileOutputStream(partyLocksFile)); e.printStackTrace();
obj.writeObject(this.partyLocks);
obj.close();
} catch (FileNotFoundException e) { e.printStackTrace();
} catch (IOException e) { e.printStackTrace(); }
} }
public void savePartyPasswords() {
try {
new File(partyPasswordsFile).createNewFile();
ObjectOutputStream obj = new ObjectOutputStream(new FileOutputStream(partyPasswordsFile));
obj.writeObject(this.partyPasswords);
obj.close();
} catch (FileNotFoundException e) { e.printStackTrace();
} catch (IOException e) { e.printStackTrace(); }
} }
} }