From 5da51e78cc3905849a4a47843e49de46683afb0c Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 11 Feb 2013 00:25:03 -0500 Subject: [PATCH] Change /party kick to a subcommand --- .../nossr50/party/commands/PartyCommand.java | 52 +----------- .../party/commands/PartyKickCommand.java | 81 +++++++++++++++++++ 2 files changed, 83 insertions(+), 50 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/party/commands/PartyKickCommand.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 030f63063..8dcdedad5 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java @@ -30,6 +30,7 @@ public class PartyCommand implements CommandExecutor { private CommandExecutor partyExpShareCommand = new PartyExpShareCommand(); private CommandExecutor partyItemShareCommand = new PartyItemShareCommand(); private CommandExecutor partyInviteCommand = new PartyInviteCommand(); + private CommandExecutor partyKickCommand = new PartyKickCommand(); @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -80,7 +81,7 @@ public class PartyCommand implements CommandExecutor { return partyInviteCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("kick")) { - return kick(args); + return partyKickCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("disband")) { return disband(); @@ -188,55 +189,6 @@ public class PartyCommand implements CommandExecutor { return true; } - /** - * Kick a party member - */ - private boolean kick(String[] args) { - if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.kick")) { - return true; - } - - switch (args.length) { - case 2: - String playerName = player.getName(); - Party party = mcMMOPlayer.getParty(); - - if (party.getLeader().equals(playerName)) { - OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(args[1]); - - if (!party.getMembers().contains(member)) { - player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1])); - return true; - } - - if (member.isOnline()) { - Player onlineMember = member.getPlayer(); - String partyName = party.getName(); - McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(onlineMember, partyName, null, EventReason.KICKED_FROM_PARTY); - - mcMMO.p.getServer().getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return true; - } - - onlineMember.sendMessage(LocaleLoader.getString("Commands.Party.Kick", partyName)); - } - - PartyManager.removeFromParty(member, party); - } - else { - player.sendMessage(LocaleLoader.getString("Party.NotOwner")); - } - - return true; - - default: - player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "kick", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">")); - return true; - } - } - /** * Disband the current party, kicks out all party members. */ diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyKickCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyKickCommand.java new file mode 100644 index 000000000..1b30b773e --- /dev/null +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyKickCommand.java @@ -0,0 +1,81 @@ +package com.gmail.nossr50.party.commands; + +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.commands.CommandHelper; +import com.gmail.nossr50.datatypes.McMMOPlayer; +import com.gmail.nossr50.events.party.McMMOPartyChangeEvent; +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 PartyKickCommand 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.kick")) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + + switch (args.length) { + case 2: + player = (Player) sender; + playerParty = Users.getPlayer(player).getParty(); + + if (!playerParty.getLeader().equals(player.getName())) { + sender.sendMessage(LocaleLoader.getString("Party.NotOwner")); + return true; + } + + McMMOPlayer mcMMOTarget = Users.getPlayer(args[1]); + + // Would be nice to find a way to check if a player is valid here - this won't work directly because it'll also throw null for an offline player +// if (mcMMOTarget == null) { +// sender.sendMessage(LocaleLoader.getString("Party.Player.Invalid")); +// return false; +// } + + Player target = mcMMOTarget.getPlayer(); + + if (!PartyManager.inSameParty(player, target)) { + sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1])); + return true; + } + + if (mcMMO.p.getServer().getOfflinePlayer(args[1]).isOnline()) { + String partyName = playerParty.getName(); + + McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(target, partyName, null, EventReason.KICKED_FROM_PARTY); + mcMMO.p.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return true; + } + + target.sendMessage(LocaleLoader.getString("Commands.Party.Kick", partyName)); + } + + PartyManager.removeFromParty(target, playerParty); + return true; + + default: + sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "kick", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">")); + return true; + } + + // TODO Auto-generated method stub + return false; + } + +}