Change /party accept to a subcommand.

This commit is contained in:
GJ 2013-02-07 22:09:43 -05:00
parent 9de6b4724a
commit 70ba4a0f3d
2 changed files with 61 additions and 37 deletions

View File

@ -0,0 +1,60 @@
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.datatypes.McMMOPlayer;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
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 PartyAcceptCommand implements CommandExecutor {
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.accept")) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
switch (args.length) {
case 1:
player = (Player) sender;
mcMMOPlayer = Users.getPlayer(player);
if (!mcMMOPlayer.hasPartyInvite()) {
sender.sendMessage(LocaleLoader.getString("mcMMO.NoInvites"));
return true;
}
// Changing parties
if (mcMMOPlayer.inParty()) {
playerParty = mcMMOPlayer.getParty();
if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), mcMMOPlayer.getPartyInvite().getName(), EventReason.CHANGED_PARTIES)) {
return true;
}
PartyManager.removeFromParty(player.getName(), playerParty);
}
else if (!PartyManager.handlePartyChangeEvent(player, null, mcMMOPlayer.getPartyInvite().getName(), EventReason.JOINED_PARTY)) {
return true;
}
PartyManager.joinInvitedParty(player, mcMMOPlayer);
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "accept"));
return true;
}
}
}

View File

@ -47,7 +47,7 @@ public class PartyCommand implements CommandExecutor {
return partyJoinCommand.onCommand(sender, command, label, args); return partyJoinCommand.onCommand(sender, command, label, args);
} }
else if (args[0].equalsIgnoreCase("accept")) { else if (args[0].equalsIgnoreCase("accept")) {
return accept(); return partyAcceptCommand.onCommand(sender, command, label, args);
} }
else if (args[0].equalsIgnoreCase("create")) { else if (args[0].equalsIgnoreCase("create")) {
return create(args); return create(args);
@ -172,42 +172,6 @@ public class PartyCommand implements CommandExecutor {
return true; return true;
} }
private boolean accept() {
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.accept")) {
return true;
}
if (mcMMOPlayer.hasPartyInvite()) {
if (mcMMOPlayer.inParty()) {
Party party = mcMMOPlayer.getParty();
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), mcMMOPlayer.getPartyInvite().getName(), EventReason.CHANGED_PARTIES);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
PartyManager.removeFromParty(player.getName(), party);
}
else {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, mcMMOPlayer.getPartyInvite().getName(), EventReason.JOINED_PARTY);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
}
PartyManager.joinInvitedParty(player, mcMMOPlayer);
}
else {
player.sendMessage(LocaleLoader.getString("mcMMO.NoInvites"));
}
return true;
}
private boolean create(String[] args) { private boolean create(String[] args) {
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.create")) { if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.create")) {
return true; return true;