Fixed possible "array overflow" with /party kick

This commit is contained in:
bm01 2013-02-03 16:46:46 +01:00
parent e37e913f6a
commit 2de8962887

View File

@ -67,7 +67,7 @@ public class PartyCommand implements CommandExecutor {
return invite(args); return invite(args);
} }
else if (args[0].equalsIgnoreCase("kick")) { else if (args[0].equalsIgnoreCase("kick")) {
return kick(args[1]); return kick(args);
} }
else if (args[0].equalsIgnoreCase("disband")) { else if (args[0].equalsIgnoreCase("disband")) {
return disband(); return disband();
@ -449,21 +449,23 @@ public class PartyCommand implements CommandExecutor {
/** /**
* Kick a party member * Kick a party member
*/ */
private boolean kick(String targetName) { private boolean kick(String[] args) {
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.kick")) { if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.kick")) {
return true; return true;
} }
switch (args.length) {
case 2:
String playerName = player.getName(); String playerName = player.getName();
Party party = mcMMOPlayer.getParty(); Party party = mcMMOPlayer.getParty();
if (party.getLeader().equals(playerName)) { if (party.getLeader().equals(playerName)) {
if (!party.getMembers().contains(targetName)) { if (!party.getMembers().contains(args[1])) {
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName)); player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1]));
return true; return true;
} }
Player target = mcMMO.p.getServer().getOfflinePlayer(targetName).getPlayer(); Player target = mcMMO.p.getServer().getOfflinePlayer(args[1]).getPlayer();
if (target != null) { if (target != null) {
String partyName = party.getName(); String partyName = party.getName();
@ -478,13 +480,18 @@ public class PartyCommand implements CommandExecutor {
target.sendMessage(LocaleLoader.getString("Commands.Party.Kick", partyName)); target.sendMessage(LocaleLoader.getString("Commands.Party.Kick", partyName));
} }
PartyManager.removeFromParty(targetName, party); PartyManager.removeFromParty(args[1], party);
} }
else { else {
player.sendMessage(LocaleLoader.getString("Party.NotOwner")); player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
} }
return true; return true;
default:
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "invite", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
return true;
}
} }
/** /**
@ -531,7 +538,7 @@ public class PartyCommand implements CommandExecutor {
Party party = mcMMOPlayer.getParty(); Party party = mcMMOPlayer.getParty();
if (args.length < 2) { if (args.length < 2) {
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "owner", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]")); player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "kick", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]"));
return true; return true;
} }