Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P L2J_Server_BETA
- Index: java/com/l2jserver/gameserver/network/serverpackets/NpcHtmlMessage.java
- ===================================================================
- --- java/com/l2jserver/gameserver/network/serverpackets/NpcHtmlMessage.java (revision 4769)
- +++ java/com/l2jserver/gameserver/network/serverpackets/NpcHtmlMessage.java (working copy)
- @@ -236,6 +236,11 @@
- }
- }
- + public String getHTML()
- + {
- + return _html;
- + }
- +
- @Override
- protected final void writeImpl()
- {
- #P L2J_DataPack_BETA
- Index: data/scripts/custom/ClanSearcher/ClanSearcher.java
- ===================================================================
- --- data/scripts/custom/ClanSearcher/ClanSearcher.java (revision 0)
- +++ data/scripts/custom/ClanSearcher/ClanSearcher.java (revision 0)
- @@ -0,0 +1,379 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package custom.ClanSearcher;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.sql.SQLException;
- +import java.util.List;
- +import java.util.Map;
- +
- +import javolution.util.FastList;
- +import javolution.util.FastMap;
- +
- +import com.l2jserver.L2DatabaseFactory;
- +import com.l2jserver.gameserver.datatables.ClanTable;
- +import com.l2jserver.gameserver.instancemanager.QuestManager;
- +import com.l2jserver.gameserver.model.L2Clan;
- +import com.l2jserver.gameserver.model.L2ClanMember;
- +import com.l2jserver.gameserver.model.actor.L2Npc;
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.model.quest.Quest;
- +import com.l2jserver.gameserver.model.quest.QuestState;
- +import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
- +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
- +import com.l2jserver.gameserver.network.serverpackets.ShowBoard;
- +
- +/*
- + * @author Horato
- + */
- +public class ClanSearcher extends Quest
- +{
- + private static final int NpcId = 152036;
- +
- + public ClanSearcher(int questId, String name, String descr)
- + {
- + super(questId, name, descr);
- + addFirstTalkId(NpcId);
- + addTalkId(NpcId);
- + addStartNpc(NpcId);
- + }
- +
- + @Override
- + public String onTalk(L2Npc npc, L2PcInstance player)
- + {
- + talk(npc, player);
- + return "";
- + }
- +
- + @Override
- + public String onFirstTalk(L2Npc npc, L2PcInstance player)
- + {
- + talk(npc, player);
- + return "";
- + }
- +
- + @Override
- + public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
- + {
- + if (event.startsWith("show_list"))
- + {
- + loadClansAndShowWindow(npc, player, 1);
- + }
- + else if (event.startsWith("add"))
- + {
- + saveClanPresentation(event, npc, player);
- + }
- + else if (event.startsWith("moreinfo_"))
- + {
- + showMoreClanInfo(event, npc, player);
- + }
- + else if (event.startsWith("requestjoin_"))
- + {
- + sendClanJoinRequest(event, npc, player);
- + }
- + else if (event.startsWith("remove"))
- + {
- + removeClanPresentation(npc, player);
- + }
- + else if (event.startsWith("newclan.htm"))
- + {
- + NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
- + html.setFile(player.getHtmlPrefix(), "data/scripts/custom/ClanSearcher/newclan.htm");
- + html.replace("%clanname%", player.getClan().getName());
- + html.replace("%clanlevel%", "" + player.getClan().getLevel());
- + html.replace("%clanleader%", player.getClan().getLeaderName());
- +
- + sendCBHtml(player, html.getHTML(), loadClansAndShowWindow(npc, player, 2));
- + }
- + else if (event.startsWith("deleteclan.htm"))
- + {
- + NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
- + html.setFile(player.getHtmlPrefix(), "data/scripts/custom/ClanSearcher/deleteclan.htm");
- + sendCBHtml(player, html.getHTML());
- + }
- + return "";
- + }
- +
- + private void removeClanPresentation(L2Npc npc, L2PcInstance player)
- + {
- + Connection con = null;
- + try
- + {
- + con = L2DatabaseFactory.getInstance().getConnection();
- + PreparedStatement statement = con.prepareStatement("DELETE FROM clan_search WHERE clanId=?");
- + statement.setInt(1, player.getClanId());
- + statement.execute();
- + sendCBHtml(player, "<html><body><br> Your presentation has been deleted.</body></html>");
- + statement.close();
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + finally
- + {
- + L2DatabaseFactory.close(con);
- + }
- + }
- +
- + private void sendClanJoinRequest(String event, L2Npc npc, L2PcInstance requester)
- + {
- + L2Clan clan = ClanTable.getInstance().getClan(Integer.parseInt(event.split("_")[1]));
- + String text = "Player " + requester.getName() + " requested to join your clan. If you agree type .claninvite " + requester.getName() + " <subpledgeName>";
- + int success = 0;
- + for (L2ClanMember member : clan.getMembers())
- + {
- + if (member.getPlayerInstance() == null && !member.isOnline())
- + continue;
- + L2PcInstance player = member.getPlayerInstance();
- +
- + if ((player.getClanPrivileges() & L2Clan.CP_CL_JOIN_CLAN) == L2Clan.CP_CL_JOIN_CLAN)
- + {
- + player.sendPacket(new CreatureSay(player.getObjectId(), 2, player.getName(), text));
- + success++;
- + }
- + }
- + if (success > 0)
- + sendCBHtml(requester, "<html><body><br> Your request was successfully send.</body></html>");
- + else
- + sendCBHtml(requester, "<html><body><br> Nobody was able to see your request, try it again later.</body></html>");
- + }
- +
- + private void showMoreClanInfo(String event, L2Npc npc, L2PcInstance player)
- + {
- + Connection con = null;
- + StringBuilder sb = new StringBuilder();
- + try
- + {
- + con = L2DatabaseFactory.getInstance().getConnection();
- + PreparedStatement statement = con.prepareStatement("SELECT * FROM clan_search WHERE clanId=?");
- + statement.setInt(1, Integer.parseInt(event.split("_")[1]));
- + final ResultSet set = statement.executeQuery();
- +
- + if (set.next())
- + {
- + L2Clan clan = ClanTable.getInstance().getClan(set.getInt("clanId"));
- + String message = set.getString("message");
- + sb.append("<html><body><br><table border=\"0\" width=\"280\">");
- + sb.append("<tr><td width=\"93\">Clan Name</td><td width=\"93\">Clan Level</td><td width=\"94\">Clan Leader</td></tr>");
- + sb.append("<tr><td>" + clan.getName() + "</td><td>" + clan.getLevel() + "</td><td>" + clan.getLeaderName() + "</td></tr></table>");
- + sb.append("<br> " + message + "<br><br>");
- + sb.append(" <a action=\"bypass -h Quest ClanSearcher requestjoin_" + clan.getClanId() + "\">Send invitation request</a>");
- + sb.append("</body></html>");
- + sendCBHtml(player, sb.toString());
- + }
- + statement.close();
- + set.close();
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + finally
- + {
- + L2DatabaseFactory.close(con);
- + }
- + }
- +
- + private void saveClanPresentation(String event, L2Npc npc, L2PcInstance player)
- + {
- + if (event.length() < 5)
- + return;
- + Connection con = null;
- + String message = null;
- + try
- + {
- + con = L2DatabaseFactory.getInstance().getConnection();
- + PreparedStatement statement = con.prepareStatement("INSERT INTO clan_search (clanId,message) values (?,?) ON DUPLICATE KEY UPDATE clanId=?,message=?");
- + message = event.substring(4);
- + message = message.replaceAll("\n", "<br>");
- + statement.setInt(1, player.getClanId());
- + statement.setString(2, message);
- + statement.setInt(3, player.getClanId());
- + statement.setString(4, message);
- + statement.execute();
- + statement.close();
- + sendCBHtml(player, "<html><body><br> Your presentation has been saved.</body></html>");
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + finally
- + {
- + L2DatabaseFactory.close(con);
- + }
- + }
- +
- + private String loadClansAndShowWindow(L2Npc npc, L2PcInstance player, int mode)
- + {
- + Connection con = null;
- + StringBuilder sb = new StringBuilder();
- + try
- + {
- + L2Clan clan = null;
- + Map<L2Clan, String> clans = new FastMap<L2Clan, String>();
- + con = L2DatabaseFactory.getInstance().getConnection();
- + final ResultSet set = con.prepareStatement("SELECT * FROM clan_search ORDER BY clanId").executeQuery();
- + while (set.next())
- + {
- + clan = ClanTable.getInstance().getClan(set.getInt("clanId"));
- + if (clan == null)
- + continue;
- + clans.put(clan, set.getString("message"));
- + }
- + set.close();
- + if (mode == 2)
- + {
- + return clans.get(player.getClan());
- + }
- + sb.append("<html><body><br><table border=\"0\" width=\"280\">");
- + sb.append("<tr><td width=\"70\">Clan Name</td><td width=\"70\">Clan Level</td><td width=\"70\">Clan Leader</td><td width=\"70\"> </td></tr>");
- + for (Map.Entry<L2Clan, String> entry : clans.entrySet())
- + {
- + if (entry.getKey() == null)
- + continue;
- + sb.append("<tr><td>" + entry.getKey().getName() + "</td><td>" + entry.getKey().getLevel() + "</td><td>" + entry.getKey().getLeaderName() + "</td><td><a action=\"bypass -h Quest ClanSearcher moreinfo_" + entry.getKey().getClanId() + "\">More Info</a></td></tr>");
- + }
- + sb.append("</table></body></html>");
- + sendCBHtml(player, sb.toString());
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + finally
- + {
- + L2DatabaseFactory.close(con);
- + }
- + return "";
- + }
- +
- + private void talk(L2Npc npc, L2PcInstance player)
- + {
- + if (npc.getNpcId() == NpcId)
- + {
- + QuestState qs = player.getQuestState("ClanSearcher");
- + if (qs == null)
- + QuestManager.getInstance().getQuest("ClanSearcher").newQuestState(player);
- +
- + NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
- + html.setFile(player.getHtmlPrefix(), "data/scripts/custom/ClanSearcher/1.htm");
- + html.replace("%player%", player.getName());
- +
- + if (player.getClan() == null)
- + html.replace("%text%", "Iam here to help you find a clan. Good luck!");
- + else if (player.isClanLeader())
- + html.replace("%text%", "Do you wish to present your clan?");
- + else
- + html.replace("%text%", "Do you want see your concurence?");
- +
- + if (player.isClanLeader())
- + {
- + html.replace("%add%", "<a action=\"bypass -h Quest ClanSearcher newclan.htm\">Add/Change clan presentation</a>");
- + html.replace("%remove%", "<a action=\"bypass -h Quest ClanSearcher deleteclan.htm\">Remove clan presentation</a>");
- + }
- + else
- + {
- + html.replace("%add%", "");
- + html.replace("%remove%", "");
- + }
- + sendCBHtml(player, html.getHTML());
- + }
- + }
- +
- + private final void sendCBHtml(L2PcInstance activeChar, String html)
- + {
- + sendCBHtml(activeChar, html, "");
- + }
- +
- + private final void sendCBHtml(L2PcInstance activeChar, String html, String fillMultiEdit)
- + {
- + if (activeChar == null)
- + return;
- +
- + if (html != null)
- + {
- + activeChar.clearBypass();
- + int len = html.length();
- + for (int i = 0; i < len; i++)
- + {
- + int start = html.indexOf("\"bypass ", i);
- + int finish = html.indexOf("\"", start + 1);
- + if (start < 0 || finish < 0)
- + break;
- +
- + if (html.substring(start + 8, start + 10).equals("-h"))
- + start += 11;
- + else
- + start += 8;
- +
- + i = finish;
- + int finish2 = html.indexOf("$", start);
- + if (finish2 < finish && finish2 > 0)
- + activeChar.addBypass2(html.substring(start, finish2).trim());
- + else
- + activeChar.addBypass(html.substring(start, finish).trim());
- + }
- + }
- +
- + if (fillMultiEdit != null)
- + {
- + activeChar.sendPacket(new ShowBoard(html, "1001"));
- + fillMultiEditContent(activeChar, fillMultiEdit);
- + }
- + else
- + {
- + activeChar.sendPacket(new ShowBoard(null, "101"));
- + activeChar.sendPacket(new ShowBoard(html, "101"));
- + activeChar.sendPacket(new ShowBoard(null, "102"));
- + activeChar.sendPacket(new ShowBoard(null, "103"));
- + }
- + }
- +
- + /**
- + *
- + * Must send after sendCBHtml
- + */
- + private void fillMultiEditContent(L2PcInstance activeChar, String text)
- + {
- + List<String> _arg = new FastList<String>();
- + _arg.add("0");
- + _arg.add("0");
- + _arg.add("0");
- + _arg.add("0");
- + _arg.add("0");
- + _arg.add("0");
- + _arg.add(activeChar.getName());
- + _arg.add(Integer.toString(activeChar.getObjectId()));
- + _arg.add(activeChar.getAccountName());
- + _arg.add("9");
- + _arg.add(" ");
- + _arg.add(" ");
- + _arg.add(text);
- + _arg.add("0");
- + _arg.add("0");
- + _arg.add("0");
- + _arg.add("0");
- + activeChar.sendPacket(new ShowBoard(_arg));
- + }
- +
- + public static void main(String[] args)
- + {
- + new ClanSearcher(-1, "ClanSearcher", "custom");
- + }
- +}
- Index: data/scripts/custom/ClanSearcher/newclan.htm
- ===================================================================
- --- data/scripts/custom/ClanSearcher/newclan.htm (revision 0)
- +++ data/scripts/custom/ClanSearcher/newclan.htm (revision 0)
- @@ -0,0 +1,12 @@
- +<html>
- +<body><br>
- +<table border="0" width="280">
- +<tr><td width="93">Clan Name</td><td width="93">Clan Level</td><td width="93">Clan Leader</td></tr>
- +<tr><td width="93">%clanname%</td><td width="93">%clanlevel%</td><td width="93">%clanleader%</td></tr>
- +</table><br>
- + Add some info about your clan:
- + <multiedit var="msg" width=150 height=150><br>
- + If you dont want add any info, put None.
- +<button value="Submit" action="bypass -h Quest ClanSearcher add $msg" width=160 height=25 back="L2UI_ct1.button_df" fore="L2UI_ct1.button_df">
- +</body>
- +</html>
- \ No newline at end of file
- Index: data/scripts/custom/ClanSearcher/1.htm
- ===================================================================
- --- data/scripts/custom/ClanSearcher/1.htm (revision 0)
- +++ data/scripts/custom/ClanSearcher/1.htm (revision 0)
- @@ -0,0 +1,10 @@
- +<html><body><br>
- +<table border="0">
- +<tr><td height="30">Clan presenter:</td></tr>
- +<tr><td>Hello %player%.</td></tr>
- +<tr><td height="30">%text%</td></tr>
- +<tr><td><a action="bypass -h Quest ClanSearcher show_list">Show me the list</a></td></tr>
- +<tr><td>%add%</td></tr>
- +<tr><td>%remove%</td></tr>
- +</table>
- +</body></html>
- \ No newline at end of file
- Index: data/scripts/custom/ClanSearcher/deleteclan.htm
- ===================================================================
- --- data/scripts/custom/ClanSearcher/deleteclan.htm (revision 0)
- +++ data/scripts/custom/ClanSearcher/deleteclan.htm (revision 0)
- @@ -0,0 +1,4 @@
- +<html><body><br>
- + Your clan presentation will be erased. Are you sure?<br>
- + <a action="bypass -h Quest ClanSearcher remove">Remove presentation</a><br>
- +</body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement