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