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 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 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 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 /mcremove being applied only after a reload
= Fixed Archery PVE disablement not working properly = Fixed Archery PVE disablement not working properly
= Fixed possible NPE when a projectile is shot by a dispenser or doesn't have any shooter = 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 = Fixed bug with repairing items that use metadata
! API methods can now only be used in a static way ! API methods can now only be used in a static way
! Changed Spout settings to be in their own config file (spout.yml) ! 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 Version 1.3.08
+ Added more notifications about Vampirism and Hardcore mode on player death + 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()) { for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
if (Users.getProfile(player).inParty()) { 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()); player.sendMessage(pPrefix + chatEvent.getMessage());
} }
} }

View File

@ -1,10 +1,10 @@
package com.gmail.nossr50.api; package com.gmail.nossr50.api;
import java.util.ArrayList; import java.util.List;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public final class PartyAPI { public final class PartyAPI {
@ -20,7 +20,7 @@ public final class PartyAPI {
* @return the name of the player's party * @return the name of the player's party
*/ */
public static String getPartyName(Player player) { 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 * @return true if the two players are in the same party, false otherwise
*/ */
public static boolean inSameParty(Player playera, Player playerb) { 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. * @return the list of parties.
*/ */
public static ArrayList<String> getParties() { public static List<String> getParties() {
return Party.getInstance().getParties(); return PartyManager.getInstance().getParties();
} }
/** /**
@ -68,7 +68,7 @@ public final class PartyAPI {
* @param partyName The party to add the player to * @param partyName The party to add the player to
*/ */
public static void addToParty(Player player, String partyName) { 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 * @param player The player to remove
*/ */
public static void removeFromParty(Player player) { 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 * @param partyName The party name
* @return the leader of the party * @return the leader of the party
*/ */
public static Player getPartyLeader(String partyName) { public static String getPartyLeader(String partyName) {
return Party.getInstance().getPartyLeader(partyName); return PartyManager.getInstance().getPartyLeader(partyName);
} }
/** /**
@ -103,7 +103,7 @@ public final class PartyAPI {
* @param player The player to set as leader * @param player The player to set as leader
*/ */
public static void setPartyLeader(String partyName, String player) { 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 * @param player The player to check
* @return all the players in the player's party * @return all the players in the player's party
*/ */
public static ArrayList<Player> getAllMembers(Player player) { public static List<String> getAllMembers(Player player) {
return Party.getInstance().getAllMembers(player); return PartyManager.getInstance().getAllMembers(player);
} }
/** /**
@ -126,8 +126,8 @@ public final class PartyAPI {
* @param partyName The party to check * @param partyName The party to check
* @return all online players in this party * @return all online players in this party
*/ */
public static ArrayList<Player> getOnlineMembers(String partyName) { public static List<Player> getOnlineMembers(String partyName) {
return Party.getInstance().getOnlineMembers(partyName); return PartyManager.getInstance().getOnlineMembers(partyName);
} }
/** /**
@ -138,7 +138,7 @@ public final class PartyAPI {
* @param player The player to check * @param player The player to check
* @return all online players in the player's party * @return all online players in the player's party
*/ */
public static ArrayList<Player> getOnlineMembers(Player player) { public static List<Player> getOnlineMembers(Player player) {
return Party.getInstance().getOnlineMembers(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;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason; import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class AcceptCommand implements CommandExecutor { public class AcceptCommand implements CommandExecutor {
@ -35,29 +35,28 @@ public class AcceptCommand implements CommandExecutor {
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
if (PP.hasPartyInvite()) { if (PP.hasPartyInvite()) {
Party partyInstance = Party.getInstance(); PartyManager partyManagerInstance = PartyManager.getInstance();
if (PP.inParty()) { 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); plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return true; return true;
} }
partyInstance.removeFromParty(player, PP); partyManagerInstance.removeFromParty(player, PP);
} }
else { 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); plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return true; return true;
} }
} }
PP.acceptInvite();
partyInstance.addToParty(player, PP, PP.getParty(), true, null);
partyManagerInstance.addToInvitedParty(player, PP, PP.getInvite());
} }
else { else {
player.sendMessage(LocaleLoader.getString("mcMMO.NoInvites")); 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.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
//TODO: Make this work from console. //TODO: Make this work from console.
@ -36,11 +37,9 @@ public class InviteCommand implements CommandExecutor {
switch (args.length) { switch (args.length) {
case 1: case 1:
Player player = (Player) sender; Player player = (Player) sender;
PlayerProfile PP = Users.getProfile(player); PlayerProfile playerProfile = Users.getProfile(player);
Party partyInstance = Party.getInstance(); if (!playerProfile.inParty()) {
if (!PP.inParty()) {
player.sendMessage(LocaleLoader.getString("Commands.Party.None")); player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return true; return true;
} }
@ -48,13 +47,12 @@ public class InviteCommand implements CommandExecutor {
Player target = plugin.getServer().getPlayer(args[0]); Player target = plugin.getServer().getPlayer(args[0]);
if (target != null) { if (target != null) {
if (partyInstance.canInvite(player, PP)) { if (PartyManager.getInstance().canInvite(player, playerProfile)) {
PlayerProfile PPt = Users.getProfile(target); Party party = playerProfile.getParty();
PPt.modifyInvite(PP.getParty());
Users.getProfile(target).setInvite(party);
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success")); player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.0", new Object[] {party.getName(), player.getName()}));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.0", new Object[] { PPt.getInvite(), player.getName() }));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.1")); target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.1"));
return true; 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.events.chat.McMMOPartyChatEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class PCommand implements CommandExecutor { public class PCommand implements CommandExecutor {
@ -57,9 +58,9 @@ public class PCommand implements CommandExecutor {
default: default:
if (sender instanceof Player) { if (sender instanceof Player) {
Player player = (Player) sender; 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")); player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return true; return true;
} }
@ -70,7 +71,7 @@ public class PCommand implements CommandExecutor {
message = message + " " + args [i]; 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); plugin.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) { if (chatEvent.isCancelled()) {
@ -80,10 +81,10 @@ public class PCommand implements CommandExecutor {
message = chatEvent.getMessage(); message = chatEvent.getMessage();
String prefix = ChatColor.GREEN + "(" + ChatColor.WHITE + player.getName() + ChatColor.GREEN + ") "; 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())) { for (Player member : party.getOnlineMembers()) {
p.sendMessage(prefix + message); member.sendMessage(prefix + message);
} }
} }
else { else {
@ -92,7 +93,7 @@ public class PCommand implements CommandExecutor {
return true; return true;
} }
if (!Party.getInstance().isParty(args[0])) { if (!PartyManager.getInstance().isParty(args[0])) {
sender.sendMessage(LocaleLoader.getString("Party.InvalidName")); sender.sendMessage(LocaleLoader.getString("Party.InvalidName"));
return true; return true;
} }
@ -115,8 +116,8 @@ public class PCommand implements CommandExecutor {
plugin.getLogger().info("[P](" + args[0] + ")" + "<*Console*> " + message); plugin.getLogger().info("[P](" + args[0] + ")" + "<*Console*> " + message);
for (Player player : Party.getInstance().getOnlineMembers(args[0])) { for (Player member : PartyManager.getInstance().getOnlineMembers(args[0])) {
player.sendMessage(prefix + message); member.sendMessage(prefix + message);
} }
} }

View File

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

View File

@ -12,7 +12,7 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent; import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class PtpCommand implements CommandExecutor { public class PtpCommand implements CommandExecutor {
@ -39,11 +39,6 @@ public class PtpCommand implements CommandExecutor {
Player player = (Player) sender; Player player = (Player) sender;
PlayerProfile PP = Users.getProfile(player); 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()) { if (PP.getRecentlyHurt() + (Config.getInstance().getPTPCommandCooldown() * 1000) > System.currentTimeMillis()) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Hurt", new Object[] { Config.getInstance().getPTPCommandCooldown() })); player.sendMessage(LocaleLoader.getString("Party.Teleport.Hurt", new Object[] { Config.getInstance().getPTPCommandCooldown() }));
return true; return true;
@ -66,8 +61,8 @@ public class PtpCommand implements CommandExecutor {
return true; return true;
} }
if (Party.getInstance().inSameParty(player, target)) { if (PartyManager.getInstance().inSameParty(player, target)) {
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, PP.getParty()); McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, PP.getParty().getName());
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { 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.datatypes.mods.CustomTool;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent; import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModChecks; import com.gmail.nossr50.util.ModChecks;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
@ -30,8 +31,8 @@ public class PlayerProfile {
private SkillType skillLock; private SkillType skillLock;
/* Party Stuff */ /* Party Stuff */
private String party; private Party party;
private String invite; private Party invite;
/* Toggles */ /* Toggles */
private boolean loaded = false; private boolean loaded = false;
@ -109,7 +110,7 @@ public class PlayerProfile {
int id = 0; int id = 0;
id = mcMMO.database.getInt("SELECT id FROM "+Config.getInstance().getMySQLTablePrefix()+"users WHERE user = '" + playerName + "'"); id = mcMMO.database.getInt("SELECT id FROM "+Config.getInstance().getMySQLTablePrefix()+"users WHERE user = '" + playerName + "'");
this.userid = id; userid = id;
if (id > 0) { if (id > 0) {
HashMap<Integer, ArrayList<String>> huds = mcMMO.database.read("SELECT hudtype FROM "+Config.getInstance().getMySQLTablePrefix()+"huds WHERE user_id = " + id); HashMap<Integer, ArrayList<String>> huds = mcMMO.database.read("SELECT hudtype FROM "+Config.getInstance().getMySQLTablePrefix()+"huds WHERE user_id = " + id);
@ -131,8 +132,8 @@ public class PlayerProfile {
} }
} }
HashMap<Integer, ArrayList<String>> users = mcMMO.database.read("SELECT lastlogin, party FROM "+Config.getInstance().getMySQLTablePrefix()+"users WHERE id = " + id); 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)); //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); 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 * 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])); skills.put(SkillType.MINING, Integer.valueOf(character[1]));
//Party //Party
if(character.length > 3) if(character.length > 3)
party = character[3]; party = PartyManager.getInstance().getParty(character[3]);
//Mining XP //Mining XP
if(character.length > 4 && Misc.isInt(character[4])) if(character.length > 4 && Misc.isInt(character[4]))
skillsXp.put(SkillType.MINING, Integer.valueOf(character[4])); skillsXp.put(SkillType.MINING, Integer.valueOf(character[4]));
@ -306,47 +307,54 @@ public class PlayerProfile {
// if we are using mysql save to database // if we are using mysql save to database
if (Config.getInstance().getUseMySQL()) { 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() + "huds SET hudtype = '" + hud.toString() + "' WHERE user_id = " + 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 lastlogin = " + timestamp.intValue() + " WHERE id = " + userid);
mcMMO.database.write("UPDATE "+Config.getInstance().getMySQLTablePrefix()+"users SET party = '"+this.party+"' WHERE id = " +this.userid);
mcMMO.database.write("UPDATE "+Config.getInstance().getMySQLTablePrefix()+"cooldowns SET " String partyName = "";
+" mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER)
+", woodcutting = " + skillsDATS.get(AbilityType.TREE_FELLER) if (party != null) {
+", unarmed = " + skillsDATS.get(AbilityType.BERSERK) partyName = party.getName();
+", herbalism = " + skillsDATS.get(AbilityType.GREEN_TERRA) }
+", excavation = " + skillsDATS.get(AbilityType.GIGA_DRILL_BREAKER)
+", swords = " + skillsDATS.get(AbilityType.SERRATED_STRIKES) mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "users SET party = '" + partyName + "' WHERE id = " + userid);
+", axes = " + skillsDATS.get(AbilityType.SKULL_SPLIITER) mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "cooldowns SET "
+", blast_mining = " + skillsDATS.get(AbilityType.BLAST_MINING) + " mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER)
+" WHERE user_id = "+this.userid); + ", woodcutting = " + skillsDATS.get(AbilityType.TREE_FELLER)
mcMMO.database.write("UPDATE "+Config.getInstance().getMySQLTablePrefix()+"skills SET " + ", unarmed = " + skillsDATS.get(AbilityType.BERSERK)
+" taming = "+skills.get(SkillType.TAMING) + ", herbalism = " + skillsDATS.get(AbilityType.GREEN_TERRA)
+", mining = "+skills.get(SkillType.MINING) + ", excavation = " + skillsDATS.get(AbilityType.GIGA_DRILL_BREAKER)
+", repair = "+skills.get(SkillType.REPAIR) + ", swords = " + skillsDATS.get(AbilityType.SERRATED_STRIKES)
+", woodcutting = "+skills.get(SkillType.WOODCUTTING) + ", axes = " + skillsDATS.get(AbilityType.SKULL_SPLIITER)
+", unarmed = "+skills.get(SkillType.UNARMED) + ", blast_mining = " + skillsDATS.get(AbilityType.BLAST_MINING)
+", herbalism = "+skills.get(SkillType.HERBALISM) + " WHERE user_id = " + userid);
+", excavation = "+skills.get(SkillType.EXCAVATION) mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "skills SET "
+", archery = " +skills.get(SkillType.ARCHERY) + " taming = " + skills.get(SkillType.TAMING)
+", swords = " +skills.get(SkillType.SWORDS) + ", mining = " + skills.get(SkillType.MINING)
+", axes = "+skills.get(SkillType.AXES) + ", repair = " + skills.get(SkillType.REPAIR)
+", acrobatics = "+skills.get(SkillType.ACROBATICS) + ", woodcutting = " + skills.get(SkillType.WOODCUTTING)
+", fishing = "+skills.get(SkillType.FISHING) + ", unarmed = " + skills.get(SkillType.UNARMED)
+" WHERE user_id = "+this.userid); + ", herbalism = " + skills.get(SkillType.HERBALISM)
mcMMO.database.write("UPDATE "+Config.getInstance().getMySQLTablePrefix()+"experience SET " + ", excavation = " + skills.get(SkillType.EXCAVATION)
+" taming = "+skillsXp.get(SkillType.TAMING) + ", archery = " + skills.get(SkillType.ARCHERY)
+", mining = "+skillsXp.get(SkillType.MINING) + ", swords = " + skills.get(SkillType.SWORDS)
+", repair = "+skillsXp.get(SkillType.REPAIR) + ", axes = " + skills.get(SkillType.AXES)
+", woodcutting = "+skillsXp.get(SkillType.WOODCUTTING) + ", acrobatics = " + skills.get(SkillType.ACROBATICS)
+", unarmed = "+skillsXp.get(SkillType.UNARMED) + ", fishing = " + skills.get(SkillType.FISHING)
+", herbalism = "+skillsXp.get(SkillType.HERBALISM) + " WHERE user_id = " + userid);
+", excavation = "+skillsXp.get(SkillType.EXCAVATION) mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "experience SET "
+", archery = " +skillsXp.get(SkillType.ARCHERY) + " taming = " + skillsXp.get(SkillType.TAMING)
+", swords = " +skillsXp.get(SkillType.SWORDS) + ", mining = " + skillsXp.get(SkillType.MINING)
+", axes = "+skillsXp.get(SkillType.AXES) + ", repair = " + skillsXp.get(SkillType.REPAIR)
+", acrobatics = "+skillsXp.get(SkillType.ACROBATICS) + ", woodcutting = " + skillsXp.get(SkillType.WOODCUTTING)
+", fishing = "+skillsXp.get(SkillType.FISHING) + ", unarmed = " + skillsXp.get(SkillType.UNARMED)
+" WHERE user_id = "+this.userid); + ", herbalism = " + skillsXp.get(SkillType.HERBALISM)
+ ", excavation = " + skillsXp.get(SkillType.EXCAVATION)
+ ", archery = " + skillsXp.get(SkillType.ARCHERY)
+ ", swords = " + skillsXp.get(SkillType.SWORDS)
+ ", axes = " + skillsXp.get(SkillType.AXES)
+ ", acrobatics = " + skillsXp.get(SkillType.ACROBATICS)
+ ", fishing = " + skillsXp.get(SkillType.FISHING)
+ " WHERE user_id = " + userid);
} }
else { else {
// otherwise save to flatfile // otherwise save to flatfile
@ -369,7 +377,14 @@ public class PlayerProfile {
writer.append(playerName + ":"); writer.append(playerName + ":");
writer.append(skills.get(SkillType.MINING) + ":"); writer.append(skills.get(SkillType.MINING) + ":");
writer.append("" + ":"); writer.append("" + ":");
writer.append(party+":");
String partyName = "";
if (party != null) {
partyName = party.getName();
}
writer.append(partyName + ":");
writer.append(skillsXp.get(SkillType.MINING) + ":"); writer.append(skillsXp.get(SkillType.MINING) + ":");
writer.append(skills.get(SkillType.WOODCUTTING) + ":"); writer.append(skills.get(SkillType.WOODCUTTING) + ":");
writer.append(skillsXp.get(SkillType.WOODCUTTING) + ":"); writer.append(skillsXp.get(SkillType.WOODCUTTING) + ":");
@ -389,19 +404,19 @@ public class PlayerProfile {
writer.append(skillsXp.get(SkillType.SWORDS) + ":"); writer.append(skillsXp.get(SkillType.SWORDS) + ":");
writer.append(skillsXp.get(SkillType.AXES) + ":"); writer.append(skillsXp.get(SkillType.AXES) + ":");
writer.append(skillsXp.get(SkillType.ACROBATICS) + ":"); writer.append(skillsXp.get(SkillType.ACROBATICS) + ":");
writer.append(""+":"); writer.append("" + ":");
writer.append(skills.get(SkillType.TAMING) + ":"); writer.append(skills.get(SkillType.TAMING) + ":");
writer.append(skillsXp.get(SkillType.TAMING) + ":"); writer.append(skillsXp.get(SkillType.TAMING) + ":");
//Need to store the DATS of abilities nao //Need to store the DATS of abilities nao
//Berserk, Gigadrillbreaker, Tree Feller, Green Terra, Serrated Strikes, Skull Splitter, Super Breaker //Berserk, Gigadrillbreaker, Tree Feller, Green Terra, Serrated Strikes, Skull Splitter, Super Breaker
writer.append(String.valueOf(skillsDATS.get(AbilityType.BERSERK))+":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.BERSERK)) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.GIGA_DRILL_BREAKER))+":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.GIGA_DRILL_BREAKER)) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.TREE_FELLER))+":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.TREE_FELLER)) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.GREEN_TERRA))+":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.GREEN_TERRA)) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.SERRATED_STRIKES))+":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.SERRATED_STRIKES)) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.SKULL_SPLIITER))+":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.SKULL_SPLIITER)) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.SUPER_BREAKER))+":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.SUPER_BREAKER)) + ":");
writer.append(hud.toString()+":"); writer.append(hud.toString() + ":");
writer.append(skills.get(SkillType.FISHING) + ":"); writer.append(skills.get(SkillType.FISHING) + ":");
writer.append(skillsXp.get(SkillType.FISHING) + ":"); writer.append(skillsXp.get(SkillType.FISHING) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.BLAST_MINING)) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.BLAST_MINING)) + ":");
@ -435,7 +450,7 @@ public class PlayerProfile {
} }
//Misc stuff //Misc stuff
party = ""; party = null;
save(); save();
} }
@ -450,41 +465,48 @@ public class PlayerProfile {
//Add the player to the end //Add the player to the end
out.append(playerName + ":"); out.append(playerName + ":");
out.append(0 + ":"); //mining out.append(0 + ":"); //mining
out.append(""+":"); out.append("" + ":");
out.append(party+":");
out.append(0+":"); //XP String partyName = "";
out.append(0+":"); //woodcutting
out.append(0+":"); //woodCuttingXP if (party != null) {
out.append(0+":"); //repair partyName = party.getName();
out.append(0+":"); //unarmed }
out.append(0+":"); //herbalism
out.append(0+":"); //excavation out.append(partyName + ":");
out.append(0+":"); //archery out.append(0 + ":"); //XP
out.append(0+":"); //swords out.append(0 + ":"); //woodcutting
out.append(0+":"); //axes out.append(0 + ":"); //woodCuttingXP
out.append(0+":"); //acrobatics out.append(0 + ":"); //repair
out.append(0+":"); //repairXP out.append(0 + ":"); //unarmed
out.append(0+":"); //unarmedXP out.append(0 + ":"); //herbalism
out.append(0+":"); //herbalismXP out.append(0 + ":"); //excavation
out.append(0+":"); //excavationXP out.append(0 + ":"); //archery
out.append(0+":"); //archeryXP out.append(0 + ":"); //swords
out.append(0+":"); //swordsXP out.append(0 + ":"); //axes
out.append(0+":"); //axesXP out.append(0 + ":"); //acrobatics
out.append(0+":"); //acrobaticsXP out.append(0 + ":"); //repairXP
out.append(""+":"); out.append(0 + ":"); //unarmedXP
out.append(0+":"); //taming out.append(0 + ":"); //herbalismXP
out.append(0+":"); //tamingXP out.append(0 + ":"); //excavationXP
out.append(0+":"); //DATS out.append(0 + ":"); //archeryXP
out.append(0+":"); //DATS out.append(0 + ":"); //swordsXP
out.append(0+":"); //DATS out.append(0 + ":"); //axesXP
out.append(0+":"); //DATS out.append(0 + ":"); //acrobaticsXP
out.append(0+":"); //DATS out.append("" + ":");
out.append(0+":"); //DATS out.append(0 + ":"); //taming
out.append(0+":"); //DATS out.append(0 + ":"); //tamingXP
out.append(SpoutConfig.getInstance().defaulthud.toString()+":");//HUD out.append(0 + ":"); //DATS
out.append(0+":"); //Fishing out.append(0 + ":"); //DATS
out.append(0+":"); //FishingXP out.append(0 + ":"); //DATS
out.append(0+":"); //Blast Mining out.append(0 + ":"); //DATS
out.append(0 + ":"); //DATS
out.append(0 + ":"); //DATS
out.append(0 + ":"); //DATS
out.append(SpoutConfig.getInstance().defaulthud.toString() + ":");//HUD
out.append(0 + ":"); //Fishing
out.append(0 +":"); //FishingXP
out.append(0 + ":"); //Blast Mining
//Add more in the same format as the line above //Add more in the same format as the line above
@ -1165,8 +1187,8 @@ public class PlayerProfile {
private double partyModifier(SkillType skillType) { private double partyModifier(SkillType skillType) {
double bonusModifier = 0.0; double bonusModifier = 0.0;
for (Player member : Party.getInstance().getOnlineMembers(player)) { for (Player member : party.getOnlineMembers()) {
if (!member.equals(player) && Party.getInstance().isPartyLeader(member.getName(), getParty())) { if (party.getLeader().equals(member.getName())) {
if (Misc.isNear(player.getLocation(), member.getLocation(), 25.0)) { if (Misc.isNear(player.getLocation(), member.getLocation(), 25.0)) {
PlayerProfile PartyLeader = Users.getProfile(member); PlayerProfile PartyLeader = Users.getProfile(member);
int leaderSkill = PartyLeader.getSkillLevel(skillType); int leaderSkill = PartyLeader.getSkillLevel(skillType);
@ -1187,21 +1209,16 @@ public class PlayerProfile {
* Party Stuff * Party Stuff
*/ */
public void acceptInvite() { public void setInvite(Party invite) {
party = invite; this.invite = invite;
invite = "";
} }
public void modifyInvite(String invitename) { public Party getInvite() {
invite = invitename;
}
public String getInvite() {
return invite; return invite;
} }
public boolean hasPartyInvite() { public boolean hasPartyInvite() {
if (invite != null && !invite.equals("") && !invite.equals("null")) { if (invite != null) {
return true; return true;
} }
else { else {
@ -1209,24 +1226,28 @@ public class PlayerProfile {
} }
} }
public void setParty(String newParty) { public void setParty(Party party) {
party = newParty; this.party = party;
} }
public String getParty() { public Party getParty() {
return party; return party;
} }
public boolean inParty() {
if (party != null) {
return true;
}
else {
return false;
}
}
public void removeParty() { public void removeParty() {
party = null; party = null;
} }
public boolean inParty() { public void removeInvite() {
if (party != null && !party.equals("") && !party.equals("null")) { invite = null;
return true;
}
else {
return false;
}
} }
} }

View File

@ -30,7 +30,7 @@ import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent; 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.runnables.BleedTimer;
import com.gmail.nossr50.skills.combat.Archery; import com.gmail.nossr50.skills.combat.Archery;
import com.gmail.nossr50.skills.combat.Taming; import com.gmail.nossr50.skills.combat.Taming;
@ -81,7 +81,7 @@ public class EntityListener implements Listener {
Entity defender = event.getEntity(); Entity defender = event.getEntity();
if (attacker instanceof Player && defender instanceof Player) { 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); event.setCancelled(true);
return; return;
} }
@ -89,7 +89,7 @@ public class EntityListener implements Listener {
/* Check for invincibility */ /* Check for invincibility */
if (defender instanceof LivingEntity) { if (defender instanceof LivingEntity) {
LivingEntity livingDefender = (LivingEntity)defender; LivingEntity livingDefender = (LivingEntity) defender;
if (!Misc.isInvincible(livingDefender, event)) { if (!Misc.isInvincible(livingDefender, event)) {
Combat.combatChecks(event); Combat.combatChecks(event);

View File

@ -318,39 +318,44 @@ public class PlayerListener implements Listener {
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
if (PP.getPartyChatMode()) { 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 player.sendMessage("You're not in a party, type /p to leave party chat mode."); //TODO: Use mcLocale
return; 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); plugin.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) { if (chatEvent.isCancelled()) {
return; 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())) { for (Player member : party.getOnlineMembers()) {
p.sendMessage(prefix + chatEvent.getMessage()); member.sendMessage(prefix + chatEvent.getMessage());
} }
event.setCancelled(true); event.setCancelled(true);
} }
else if (PP.getAdminChatMode()) { 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); plugin.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) { if (chatEvent.isCancelled()) {
return; 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()) { for (Player p : plugin.getServer().getOnlinePlayers()) {
if (Permissions.getInstance().adminChat(player) || player.isOp()) { 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.PlayerListener;
import com.gmail.nossr50.listeners.WorldListener; import com.gmail.nossr50.listeners.WorldListener;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.BleedTimer; import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.runnables.SaveTimer; import com.gmail.nossr50.runnables.SaveTimer;
import com.gmail.nossr50.runnables.SkillMonitor; import com.gmail.nossr50.runnables.SkillMonitor;
@ -270,6 +271,8 @@ public class mcMMO extends JavaPlugin {
playerProfile.save(); playerProfile.save();
} }
PartyManager.getInstance().saveParties();
getServer().getScheduler().cancelTasks(this); //This removes our tasks getServer().getScheduler().cancelTasks(this); //This removes our tasks
//Save our metadata //Save our metadata

View File

@ -1,649 +1,65 @@
package com.gmail.nossr50.party; 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.ArrayList;
import java.util.HashMap; import java.util.List;
import java.util.Map;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; 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 class Party {
public static String pluginPath; private List<String> members = new ArrayList<String>();
public static String partyPlayersFile; private String leader;
public static String partyLocksFile; private String name;
public static String partyPasswordsFile; private String password;
private boolean locked;
HashMap<String, HashMap<String, Boolean>> partyPlayers = new HashMap<String, HashMap<String, Boolean>>(); public List<String> getMembers() {
HashMap<String, Boolean> partyLocks = new HashMap<String, Boolean>(); return members;
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 static Party getInstance() { public List<Player> getOnlineMembers() {
if (instance == null) { Player[] onlinePlayers = mcMMO.p.getServer().getOnlinePlayers();
instance = new Party(); List<Player> onlineMembers = new ArrayList<Player>();
}
return instance;
}
/** for (Player onlinePlayer : onlinePlayers) {
* Check if two players are in the same party. if (members.contains(onlinePlayer.getName())) {
* onlineMembers.add(onlinePlayer);
* @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;
}
}
/**
* 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; return onlineMembers;
} }
/** public String getLeader() {
* 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 leader; return leader;
} }
/** public String getName() {
* Set the leader of a party. return name;
*
* @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;
}
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() {
* Get the password of a party. return password;
*
* @param partyName The party name
* @return The password of this party
*/
public String getPartyPassword(String partyName) {
return partyPasswords.get(partyName);
} }
/** public boolean isLocked() {
* Check if a player can invite others to their party. return locked;
*
* @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) {
* Check if a string is a valid party name. this.name = 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) {
* Check if a party is empty. this.leader = leader;
*
* @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) {
* Check if a player is the party leader. this.password = password;
*
* @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;
}
} }
/** public void setLocked(boolean locked) {
* Check if this party is locked. this.locked = 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();
}
} }
} }

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 org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.PartyManager;
public class SaveTimer implements Runnable { public class SaveTimer implements Runnable {
private final mcMMO plugin; private final mcMMO plugin;
@ -20,5 +21,7 @@ public class SaveTimer implements Runnable {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new ProfileSaveTask(player), count); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new ProfileSaveTask(player), count);
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.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; 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.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
@ -60,7 +60,7 @@ public class Axes {
if (tamer instanceof Player) { if (tamer instanceof Player) {
Player owner = (Player) tamer; Player owner = (Player) tamer;
if (owner == attacker || Party.getInstance().inSameParty(attacker, owner)) { if (owner == attacker || PartyManager.getInstance().inSameParty(attacker, owner)) {
return; return;
} }
} }

View File

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

View File

@ -9,7 +9,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; 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.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Skills; import com.gmail.nossr50.util.Skills;
@ -96,7 +96,7 @@ public class Acrobatics {
if (event.getDamager() instanceof Player) { if (event.getDamager() instanceof Player) {
Player attacker = (Player) event.getDamager(); Player attacker = (Player) event.getDamager();
if (Party.getInstance().inSameParty(defender, attacker)) { if (PartyManager.getInstance().inSameParty(defender, attacker)) {
return; 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.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.locale.LocaleLoader; 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.BleedTimer;
import com.gmail.nossr50.runnables.GainXp; import com.gmail.nossr50.runnables.GainXp;
import com.gmail.nossr50.skills.combat.Archery; import com.gmail.nossr50.skills.combat.Archery;
@ -396,7 +396,7 @@ public class Combat {
continue; continue;
} }
if (Party.getInstance().inSameParty(attacker, defender)) { if (PartyManager.getInstance().inSameParty(attacker, defender)) {
continue; continue;
} }
@ -410,7 +410,7 @@ public class Combat {
AnimalTamer tamer = ((Tameable) entity).getOwner(); AnimalTamer tamer = ((Tameable) entity).getOwner();
if (tamer instanceof Player) { 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; continue;
} }
} }