mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-02 00:30:07 +01:00
commit
20b2a11292
@ -103,6 +103,8 @@ public class mcMMO extends JavaPlugin
|
|||||||
|
|
||||||
mcPermissions.initialize(getServer());
|
mcPermissions.initialize(getServer());
|
||||||
config.configCheck();
|
config.configCheck();
|
||||||
|
Party.getInstance().loadParties();
|
||||||
|
new Party(this);
|
||||||
|
|
||||||
if(!LoadProperties.useMySQL)
|
if(!LoadProperties.useMySQL)
|
||||||
Users.getInstance().loadUsers(); //Load Users file
|
Users.getInstance().loadUsers(); //Load Users file
|
||||||
@ -1199,6 +1201,8 @@ public class mcMMO extends JavaPlugin
|
|||||||
//Invite Command
|
//Invite Command
|
||||||
else if(LoadProperties.inviteEnable && label.equalsIgnoreCase(LoadProperties.invite) && mcPermissions.getInstance().party(player)){
|
else if(LoadProperties.inviteEnable && label.equalsIgnoreCase(LoadProperties.invite) && mcPermissions.getInstance().party(player)){
|
||||||
|
|
||||||
|
Party Pinstance = Party.getInstance();
|
||||||
|
|
||||||
if(!PP.inParty())
|
if(!PP.inParty())
|
||||||
{
|
{
|
||||||
player.sendMessage(mcLocale.getString("mcPlayerListener.NotInParty"));
|
player.sendMessage(mcLocale.getString("mcPlayerListener.NotInParty"));
|
||||||
@ -1211,27 +1215,34 @@ public class mcMMO extends JavaPlugin
|
|||||||
}
|
}
|
||||||
if(PP.inParty() && split.length >= 2 && isPlayer(split[1]))
|
if(PP.inParty() && split.length >= 2 && isPlayer(split[1]))
|
||||||
{
|
{
|
||||||
Player target = getPlayer(split[1]);
|
if(Pinstance.canInvite(player, PP)) {
|
||||||
PlayerProfile PPt = Users.getProfile(target);
|
Player target = getPlayer(split[1]);
|
||||||
PPt.modifyInvite(PP.getParty());
|
PlayerProfile PPt = Users.getProfile(target);
|
||||||
|
PPt.modifyInvite(PP.getParty());
|
||||||
|
|
||||||
player.sendMessage(mcLocale.getString("mcPlayerListener.InviteSuccess"));
|
|
||||||
//target.sendMessage(ChatColor.RED+"ALERT: "+ChatColor.GREEN+"You have received a party invite for "+PPt.getInvite()+" from "+player.getName());
|
player.sendMessage(mcLocale.getString("mcPlayerListener.InviteSuccess"));
|
||||||
target.sendMessage(mcLocale.getString("mcPlayerListener.ReceivedInvite1", new Object[] {PPt.getInvite(), player.getName()}));
|
//target.sendMessage(ChatColor.RED+"ALERT: "+ChatColor.GREEN+"You have received a party invite for "+PPt.getInvite()+" from "+player.getName());
|
||||||
//target.sendMessage(ChatColor.YELLOW+"Type "+ChatColor.GREEN+LoadProperties.accept+ChatColor.YELLOW+" to accept the invite");
|
target.sendMessage(mcLocale.getString("mcPlayerListener.ReceivedInvite1", new Object[] {PPt.getInvite(), player.getName()}));
|
||||||
target.sendMessage(mcLocale.getString("mcPlayerListener.ReceivedInvite2", new Object[] {LoadProperties.accept}));
|
//target.sendMessage(ChatColor.YELLOW+"Type "+ChatColor.GREEN+LoadProperties.accept+ChatColor.YELLOW+" to accept the invite");
|
||||||
|
target.sendMessage(mcLocale.getString("mcPlayerListener.ReceivedInvite2", new Object[] {LoadProperties.accept}));
|
||||||
|
} else {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("Party is locked, only party leader may invite.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Accept invite
|
//Accept invite
|
||||||
else if(LoadProperties.acceptEnable && label.equalsIgnoreCase(LoadProperties.accept) && mcPermissions.getInstance().party(player)){
|
else if(LoadProperties.acceptEnable && label.equalsIgnoreCase(LoadProperties.accept) && mcPermissions.getInstance().party(player)){
|
||||||
if(PP.hasPartyInvite()){
|
if(PP.hasPartyInvite()){
|
||||||
if(PP.inParty()){
|
Party Pinstance = Party.getInstance();
|
||||||
Party.getInstance().informPartyMembersQuit(player, getPlayersOnline());
|
|
||||||
|
if(PP.inParty()) {
|
||||||
|
Pinstance.removeFromParty(player, PP);
|
||||||
}
|
}
|
||||||
PP.acceptInvite();
|
PP.acceptInvite();
|
||||||
Party.getInstance().informPartyMembers(player, getPlayersOnline());
|
Pinstance.addToParty(player, PP, PP.getParty(), true);
|
||||||
player.sendMessage(mcLocale.getString("mcPlayerListener.InviteAccepted", new Object[]{PP.getParty()}));
|
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(mcLocale.getString("mcPlayerListener.NoInvites"));
|
player.sendMessage(mcLocale.getString("mcPlayerListener.NoInvites"));
|
||||||
}
|
}
|
||||||
@ -1242,40 +1253,159 @@ public class mcMMO extends JavaPlugin
|
|||||||
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +mcLocale.getString("mcPlayerListener.NoPermission"));
|
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +mcLocale.getString("mcPlayerListener.NoPermission"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(split.length == 1 && !PP.inParty()){
|
|
||||||
player.sendMessage("Proper usage is "+LoadProperties.party+" <name> or 'q' to quit");
|
Party Pinstance = Party.getInstance();
|
||||||
return true;
|
|
||||||
|
if(PP.inParty() && (!Pinstance.isParty(PP.getParty()) || !Pinstance.isInParty(player, PP))) {
|
||||||
|
Pinstance.addToParty(player, PP, PP.getParty(), false);
|
||||||
}
|
}
|
||||||
if(split.length == 1 && PP.inParty()){
|
|
||||||
|
if(args.length == 0 && !PP.inParty()){
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("Proper usage is "+LoadProperties.party+" <name> or 'q' to quit");
|
||||||
|
player.sendMessage("To join a password protected party use "+LoadProperties.party+" <name> <password>");
|
||||||
|
player.sendMessage("Or "+LoadProperties.party+" ? for more information.");
|
||||||
|
return true;
|
||||||
|
} else if(args.length == 0 && PP.inParty()){
|
||||||
String tempList = "";
|
String tempList = "";
|
||||||
int x = 0;
|
int x = 0;
|
||||||
for(Player p : this.getServer().getOnlinePlayers()){
|
for(Player p : this.getServer().getOnlinePlayers()){
|
||||||
if(PP.getParty().equals(Users.getProfile(p).getParty())){
|
if(PP.getParty().equals(Users.getProfile(p).getParty())){
|
||||||
if(p != null && x+1 >= Party.getInstance().partyCount(player, getPlayersOnline())){
|
if(p != null && x+1 >= Pinstance.partyCount(player, getPlayersOnline())){
|
||||||
tempList+= p.getName();
|
tempList+= p.getName();
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
if(p != null && x < Party.getInstance().partyCount(player, getPlayersOnline())){
|
if(p != null && x < Pinstance.partyCount(player, getPlayersOnline())){
|
||||||
tempList+= p.getName() +", ";
|
tempList+= p.getName() +", ";
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
player.sendMessage(mcLocale.getString("mcPlayerListener.YouAreInParty", new Object[] {PP.getParty()}));
|
player.sendMessage(mcLocale.getString("mcPlayerListener.YouAreInParty", new Object[] {PP.getParty()}));
|
||||||
player.sendMessage(mcLocale.getString("mcPlayerListener.PartyMembers")+" ("+ChatColor.WHITE+tempList+ChatColor.GREEN+")");
|
player.sendMessage(mcLocale.getString("mcPlayerListener.PartyMembers")+" ("+ChatColor.WHITE+tempList+ChatColor.GREEN+")");
|
||||||
}
|
|
||||||
if(split.length > 1 && split[1].equals("q") && PP.inParty()){
|
|
||||||
Party.getInstance().informPartyMembersQuit(player, getPlayersOnline());
|
|
||||||
PP.removeParty();
|
|
||||||
player.sendMessage(mcLocale.getString("mcPlayerListener.LeftParty"));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if(args.length == 1){
|
||||||
if(split.length >= 2){
|
if(args[0].equals("q") && PP.inParty()) {
|
||||||
if(PP.inParty())
|
Pinstance.removeFromParty(player, PP);
|
||||||
Party.getInstance().informPartyMembersQuit(player, getPlayersOnline());
|
player.sendMessage(mcLocale.getString("mcPlayerListener.LeftParty"));
|
||||||
PP.setParty(split[1]);
|
return true;
|
||||||
player.sendMessage(mcLocale.getString("mcPlayerListener.JoinedParty", new Object[] {split[1]}));
|
} else if (args[0].equalsIgnoreCase("?")) {
|
||||||
Party.getInstance().informPartyMembers(player, getPlayersOnline());
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("Use "+LoadProperties.party+" <name> to join a party or 'q' to quit");
|
||||||
|
player.sendMessage("To join a password protected party use "+LoadProperties.party+" <name> <password>");
|
||||||
|
player.sendMessage("To lock your party use "+LoadProperties.party+" lock");
|
||||||
|
player.sendMessage("To unlock your party use "+LoadProperties.party+" unlock");
|
||||||
|
player.sendMessage("To password protect your party use "+LoadProperties.party+" password <password>");
|
||||||
|
player.sendMessage("To kick from your party use "+LoadProperties.party+" kick <player>");
|
||||||
|
player.sendMessage("To transfer ownership of your party use "+LoadProperties.party+" owner <player>");
|
||||||
|
} else if (args[0].equalsIgnoreCase("lock")) {
|
||||||
|
if(PP.inParty()) {
|
||||||
|
if(Pinstance.isPartyLeader(player, PP.getParty())) {
|
||||||
|
Pinstance.lockParty(PP.getParty());
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("Party locked.");
|
||||||
|
} else {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("You are not the party owner.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("This is not a valid party name");
|
||||||
|
}
|
||||||
|
} else if (args[0].equalsIgnoreCase("unlock")) {
|
||||||
|
if(PP.inParty()) {
|
||||||
|
if(Pinstance.isPartyLeader(player, PP.getParty())) {
|
||||||
|
Pinstance.unlockParty(PP.getParty());
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("Party unlocked");
|
||||||
|
} else {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("You are not the party owner.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("This is not a valid party name");
|
||||||
|
}
|
||||||
|
//Party debugging command.
|
||||||
|
//} else if (args[0].equalsIgnoreCase("dump")) {
|
||||||
|
// Pinstance.dump(player);
|
||||||
|
} else {
|
||||||
|
if(PP.inParty()) {
|
||||||
|
Pinstance.removeFromParty(player, PP);
|
||||||
|
}
|
||||||
|
Pinstance.addToParty(player, PP, args[0], false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if(args.length == 2 && PP.inParty()) {
|
||||||
|
if(args[0].equalsIgnoreCase("password")) {
|
||||||
|
if(Pinstance.isPartyLeader(player, PP.getParty())) {
|
||||||
|
if(Pinstance.isPartyLocked(PP.getParty())) {
|
||||||
|
Pinstance.setPartyPassword(PP.getParty(), args[1]);
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("Party password set to "+args[1]);
|
||||||
|
} else {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("Party not locked.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("You are not the party owner.");
|
||||||
|
}
|
||||||
|
} else if(args[0].equalsIgnoreCase("kick")) {
|
||||||
|
if(Pinstance.isPartyLeader(player, PP.getParty())) {
|
||||||
|
if(Pinstance.isPartyLocked(PP.getParty())) {
|
||||||
|
Player tPlayer = null;
|
||||||
|
if(this.getServer().getPlayer(args[1]) != null) tPlayer = this.getServer().getPlayer(args[1]);
|
||||||
|
if(tPlayer == null) {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("Could not kick player "+args[1]);
|
||||||
|
}
|
||||||
|
if(!Pinstance.inSameParty(player, tPlayer)) {
|
||||||
|
player.sendMessage(tPlayer.getName()+" not in your party.");
|
||||||
|
} else {
|
||||||
|
//Not an admin
|
||||||
|
if(!mcPermissions.getInstance().admin(player)) {
|
||||||
|
//Can't kick an admin
|
||||||
|
if(mcPermissions.getInstance().admin(tPlayer)) {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("Could not kick player "+tPlayer.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PlayerProfile tPP = Users.getProfile(tPlayer);
|
||||||
|
Pinstance.removeFromParty(tPlayer, tPP);
|
||||||
|
tPlayer.sendMessage(mcLocale.getString("mcPlayerListener.LeftParty"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("Party not locked.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("You are not the party owner.");
|
||||||
|
}
|
||||||
|
} else if(args[0].equalsIgnoreCase("owner")) {
|
||||||
|
if(Pinstance.isPartyLeader(player, PP.getParty())) {
|
||||||
|
Player tPlayer = null;
|
||||||
|
if(this.getServer().getPlayer(args[1]) != null) tPlayer = this.getServer().getPlayer(args[1]);
|
||||||
|
if(tPlayer == null) {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("Could not set owner to "+args[1]);
|
||||||
|
}
|
||||||
|
if(!Pinstance.inSameParty(player, tPlayer)) {
|
||||||
|
player.sendMessage("Could not set owner to "+tPlayer.getName());
|
||||||
|
} else {
|
||||||
|
Pinstance.setPartyLeader(PP.getParty(), tPlayer.getName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("You are not the party owner.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Pinstance.removeFromParty(player, PP);
|
||||||
|
Pinstance.addToParty(player, PP, args[0], false, args[1]);
|
||||||
|
}
|
||||||
|
} else if(args.length == 2 && !PP.inParty()) {
|
||||||
|
Pinstance.addToParty(player, PP, args[0], false, args[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(LoadProperties.partyEnable && label.equalsIgnoreCase("p")){
|
else if(LoadProperties.partyEnable && label.equalsIgnoreCase("p")){
|
||||||
|
@ -194,6 +194,13 @@ public class mcPermissions
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public boolean partyLock(Player player) {
|
||||||
|
if (permissionsEnabled) {
|
||||||
|
return permission(player, "mcmmo.chat.partylock");
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
public boolean partyTeleport(Player player) {
|
public boolean partyTeleport(Player player) {
|
||||||
if (permissionsEnabled) {
|
if (permissionsEnabled) {
|
||||||
return permission(player, "mcmmo.commands.ptp");
|
return permission(player, "mcmmo.commands.ptp");
|
||||||
|
@ -1,28 +1,47 @@
|
|||||||
package com.gmail.nossr50.party;
|
package com.gmail.nossr50.party;
|
||||||
|
|
||||||
|
import java.io.EOFException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.nossr50.Users;
|
import com.gmail.nossr50.Users;
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
|
import com.gmail.nossr50.config.LoadProperties;
|
||||||
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||||
import com.gmail.nossr50.locale.mcLocale;
|
import com.gmail.nossr50.locale.mcLocale;
|
||||||
|
|
||||||
|
|
||||||
public class Party
|
public class Party
|
||||||
{
|
{
|
||||||
|
public static String partyPlayersFile = mcMMO.maindirectory + File.separator + "FlatFileStuff" + File.separator + "partyPlayers";
|
||||||
|
public static String partyLocksFile = mcMMO.maindirectory + File.separator + "FlatFileStuff" + File.separator + "partyLocks";
|
||||||
|
public static String partyPasswordsFile = mcMMO.maindirectory + File.separator + "FlatFileStuff" + File.separator + "partyPasswords";
|
||||||
|
|
||||||
|
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 mcMMO plugin;
|
||||||
public Party(mcMMO instance)
|
public Party(mcMMO instance) {
|
||||||
{
|
|
||||||
plugin = instance;
|
plugin = instance;
|
||||||
}
|
}
|
||||||
private static volatile Party 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;
|
||||||
}
|
}
|
||||||
public boolean inSameParty(Player playera, Player playerb){
|
public boolean inSameParty(Player playera, Player playerb){
|
||||||
if(Users.getProfile(playera) == null || Users.getProfile(playerb) == null)
|
if(Users.getProfile(playera) == null || Users.getProfile(playerb) == null)
|
||||||
{
|
{
|
||||||
@ -57,6 +76,13 @@ public class Party
|
|||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void informPartyMembers(Player player) {
|
||||||
|
Player[] players = plugin.getPlayersOnline();
|
||||||
|
informPartyMembers(player, players);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void informPartyMembers(Player player, Player[] players)
|
public void informPartyMembers(Player player, Player[] players)
|
||||||
{
|
{
|
||||||
int x = 0;
|
int x = 0;
|
||||||
@ -72,6 +98,32 @@ public class Party
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void informPartyMembersOwnerChange(String newOwner) {
|
||||||
|
Player newOwnerPlayer = plugin.getServer().getPlayer(newOwner);
|
||||||
|
Player[] players = plugin.getPlayersOnline();
|
||||||
|
informPartyMembersOwnerChange(newOwnerPlayer, players);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void informPartyMembersOwnerChange(Player newOwner, Player[] players) {
|
||||||
|
int x = 0;
|
||||||
|
for(Player p : players){
|
||||||
|
if(newOwner != null && p != null){
|
||||||
|
if(inSameParty(newOwner, p) && !p.getName().equals(newOwner.getName()))
|
||||||
|
{
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
p.sendMessage(newOwner.getName()+" is the new party owner.");
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void informPartyMembersQuit(Player player) {
|
||||||
|
Player[] players = plugin.getPlayersOnline();
|
||||||
|
informPartyMembersQuit(player, players);
|
||||||
|
}
|
||||||
|
|
||||||
public void informPartyMembersQuit(Player player, Player[] players)
|
public void informPartyMembersQuit(Player player, Player[] players)
|
||||||
{
|
{
|
||||||
int x = 0;
|
int x = 0;
|
||||||
@ -85,5 +137,252 @@ public class Party
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeFromParty(Player player, PlayerProfile PP) {
|
||||||
|
informPartyMembersQuit(player);
|
||||||
|
String party = PP.getParty();
|
||||||
|
if(isPartyLeader(player, party)) {
|
||||||
|
if(isPartyLocked(party)) {
|
||||||
|
unlockParty(party);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.partyPlayers.get(party).remove(player.getName());
|
||||||
|
if(isPartyEmpty(party)) deleteParty(party);
|
||||||
|
PP.removeParty();
|
||||||
|
savePartyPlayers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addToParty(Player player, PlayerProfile PP, String newParty, Boolean invite) {
|
||||||
|
addToParty(player, PP, newParty, invite, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addToParty(Player player, PlayerProfile PP, String newParty, Boolean invite, String password) {
|
||||||
|
//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) {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("This party requires a password. Use "+LoadProperties.party+" <party> <password> to join it.");
|
||||||
|
return;
|
||||||
|
} else if(!password.equalsIgnoreCase(getPartyPassword(newParty))) {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("Party password incorrect.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
player.sendMessage("Party is locked.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
PP.acceptInvite();
|
||||||
|
}
|
||||||
|
//New party?
|
||||||
|
if(!isParty(newParty)) {
|
||||||
|
putNestedEntry(this.partyPlayers, newParty, player.getName(), true);
|
||||||
|
|
||||||
|
//Get default locking behavior from config?
|
||||||
|
this.partyLocks.put(newParty, false);
|
||||||
|
this.partyPasswords.put(newParty, null);
|
||||||
|
saveParties();
|
||||||
|
} else {
|
||||||
|
putNestedEntry(this.partyPlayers, newParty, player.getName(), false);
|
||||||
|
|
||||||
|
savePartyPlayers();
|
||||||
|
}
|
||||||
|
PP.setParty(newParty);
|
||||||
|
informPartyMembers(player);
|
||||||
|
|
||||||
|
if(!invite) {
|
||||||
|
player.sendMessage(mcLocale.getString("mcPlayerListener.JoinedParty", new Object[] { newParty }));
|
||||||
|
} 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)
|
||||||
|
{
|
||||||
|
HashMap<V,W> nested = nest.get(nestKey);
|
||||||
|
|
||||||
|
if (nested == null) {
|
||||||
|
nested = new HashMap<V,W>();
|
||||||
|
nest.put(nestKey, nested);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nested.put(nestedKey, nestedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dump(Player player) {
|
||||||
|
player.sendMessage(partyPlayers.toString());
|
||||||
|
player.sendMessage(partyLocks.toString());
|
||||||
|
player.sendMessage(partyPasswords.toString());
|
||||||
|
Iterator<String> i = partyPlayers.keySet().iterator();
|
||||||
|
while(i.hasNext()) {
|
||||||
|
String nestkey = i.next();
|
||||||
|
player.sendMessage(nestkey);
|
||||||
|
Iterator<String> j = partyPlayers.get(nestkey).keySet().iterator();
|
||||||
|
while(j.hasNext()) {
|
||||||
|
String nestedkey = j.next();
|
||||||
|
player.sendMessage("."+nestedkey);
|
||||||
|
if(partyPlayers.get(nestkey).get(nestedkey)) {
|
||||||
|
player.sendMessage("..True");
|
||||||
|
} else {
|
||||||
|
player.sendMessage("..False");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lockParty(String partyName) {
|
||||||
|
this.partyLocks.put(partyName, true);
|
||||||
|
savePartyLocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unlockParty(String partyName) {
|
||||||
|
this.partyLocks.put(partyName, false);
|
||||||
|
savePartyLocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteParty(String partyName) {
|
||||||
|
this.partyPlayers.remove(partyName);
|
||||||
|
this.partyLocks.remove(partyName);
|
||||||
|
this.partyPasswords.remove(partyName);
|
||||||
|
saveParties();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPartyPassword(String partyName, String password) {
|
||||||
|
if(password.equalsIgnoreCase("\"\"")) password = null;
|
||||||
|
this.partyPasswords.put(partyName, password);
|
||||||
|
savePartyPasswords();
|
||||||
|
}
|
||||||
|
|
||||||
|
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)) {
|
||||||
|
partyPlayers.get(partyName).put(playerName, true);
|
||||||
|
informPartyMembersOwnerChange(playerName);
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
plugin.getServer().getPlayer(playerName).sendMessage("You are now the party owner.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(partyPlayers.get(partyName).get(playerKey)) {
|
||||||
|
//TODO: Needs more locale.
|
||||||
|
plugin.getServer().getPlayer(playerKey).sendMessage("You are no longer party owner.");
|
||||||
|
partyPlayers.get(partyName).put(playerKey, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPartyPassword(String partyName) {
|
||||||
|
return this.partyPasswords.get(partyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canInvite(Player player, PlayerProfile PP) {
|
||||||
|
return (isPartyLocked(PP.getParty()) && !isPartyLeader(player, PP.getParty())) ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isParty(String partyName) {
|
||||||
|
return this.partyPlayers.containsKey(partyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPartyEmpty(String partyName) {
|
||||||
|
return this.partyPlayers.get(partyName).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPartyLeader(Player player, String partyName) {
|
||||||
|
if(this.partyPlayers.get(partyName).get(player.getName()) == null) return false;
|
||||||
|
return this.partyPlayers.get(partyName).get(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPartyLocked(String partyName) {
|
||||||
|
if(this.partyLocks.get(partyName) == null) return false;
|
||||||
|
return this.partyLocks.get(partyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPartyPasswordProtected(String partyName) {
|
||||||
|
return !(this.partyPasswords.get(partyName) == null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInParty(Player player, PlayerProfile PP) {
|
||||||
|
return partyPlayers.get(PP.getParty()).containsKey(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@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) { mcMMO.log.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) { mcMMO.log.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) { mcMMO.log.info("partyPasswordsFile empty.");
|
||||||
|
} catch (IOException e) { e.printStackTrace();
|
||||||
|
} catch (ClassNotFoundException e) { e.printStackTrace(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveParties() {
|
||||||
|
savePartyPlayers();
|
||||||
|
savePartyLocks();
|
||||||
|
savePartyPasswords();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void savePartyPlayers() {
|
||||||
|
try {
|
||||||
|
new File(partyPlayersFile).createNewFile();
|
||||||
|
ObjectOutputStream obj = new ObjectOutputStream(new FileOutputStream(partyPlayersFile));
|
||||||
|
obj.writeObject(this.partyPlayers);
|
||||||
|
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(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
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