From 1c0e3925527acad5e66c8db8b1dfe18e005a6f0c Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 11 Feb 2013 15:19:41 -0500 Subject: [PATCH] Convert /party disband to a subcommand --- .../nossr50/party/commands/PartyCommand.java | 35 +------------- .../party/commands/PartyDisbandCommand.java | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+), 33 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/party/commands/PartyDisbandCommand.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 8dcdedad5..12144ba1b 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java @@ -31,6 +31,7 @@ public class PartyCommand implements CommandExecutor { private CommandExecutor partyItemShareCommand = new PartyItemShareCommand(); private CommandExecutor partyInviteCommand = new PartyInviteCommand(); private CommandExecutor partyKickCommand = new PartyKickCommand(); + private CommandExecutor partyDisbandCommand = new PartyDisbandCommand(); @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -84,7 +85,7 @@ public class PartyCommand implements CommandExecutor { return partyKickCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("disband")) { - return disband(); + return partyDisbandCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("owner")) { return changeOwner(args); @@ -189,38 +190,6 @@ public class PartyCommand implements CommandExecutor { return true; } - /** - * Disband the current party, kicks out all party members. - */ - private boolean disband() { - if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.disband")) { - return true; - } - - String playerName = player.getName(); - Party party = mcMMOPlayer.getParty(); - - if (party.getLeader().equals(playerName)) { - for (Player onlineMembers : party.getOnlineMembers()) { - McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(onlineMembers, party.getName(), null, EventReason.KICKED_FROM_PARTY); - mcMMO.p.getServer().getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return true; - } - - onlineMembers.sendMessage(LocaleLoader.getString("Party.Disband")); - } - - PartyManager.disbandParty(party); - } - else { - player.sendMessage(LocaleLoader.getString("Party.NotOwner")); - } - - return true; - } - /** * Change the owner of the current party */ diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyDisbandCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyDisbandCommand.java new file mode 100644 index 000000000..839ca7370 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyDisbandCommand.java @@ -0,0 +1,47 @@ +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 PartyDisbandCommand 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.disband")) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + + player = (Player) sender; + playerParty = Users.getPlayer(player).getParty(); + + if (!playerParty.getLeader().equals(player.getName())) { + sender.sendMessage(LocaleLoader.getString("Party.NotOwner")); + return true; + } + + for (Player member : playerParty.getOnlineMembers()) { + if (!PartyManager.handlePartyChangeEvent(member, playerParty.getName(), null, EventReason.KICKED_FROM_PARTY)) { + return true; + } + + member.sendMessage(LocaleLoader.getString("Party.Disband")); + } + + PartyManager.disbandParty(playerParty); + return true; + + } + +}