diff --git a/src/main/java/com/gmail/nossr50/api/PartyAPI.java b/src/main/java/com/gmail/nossr50/api/PartyAPI.java index 4f9f10e99..714b83f24 100644 --- a/src/main/java/com/gmail/nossr50/api/PartyAPI.java +++ b/src/main/java/com/gmail/nossr50/api/PartyAPI.java @@ -1,13 +1,10 @@ package com.gmail.nossr50.api; -import java.io.BufferedReader; -import java.io.FileReader; import java.util.ArrayList; import org.bukkit.entity.Player; import com.gmail.nossr50.Users; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.party.Party; public class PartyAPI { @@ -57,47 +54,7 @@ public class PartyAPI { * @return the list of parties. */ public ArrayList getParties() { - String location = mcMMO.usersFile; - ArrayList parties = new ArrayList(); - - try { - - //Open the users file - 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) { - mcMMO.p.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString()); - } - return parties; - } - - /** - * Get a list of all online players in this player's party. - *
- * This function is designed for API usage. - * - * @param player The player to check - * @return all online players in the player's party - */ - public ArrayList getOnlineMembers(Player player) { - return Party.getInstance().getOnlineMembers(player); + return Party.getInstance().getParties(); } /** @@ -158,4 +115,28 @@ public class PartyAPI { public ArrayList getAllMembers(Player player) { return Party.getInstance().getAllMembers(player); } + + /** + * Get a list of all online players in this party. + *
+ * This function is designed for API usage. + * + * @param partyName The party to check + * @return all online players in this party + */ + public ArrayList getOnlineMembers(String partyName) { + return Party.getInstance().getOnlineMembers(partyName); + } + + /** + * Get a list of all online players in this player's party. + *
+ * This function is designed for API usage. + * + * @param player The player to check + * @return all online players in the player's party + */ + public ArrayList getOnlineMembers(Player player) { + return Party.getInstance().getOnlineMembers(player); + } } diff --git a/src/main/java/com/gmail/nossr50/commands/party/ACommand.java b/src/main/java/com/gmail/nossr50/commands/party/ACommand.java index f82c9b330..9c1b391cf 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/ACommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/ACommand.java @@ -24,7 +24,7 @@ public class ACommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { PlayerProfile PP; - String usage = ChatColor.RED + "Proper usage is /a [message]"; //TODO: Needs more locale. + String usage = ChatColor.RED + "Proper usage is /a "; //TODO: Needs more locale. if (CommandHelper.noCommandPermissions(sender, "mcmmo.chat.adminchat")) { return true; @@ -78,7 +78,6 @@ public class ACommand implements CommandExecutor { } message = chatEvent.getMessage(); - String prefix = ChatColor.AQUA + "{" + ChatColor.WHITE + "*Console*" + ChatColor.AQUA + "} "; plugin.getLogger().info("[A]<*Console*> " + message); diff --git a/src/main/java/com/gmail/nossr50/commands/party/PCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PCommand.java index 8ed91b20c..c9a20d25b 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PCommand.java @@ -8,10 +8,11 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.mcPermissions; +import com.gmail.nossr50.commands.CommandHelper; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.events.chat.McMMOPartyChatEvent; import com.gmail.nossr50.locale.mcLocale; +import com.gmail.nossr50.party.Party; public class PCommand implements CommandExecutor { private final mcMMO plugin; @@ -20,78 +21,95 @@ public class PCommand implements CommandExecutor { this.plugin = plugin; } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + PlayerProfile PP; + String usage = ChatColor.RED + "Proper usage is /p "; //TODO: Needs more locale. - // Console message? - if (!(sender instanceof Player)) { - if (args.length < 2) - return true; - String pMessage = args[1]; - for (int i = 2; i <= args.length - 1; i++) { - pMessage = pMessage + " " + args[i]; - } + if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party")) { + return true; + } - McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent("Console", args[0], pMessage); - plugin.getServer().getPluginManager().callEvent(chatEvent); - if(chatEvent.isCancelled()) return true; + switch (args.length) { + case 0: + if (sender instanceof Player) { + PP = Users.getProfile((Player) sender); - pMessage = chatEvent.getMessage(); + if (PP.getAdminChatMode()) { + PP.toggleAdminChat(); + } - String pPrefix = ChatColor.GREEN + "(" + ChatColor.WHITE + "*Console*" + ChatColor.GREEN + ") "; + PP.togglePartyChat(); - plugin.getLogger().info("[P](" + args[0] + ")" + "<*Console*> " + pMessage); + if (PP.getPartyChatMode()) { + sender.sendMessage(mcLocale.getString("Commands.Party.Chat.On")); + } + else { + sender.sendMessage(mcLocale.getString("Commands.Party.Chat.Off")); + } + } + else { + sender.sendMessage(usage); + } - for (Player herp : plugin.getServer().getOnlinePlayers()) { - if (Users.getProfile(herp).inParty()) { - if (Users.getProfile(herp).getParty().equalsIgnoreCase(args[0])) { - herp.sendMessage(pPrefix + pMessage); - } - } - } - return true; - } + return true; - Player player = (Player) sender; - PlayerProfile PP = Users.getProfile(player); + default: + if (sender instanceof Player) { + Player player = (Player) sender; + PP = Users.getProfile(player); - if (!mcPermissions.getInstance().party(player)) { - player.sendMessage(ChatColor.YELLOW + "[mcMMO] " + ChatColor.DARK_RED + mcLocale.getString("mcPlayerListener.NoPermission")); - return true; - } + if (!PP.inParty()) { + player.sendMessage(mcLocale.getString("Commands.Party.None")); + return true; + } - // Not a toggle, a message + String message = args[0]; - if (args.length >= 1) { - if(!PP.inParty()) { - player.sendMessage("You're not in a party."); //TODO: Use mcLocale - return true; - } - - String pMessage = args[0]; - for (int i = 1; i <= args.length - 1; i++) { - pMessage = pMessage + " " + args[i]; - } - - PP.togglePartyChat(); - player.chat(pMessage); - PP.togglePartyChat(); + for (int i = 1; i < args.length; i++) { + message = message + " " + args [i]; + } - return true; - } + PP.togglePartyChat(); + player.chat(message); + PP.togglePartyChat(); + } + else { + if (args.length < 2) { + sender.sendMessage(usage); + return true; + } - if (PP.getAdminChatMode()) - PP.toggleAdminChat(); + if (!Party.getInstance().getParties().contains(args[0])) { + sender.sendMessage(mcLocale.getString("Party.InvalidName")); + return true; + } - PP.togglePartyChat(); + String message = args[1]; - if (PP.getPartyChatMode()) { - player.sendMessage(mcLocale.getString("mcPlayerListener.PartyChatOn")); - } else { - player.sendMessage(mcLocale.getString("mcPlayerListener.PartyChatOff")); - } + for (int i = 2; i < args.length; i++) { + message = message + " " + args [i]; + } - return true; - } + McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent("Console", args[0], message); + plugin.getServer().getPluginManager().callEvent(chatEvent); + + if (chatEvent.isCancelled()) { + return true; + } + + message = chatEvent.getMessage(); + String prefix = ChatColor.GREEN + "(" + ChatColor.WHITE + "*Console*" + ChatColor.GREEN + ") "; + + plugin.getLogger().info("[P](" + args[0] + ")" + "<*Console*> " + message); + + for (Player player : Party.getInstance().getOnlineMembers(args[0])) { + player.sendMessage(prefix + message); + } + } + + return true; + } + } } diff --git a/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java index 315209516..ea0fe4fa8 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java @@ -24,7 +24,6 @@ public class PartyCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (CommandHelper.noConsoleUsage(sender)) { return true; } diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java index d7d27e2cd..c20dfd7fa 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java @@ -1173,18 +1173,20 @@ public class PlayerProfile { * @return the party bonus multiplier */ private double partyModifier(SkillType skillType) { - Player player = mcMMO.p.getServer().getPlayer(playerName); + Player player = getPlayer(); double bonusModifier = 0.0; for (Player x : Party.getInstance().getOnlineMembers(player)) { - if (x.isOnline() && !x.getName().equals(player.getName()) && Party.getInstance().isPartyLeader(x.getName(), this.getParty())) { + String memberName = x.getName(); + + if (!memberName.equals(playerName) && Party.getInstance().isPartyLeader(memberName, getParty())) { if (m.isNear(player.getLocation(), x.getLocation(), 25.0)) { PlayerProfile PartyLeader = Users.getProfile(x); + int leaderSkill = PartyLeader.getSkillLevel(skillType); + int playerSkill = getSkillLevel(skillType); - if (PartyLeader.getSkillLevel(skillType) >= this.getSkillLevel(skillType)) { - - int leaderLevel = PartyLeader.getSkillLevel(skillType); - int difference = leaderLevel - this.getSkillLevel(skillType); + if (leaderSkill >= playerSkill) { + int difference = leaderSkill - playerSkill; bonusModifier = (difference * 0.75) / 100.0; } } diff --git a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java index 8dd180e97..16b6e35b6 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java @@ -316,10 +316,8 @@ public class mcPlayerListener implements Listener { event.setMessage(chatEvent.getMessage()); - for (Player x : plugin.getServer().getOnlinePlayers()) { - if (Party.getInstance().inSameParty(player, x)) { - intendedRecipients.add(x); - } + for (Player x : Party.getInstance().getOnlineMembers(player)) { + intendedRecipients.add(x); } event.setFormat(color + "(" + ChatColor.WHITE + "%1$s" + color + ") %2$s"); diff --git a/src/main/java/com/gmail/nossr50/party/Party.java b/src/main/java/com/gmail/nossr50/party/Party.java index 0f0eb8ab4..72006bd90 100644 --- a/src/main/java/com/gmail/nossr50/party/Party.java +++ b/src/main/java/com/gmail/nossr50/party/Party.java @@ -1,10 +1,12 @@ 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; @@ -73,18 +75,12 @@ public class Party { * @return the number of players in this player's party */ public int partyCount(Player player) { - PlayerProfile PP = Users.getProfile(player); - int partyMembers = 0; - - for (Player p : plugin.getServer().getOnlinePlayers()) { - if (player != null && p != null) { //Is this even possible? - if (PP.getParty().equals(Users.getProfile(p).getParty())) { - partyMembers++; - } - } + if (player != null) { + return getAllMembers(player).size(); + } + else { + return 0; } - - return partyMembers; } private void informPartyMembers(Player player) { @@ -92,7 +88,9 @@ public class Party { if (player != null) { for (Player p : getOnlineMembers(player)) { - p.sendMessage(mcLocale.getString("Party.InformedOnJoin", new Object[] {playerName})); + if (p.getName() != playerName) { + p.sendMessage(mcLocale.getString("Party.InformedOnJoin", new Object[] {playerName})); + } } } } @@ -106,9 +104,31 @@ public class Party { public ArrayList getOnlineMembers(Player player) { ArrayList players = new ArrayList(); + 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 getOnlineMembers(String partyName) { + ArrayList players = new ArrayList(); + for (Player p : plugin.getServer().getOnlinePlayers()) { - if (player != null && p != null) { - if (inSameParty(player, p) && !p.getName().equals(player.getName())) { + PlayerProfile PP = Users.getProfile(p); + + if (PP.inParty()) { + if (PP.getParty().equalsIgnoreCase(partyName)) { players.add(p); } } @@ -139,6 +159,42 @@ public class Party { return players; } + + /** + * Get a list of all current party names. + * + * @return the list of parties. + */ + public ArrayList getParties() { + String location = mcMMO.usersFile; + ArrayList parties = new ArrayList(); + + 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) { + mcMMO.p.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. * @@ -149,7 +205,9 @@ public class Party { if (newOwner != null) { for (Player p : getOnlineMembers(newOwner)) { - p.sendMessage(newOwnerName + " is the new party owner."); //TODO: Needs more locale + if (p.getName() != newOwnerName) { + p.sendMessage(newOwnerName + " is the new party owner."); //TODO: Needs more locale + } } } } @@ -164,7 +222,9 @@ public class Party { if (player != null) { for (Player p : getOnlineMembers(player)) { - p.sendMessage(mcLocale.getString("Party.InformedOnQuit", new Object[] {playerName})); + if (p.getName() != playerName) { + p.sendMessage(mcLocale.getString("Party.InformedOnQuit", new Object[] {playerName})); + } } } }