From 70ba4a0f3d4cc5e1676790c6514ae036bca66e7a Mon Sep 17 00:00:00 2001 From: GJ Date: Thu, 7 Feb 2013 22:09:43 -0500 Subject: [PATCH] Change /party accept to a subcommand. --- .../party/commands/PartyAcceptCommand.java | 60 +++++++++++++++++++ .../nossr50/party/commands/PartyCommand.java | 38 +----------- 2 files changed, 61 insertions(+), 37 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/party/commands/PartyAcceptCommand.java diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyAcceptCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyAcceptCommand.java new file mode 100644 index 000000000..01c3514d1 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyAcceptCommand.java @@ -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; + } + } +} 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 121638973..e8993e944 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java @@ -47,7 +47,7 @@ public class PartyCommand implements CommandExecutor { return partyJoinCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("accept")) { - return accept(); + return partyAcceptCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("create")) { return create(args); @@ -172,42 +172,6 @@ public class PartyCommand implements CommandExecutor { 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) { if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.create")) { return true;