Convert /party rename to a subcommand

This commit is contained in:
GJ 2013-02-12 09:22:57 -05:00
parent 200ac53078
commit e92c6b8f26
3 changed files with 68 additions and 59 deletions

View File

@ -7,12 +7,9 @@ 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.config.Config;
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;
@ -35,6 +32,7 @@ public class PartyCommand implements CommandExecutor {
private CommandExecutor partyChangeOwnerCommand = new PartyChangeOwnerCommand();
private CommandExecutor partyLockCommand = new PartyLockCommand();
private CommandExecutor partyChangePasswordCommand = new PartyChangePasswordCommand();
private CommandExecutor partyRenameCommand = new PartyRenameCommand();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -106,7 +104,7 @@ public class PartyCommand implements CommandExecutor {
return partyChangePasswordCommand.onCommand(sender, command, label, args);
}
else if (args[0].equalsIgnoreCase("rename")) {
return rename(args);
return partyRenameCommand.onCommand(sender, command, label, args);
}
else {
return printUsage();
@ -195,59 +193,4 @@ public class PartyCommand implements CommandExecutor {
player.sendMessage(LocaleLoader.getString("Party.Help.8"));
return true;
}
/**
* Rename the current party
*/
private boolean rename(String[] args) {
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.rename")) {
return true;
}
String playerName = player.getName();
Party party = mcMMOPlayer.getParty();
String leader = party.getLeader();
if (party.getLeader().equals(playerName)) {
if (args.length < 2) {
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "rename", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">"));
return true;
}
String newPartyName = args[1];
// This is to prevent party leaders from spamming other players with the rename message
if (!party.getName().equals(newPartyName)) {
Party newParty = PartyManager.getParty(newPartyName);
// Check to see if the party exists, and if it does cancel renaming the party
if (newParty != null) {
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", newPartyName));
return true;
}
for (Player onlineMembers : party.getOnlineMembers()) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(onlineMembers, party.getName(), newPartyName, EventReason.CHANGED_PARTIES);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
if (!onlineMembers.getName().equals(leader)) {
onlineMembers.sendMessage(LocaleLoader.getString("Party.InformedOnNameChange", leader, newPartyName));
}
}
party.setName(newPartyName);
}
player.sendMessage(LocaleLoader.getString("Commands.Party.Rename", newPartyName));
}
else {
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
}
return true;
}
}

View File

@ -0,0 +1,65 @@
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 PartyRenameCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Permissions.hasPermission(sender, "mcmmo.commands.party.rename")) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
Party playerParty = Users.getPlayer((Player) sender).getParty();
String leaderName = playerParty.getLeader();
switch (args.length) {
case 2:
String newPartyName = args[1];
// This is to prevent party leaders from spamming other players with the rename message
if (playerParty.getName().equalsIgnoreCase(newPartyName)) {
sender.sendMessage(LocaleLoader.getString("Party.Rename.Same"));
return true;
}
Party newParty = PartyManager.getParty(newPartyName);
// Check to see if the party exists, and if it does cancel renaming the party
if (newParty != null) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", newPartyName));
return true;
}
for (Player member : playerParty.getOnlineMembers()) {
if (!PartyManager.handlePartyChangeEvent(member, playerParty.getName(), newPartyName, EventReason.CHANGED_PARTIES)) {
return true;
}
if (!member.getName().equals(leaderName)) {
member.sendMessage(LocaleLoader.getString("Party.InformedOnNameChange", leaderName, newPartyName));
}
}
playerParty.setName(newPartyName);
sender.sendMessage(LocaleLoader.getString("Commands.Party.Rename", newPartyName));
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "rename", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">"));
return true;
}
}
}

View File

@ -543,6 +543,7 @@ Party.Teleport.Player=[[GREEN]]You have teleported to {0}.
Party.Teleport.Self=[[RED]]You can't teleport to yourself!
Party.Teleport.Target=[[GREEN]]{0} has teleported to you.
Party.Teleport.Disabled=[[RED]]{0} doesn't allow party teleportation.
Party.Rename.Same=[[RED]]That is already the name of your party!
Party.Join.Self=[[RED]]You can't join to yourself!
Party.Unlocked=[[GRAY]]Party is unlocked
Party.Disband=[[GRAY]]The party has been disbanded