From 340c47eebdd5a7e0cf627b967fea7cca7f9d424f Mon Sep 17 00:00:00 2001 From: GJ Date: Fri, 8 Feb 2013 16:56:54 -0500 Subject: [PATCH] Switch /party invite to a subcommand --- .../com/gmail/nossr50/party/PartyManager.java | 6 +- .../nossr50/party/commands/PartyCommand.java | 46 +----------- .../party/commands/PartyInviteCommand.java | 73 +++++++++++++++++++ 3 files changed, 77 insertions(+), 48 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/party/commands/PartyInviteCommand.java diff --git a/src/main/java/com/gmail/nossr50/party/PartyManager.java b/src/main/java/com/gmail/nossr50/party/PartyManager.java index 2e183fb41..97a8bb8eb 100644 --- a/src/main/java/com/gmail/nossr50/party/PartyManager.java +++ b/src/main/java/com/gmail/nossr50/party/PartyManager.java @@ -425,10 +425,8 @@ public final class PartyManager { * @param mcMMOPlayer The player to check * @return true if the player can invite */ - public static boolean canInvite(Player player, McMMOPlayer mcMMOPlayer) { - Party party = mcMMOPlayer.getParty(); - - if (party == null || (party.isLocked() && !party.getLeader().equals(player.getName()))) { + public static boolean canInvite(Player player, Party party) { + if (party.isLocked() && !party.getLeader().equals(player.getName())) { return false; } diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java index af95d89a6..72287ddfc 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java @@ -28,6 +28,7 @@ public class PartyCommand implements CommandExecutor { private CommandExecutor partyCreateCommand = new PartyCreateCommand(); private CommandExecutor partyQuitCommand = new PartyQuitCommand(); private CommandExecutor partyExpShareCommand = new PartyExpShareCommand(); + private CommandExecutor partyInviteCommand = new PartyInviteCommand(); @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -75,7 +76,7 @@ public class PartyCommand implements CommandExecutor { return shareItem(); } else if (args[0].equalsIgnoreCase("invite")) { - return invite(args); + return partyInviteCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("kick")) { return kick(args); @@ -191,49 +192,6 @@ public class PartyCommand implements CommandExecutor { return true; } - private boolean invite(String[] args) { - if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.invite")) { - return true; - } - - switch (args.length) { - case 2: - if (!mcMMOPlayer.inParty()) { - player.sendMessage(LocaleLoader.getString("Commands.Party.None")); - return true; - } - - Player target = mcMMO.p.getServer().getPlayer(args[1]); - - if (target != null) { - if (PartyManager.inSameParty(player, target)) { - player.sendMessage(LocaleLoader.getString("Party.Player.InSameParty", target.getName())); - return true; - } - - if (PartyManager.canInvite(player, mcMMOPlayer)) { - Party party = mcMMOPlayer.getParty(); - - Users.getPlayer(target).setPartyInvite(party); - player.sendMessage(LocaleLoader.getString("Commands.Invite.Success")); - target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.0", party.getName(), player.getName())); - target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.1")); - return true; - } - - player.sendMessage(LocaleLoader.getString("Party.Locked")); - return true; - } - - player.sendMessage(LocaleLoader.getString("Party.Player.Invalid")); - return true; - - default: - player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "invite", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">")); - return true; - } - } - /** * Kick a party member */ diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyInviteCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyInviteCommand.java new file mode 100644 index 000000000..cc49c9b26 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyInviteCommand.java @@ -0,0 +1,73 @@ +package com.gmail.nossr50.party.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.gmail.nossr50.mcMMO; +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.Permissions; +import com.gmail.nossr50.util.Users; + +public class PartyInviteCommand implements CommandExecutor { + private McMMOPlayer mcMMOTarget; + private Player target; + + private McMMOPlayer mcMMOPlayer; + private Player player; + private Party playerParty; + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!Permissions.hasPermission(sender, "mcmmo.commands.party.invite")) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + + switch (args.length) { + case 2: + if (!mcMMO.p.getServer().getOfflinePlayer(args[0]).isOnline()) { + sender.sendMessage(LocaleLoader.getString("Party.NotOnline", args[0])); + return false; + } + + mcMMOTarget = Users.getPlayer(args[0]); + + if (mcMMOTarget == null) { + sender.sendMessage(LocaleLoader.getString("Party.Player.Invalid")); + return false; + } + + target = mcMMOTarget.getPlayer(); + mcMMOPlayer = Users.getPlayer((Player) sender); + player = mcMMOPlayer.getPlayer(); + + if (PartyManager.inSameParty(player, target)) { + sender.sendMessage(LocaleLoader.getString("Party.Player.InSameParty", target.getName())); + return true; + } + + playerParty = mcMMOPlayer.getParty(); + + if (!PartyManager.canInvite(player, playerParty)) { + player.sendMessage(LocaleLoader.getString("Party.Locked")); + return true; + } + + mcMMOTarget.setPartyInvite(playerParty); + + sender.sendMessage(LocaleLoader.getString("Commands.Invite.Success")); + target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.0", playerParty.getName(), player.getName())); + target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.1")); + return true; + + default: + player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "invite", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">")); + return true; + } + } +}