2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.commands.party;
|
|
|
|
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.datatypes.party.Party;
|
2013-03-12 21:25:42 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.party.PartyManager;
|
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
|
|
|
|
|
|
|
public class PartyRenameCommand implements CommandExecutor {
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
switch (args.length) {
|
|
|
|
case 2:
|
2013-03-12 21:25:42 +01:00
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
|
|
|
Party playerParty = mcMMOPlayer.getParty();
|
|
|
|
|
|
|
|
String oldPartyName = playerParty.getName();
|
2013-03-01 06:52:01 +01:00
|
|
|
String newPartyName = args[1];
|
|
|
|
|
|
|
|
// This is to prevent party leaders from spamming other players with the rename message
|
2013-03-12 21:25:42 +01:00
|
|
|
if (oldPartyName.equalsIgnoreCase(newPartyName)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Party.Rename.Same"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
2013-03-01 06:52:01 +01:00
|
|
|
Party newParty = PartyManager.getParty(newPartyName);
|
|
|
|
|
|
|
|
// Check to see if the party exists, and if it does cancel renaming the party
|
2013-03-12 21:25:42 +01:00
|
|
|
if (PartyManager.checkPartyExistence(player, newParty, newPartyName)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
String leaderName = playerParty.getLeader();
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
for (Player member : playerParty.getOnlineMembers()) {
|
2013-03-12 21:25:42 +01:00
|
|
|
if (!PartyManager.handlePartyChangeEvent(member, oldPartyName, newPartyName, EventReason.CHANGED_PARTIES)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-10 22:07:07 +01:00
|
|
|
if (!member.getName().equalsIgnoreCase(leaderName)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|