package net.sf.l2j.gameserver.communitybbs.Manager;
import java.util.StringTokenizer;
import javolution.text.TextBuilder;
import net.sf.l2j.gameserver.datatables.ClanTable;
import net.sf.l2j.gameserver.model.L2Clan;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.serverpackets.SystemMessage;
public class ClanBBSManager extends BaseBBSManager
{
private static ClanBBSManager _Instance = new ClanBBSManager();
/**
* @return
*/
public static ClanBBSManager getInstance()
{
return _Instance;
}
/**
* @param command
* @param activeChar
*/
public void parsecmd(String command, L2PcInstance activeChar)
{
if (command.equals("_bbsclan"))
{
if (activeChar.getClan() != null)
{
if (activeChar.getClan().getLevel() >= 2)
{
clanhome(activeChar);
}
else
{
clanlist(activeChar, 1);
}
}
else
{
clanlist(activeChar, 1);
}
}
else if (command.startsWith("_bbsclan_clanlist"))
{
if (command.equals("_bbsclan_clanlist"))
{
clanlist(activeChar, 1);
}
else if (command.startsWith("_bbsclan_clanlist;"))
{
StringTokenizer st = new StringTokenizer(command, ";");
st.nextToken();
int index = Integer.parseInt(st.nextToken());
clanlist(activeChar, index);
}
}
else if (command.startsWith("_bbsclan_clanhome"))
{
if (command.equals("_bbsclan_clanhome"))
{
clanhome(activeChar);
}
else if (command.startsWith("_bbsclan_clanhome;"))
{
StringTokenizer st = new StringTokenizer(command, ";");
st.nextToken();
int index = Integer.parseInt(st.nextToken());
clanhome(activeChar, index);
}
}
else
{
separateAndSend("
Commande : " + command
+ " pas encore implante ", activeChar);
}
}
/**
* @param activeChar
*/
private void clanlist(L2PcInstance activeChar, int index)
{
if (index < 1)
{
index = 1;
}
//header
TextBuilder html = new TextBuilder("");
html.append("");
html.append(" ");
html.append("");
html.append(" CLAN COMMUNITY ");
html.append("
");
html.append("");
html.append(" ");
html.append("");
html.append(" ");
html.append("");
html.append("[GO TO MY CLAN] ");
html.append(" ");
html.append(" ");
html.append(" ");
html.append(" ");
html.append("
");
//body
html.append(" ");
html.append("");
html.append("");
html.append(" ");
html.append("CLAN NAME ");
html.append("CLAN LEADER ");
html.append("CLAN LEVEL ");
html.append("CLAN MEMBERS ");
html.append(" ");
html.append(" ");
html.append("
");
html.append(" ");
int i = 0;
for (L2Clan cl : ClanTable.getInstance().getClans())
{
if(i > (index + 1)*7)
{
break;
}
if(i >= (index - 1)*7)
{
html.append(" ");
html.append("");
html.append(" ");
html.append(" ");
html.append("" + cl.getName() + " ");
html.append("" + cl.getLeaderName() + " ");
html.append("" + cl.getLevel() + " ");
html.append("" + cl.getMembersCount() + " ");
html.append(" ");
html.append(" ");
html.append(" ");
html.append("
");
html.append(" ");
html.append(" ");
}
i++;
}
html.append(" ");
html.append("");
if (index == 1)
{
html.append(" ");
}
else
{
html.append(" ");
}
i = 0;
int nbp;
nbp = ClanTable.getInstance().getClans().length / 8;
if (nbp * 8 != ClanTable.getInstance().getClans().length)
{
nbp++;
}
for (i = 1; i <= nbp; i++)
{
if (i == index)
{
html.append(" " + i + " ");
}
else
{
html.append(" " + i + " ");
}
}
if (index == nbp)
{
html.append(" ");
}
else
{
html.append(" ");
}
html.append("
");
html.append("");
html.append(" ");
html.append("
");
html.append(" ");
//TODO: search (Write in BBS)
html.append("
");
html.append(" ");
html.append(" ");
html.append(" ");
html.append("");
html.append("");
separateAndSend(html.toString(), activeChar);
}
/**
* @param activeChar
*/
private void clanhome(L2PcInstance activeChar)
{
clanhome(activeChar, activeChar.getClan().getClanId());
}
/**
* @param activeChar
* @param clanId
*/
private void clanhome(L2PcInstance activeChar, int clanId)
{
L2Clan cl = ClanTable.getInstance().getClan(clanId);
if (cl != null)
{
if (cl.getLevel() < 2)
{
activeChar.sendPacket(new SystemMessage(SystemMessage.NO_CB_IN_MY_CLAN));
parsecmd("_bbsclan_clanlist",activeChar);
}
else
{
TextBuilder html = new TextBuilder(" ");
html.append("");
html.append("");
html.append("");
html.append(" ");
html.append(" ");
html.append("");
html.append(" ");
html.append(" ");
html.append(" ");
html.append(" ");
html.append("");
html.append("");
html.append("");
html.append("CLAN NAME ");
html.append("" + cl.getName() + " ");
html.append(" ");
html.append(" ");
html.append("");
html.append("CLAN LEVEL ");
html.append("" + cl.getLevel() + " ");
html.append(" ");
html.append(" ");
html.append("");
html.append("CLAN MEMBERS ");
html.append("" + cl.getMembersCount() + " ");
html.append(" ");
html.append(" ");
html.append("");
html.append("CLAN LEADER ");
html.append("" + cl.getLeaderName() + " ");
html.append(" ");
html.append(" ");
//ADMINISTRATOR ??
/*html.append("");
html.append("ADMINISTRATOR ");
html.append(""+cl.getLeaderName()+" ");
html.append(" ");*/
html.append(" ");
html.append("");
html.append("ALLIANCE ");
html.append(""
+ ((cl.getAllyName() != null) ? cl.getAllyName() : "") + " ");
html.append(" ");
html.append("
");
html.append(" ");
html.append(" ");
html.append(" ");
html.append(" ");
html.append("
");
//TODO: the BB for clan :)
//html.append("");
html.append(" ");
html.append(" ");
html.append(" ");
html.append("");
html.append(" ");
html.append("");
html.append("");
separateAndSend(html.toString(), activeChar);
}
}
}
/* (non-Javadoc)
* @see net.sf.l2j.gameserver.communitybbs.Manager.BaseBBSManager#parsewrite(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance)
*/
@Override
public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
{
// TODO Auto-generated method stub
}
}