package com.gmail.nossr50.commands.party; import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.PartyMember; import com.neetgames.mcmmo.player.OnlineMMOPlayer; import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; public class PartyRenameCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { if (args.length == 2) { if (mcMMO.getUserManager().queryPlayer((Player) sender) == null) { sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad")); return true; } OnlineMMOPlayer mmoPlayer = mcMMO.getUserManager().queryPlayer((Player) sender); Party playerParty = mmoPlayer.getParty(); String oldPartyName = playerParty.getPartyName(); String newPartyName = args[1]; // This is to prevent party leaders from spamming other players with the rename message if (oldPartyName.equalsIgnoreCase(newPartyName)) { sender.sendMessage(LocaleLoader.getString("Party.Rename.Same")); return true; } Player player = Misc.adaptPlayer(mmoPlayer); // Check to see if the party exists, and if it does cancel renaming the party if (mcMMO.getPartyManager().isParty(newPartyName)) { player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", newPartyName)); return true; } String leaderName = playerParty.getLeader().getPlayerName(); for (PartyMember partyMember : playerParty.getPartyMembers()) { if (!mcMMO.getPartyManager().handlePartyChangeEvent(partyMember, oldPartyName, newPartyName, EventReason.CHANGED_PARTIES)) { return true; } if (!partyMember.getName().equalsIgnoreCase(leaderName)) { partyMember.sendMessage(LocaleLoader.getString("Party.InformedOnNameChange", leaderName, newPartyName)); } } playerParty.setPartyName(newPartyName); sender.sendMessage(LocaleLoader.getString("Commands.Party.Rename", newPartyName)); return true; } sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "rename", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">")); return true; } }