}
public void createSubPledge(L2Player player, String clanName, int pledgeType, int minClanLvl, String leaderName)
{
int subLeaderId = 0;
L2ClanMember subLeader = null;
L2Clan clan = player.getClan();
if(clan == null || !player.isClanLeader())
{
player.sendPacket(Msg.YOU_HAVE_FAILED_TO_CREATE_A_CLAN);
return;
}
if(!Util.isMatchingRegexp(clanName, Config.CLAN_NAME_TEMPLATE))
{
player.sendPacket(Msg.CLAN_NAME_IS_INCORRECT);
return;
}
SubPledge[] subPledge = clan.getAllSubPledges();
for(SubPledge element : subPledge)
{
if(element.getName().equals(clanName))
{
player.sendPacket(Msg.ANOTHER_MILITARY_UNIT_IS_ALREADY_USING_THAT_NAME_PLEASE_ENTER_A_DIFFERENT_NAME);
return;
}
}
if(ClanTable.getInstance().getClanByName(clanName) != null)
{
player.sendPacket(Msg.ANOTHER_MILITARY_UNIT_IS_ALREADY_USING_THAT_NAME_PLEASE_ENTER_A_DIFFERENT_NAME);
return;
}
if(clan.getLevel() < minClanLvl)
{
player.sendPacket(Msg.THE_CONDITIONS_NECESSARY_TO_CREATE_A_MILITARY_UNIT_HAVE_NOT_BEEN_MET);
return;
}
if(pledgeType != L2Clan.SUBUNIT_ACADEMY)
{
subLeader = clan.getClanMember(leaderName);
if(subLeader == null || subLeader.getPledgeType() != L2Clan.SUBUNIT_NONE)
{
player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2VillageMasterInstance.PlayerCantBeAssignedAsSubUnitLeader", player));
return;
}
else if(subLeader.isClanLeader())
{
player.sendMessage(new CustomMessage("l2p.gameserver.model.instances.L2VillageMasterInstance.YouCantBeASubUnitLeader", player));
return;
}
else
{
subLeaderId = subLeader.getObjectId();
}
}
pledgeType = clan.createSubPledge(player, pledgeType, subLeaderId, clanName);
if(pledgeType == L2Clan.SUBUNIT_NONE)
{
return;
}
clan.broadcastToOnlineMembers(new PledgeReceiveSubPledgeCreated(clan.getSubPledge(pledgeType)));
SystemMessage sm;
if(pledgeType == L2Clan.SUBUNIT_ACADEMY)
{
sm = new SystemMessage(SystemMessage.CONGRATULATIONS_THE_S1S_CLAN_ACADEMY_HAS_BEEN_CREATED);
sm.addString(player.getClan().getName());
}
else if(pledgeType >= L2Clan.SUBUNIT_KNIGHT1)
{
sm = new SystemMessage(SystemMessage.THE_KNIGHTS_OF_S1_HAVE_BEEN_CREATED);
sm.addString(player.getClan().getName());
}
else if(pledgeType >= L2Clan.SUBUNIT_ROYAL1)
{
sm = new SystemMessage(SystemMessage.THE_ROYAL_GUARD_OF_S1_HAVE_BEEN_CREATED);
sm.addString(player.getClan().getName());
}
else
{
sm = Msg.CLAN_HAS_BEEN_CREATED;
}
player.sendPacket(sm);
if(subLeader != null)
{
clan.broadcastToOnlineMembers(new PledgeShowMemberListUpdate(subLeader));
if(subLeader.isOnline())
{
subLeader.getPlayer().updatePledgeClass();
subLeader.getPlayer().broadcastUserInfo(true);
}
}
}