Make PartyJoinCommand use PartyManager directly for lookup

This commit is contained in:
riking 2013-10-28 13:02:23 -07:00
parent f64f62492f
commit eb10db5b06
2 changed files with 12 additions and 21 deletions

View File

@ -14,26 +14,23 @@ import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class PartyJoinCommand implements CommandExecutor { public class PartyJoinCommand implements CommandExecutor {
private McMMOPlayer mcMMOTarget;
private Player target;
private Party targetParty;
private McMMOPlayer mcMMOPlayer; private McMMOPlayer mcMMOPlayer;
private Player player; private Player player;
private Party targetParty;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 2: case 2:
case 3: case 3:
player = (Player) sender;
mcMMOPlayer = UserManager.getPlayer(player);
// Verify target exists and is in a different party than the player // Verify target exists and is in a different party than the player
if (!canJoinParty(sender, args[1])) { if (!canJoinParty(sender, args[1])) {
return true; return true;
} }
mcMMOPlayer = UserManager.getPlayer((Player) sender);
player = mcMMOPlayer.getPlayer();
String password = getPassword(args); String password = getPassword(args);
// Make sure party passwords match // Make sure party passwords match
@ -67,25 +64,21 @@ public class PartyJoinCommand implements CommandExecutor {
} }
private boolean canJoinParty(CommandSender sender, String targetName) { private boolean canJoinParty(CommandSender sender, String targetName) {
targetName = Misc.getMatchedPlayerName(targetName); // Short-circuit for joining your own party
mcMMOTarget = UserManager.getPlayer(targetName); if (sender.getName().equalsIgnoreCase(targetName)) {
sender.sendMessage(LocaleLoader.getString("Party.Join.Self"));
if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
return false; return false;
} }
target = mcMMOTarget.getPlayer(); targetParty = PartyManager.getPlayerParty(targetName);
if (!mcMMOTarget.inParty()) { if (targetParty == null) {
sender.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", targetName)); sender.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", targetName));
return false; return false;
} }
player = (Player) sender; // Can't join your own party
mcMMOPlayer = UserManager.getPlayer(player); if (mcMMOPlayer.inParty() && mcMMOPlayer.getParty().equals(targetParty)) {
targetParty = mcMMOTarget.getParty();
if (player.equals(target) || (mcMMOPlayer.inParty() && mcMMOPlayer.getParty().equals(targetParty))) {
sender.sendMessage(LocaleLoader.getString("Party.Join.Self")); sender.sendMessage(LocaleLoader.getString("Party.Join.Self"));
return false; return false;
} }

View File

@ -96,9 +96,7 @@ public final class CommandUtils {
return true; return true;
} }
PlayerProfile profile = new PlayerProfile(playerName, false); if (unloadedProfile(sender, mcMMOPlayer.getProfile())) {
if (unloadedProfile(sender, profile)) {
return false; return false;
} }