Reworked Party

This commit is contained in:
bm01 2012-06-08 23:48:41 +02:00
parent e9ccdcfbbe
commit 3732db2226
19 changed files with 743 additions and 859 deletions

View File

@ -11,6 +11,7 @@ Version 1.3.09
+ Added compatibility with AntiCheat (Which I highly recommend to prevent cheating)
+ Added several permission nodes to give individual users special perks (Double/Triple/Quadruple XP)
+ Added API for plugins to add custom tools directly via Spout - repair / abilities do not work ATM
+ Added offline party members to the list displayed by /party
= Fixed /mcremove being applied only after a reload
= Fixed Archery PVE disablement not working properly
= Fixed possible NPE when a projectile is shot by a dispenser or doesn't have any shooter
@ -25,6 +26,7 @@ Version 1.3.09
= Fixed bug with repairing items that use metadata
! API methods can now only be used in a static way
! Changed Spout settings to be in their own config file (spout.yml)
! Changed file format for parties (parties.yml), previous files are no longer used
Version 1.3.08
+ Added more notifications about Vampirism and Hardcore mode on player death

View File

@ -36,7 +36,7 @@ public final class ChatAPI {
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
if (Users.getProfile(player).inParty()) {
if (Users.getProfile(player).getParty().equalsIgnoreCase(chatEvent.getParty())) {
if (Users.getProfile(player).getParty().getName().equalsIgnoreCase(chatEvent.getParty())) {
player.sendMessage(pPrefix + chatEvent.getMessage());
}
}

View File

@ -1,10 +1,10 @@
package com.gmail.nossr50.api;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users;
public final class PartyAPI {
@ -20,7 +20,7 @@ public final class PartyAPI {
* @return the name of the player's party
*/
public static String getPartyName(Player player) {
return Users.getProfile(player).getParty();
return Users.getProfile(player).getParty().getName();
}
/**
@ -45,7 +45,7 @@ public final class PartyAPI {
* @return true if the two players are in the same party, false otherwise
*/
public static boolean inSameParty(Player playera, Player playerb) {
return Party.getInstance().inSameParty(playera, playerb);
return PartyManager.getInstance().inSameParty(playera, playerb);
}
/**
@ -55,8 +55,8 @@ public final class PartyAPI {
*
* @return the list of parties.
*/
public static ArrayList<String> getParties() {
return Party.getInstance().getParties();
public static List<String> getParties() {
return PartyManager.getInstance().getParties();
}
/**
@ -68,7 +68,7 @@ public final class PartyAPI {
* @param partyName The party to add the player to
*/
public static void addToParty(Player player, String partyName) {
Party.getInstance().addToParty(player, Users.getProfile(player), partyName, false, null);
PartyManager.getInstance().addToParty(player, Users.getProfile(player), partyName, null);
}
/**
@ -79,7 +79,7 @@ public final class PartyAPI {
* @param player The player to remove
*/
public static void removeFromParty(Player player) {
Party.getInstance().removeFromParty(player, Users.getProfile(player));
PartyManager.getInstance().removeFromParty(player, Users.getProfile(player));
}
/**
@ -90,8 +90,8 @@ public final class PartyAPI {
* @param partyName The party name
* @return the leader of the party
*/
public static Player getPartyLeader(String partyName) {
return Party.getInstance().getPartyLeader(partyName);
public static String getPartyLeader(String partyName) {
return PartyManager.getInstance().getPartyLeader(partyName);
}
/**
@ -103,7 +103,7 @@ public final class PartyAPI {
* @param player The player to set as leader
*/
public static void setPartyLeader(String partyName, String player) {
Party.getInstance().setPartyLeader(partyName, player);
PartyManager.getInstance().setPartyLeader(partyName, player);
}
/**
@ -114,8 +114,8 @@ public final class PartyAPI {
* @param player The player to check
* @return all the players in the player's party
*/
public static ArrayList<Player> getAllMembers(Player player) {
return Party.getInstance().getAllMembers(player);
public static List<String> getAllMembers(Player player) {
return PartyManager.getInstance().getAllMembers(player);
}
/**
@ -126,8 +126,8 @@ public final class PartyAPI {
* @param partyName The party to check
* @return all online players in this party
*/
public static ArrayList<Player> getOnlineMembers(String partyName) {
return Party.getInstance().getOnlineMembers(partyName);
public static List<Player> getOnlineMembers(String partyName) {
return PartyManager.getInstance().getOnlineMembers(partyName);
}
/**
@ -138,7 +138,7 @@ public final class PartyAPI {
* @param player The player to check
* @return all online players in the player's party
*/
public static ArrayList<Player> getOnlineMembers(Player player) {
return Party.getInstance().getOnlineMembers(player);
public static List<Player> getOnlineMembers(Player player) {
return PartyManager.getInstance().getOnlineMembers(player);
}
}

View File

@ -11,7 +11,7 @@ import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users;
public class AcceptCommand implements CommandExecutor {
@ -35,29 +35,28 @@ public class AcceptCommand implements CommandExecutor {
PlayerProfile PP = Users.getProfile(player);
if (PP.hasPartyInvite()) {
Party partyInstance = Party.getInstance();
PartyManager partyManagerInstance = PartyManager.getInstance();
if (PP.inParty()) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, PP.getParty(), PP.getInvite(), EventReason.CHANGED_PARTIES);
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, PP.getParty().getName(), PP.getInvite().getName(), EventReason.CHANGED_PARTIES);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
partyInstance.removeFromParty(player, PP);
partyManagerInstance.removeFromParty(player, PP);
}
else {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, PP.getInvite(), EventReason.JOINED_PARTY);
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, PP.getInvite().getName(), EventReason.JOINED_PARTY);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
}
PP.acceptInvite();
partyInstance.addToParty(player, PP, PP.getParty(), true, null);
partyManagerInstance.addToInvitedParty(player, PP, PP.getInvite());
}
else {
player.sendMessage(LocaleLoader.getString("mcMMO.NoInvites"));

View File

@ -11,6 +11,7 @@ import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users;
//TODO: Make this work from console.
@ -36,11 +37,9 @@ public class InviteCommand implements CommandExecutor {
switch (args.length) {
case 1:
Player player = (Player) sender;
PlayerProfile PP = Users.getProfile(player);
PlayerProfile playerProfile = Users.getProfile(player);
Party partyInstance = Party.getInstance();
if (!PP.inParty()) {
if (!playerProfile.inParty()) {
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return true;
}
@ -48,13 +47,12 @@ public class InviteCommand implements CommandExecutor {
Player target = plugin.getServer().getPlayer(args[0]);
if (target != null) {
if (partyInstance.canInvite(player, PP)) {
PlayerProfile PPt = Users.getProfile(target);
PPt.modifyInvite(PP.getParty());
if (PartyManager.getInstance().canInvite(player, playerProfile)) {
Party party = playerProfile.getParty();
Users.getProfile(target).setInvite(party);
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.0", new Object[] { PPt.getInvite(), player.getName() }));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.0", new Object[] {party.getName(), player.getName()}));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.1"));
return true;
}

View File

@ -12,6 +12,7 @@ import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.chat.McMMOPartyChatEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users;
public class PCommand implements CommandExecutor {
@ -57,9 +58,9 @@ public class PCommand implements CommandExecutor {
default:
if (sender instanceof Player) {
Player player = (Player) sender;
PP = Users.getProfile(player);
Party party = Users.getProfile(player).getParty();
if (!PP.inParty()) {
if (party == null) {
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return true;
}
@ -70,7 +71,7 @@ public class PCommand implements CommandExecutor {
message = message + " " + args [i];
}
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(player.getName(), PP.getParty(), message);
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(player.getName(), party.getName(), message);
plugin.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) {
@ -80,10 +81,10 @@ public class PCommand implements CommandExecutor {
message = chatEvent.getMessage();
String prefix = ChatColor.GREEN + "(" + ChatColor.WHITE + player.getName() + ChatColor.GREEN + ") ";
plugin.getLogger().info("[P](" + PP.getParty() + ")" + "<" + player.getName() + "> " + message);
plugin.getLogger().info("[P](" + party.getName() + ")" + "<" + player.getName() + "> " + message);
for (Player p : Party.getInstance().getOnlineMembers(PP.getParty())) {
p.sendMessage(prefix + message);
for (Player member : party.getOnlineMembers()) {
member.sendMessage(prefix + message);
}
}
else {
@ -92,7 +93,7 @@ public class PCommand implements CommandExecutor {
return true;
}
if (!Party.getInstance().isParty(args[0])) {
if (!PartyManager.getInstance().isParty(args[0])) {
sender.sendMessage(LocaleLoader.getString("Party.InvalidName"));
return true;
}
@ -115,8 +116,8 @@ public class PCommand implements CommandExecutor {
plugin.getLogger().info("[P](" + args[0] + ")" + "<*Console*> " + message);
for (Player player : Party.getInstance().getOnlineMembers(args[0])) {
player.sendMessage(prefix + message);
for (Player member : PartyManager.getInstance().getOnlineMembers(args[0])) {
member.sendMessage(prefix + message);
}
}

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.commands.party;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -13,6 +14,7 @@ import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users;
public class PartyCommand implements CommandExecutor {
@ -34,39 +36,31 @@ public class PartyCommand implements CommandExecutor {
Player player = (Player) sender;
String playerName = player.getName();
PlayerProfile PP = Users.getProfile(player);
PlayerProfile playerProfile = Users.getProfile(player);
Party partyInstance = Party.getInstance();
boolean inParty = PP.inParty();
String partyName = PP.getParty();
boolean isLeader = partyInstance.isPartyLeader(playerName, partyName);
if (PP.inParty() && (!partyInstance.isParty(PP.getParty()) || !partyInstance.isInParty(player, PP))) {
partyInstance.addToParty(player, PP, PP.getParty(), false, null);
}
PartyManager partyManagerInstance = PartyManager.getInstance();
Party party = playerProfile.getParty();
switch (args.length) {
case 0:
if (!inParty) {
if (party == null) {
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
player.sendMessage(LocaleLoader.getString("Party.Help.2"));
}
else {
String tempList = "";
String tempList = ChatColor.GOLD + party.getLeader() + " ";
for (Player p : partyInstance.getAllMembers(player)) {
if (p.equals(partyInstance.getPartyLeader(partyName))) {
tempList += ChatColor.GOLD;
for (String otherPlayerName : party.getMembers()) {
if (plugin.getServer().getPlayer(otherPlayerName) == null) {
tempList += ChatColor.GRAY + otherPlayerName + " ";
}
else if (!party.getLeader().equals(otherPlayerName)){
tempList += ChatColor.WHITE + otherPlayerName + " ";
}
else {
tempList += ChatColor.WHITE;
}
tempList += p.getName() + " ";
}
player.sendMessage(LocaleLoader.getString("Commands.Party.InParty", new Object[] { partyName }));
player.sendMessage(LocaleLoader.getString("Commands.Party.InParty", new Object[] {party.getName()}));
player.sendMessage(LocaleLoader.getString("Commands.Party.Members", new Object[] {tempList}));
}
@ -74,15 +68,15 @@ public class PartyCommand implements CommandExecutor {
case 1:
if (args[0].equalsIgnoreCase("q")) {
if (inParty) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, partyName, null, EventReason.LEFT_PARTY);
if (party != null) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), null, EventReason.LEFT_PARTY);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
partyInstance.removeFromParty(player, PP);
partyManagerInstance.removeFromParty(player, playerProfile);
player.sendMessage(LocaleLoader.getString("Commands.Party.Leave"));
}
else {
@ -98,13 +92,13 @@ public class PartyCommand implements CommandExecutor {
player.sendMessage(LocaleLoader.getString("Party.Help.7"));
}
else if (args[0].equalsIgnoreCase("lock")) {
if (inParty) {
if (isLeader) {
if (partyInstance.isPartyLocked(partyName)) {
if (party != null) {
if (party.getLeader().equals(playerName)) {
if (party.isLocked()) {
player.sendMessage(LocaleLoader.getString("Party.IsLocked"));
}
else {
partyInstance.lockParty(partyName);
party.setLocked(true);
player.sendMessage(LocaleLoader.getString("Party.Locked"));
}
}
@ -117,13 +111,13 @@ public class PartyCommand implements CommandExecutor {
}
}
else if (args[0].equalsIgnoreCase("unlock")) {
if (inParty) {
if (isLeader) {
if (!partyInstance.isPartyLocked(partyName)) {
if (party != null) {
if (party.getLeader().equals(playerName)) {
if (!party.isLocked()) {
player.sendMessage(LocaleLoader.getString("Party.IsntLocked"));
}
else {
partyInstance.unlockParty(partyName);
party.setLocked(false);
player.sendMessage(LocaleLoader.getString("Party.Unlocked"));
}
}
@ -136,15 +130,15 @@ public class PartyCommand implements CommandExecutor {
}
}
else {
if (inParty) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, partyName, args[0], EventReason.CHANGED_PARTIES);
if (party != null) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), args[0], EventReason.CHANGED_PARTIES);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
partyInstance.removeFromParty(player, PP);
partyManagerInstance.removeFromParty(player, playerProfile);
}
else {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, args[0], EventReason.JOINED_PARTY);
@ -155,20 +149,17 @@ public class PartyCommand implements CommandExecutor {
}
}
partyInstance.addToParty(player, PP, args[0], false, null);
partyManagerInstance.addToParty(player, playerProfile, args[0], null);
}
return true;
case 2:
if (PP.inParty()) {
if (playerProfile.inParty()) {
if (args[0].equalsIgnoreCase("password")) {
if (isLeader) {
if (!partyInstance.isPartyLocked(partyName)) {
partyInstance.lockParty(partyName);
}
partyInstance.setPartyPassword(partyName, args[1]);
if (party.getLeader().equals(playerName)) {
party.setLocked(true);
party.setPassword(args[1]);
player.sendMessage(LocaleLoader.getString("Party.PasswordSet", new Object[] {args[1]}));
}
else {
@ -176,7 +167,8 @@ public class PartyCommand implements CommandExecutor {
}
}
else if (args[0].equalsIgnoreCase("kick")) {
if (isLeader) {
if (party.getLeader().equals(playerName)) {
//TODO allow to kick offline players
Player target = plugin.getServer().getPlayer(args[1]);
if (target == null) {
@ -184,15 +176,16 @@ public class PartyCommand implements CommandExecutor {
return true;
}
PlayerProfile PPt = Users.getProfile(target);
PlayerProfile otherPlayerProfile = Users.getProfile(target);
String targetName = target.getName();
if (!partyInstance.inSameParty(player, target)) {
if (!partyManagerInstance.inSameParty(player, target)) {
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] {targetName}));
return true;
}
else {
String partyName = party.getName();
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, partyName, null, EventReason.KICKED_FROM_PARTY);
plugin.getServer().getPluginManager().callEvent(event);
@ -200,7 +193,7 @@ public class PartyCommand implements CommandExecutor {
return true;
}
partyInstance.removeFromParty(target, PPt);
partyManagerInstance.removeFromParty(target, otherPlayerProfile);
target.sendMessage(LocaleLoader.getString("Commands.Party.Kick", new Object[] {partyName}));
}
}
@ -209,8 +202,9 @@ public class PartyCommand implements CommandExecutor {
}
}
else if (args[0].equalsIgnoreCase("owner")) {
if (isLeader) {
Player target = plugin.getServer().getPlayer(args[1]);
if (party.getLeader().equals(playerName)) {
//TODO allow to set the ownership to offline players
OfflinePlayer target = plugin.getServer().getOfflinePlayer(args[1]);
if (target == null) {
player.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
@ -219,13 +213,13 @@ public class PartyCommand implements CommandExecutor {
String targetName = target.getName();
if (!partyInstance.inSameParty(player, target)) {
if (!partyManagerInstance.inSameParty(player, target)) {
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] {targetName}));
return true;
}
else {
partyInstance.setPartyLeader(partyName, targetName);
partyManagerInstance.setPartyLeader(party.getName(), targetName);
}
}
else {
@ -233,15 +227,15 @@ public class PartyCommand implements CommandExecutor {
}
}
else {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, partyName, args[0], EventReason.CHANGED_PARTIES);
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), args[0], EventReason.CHANGED_PARTIES);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
partyInstance.removeFromParty(player, PP);
partyInstance.addToParty(player, PP, args[0], false, args[1]);
partyManagerInstance.removeFromParty(player, playerProfile);
partyManagerInstance.addToParty(player, playerProfile, args[0], args[1]);
}
}
else {
@ -252,7 +246,7 @@ public class PartyCommand implements CommandExecutor {
return true;
}
partyInstance.addToParty(player, PP, args[0], false, args[1]);
partyManagerInstance.addToParty(player, playerProfile, args[0], args[1]);
}
return true;

View File

@ -12,7 +12,7 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users;
public class PtpCommand implements CommandExecutor {
@ -39,11 +39,6 @@ public class PtpCommand implements CommandExecutor {
Player player = (Player) sender;
PlayerProfile PP = Users.getProfile(player);
if (!Party.getInstance().isInParty(player, PP)) {
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return true;
}
if (PP.getRecentlyHurt() + (Config.getInstance().getPTPCommandCooldown() * 1000) > System.currentTimeMillis()) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Hurt", new Object[] { Config.getInstance().getPTPCommandCooldown() }));
return true;
@ -66,8 +61,8 @@ public class PtpCommand implements CommandExecutor {
return true;
}
if (Party.getInstance().inSameParty(player, target)) {
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, PP.getParty());
if (PartyManager.getInstance().inSameParty(player, target)) {
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, PP.getParty().getName());
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {

View File

@ -17,6 +17,7 @@ import com.gmail.nossr50.config.SpoutConfig;
import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModChecks;
import com.gmail.nossr50.util.Users;
@ -30,8 +31,8 @@ public class PlayerProfile {
private SkillType skillLock;
/* Party Stuff */
private String party;
private String invite;
private Party party;
private Party invite;
/* Toggles */
private boolean loaded = false;
@ -109,7 +110,7 @@ public class PlayerProfile {
int id = 0;
id = mcMMO.database.getInt("SELECT id FROM "+Config.getInstance().getMySQLTablePrefix()+"users WHERE user = '" + playerName + "'");
this.userid = id;
userid = id;
if (id > 0) {
HashMap<Integer, ArrayList<String>> huds = mcMMO.database.read("SELECT hudtype FROM "+Config.getInstance().getMySQLTablePrefix()+"huds WHERE user_id = " + id);
@ -132,7 +133,7 @@ public class PlayerProfile {
}
HashMap<Integer, ArrayList<String>> users = mcMMO.database.read("SELECT lastlogin, party FROM "+Config.getInstance().getMySQLTablePrefix()+"users WHERE id = " + id);
//lastlogin = Integer.parseInt(users.get(1).get(0));
party = users.get(1).get(1);
party = PartyManager.getInstance().getParty(users.get(1).get(1));
HashMap<Integer, ArrayList<String>> cooldowns = mcMMO.database.read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM "+Config.getInstance().getMySQLTablePrefix()+"cooldowns WHERE user_id = " + id);
/*
* I'm still learning MySQL, this is a fix for adding a new table
@ -216,7 +217,7 @@ public class PlayerProfile {
skills.put(SkillType.MINING, Integer.valueOf(character[1]));
//Party
if(character.length > 3)
party = character[3];
party = PartyManager.getInstance().getParty(character[3]);
//Mining XP
if(character.length > 4 && Misc.isInt(character[4]))
skillsXp.put(SkillType.MINING, Integer.valueOf(character[4]));
@ -306,9 +307,16 @@ public class PlayerProfile {
// if we are using mysql save to database
if (Config.getInstance().getUseMySQL()) {
mcMMO.database.write("UPDATE "+Config.getInstance().getMySQLTablePrefix()+"huds SET hudtype = '"+hud.toString()+"' WHERE user_id = "+this.userid);
mcMMO.database.write("UPDATE "+Config.getInstance().getMySQLTablePrefix()+"users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + this.userid);
mcMMO.database.write("UPDATE "+Config.getInstance().getMySQLTablePrefix()+"users SET party = '"+this.party+"' WHERE id = " +this.userid);
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "huds SET hudtype = '" + hud.toString() + "' WHERE user_id = " + userid);
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + userid);
String partyName = "";
if (party != null) {
partyName = party.getName();
}
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "users SET party = '" + partyName + "' WHERE id = " + userid);
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "cooldowns SET "
+ " mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER)
+ ", woodcutting = " + skillsDATS.get(AbilityType.TREE_FELLER)
@ -318,7 +326,7 @@ public class PlayerProfile {
+ ", swords = " + skillsDATS.get(AbilityType.SERRATED_STRIKES)
+ ", axes = " + skillsDATS.get(AbilityType.SKULL_SPLIITER)
+ ", blast_mining = " + skillsDATS.get(AbilityType.BLAST_MINING)
+" WHERE user_id = "+this.userid);
+ " WHERE user_id = " + userid);
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "skills SET "
+ " taming = " + skills.get(SkillType.TAMING)
+ ", mining = " + skills.get(SkillType.MINING)
@ -332,7 +340,7 @@ public class PlayerProfile {
+ ", axes = " + skills.get(SkillType.AXES)
+ ", acrobatics = " + skills.get(SkillType.ACROBATICS)
+ ", fishing = " + skills.get(SkillType.FISHING)
+" WHERE user_id = "+this.userid);
+ " WHERE user_id = " + userid);
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "experience SET "
+ " taming = " + skillsXp.get(SkillType.TAMING)
+ ", mining = " + skillsXp.get(SkillType.MINING)
@ -346,7 +354,7 @@ public class PlayerProfile {
+ ", axes = " + skillsXp.get(SkillType.AXES)
+ ", acrobatics = " + skillsXp.get(SkillType.ACROBATICS)
+ ", fishing = " + skillsXp.get(SkillType.FISHING)
+" WHERE user_id = "+this.userid);
+ " WHERE user_id = " + userid);
}
else {
// otherwise save to flatfile
@ -369,7 +377,14 @@ public class PlayerProfile {
writer.append(playerName + ":");
writer.append(skills.get(SkillType.MINING) + ":");
writer.append("" + ":");
writer.append(party+":");
String partyName = "";
if (party != null) {
partyName = party.getName();
}
writer.append(partyName + ":");
writer.append(skillsXp.get(SkillType.MINING) + ":");
writer.append(skills.get(SkillType.WOODCUTTING) + ":");
writer.append(skillsXp.get(SkillType.WOODCUTTING) + ":");
@ -435,7 +450,7 @@ public class PlayerProfile {
}
//Misc stuff
party = "";
party = null;
save();
}
@ -451,7 +466,14 @@ public class PlayerProfile {
out.append(playerName + ":");
out.append(0 + ":"); //mining
out.append("" + ":");
out.append(party+":");
String partyName = "";
if (party != null) {
partyName = party.getName();
}
out.append(partyName + ":");
out.append(0 + ":"); //XP
out.append(0 + ":"); //woodcutting
out.append(0 + ":"); //woodCuttingXP
@ -1165,8 +1187,8 @@ public class PlayerProfile {
private double partyModifier(SkillType skillType) {
double bonusModifier = 0.0;
for (Player member : Party.getInstance().getOnlineMembers(player)) {
if (!member.equals(player) && Party.getInstance().isPartyLeader(member.getName(), getParty())) {
for (Player member : party.getOnlineMembers()) {
if (party.getLeader().equals(member.getName())) {
if (Misc.isNear(player.getLocation(), member.getLocation(), 25.0)) {
PlayerProfile PartyLeader = Users.getProfile(member);
int leaderSkill = PartyLeader.getSkillLevel(skillType);
@ -1187,21 +1209,16 @@ public class PlayerProfile {
* Party Stuff
*/
public void acceptInvite() {
party = invite;
invite = "";
public void setInvite(Party invite) {
this.invite = invite;
}
public void modifyInvite(String invitename) {
invite = invitename;
}
public String getInvite() {
public Party getInvite() {
return invite;
}
public boolean hasPartyInvite() {
if (invite != null && !invite.equals("") && !invite.equals("null")) {
if (invite != null) {
return true;
}
else {
@ -1209,24 +1226,28 @@ public class PlayerProfile {
}
}
public void setParty(String newParty) {
party = newParty;
public void setParty(Party party) {
this.party = party;
}
public String getParty() {
public Party getParty() {
return party;
}
public boolean inParty() {
if (party != null) {
return true;
}
else {
return false;
}
}
public void removeParty() {
party = null;
}
public boolean inParty() {
if (party != null && !party.equals("") && !party.equals("null")) {
return true;
}
else {
return false;
}
public void removeInvite() {
invite = null;
}
}

View File

@ -30,7 +30,7 @@ import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.skills.combat.Archery;
import com.gmail.nossr50.skills.combat.Taming;
@ -81,7 +81,7 @@ public class EntityListener implements Listener {
Entity defender = event.getEntity();
if (attacker instanceof Player && defender instanceof Player) {
if (Party.getInstance().inSameParty((Player)defender, (Player)attacker)) {
if (PartyManager.getInstance().inSameParty((Player) defender, (Player) attacker)) {
event.setCancelled(true);
return;
}

View File

@ -318,39 +318,44 @@ public class PlayerListener implements Listener {
PlayerProfile PP = Users.getProfile(player);
if (PP.getPartyChatMode()) {
if (!PP.inParty()) {
Party party = PP.getParty();
if (party == null) {
player.sendMessage("You're not in a party, type /p to leave party chat mode."); //TODO: Use mcLocale
return;
}
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(player.getName(), PP.getParty(), event.getMessage());
String partyName = party.getName();
String playerName = player.getName();
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(playerName, partyName, event.getMessage());
plugin.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) {
return;
}
String prefix = ChatColor.GREEN + "(" + ChatColor.WHITE + player.getName() + ChatColor.GREEN + ") ";
String prefix = ChatColor.GREEN + "(" + ChatColor.WHITE + playerName + ChatColor.GREEN + ") ";
plugin.getLogger().info("[P](" + PP.getParty() + ")" + "<" + player.getName() + "> " + chatEvent.getMessage());
plugin.getLogger().info("[P](" + partyName + ")" + "<" + playerName + "> " + chatEvent.getMessage());
for (Player p : Party.getInstance().getOnlineMembers(PP.getParty())) {
p.sendMessage(prefix + chatEvent.getMessage());
for (Player member : party.getOnlineMembers()) {
member.sendMessage(prefix + chatEvent.getMessage());
}
event.setCancelled(true);
}
else if (PP.getAdminChatMode()) {
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(player.getName(), event.getMessage());
String playerName = player.getName();
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(playerName, event.getMessage());
plugin.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) {
return;
}
String prefix = ChatColor.AQUA + "{" + ChatColor.WHITE + player.getName() + ChatColor.AQUA + "} ";
String prefix = ChatColor.AQUA + "{" + ChatColor.WHITE + playerName + ChatColor.AQUA + "} ";
plugin.getLogger().info("[A]<" + player.getName() + "> " + chatEvent.getMessage());
plugin.getLogger().info("[A]<" + playerName + "> " + chatEvent.getMessage());
for (Player p : plugin.getServer().getOnlinePlayers()) {
if (Permissions.getInstance().adminChat(player) || player.isOp()) {

View File

@ -63,6 +63,7 @@ import com.gmail.nossr50.listeners.HardcoreListener;
import com.gmail.nossr50.listeners.PlayerListener;
import com.gmail.nossr50.listeners.WorldListener;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.runnables.SaveTimer;
import com.gmail.nossr50.runnables.SkillMonitor;
@ -270,6 +271,8 @@ public class mcMMO extends JavaPlugin {
playerProfile.save();
}
PartyManager.getInstance().saveParties();
getServer().getScheduler().cancelTasks(this); //This removes our tasks
//Save our metadata

View File

@ -1,649 +1,65 @@
package com.gmail.nossr50.party;
import java.io.BufferedReader;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Users;
public class Party {
public static String pluginPath;
public static String partyPlayersFile;
public static String partyLocksFile;
public static String partyPasswordsFile;
private List<String> members = new ArrayList<String>();
private String leader;
private String name;
private String password;
private boolean locked;
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;
private Party() {
plugin = mcMMO.p;
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();
loadParties();
public List<String> getMembers() {
return members;
}
public static Party getInstance() {
if (instance == null) {
instance = new Party();
}
return instance;
}
public List<Player> getOnlineMembers() {
Player[] onlinePlayers = mcMMO.p.getServer().getOnlinePlayers();
List<Player> onlineMembers = new ArrayList<Player>();
/**
* 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){
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;
for (Player onlinePlayer : onlinePlayers) {
if (members.contains(onlinePlayer.getName())) {
onlineMembers.add(onlinePlayer);
}
}
/**
* 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) {
if (player != null) {
return getAllMembers(player).size();
}
else {
return 0;
}
}
private void informPartyMembers(Player player) {
String playerName = player.getName();
if (player != null) {
for (Player p : getOnlineMembers(player)) {
if (p.getName() != playerName) {
p.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", new Object[] {playerName}));
}
}
}
}
/**
* 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>();
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>();
for (Player p : plugin.getServer().getOnlinePlayers()) {
PlayerProfile PP = Users.getProfile(p);
if (PP.inParty()) {
if (PP.getParty().equalsIgnoreCase(partyName)) {
players.add(p);
}
}
}
return players;
}
/**
* 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> getAllMembers(Player player) {
ArrayList<Player> players = new ArrayList<Player>();
if (player != null) {
for (PlayerProfile playerProfile : Users.getProfiles()) {
Player otherPlayer = playerProfile.getPlayer();
if (otherPlayer != null && inSameParty(otherPlayer, player)) {
players.add(otherPlayer);
}
}
}
return players;
}
/**
* Get a list of all current party names.
*
* @return the list of parties.
*/
public ArrayList<String> getParties() {
String location = mcMMO.usersFile;
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) {
plugin.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
}
return parties;
}
/**
* 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);
if (newOwner != null) {
for (Player p : getOnlineMembers(newOwner)) {
if (p.getName() != newOwnerName) {
p.sendMessage(newOwnerName + " is the new party owner."); //TODO: Needs more locale
}
}
}
}
/**
* Notify party members when the a party member quits.
*
* @param player The player that quit
*/
private void informPartyMembersQuit(Player player) {
String playerName = player.getName();
if (player != null) {
for (Player p : getOnlineMembers(player)) {
if (p.getName() != playerName) {
p.sendMessage(LocaleLoader.getString("Party.InformedOnQuit", new Object[] {playerName}));
}
}
}
}
/**
* 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);
}
/**
* 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) {
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", new Object[]{ newParty }));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.Invite.Accepted", 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);
}
/**
* Lock a party.
*
* @param partyName The party to lock
*/
public void lockParty(String partyName) {
partyLocks.put(partyName, true);
savePartyFile(partyLocksFile, partyLocks);
}
/**
* Unlock a party.
*
* @param partyName The party to unlock
*/
public void unlockParty(String partyName) {
partyLocks.put(partyName, false);
savePartyFile(partyLocksFile, partyLocks);
}
/**
* Delete a party.
*
* @param partyName The party to delete
*/
private void deleteParty(String 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("\"\"")) { //What's with that password string?
password = null;
}
partyPasswords.put(partyName, password);
savePartyFile(partyPasswordsFile, partyPasswords);
}
/**
* 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 onlineMembers;
}
public String getLeader() {
return leader;
}
/**
* 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) {
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;
public String getName() {
return name;
}
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);
}
}
public String getPassword() {
return password;
}
/**
* Get the password of a party.
*
* @param partyName The party name
* @return The password of this party
*/
public String getPartyPassword(String partyName) {
return partyPasswords.get(partyName);
public boolean isLocked() {
return locked;
}
/**
* 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) {
String party = PP.getParty();
if (isPartyLocked(party) && !isPartyLeader(player.getName(), party)) {
return false;
}
else {
return true;
}
public void setName(String name) {
this.name = name;
}
/**
* 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);
public void setLeader(String leader) {
this.leader = leader;
}
/**
* 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();
public void setPassword(String password) {
this.password = password;
}
/**
* 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) {
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) {
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) {
Map<String, Boolean> party = partyPlayers.get(PP.getParty());
if (party != null && party.containsKey(player.getName())) {
return true;
}
else {
return false;
}
}
/**
* Load all party related files.
*/
@SuppressWarnings("unchecked")
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) {
plugin.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));
partyLocks = (HashMap<String, Boolean>) obj.readObject();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (EOFException e) {
plugin.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) {
plugin.getLogger().info("partyPasswordsFile empty.");
}
catch (IOException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
/**
* Save all party-related files.
*/
private void saveParties() {
savePartyFile(partyPlayersFile, partyPlayers);
savePartyFile(partyLocksFile, partyLocks);
savePartyFile(partyPasswordsFile, partyPasswords);
}
/**
* 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();
}
public void setLocked(boolean locked) {
this.locked = locked;
}
}

View File

@ -0,0 +1,447 @@
package com.gmail.nossr50.party;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Users;
public class PartyManager {
private static String partiesFilePath;
private static List<Party> parties = new ArrayList<Party>();
private static mcMMO plugin;
private static PartyManager instance;
private PartyManager() {
plugin = mcMMO.p;
partiesFilePath = plugin.getDataFolder().getPath() + File.separator + "FlatFileStuff" + File.separator + "parties.yml";
loadParties();
}
public static PartyManager getInstance() {
if (instance == null) {
instance = new PartyManager();
}
return instance;
}
/**
* Check if two players are in the same party.
*
* @param firstPlayer The first player
* @param secondPlayer The second player
* @return true if they are in the same party, false otherwise
*/
public boolean inSameParty(Player firstPlayer, Player secondPlayer) {
Party firstParty = Users.getProfile(firstPlayer).getParty();
Party secondParty = Users.getProfile(secondPlayer).getParty();
if (firstParty == null || secondParty == null || firstParty != secondParty) {
return false;
}
return true;
}
/**
* Check if two players are in the same party.
*
* @param firstPlayer The first player
* @param secondPlayer The second player
* @return true if they are in the same party, false otherwise
*/
public boolean inSameParty(OfflinePlayer firstPlayer, OfflinePlayer secondPlayer) {
PlayerProfile firstProfile = Users.getProfile(firstPlayer);
PlayerProfile secondProfile = Users.getProfile(secondPlayer);
if (firstProfile == null || secondProfile == null) {
return false;
}
Party firstParty = firstProfile.getParty();
Party secondParty = secondProfile.getParty();
if (firstParty == null || secondParty == null || firstParty != secondParty) {
return false;
}
return true;
}
/**
* Notify party members when a player joins
*
* @param player The player that joins
* @param party The concerned party
*/
private void informPartyMembersJoin(Player player, Party party) {
for (Player member : party.getOnlineMembers()) {
if (member != player) {
member.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", new Object[] {player.getName()}));
}
}
}
/**
* Notify party members when a party member quits.
*
* @param player The player that quits
* @param party The concerned party
*/
private void informPartyMembersQuit(Player player, Party party) {
for (Player member : party.getOnlineMembers()) {
if (member != player) {
member.sendMessage(LocaleLoader.getString("Party.InformedOnQuit", new Object[] {player.getName()}));
}
}
}
/**
* 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 List<String> getAllMembers(Player player) {
Party party = Users.getProfile(player).getParty();
if (party == null) {
return Collections.emptyList();
}
return party.getMembers();
}
/**
* Get a list of all online players in this party.
*
* @param partyName The party to check
* @return all online players in this party
*/
public List<Player> getOnlineMembers(String partyName) {
Party party = getParty(partyName);
if (party == null) {
return null;
}
return party.getOnlineMembers();
}
/**
* Get a list of all online players in this party.
*
* @param player The player to check
* @return all online players in this party
*/
public List<Player> getOnlineMembers(Player player) {
return getOnlineMembers(player.getName());
}
/**
* Retrieve a party by its name
*
* @param partyName The party name
* @return the existing party, null otherwise
*/
public Party getParty(String partyName) {
for (Party party : parties) {
if (party.getName().equals(partyName)) {
return party;
}
}
return null;
}
/**
* Get a list of all current party names.
*
* @return the list of parties.
*/
public List<String> getParties() {
String location = mcMMO.usersFile;
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) {
plugin.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
}
return parties;
}
/**
* Remove a player from a party.
*
* @param player The player to remove
* @param playerProfile The profile of the player to remove
*/
public void removeFromParty(Player player, PlayerProfile playerProfile) {
String playerName = player.getName();
Party party = playerProfile.getParty();
List<String> members = party.getMembers();
if (members.contains(playerName)) {
members.remove(playerName);
if (members.isEmpty()) {
parties.remove(party);
}
else {
if (party.getLeader().equals(playerName) && party.isLocked()) {
party.setLocked(false);
}
informPartyMembersQuit(player, party);
}
}
playerProfile.removeParty();
}
/**
* Add a player to a party.
*
* @param player The player to add to the party
* @param playerProfile The profile of the player to add to the party
* @param partyName The party to add the player to
* @param password the password for this party, null if there was no password
*/
public void addToParty(Player player, PlayerProfile playerProfile, String partyName, String password) {
//Fix for FFS
partyName = partyName.replace(":", ".");
Party party = getParty(partyName);
String playerName = player.getName();
if (party == null) {
party = new Party();
party.setName(partyName);
party.setLeader(playerName);
if (password != null) {
party.setPassword(password);
party.setLocked(true);
}
parties.add(party);
}
else {
//Don't care about passwords if it isn't locked
if (party.isLocked()) {
String partyPassword = party.getPassword();
if (partyPassword != null) {
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(partyPassword)) {
player.sendMessage("Party password incorrect."); //TODO: Needs more locale.
return;
}
}
else {
player.sendMessage("Party is locked."); //TODO: Needs more locale.
return;
}
}
}
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", new Object[]{partyName}));
informPartyMembersJoin(player, party);
playerProfile.setParty(party);
party.getMembers().add(player.getName());
}
/**
* Accept a party invitation
*
* @param player The player to add to the party
* @param playerProfile The profile of the player
* @param party The party
*/
public void addToInvitedParty(Player player, PlayerProfile playerProfile, Party party) {
if (!parties.contains(party)) {
parties.add(party);
}
player.sendMessage(LocaleLoader.getString("Commands.Invite.Accepted", new Object[]{party.getName()}));
informPartyMembersJoin(player, party);
playerProfile.removeInvite();
playerProfile.setParty(party);
party.getMembers().add(player.getName());
}
/**
* Get the leader of a party.
*
* @param partyName The party name
* @return the leader of the party
*/
public String getPartyLeader(String partyName) {
Party party = getParty(partyName);
if (party == null) {
return null;
}
return party.getLeader();
}
/**
* 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) {
Party party = getParty(partyName);
if (party == null) {
return;
}
String leaderName = party.getLeader();
for (Player member : party.getOnlineMembers()) {
if (member.getName().equals(playerName)) {
member.sendMessage("You are now the party owner."); //TODO: Needs more locale.
}
else if (member.equals(leaderName)) {
member.sendMessage("You are no longer party owner."); //TODO: Needs more locale.
}
else {
member.sendMessage(playerName + " is the new party owner."); //TODO: Needs more Locale.
}
}
party.setLeader(playerName);
}
/**
* Check if a player can invite others to their party.
*
* @param player The player to check
* @param playerProfile The profile of the given player
* @return true if the player can invite, false otherwise
*/
public boolean canInvite(Player player, PlayerProfile playerProfile) {
Party party = playerProfile.getParty();
if (party == null || (party.isLocked() && !party.getLeader().equals(player.getName()))) {
return false;
}
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) {
for (Party party : parties) {
if (party.getName().equals(partyName)) {
return true;
}
}
return false;
}
/**
* Load all party related files.
*/
private void loadParties() {
File file = new File(partiesFilePath);
if (!file.exists()) {
return;
}
YamlConfiguration partiesFile = new YamlConfiguration();
try {
partiesFile.load(file);
} catch (Exception e) {
e.printStackTrace();
}
for (String partyName : partiesFile.getConfigurationSection("").getKeys(false)) {
Party party = new Party();
party.setName(partyName);
party.setLeader(partiesFile.getString(partyName + ".Leader"));
party.setPassword(partiesFile.getString(partyName + ".Password"));
party.setLocked(partiesFile.getBoolean(partyName + ".Locked"));
party.getMembers().addAll(partiesFile.getStringList(partyName + ".Members"));
parties.add(party);
}
}
/**
* Save all party-related files.
*
* @throws Exception
*/
public void saveParties() {
File file = new File(partiesFilePath);
if (file.exists()) {
file.delete();
}
YamlConfiguration partiesFile = new YamlConfiguration();
for (Party party : parties) {
String partyName = party.getName();
partiesFile.set(partyName + ".Leader", party.getLeader());
partiesFile.set(partyName + ".Password", party.getPassword());
partiesFile.set(partyName + ".Locked", party.isLocked());
partiesFile.set(partyName + ".Members", party.getMembers());
try {
partiesFile.save(new File(partiesFilePath));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.runnables;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.PartyManager;
public class SaveTimer implements Runnable {
private final mcMMO plugin;
@ -20,5 +21,7 @@ public class SaveTimer implements Runnable {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new ProfileSaveTask(player), count);
count++;
}
PartyManager.getInstance().saveParties();
}
}

View File

@ -14,7 +14,7 @@ import org.bukkit.inventory.PlayerInventory;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
@ -60,7 +60,7 @@ public class Axes {
if (tamer instanceof Player) {
Player owner = (Player) tamer;
if (owner == attacker || Party.getInstance().inSameParty(attacker, owner)) {
if (owner == attacker || PartyManager.getInstance().inSameParty(attacker, owner)) {
return;
}
}

View File

@ -11,7 +11,7 @@ import org.bukkit.entity.Tameable;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.util.Combat;
import com.gmail.nossr50.util.ItemChecks;
@ -39,7 +39,7 @@ public class Swords {
if (tamer instanceof Player) {
Player owner = (Player) tamer;
if (owner == attacker || Party.getInstance().inSameParty(attacker, owner)) {
if (owner == attacker || PartyManager.getInstance().inSameParty(attacker, owner)) {
return;
}
}

View File

@ -9,7 +9,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Skills;
@ -96,7 +96,7 @@ public class Acrobatics {
if (event.getDamager() instanceof Player) {
Player attacker = (Player) event.getDamager();
if (Party.getInstance().inSameParty(defender, attacker)) {
if (PartyManager.getInstance().inSameParty(defender, attacker)) {
return;
}
}

View File

@ -26,7 +26,7 @@ import com.gmail.nossr50.datatypes.ToolType;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.runnables.GainXp;
import com.gmail.nossr50.skills.combat.Archery;
@ -396,7 +396,7 @@ public class Combat {
continue;
}
if (Party.getInstance().inSameParty(attacker, defender)) {
if (PartyManager.getInstance().inSameParty(attacker, defender)) {
continue;
}
@ -410,7 +410,7 @@ public class Combat {
AnimalTamer tamer = ((Tameable) entity).getOwner();
if (tamer instanceof Player) {
if (tamer.equals(attacker) || Party.getInstance().inSameParty(attacker, (Player) tamer)) {
if (tamer.equals(attacker) || PartyManager.getInstance().inSameParty(attacker, (Player) tamer)) {
continue;
}
}