Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.sf.l2j.gameserver.model.actor.instance;
- import javolution.text.TextBuilder;
- import net.sf.l2j.L2DatabaseFactory;
- import net.sf.l2j.gameserver.ai.CtrlIntention;
- import net.sf.l2j.gameserver.serverpackets.ActionFailed;
- import net.sf.l2j.gameserver.serverpackets.MyTargetSelected;
- import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
- import net.sf.l2j.gameserver.serverpackets.ValidateLocation;
- import net.sf.l2j.gameserver.templates.L2NpcTemplate;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.util.StringTokenizer;
- /**
- * Stat Manager
- *
- * @author Intrepid
- */
- public class L2StatManagerInstance extends L2FolkInstance
- {
- public L2StatManagerInstance(int objectId, L2NpcTemplate template)
- {
- super(objectId, template);
- }
- public void onAction(L2PcInstance player)
- {
- if (!canTarget(player)) return;
- player.setLastFolkNPC(this);
- // Check if the L2PcInstance already target the L2NpcInstance
- if (this != player.getTarget())
- {
- // Set the target of the L2PcInstance player
- player.setTarget(this);
- // Send a Server->Client packet MyTargetSelected to the L2PcInstance player
- MyTargetSelected my = new MyTargetSelected(getObjectId(), 0);
- player.sendPacket(my);
- // Send a Server->Client packet ValidateLocation to correct the L2NpcInstance position and heading on the client
- player.sendPacket(new ValidateLocation(this));
- }
- else
- {
- // Calculate the distance between the L2PcInstance and the L2NpcInstance
- if (!canInteract(player))
- {
- // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
- player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
- }
- else
- {
- showMessageWindow(player);
- }
- }
- // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
- player.sendPacket(new ActionFailed());
- }
- @Override
- public void onBypassFeedback(L2PcInstance player, String command)
- {
- StringTokenizer st = new StringTokenizer(command, " ");
- String actualCommand = st.nextToken();
- if (actualCommand.equalsIgnoreCase("TopPvp"))
- {
- player.sendMessage("OLOLO1");
- java.sql.Connection con = null;
- try
- {
- con = L2DatabaseFactory.getInstance().getConnection();
- PreparedStatement statement;
- statement = con.prepareStatement("SELECT char_name,pvpkills FROM characters where accesslevel = 0 order by pvpkills DESC LIMIT 10;");
- ResultSet rset = statement.executeQuery();
- while(rset.next())
- {
- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- TextBuilder sb = new TextBuilder();
- sb.append ("Character: "+rset.getString("char_name")+" ("+rset.getInt("pvpkills")+" kills");
- html.setHtml(sb.toString());
- player.sendPacket(html);
- }
- rset.close();
- statement.close();
- con.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- else if (actualCommand.equalsIgnoreCase("TopPk"))
- { player.sendMessage("OLOLO2");
- java.sql.Connection con = null;
- try
- {
- con = L2DatabaseFactory.getInstance().getConnection();
- PreparedStatement statement;
- statement = con.prepareStatement("SELECT char_name,pkkills FROM characters where accesslevel = 0 order by pkkills DESC LIMIT 10;");
- ResultSet rset = statement.executeQuery();
- while(rset.next())
- {
- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- TextBuilder sb = new TextBuilder();
- sb.append ("Character: "+rset.getString("char_name")+" ("+rset.getInt("pkkills")+" kills");
- html.setHtml(sb.toString());
- player.sendPacket(html);
- }
- rset.close();
- statement.close();
- con.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- else if (actualCommand.equalsIgnoreCase("TopLvl"))
- { player.sendMessage("OLOLO3");
- java.sql.Connection con = null;
- try
- {
- con = L2DatabaseFactory.getInstance().getConnection();
- PreparedStatement statement;
- statement = con.prepareStatement("SELECT char_name,level FROM characters where accesslevel = 0 order by level DESC LIMIT 10;");
- ResultSet rset = statement.executeQuery();
- while(rset.next())
- {
- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- TextBuilder sb = new TextBuilder();
- sb.append ("Character: "+rset.getString("char_name")+" ("+rset.getInt("level")+" level");
- html.setHtml(sb.toString());
- player.sendPacket(html);
- }
- rset.close();
- statement.close();
- con.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- else
- {
- // this class dont know any other commands, let forward
- // the command to the parent class
- super.onBypassFeedback(player, command);
- }
- }
- public void showMessageWindow(L2PcInstance player)
- {
- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- StringBuilder sb = new StringBuilder("<html><title>Статистика</title><body><br>");
- sb.append("<font color=\"00FF00\"><a action=\"bypass -h npc_%objectId%_TopPvp\">TopPvp</a></font><br>");
- sb.append("<font color=\"00FF00\"><a action=\"bypass -h npc_%objectId%_TopPk\">TopPk</a></font><br>");
- sb.append("<font color=\"00FF00\"><a action=\"bypass -h npc_%objectId%_TopLvl\">TopLvl</a></font><br>");
- sb.append("</body></html>");
- html.setHtml(sb.toString());
- player.sendPacket(html);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement