Switch /party invite to a subcommand

This commit is contained in:
GJ 2013-02-08 16:56:54 -05:00
parent ae5f39253e
commit 340c47eebd
3 changed files with 77 additions and 48 deletions

View File

@ -425,10 +425,8 @@ public final class PartyManager {
* @param mcMMOPlayer The player to check * @param mcMMOPlayer The player to check
* @return true if the player can invite * @return true if the player can invite
*/ */
public static boolean canInvite(Player player, McMMOPlayer mcMMOPlayer) { public static boolean canInvite(Player player, Party party) {
Party party = mcMMOPlayer.getParty(); if (party.isLocked() && !party.getLeader().equals(player.getName())) {
if (party == null || (party.isLocked() && !party.getLeader().equals(player.getName()))) {
return false; return false;
} }

View File

@ -28,6 +28,7 @@ public class PartyCommand implements CommandExecutor {
private CommandExecutor partyCreateCommand = new PartyCreateCommand(); private CommandExecutor partyCreateCommand = new PartyCreateCommand();
private CommandExecutor partyQuitCommand = new PartyQuitCommand(); private CommandExecutor partyQuitCommand = new PartyQuitCommand();
private CommandExecutor partyExpShareCommand = new PartyExpShareCommand(); private CommandExecutor partyExpShareCommand = new PartyExpShareCommand();
private CommandExecutor partyInviteCommand = new PartyInviteCommand();
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -75,7 +76,7 @@ public class PartyCommand implements CommandExecutor {
return shareItem(); return shareItem();
} }
else if (args[0].equalsIgnoreCase("invite")) { else if (args[0].equalsIgnoreCase("invite")) {
return invite(args); return partyInviteCommand.onCommand(sender, command, label, args);
} }
else if (args[0].equalsIgnoreCase("kick")) { else if (args[0].equalsIgnoreCase("kick")) {
return kick(args); return kick(args);
@ -191,49 +192,6 @@ public class PartyCommand implements CommandExecutor {
return true; 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 * Kick a party member
*/ */

View File

@ -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;
}
}
}