From eb10db5b06c1dbd173002c8a88ed96e550cf233b Mon Sep 17 00:00:00 2001 From: riking Date: Mon, 28 Oct 2013 13:02:23 -0700 Subject: [PATCH] Make PartyJoinCommand use PartyManager directly for lookup --- .../commands/party/PartyJoinCommand.java | 29 +++++++------------ .../nossr50/util/commands/CommandUtils.java | 4 +-- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/party/PartyJoinCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PartyJoinCommand.java index 23da0f7d5..9a122f598 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PartyJoinCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PartyJoinCommand.java @@ -14,26 +14,23 @@ import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; public class PartyJoinCommand implements CommandExecutor { - private McMMOPlayer mcMMOTarget; - private Player target; - private Party targetParty; - private McMMOPlayer mcMMOPlayer; private Player player; + private Party targetParty; @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { switch (args.length) { case 2: case 3: + player = (Player) sender; + mcMMOPlayer = UserManager.getPlayer(player); + // Verify target exists and is in a different party than the player if (!canJoinParty(sender, args[1])) { return true; } - mcMMOPlayer = UserManager.getPlayer((Player) sender); - player = mcMMOPlayer.getPlayer(); - String password = getPassword(args); // Make sure party passwords match @@ -67,25 +64,21 @@ public class PartyJoinCommand implements CommandExecutor { } private boolean canJoinParty(CommandSender sender, String targetName) { - targetName = Misc.getMatchedPlayerName(targetName); - mcMMOTarget = UserManager.getPlayer(targetName); - - if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) { + // Short-circuit for joining your own party + if (sender.getName().equalsIgnoreCase(targetName)) { + sender.sendMessage(LocaleLoader.getString("Party.Join.Self")); return false; } - target = mcMMOTarget.getPlayer(); + targetParty = PartyManager.getPlayerParty(targetName); - if (!mcMMOTarget.inParty()) { + if (targetParty == null) { sender.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", targetName)); return false; } - player = (Player) sender; - mcMMOPlayer = UserManager.getPlayer(player); - targetParty = mcMMOTarget.getParty(); - - if (player.equals(target) || (mcMMOPlayer.inParty() && mcMMOPlayer.getParty().equals(targetParty))) { + // Can't join your own party + if (mcMMOPlayer.inParty() && mcMMOPlayer.getParty().equals(targetParty)) { sender.sendMessage(LocaleLoader.getString("Party.Join.Self")); return false; } diff --git a/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java b/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java index 973dd7506..427e595d9 100644 --- a/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java +++ b/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java @@ -96,9 +96,7 @@ public final class CommandUtils { return true; } - PlayerProfile profile = new PlayerProfile(playerName, false); - - if (unloadedProfile(sender, profile)) { + if (unloadedProfile(sender, mcMMOPlayer.getProfile())) { return false; }