From ae3a95dd34e79759c10a0a29f7faf36cdb6ae909 Mon Sep 17 00:00:00 2001 From: GJ Date: Fri, 8 Feb 2013 10:26:59 -0500 Subject: [PATCH] Convert /party quit to a subcommand --- .../nossr50/party/commands/PartyCommand.java | 28 +---------- .../party/commands/PartyQuitCommand.java | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/party/commands/PartyQuitCommand.java 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 abc3969b8..253bca793 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java @@ -26,6 +26,7 @@ public class PartyCommand implements CommandExecutor { private CommandExecutor partyJoinCommand = new PartyJoinCommand(); private CommandExecutor partyAcceptCommand = new PartyAcceptCommand(); private CommandExecutor partyCreateCommand = new PartyCreateCommand(); + private CommandExecutor partyQuitCommand = new PartyQuitCommand(); @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -59,7 +60,7 @@ public class PartyCommand implements CommandExecutor { if (mcMMOPlayer.inParty()) { if (args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase("q") || args[0].equalsIgnoreCase("leave")) { - return quit(); + return partyQuitCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("expshare")) { return shareExp(args); @@ -173,31 +174,6 @@ public class PartyCommand implements CommandExecutor { return true; } - private boolean quit() { - if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.quit")) { - return true; - } - - String playerName = player.getName(); - Party party = mcMMOPlayer.getParty(); - - if (party != null) { - McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), null, EventReason.LEFT_PARTY); - mcMMO.p.getServer().getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return true; - } - PartyManager.removeFromParty(playerName, party); - player.sendMessage(LocaleLoader.getString("Commands.Party.Leave")); - } - else { - player.sendMessage(LocaleLoader.getString("Commands.Party.None")); - } - - return false; - } - private boolean shareExp(String[] args) { if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.expshare")) { return true; diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyQuitCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyQuitCommand.java new file mode 100644 index 000000000..c64b0d6ca --- /dev/null +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyQuitCommand.java @@ -0,0 +1,49 @@ +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.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 PartyQuitCommand implements CommandExecutor { + 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.quit")) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + + switch (args.length) { + case 1: + player = (Player) sender; + playerParty = Users.getPlayer(player).getParty(); + + if (playerParty == null) { + sender.sendMessage(LocaleLoader.getString("Commands.Party.None")); + return true; + } + + if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), null, EventReason.LEFT_PARTY)) { + return true; + } + + PartyManager.removeFromParty(player.getName(), playerParty); + sender.sendMessage(LocaleLoader.getString("Commands.Party.Leave")); + return true; + + default: + sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "[quit|q|leave]")); + return true; + } + } +}