mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
*CLEANUP* - Party.java
This commit is contained in:
parent
24a50346db
commit
b70e868b5c
@ -100,5 +100,26 @@ public class PartyAPI {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class AcceptCommand implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
PP.acceptInvite();
|
||||
Pinstance.addToParty(player, PP, PP.getParty(), true);
|
||||
Pinstance.addToParty(player, PP, PP.getParty(), true, null);
|
||||
|
||||
} else {
|
||||
player.sendMessage(mcLocale.getString("mcPlayerListener.NoInvites"));
|
||||
|
@ -35,7 +35,7 @@ public class PartyCommand implements CommandExecutor {
|
||||
Party Pinstance = Party.getInstance();
|
||||
|
||||
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()) {
|
||||
@ -48,7 +48,7 @@ public class PartyCommand implements CommandExecutor {
|
||||
int x = 0;
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
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())) {
|
||||
tempList += ChatColor.GOLD + p.getName();
|
||||
x++;
|
||||
@ -57,7 +57,7 @@ public class PartyCommand implements CommandExecutor {
|
||||
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())) {
|
||||
tempList += ChatColor.GOLD + p.getName() + ", ";
|
||||
x++;
|
||||
@ -175,7 +175,7 @@ public class PartyCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Pinstance.addToParty(player, PP, args[0], false);
|
||||
Pinstance.addToParty(player, PP, args[0], false, null);
|
||||
return true;
|
||||
}
|
||||
} else if (args.length == 2 && PP.inParty()) {
|
||||
|
@ -20,7 +20,6 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.mcLocale;
|
||||
|
||||
|
||||
public class Party {
|
||||
/*
|
||||
* 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>();
|
||||
|
||||
private static mcMMO plugin;
|
||||
private static volatile Party instance;
|
||||
|
||||
public Party(mcMMO instance) {
|
||||
new File(mcMMO.maindirectory + File.separator + "FlatFileStuff").mkdir();
|
||||
plugin = instance;
|
||||
}
|
||||
private static volatile Party instance;
|
||||
|
||||
public static Party getInstance()
|
||||
{
|
||||
public static Party getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new Party(plugin);
|
||||
}
|
||||
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){
|
||||
if(Users.getProfile(playera).inParty() && Users.getProfile(playerb).inParty())
|
||||
{
|
||||
if(Users.getProfile(playera).getParty().equals(Users.getProfile(playerb).getParty()))
|
||||
{
|
||||
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;
|
||||
}
|
||||
} else
|
||||
{
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int partyCount(Player player, Player[] players)
|
||||
{
|
||||
int x = 0;
|
||||
for(Player hurrdurr : players)
|
||||
{
|
||||
if(player != null && hurrdurr != null)
|
||||
{
|
||||
if(Users.getProfile(player).getParty().equals(Users.getProfile(hurrdurr).getParty()))
|
||||
x++;
|
||||
/**
|
||||
* Get the number of players in this player's party.
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param players A list of players to
|
||||
* @return the number of players in this player's party
|
||||
*/
|
||||
public int partyCount(Player player) {
|
||||
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)
|
||||
{
|
||||
informPartyMembers(player, Bukkit.getServer().getOnlinePlayers());
|
||||
return partyMembers;
|
||||
}
|
||||
|
||||
private void informPartyMembers(Player player) {
|
||||
String playerName = player.getName();
|
||||
|
||||
public void informPartyMembers(Player player, Player[] players)
|
||||
{
|
||||
for(Player p : players)
|
||||
{
|
||||
if(player != null && p != null)
|
||||
{
|
||||
if(inSameParty(player, p) && !p.getName().equals(player.getName()))
|
||||
{
|
||||
p.sendMessage(mcLocale.getString("Party.InformedOnJoin", new Object[] {player.getName()}));
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (player != null && p != null) {
|
||||
if (inSameParty(player, p) && !p.getName().equals(playerName)) {
|
||||
p.sendMessage(mcLocale.getString("Party.InformedOnJoin", new Object[] {playerName}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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>();
|
||||
|
||||
for(Player p : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
if(p.isOnline() && player != null && p != null)
|
||||
{
|
||||
if(inSameParty(player, p) && !p.getName().equals(player.getName()))
|
||||
{
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (p.isOnline() && player != null && p != null) {
|
||||
if (inSameParty(player, p) && !p.getName().equals(player.getName())) {
|
||||
players.add(p);
|
||||
}
|
||||
}
|
||||
@ -129,131 +133,139 @@ public class Party {
|
||||
return players;
|
||||
}
|
||||
|
||||
public void informPartyMembersOwnerChange(String newOwner) {
|
||||
Player newOwnerPlayer = plugin.getServer().getPlayer(newOwner);
|
||||
informPartyMembersOwnerChange(newOwnerPlayer, Bukkit.getServer().getOnlinePlayers());
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
|
||||
public void informPartyMembersOwnerChange(Player newOwner, Player[] players) {
|
||||
for(Player p : players){
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()){
|
||||
if (newOwner != null && p != null) {
|
||||
if(inSameParty(newOwner, p))
|
||||
{
|
||||
p.sendMessage(newOwner.getName()+" is the new party owner."); //TODO: Needs more locale
|
||||
if (inSameParty(newOwner, p)) {
|
||||
p.sendMessage(newOwnerName + " is the new party owner."); //TODO: Needs more locale
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void informPartyMembersQuit(Player player)
|
||||
{
|
||||
informPartyMembersQuit(player, Bukkit.getServer().getOnlinePlayers());
|
||||
}
|
||||
/**
|
||||
* Notify party members when the a party member quits.
|
||||
*
|
||||
* @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 : players){
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()){
|
||||
if (player != null && p != null){
|
||||
if(inSameParty(player, p) && !p.getName().equals(player.getName()))
|
||||
{
|
||||
p.sendMessage(mcLocale.getString("Party.InformedOnQuit", new Object[] {player.getName()}));
|
||||
if (inSameParty(player, p) && !p.getName().equals(playerName)) {
|
||||
p.sendMessage(mcLocale.getString("Party.InformedOnQuit", new Object[] {playerName}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
if(!isParty(PP.getParty()) || !isInParty(player, PP))
|
||||
addToParty(player, PP, PP.getParty(), false);
|
||||
if (!isParty(party) || !isInParty(player, PP)) {
|
||||
addToParty(player, PP, party, false, null);
|
||||
}
|
||||
|
||||
informPartyMembersQuit(player);
|
||||
String party = PP.getParty();
|
||||
if(isPartyLeader(player.getName(), party))
|
||||
{
|
||||
|
||||
if (isPartyLeader(playerName, party)) {
|
||||
if (isPartyLocked(party)) {
|
||||
unlockParty(party);
|
||||
}
|
||||
}
|
||||
|
||||
this.partyPlayers.get(party).remove(player.getName());
|
||||
if(isPartyEmpty(party)) deleteParty(party);
|
||||
partyPlayers.get(party).remove(playerName);
|
||||
|
||||
if (isPartyEmpty(party)) {
|
||||
deleteParty(party);
|
||||
}
|
||||
|
||||
PP.removeParty();
|
||||
savePartyPlayers();
|
||||
savePartyFile(partyPlayersFile, partyPlayers);
|
||||
}
|
||||
|
||||
public void addToParty(Player player, PlayerProfile PP, String newParty, Boolean invite) {
|
||||
newParty = newParty.replace(":", ".");
|
||||
addToParty(player, PP, newParty, invite, null);
|
||||
}
|
||||
/**
|
||||
* 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();
|
||||
|
||||
|
||||
public void addToParty(Player player, PlayerProfile PP, String newParty, Boolean invite, String password)
|
||||
{
|
||||
//Fix for FFS
|
||||
newParty = newParty.replace(":", ".");
|
||||
|
||||
//Don't care about passwords on invites
|
||||
if(!invite)
|
||||
{
|
||||
if (!invite) {
|
||||
|
||||
//Don't care about passwords if it isn't locked
|
||||
if(isPartyLocked(newParty))
|
||||
{
|
||||
if(isPartyPasswordProtected(newParty))
|
||||
{
|
||||
if(password == null)
|
||||
{
|
||||
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)))
|
||||
{
|
||||
}
|
||||
else if(!password.equalsIgnoreCase(getPartyPassword(newParty))) {
|
||||
player.sendMessage("Party password incorrect."); //TODO: Needs more locale.
|
||||
return;
|
||||
}
|
||||
} else
|
||||
{
|
||||
}
|
||||
else {
|
||||
player.sendMessage("Party is locked."); //TODO: Needs more locale.
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
}
|
||||
else {
|
||||
PP.acceptInvite();
|
||||
}
|
||||
|
||||
//New party?
|
||||
if(!isParty(newParty))
|
||||
{
|
||||
putNestedEntry(this.partyPlayers, newParty, player.getName(), true);
|
||||
if (!isParty(newParty)) {
|
||||
putNestedEntry(partyPlayers, newParty, playerName, true);
|
||||
|
||||
//Get default locking behavior from config?
|
||||
this.partyLocks.put(newParty, false);
|
||||
this.partyPasswords.put(newParty, null);
|
||||
partyLocks.put(newParty, false);
|
||||
partyPasswords.put(newParty, null);
|
||||
saveParties();
|
||||
} else
|
||||
{
|
||||
putNestedEntry(this.partyPlayers, newParty, player.getName(), false);
|
||||
|
||||
savePartyPlayers();
|
||||
}
|
||||
else {
|
||||
putNestedEntry(partyPlayers, newParty, playerName, false);
|
||||
savePartyFile(partyPlayersFile, partyPlayers);
|
||||
}
|
||||
|
||||
PP.setParty(newParty);
|
||||
informPartyMembers(player);
|
||||
|
||||
if(!invite)
|
||||
{
|
||||
if (!invite) {
|
||||
player.sendMessage(mcLocale.getString("mcPlayerListener.JoinedParty", new Object[]{ newParty }));
|
||||
} else
|
||||
{
|
||||
}
|
||||
else {
|
||||
player.sendMessage(mcLocale.getString("mcPlayerListener.InviteAccepted", new Object[]{ PP.getParty() }));
|
||||
}
|
||||
}
|
||||
|
||||
private static <U,V,W> W putNestedEntry(
|
||||
HashMap<U,HashMap<V,W>> nest,
|
||||
U nestKey,
|
||||
V nestedKey,
|
||||
W nestedValue)
|
||||
{
|
||||
private static <U,V,W> W putNestedEntry(HashMap<U, HashMap<V, W>> nest, U nestKey, V nestedKey, W nestedValue) {
|
||||
HashMap<V,W> nested = nest.get(nestKey);
|
||||
|
||||
if (nested == null) {
|
||||
@ -264,7 +276,10 @@ public class Party {
|
||||
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(partyLocks.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) {
|
||||
this.partyLocks.put(partyName, true);
|
||||
savePartyLocks();
|
||||
partyLocks.put(partyName, true);
|
||||
savePartyFile(partyLocksFile, partyLocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock a party.
|
||||
*
|
||||
* @param partyName The party to unlock
|
||||
*/
|
||||
public void unlockParty(String partyName) {
|
||||
this.partyLocks.put(partyName, false);
|
||||
savePartyLocks();
|
||||
partyLocks.put(partyName, false);
|
||||
savePartyFile(partyLocksFile, partyLocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a party.
|
||||
*
|
||||
* @param partyName The party to delete
|
||||
*/
|
||||
private void deleteParty(String partyName) {
|
||||
this.partyPlayers.remove(partyName);
|
||||
this.partyLocks.remove(partyName);
|
||||
this.partyPasswords.remove(partyName);
|
||||
partyPlayers.remove(partyName);
|
||||
partyLocks.remove(partyName);
|
||||
partyPasswords.remove(partyName);
|
||||
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) {
|
||||
if(password.equalsIgnoreCase("\"\"")) password = null;
|
||||
this.partyPasswords.put(partyName, password);
|
||||
savePartyPasswords();
|
||||
if (password.equalsIgnoreCase("\"\"")) { //What's with that password string?
|
||||
password = null;
|
||||
}
|
||||
|
||||
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) {
|
||||
Iterator<String> i = partyPlayers.get(partyName).keySet().iterator();
|
||||
while(i.hasNext()) {
|
||||
String playerKey = i.next();
|
||||
if(playerKey.equalsIgnoreCase(playerName)) {
|
||||
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(playerKey)) {
|
||||
plugin.getServer().getPlayer(playerKey).sendMessage("You are no longer party owner."); //TODO: Needs more locale.
|
||||
partyPlayers.get(partyName).put(playerKey, false);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the password of a party.
|
||||
*
|
||||
* @param partyName The party name
|
||||
* @return The password of this party
|
||||
*/
|
||||
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) {
|
||||
return (isPartyLocked(PP.getParty()) && !isPartyLeader(player.getName(), PP.getParty())) ? false : true;
|
||||
}
|
||||
String party = PP.getParty();
|
||||
|
||||
public boolean isParty(String partyName) {
|
||||
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
|
||||
if (isPartyLocked(party) && !isPartyLeader(player.getName(), party)) {
|
||||
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) {
|
||||
if(this.partyLocks.get(partyName) == null) return false;
|
||||
return this.partyLocks.get(partyName);
|
||||
Boolean isLocked = 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) {
|
||||
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) {
|
||||
return partyPlayers.get(PP.getParty()).containsKey(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all party related files.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void loadParties() {
|
||||
if (new File(partyPlayersFile).exists()) {
|
||||
try {
|
||||
ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyPlayersFile));
|
||||
this.partyPlayers = (HashMap<String, HashMap<String, Boolean>>)obj.readObject();
|
||||
} catch (FileNotFoundException e) { e.printStackTrace();
|
||||
} catch (EOFException e) { Bukkit.getLogger().info("partyPlayersFile empty.");
|
||||
} catch (IOException e) { e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) { e.printStackTrace(); }
|
||||
partyPlayers = (HashMap<String, HashMap<String, Boolean>>) obj.readObject();
|
||||
}
|
||||
catch (FileNotFoundException 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()) {
|
||||
try {
|
||||
ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyLocksFile));
|
||||
this.partyLocks = (HashMap<String, Boolean>)obj.readObject();
|
||||
} catch (FileNotFoundException e) { e.printStackTrace();
|
||||
} catch (EOFException e) { Bukkit.getLogger().info("partyLocksFile empty.");
|
||||
} catch (IOException e) { e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) { e.printStackTrace(); }
|
||||
partyLocks = (HashMap<String, Boolean>) obj.readObject();
|
||||
}
|
||||
catch (FileNotFoundException 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()) {
|
||||
try {
|
||||
ObjectInputStream obj = new ObjectInputStream(new FileInputStream(partyPasswordsFile));
|
||||
this.partyPasswords = (HashMap<String, String>) obj.readObject();
|
||||
} catch (FileNotFoundException e) { e.printStackTrace();
|
||||
} catch (EOFException e) { Bukkit.getLogger().info("partyPasswordsFile empty.");
|
||||
} catch (IOException e) { e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) { e.printStackTrace(); }
|
||||
}
|
||||
catch (FileNotFoundException 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();
|
||||
savePartyLocks();
|
||||
savePartyPasswords();
|
||||
/**
|
||||
* Save all party-related files.
|
||||
*/
|
||||
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 {
|
||||
new File(partyPlayersFile).createNewFile();
|
||||
ObjectOutputStream obj = new ObjectOutputStream(new FileOutputStream(partyPlayersFile));
|
||||
obj.writeObject(this.partyPlayers);
|
||||
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(); }
|
||||
}
|
||||
|
||||
public void savePartyLocks() {
|
||||
try {
|
||||
new File(partyLocksFile).createNewFile();
|
||||
ObjectOutputStream obj = new ObjectOutputStream(new FileOutputStream(partyLocksFile));
|
||||
obj.writeObject(this.partyLocks);
|
||||
obj.close();
|
||||
} catch (FileNotFoundException e) { e.printStackTrace();
|
||||
} catch (IOException e) { e.printStackTrace(); }
|
||||
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(); }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user