Convert /party info to a subcommand

This commit is contained in:
GJ 2013-02-12 10:42:42 -05:00
parent e92c6b8f26
commit 5a48d5c5f8
3 changed files with 113 additions and 70 deletions

View File

@ -33,6 +33,7 @@ public class PartyCommand implements CommandExecutor {
private CommandExecutor partyLockCommand = new PartyLockCommand();
private CommandExecutor partyChangePasswordCommand = new PartyChangePasswordCommand();
private CommandExecutor partyRenameCommand = new PartyRenameCommand();
private CommandExecutor partyInfoCommand = new PartyInfoCommand();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -49,10 +50,9 @@ public class PartyCommand implements CommandExecutor {
mcMMOPlayer = Users.getPlayer(player);
if (args.length < 1 || args[0].equalsIgnoreCase("info")) {
return party();
return partyInfoCommand.onCommand(sender, command, label, args);
}
if (args[0].equalsIgnoreCase("join")) {
else if (args[0].equalsIgnoreCase("join")) {
return partyJoinCommand.onCommand(sender, command, label, args);
}
else if (args[0].equalsIgnoreCase("accept")) {
@ -118,71 +118,6 @@ public class PartyCommand implements CommandExecutor {
return true;
}
private boolean party() {
if (mcMMOPlayer.inParty()) {
Party party = mcMMOPlayer.getParty();
String leader = party.getLeader();
StringBuilder tempList = new StringBuilder();
int membersNear = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange()).size();
int membersOnline = party.getOnlineMembers().size() - 1;
String ItemShare = "";
String ExpShare = "";
String Split = "";
for (OfflinePlayer otherMember : party.getMembers()) {
if (leader.equals(otherMember.getName())) {
tempList.append(ChatColor.GOLD);
}
else if (otherMember.isOnline()) {
tempList.append(ChatColor.WHITE);
}
else {
tempList.append(ChatColor.GRAY);
}
tempList.append(otherMember.getName()).append(" ");
}
String status = LocaleLoader.getString("Party.Status.Locked");
if (!party.isLocked()) {
status = LocaleLoader.getString("Party.Status.Unlocked");
}
player.sendMessage(LocaleLoader.getString("Commands.Party.Header"));
player.sendMessage(LocaleLoader.getString("Commands.Party.Status", party.getName(), status));
boolean xpShareEnabled = Config.getInstance().getExpShareEnabled();
boolean itemShareEnabled = Config.getInstance().getItemShareEnabled();
if (xpShareEnabled) {
ExpShare = LocaleLoader.getString("Commands.Party.ExpShare", party.getXpShareMode().toString());
}
if (itemShareEnabled) {
ItemShare = LocaleLoader.getString("Commands.Party.ItemShare", party.getItemShareMode().toString());
}
if (xpShareEnabled && itemShareEnabled) {
Split = ChatColor.DARK_GRAY + " || ";
}
if (xpShareEnabled || itemShareEnabled) {
player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode") + ExpShare + Split + ItemShare);
}
player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header"));
player.sendMessage(LocaleLoader.getString("Commands.Party.MembersNear", membersNear, membersOnline));
player.sendMessage(LocaleLoader.getString("Commands.Party.Members", tempList));
}
else {
return printUsage();
}
return true;
}
private boolean printHelp() {
player.sendMessage(LocaleLoader.getString("Party.Help.3"));
player.sendMessage(LocaleLoader.getString("Party.Help.1"));

View File

@ -0,0 +1,108 @@
package com.gmail.nossr50.party.commands;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users;
public class PartyInfoCommand implements CommandExecutor {
private Player player;
private Party playerParty;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
player = (Player) sender;
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
if (!mcMMOPlayer.inParty()) {
sendUsageStrings(sender);
}
playerParty = mcMMOPlayer.getParty();
displayPartyHeader();
displayShareModeInfo();
displayMemberInfo();
return true;
}
private void sendUsageStrings(CommandSender sender) {
sender.sendMessage(LocaleLoader.getString("Party.Help.0", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
sender.sendMessage(LocaleLoader.getString("Party.Help.1", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
sender.sendMessage(LocaleLoader.getString("Party.Help.2"));
}
private String createMembersList() {
StringBuilder memberList = new StringBuilder();
for (OfflinePlayer member : playerParty.getMembers()) {
if (playerParty.getLeader().equals(member.getName())) {
memberList.append(ChatColor.GOLD).append(member.getName()).append(" ");
}
else if (member.isOnline()) {
memberList.append(ChatColor.WHITE).append(member.getName()).append(" ");
}
else {
memberList.append(ChatColor.GRAY).append(member.getName()).append(" ");
}
}
return memberList.toString();
}
private void displayShareModeInfo() {
boolean xpShareEnabled = Config.getInstance().getExpShareEnabled();
boolean itemShareEnabled = Config.getInstance().getItemShareEnabled();
if (!xpShareEnabled && !itemShareEnabled) {
return;
}
String expShareInfo = "";
String itemShareInfo = "";
String separator = "";
if (xpShareEnabled) {
expShareInfo = LocaleLoader.getString("Commands.Party.ExpShare", playerParty.getXpShareMode().toString());
}
if (itemShareEnabled) {
itemShareInfo = LocaleLoader.getString("Commands.Party.ItemShare", playerParty.getItemShareMode().toString());
}
if (xpShareEnabled && itemShareEnabled) {
separator = ChatColor.DARK_GRAY + " || ";
}
player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode") + expShareInfo + separator + itemShareInfo);
}
private void displayPartyHeader() {
player.sendMessage(LocaleLoader.getString("Commands.Party.Header"));
if (playerParty.isLocked()) {
player.sendMessage(LocaleLoader.getString("Commands.Party.Status", playerParty.getName(), LocaleLoader.getString("Party.Status.Locked")));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.Party.Status", playerParty.getName(), LocaleLoader.getString("Party.Status.Unlocked")));
}
}
private void displayMemberInfo() {
int membersNear = PartyManager.getNearMembers(player, playerParty, Config.getInstance().getPartyShareRange()).size();
int membersOnline = playerParty.getOnlineMembers().size() - 1;
player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header"));
player.sendMessage(LocaleLoader.getString("Commands.Party.MembersNear", membersNear, membersOnline));
player.sendMessage(LocaleLoader.getString("Commands.Party.Members", createMembersList()));
}
}

View File

@ -495,7 +495,7 @@ Commands.Usage.3=[[RED]]Proper usage is /{0} {1} {2} {3}
Commands.Usage.Level=level
Commands.Usage.Message=message
Commands.Usage.Page=page
Commands.Usage.PartyName=party-name
Commands.Usage.PartyName=name
Commands.Usage.Password=password
Commands.Usage.Player=player
Commands.Usage.Rate=rate
@ -507,7 +507,7 @@ mcMMO.NoSkillNote=[[DARK_GRAY]]If you don't have access to a skill it will not b
##party
Party.Forbidden=[mcMMO] Parties not permitted on this world (See Permissions)
Party.Help.0=[[RED]]Proper usage is [[DARK_AQUA]]/party join <player> [password].
Party.Help.0=[[RED]]Proper usage is [[DARK_AQUA]]/party join {0} {1}.
Party.Help.1=[[RED]]To create a party, use [[DARK_AQUA]]/party create <name> [password]
Party.Help.2=[[RED]]Consult [[DARK_AQUA]]/party ? [[RED]]for more information
Party.Help.3=[[RED]]Use [[DARK_AQUA]]/party join <player> [[RED]]to join or [[DARK_AQUA]]/party quit [[RED]]to quit