Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.95 KB | None | 0 0
  1. package net.sf.l2j.gameserver.model.actor.instance;
  2.  
  3. import javolution.text.TextBuilder;
  4. import net.sf.l2j.L2DatabaseFactory;
  5. import net.sf.l2j.gameserver.ai.CtrlIntention;
  6. import net.sf.l2j.gameserver.serverpackets.ActionFailed;
  7. import net.sf.l2j.gameserver.serverpackets.MyTargetSelected;
  8. import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
  9. import net.sf.l2j.gameserver.serverpackets.ValidateLocation;
  10. import net.sf.l2j.gameserver.templates.L2NpcTemplate;
  11.  
  12. import java.sql.PreparedStatement;
  13. import java.sql.ResultSet;
  14. import java.util.StringTokenizer;
  15.  
  16.  
  17. /**
  18.  * Stat Manager
  19.  *
  20.  * @author Intrepid
  21.  */
  22.  
  23. public class L2StatManagerInstance extends L2FolkInstance
  24. {
  25.  
  26.     public L2StatManagerInstance(int objectId, L2NpcTemplate template)
  27.     {
  28.         super(objectId, template);
  29.     }
  30.     public void onAction(L2PcInstance player)
  31.     {
  32.         if (!canTarget(player)) return;
  33.  
  34.         player.setLastFolkNPC(this);
  35.  
  36.         // Check if the L2PcInstance already target the L2NpcInstance
  37.         if (this != player.getTarget())
  38.         {
  39.             // Set the target of the L2PcInstance player
  40.             player.setTarget(this);
  41.  
  42.             // Send a Server->Client packet MyTargetSelected to the L2PcInstance player
  43.             MyTargetSelected my = new MyTargetSelected(getObjectId(), 0);
  44.             player.sendPacket(my);
  45.  
  46.             // Send a Server->Client packet ValidateLocation to correct the L2NpcInstance position and heading on the client
  47.             player.sendPacket(new ValidateLocation(this));
  48.         }
  49.         else
  50.         {
  51.             // Calculate the distance between the L2PcInstance and the L2NpcInstance
  52.             if (!canInteract(player))
  53.             {
  54.                 // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
  55.                 player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
  56.             }
  57.             else
  58.             {
  59.                 showMessageWindow(player);
  60.             }
  61.         }
  62.         // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  63.         player.sendPacket(new ActionFailed());
  64.     }
  65.     @Override
  66.     public void onBypassFeedback(L2PcInstance player, String command)
  67.     {
  68.         StringTokenizer st = new StringTokenizer(command, " ");
  69.         String actualCommand = st.nextToken();
  70.  
  71.         if (actualCommand.equalsIgnoreCase("TopPvp"))
  72.         {
  73.             player.sendMessage("OLOLO1");
  74.               java.sql.Connection con = null;
  75.               try
  76.               {
  77.                 con = L2DatabaseFactory.getInstance().getConnection();
  78.                 PreparedStatement statement;
  79.                 statement = con.prepareStatement("SELECT char_name,pvpkills FROM characters where accesslevel = 0 order by pvpkills DESC LIMIT 10;");
  80.                 ResultSet rset = statement.executeQuery();
  81.                 while(rset.next())
  82.                 {
  83.                     NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  84.                     TextBuilder sb = new TextBuilder();
  85.                     sb.append ("Character: "+rset.getString("char_name")+" ("+rset.getInt("pvpkills")+" kills");
  86.                     html.setHtml(sb.toString());
  87.                     player.sendPacket(html);
  88.                 }
  89.                 rset.close();
  90.                 statement.close();
  91.                 con.close();
  92.               }
  93.               catch (Exception e)
  94.               {
  95.                 e.printStackTrace();
  96.               }
  97.         }
  98.         else if (actualCommand.equalsIgnoreCase("TopPk"))
  99.         {                              player.sendMessage("OLOLO2");
  100.               java.sql.Connection con = null;
  101.               try
  102.               {
  103.                 con = L2DatabaseFactory.getInstance().getConnection();
  104.                 PreparedStatement statement;
  105.                 statement = con.prepareStatement("SELECT char_name,pkkills FROM characters where accesslevel = 0 order by pkkills DESC LIMIT 10;");
  106.                 ResultSet rset = statement.executeQuery();
  107.                 while(rset.next())
  108.                 {
  109.                     NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  110.                     TextBuilder sb = new TextBuilder();
  111.                     sb.append ("Character: "+rset.getString("char_name")+" ("+rset.getInt("pkkills")+" kills");
  112.                     html.setHtml(sb.toString());
  113.                     player.sendPacket(html);
  114.                 }
  115.                 rset.close();
  116.               statement.close();
  117.               con.close();
  118.               }
  119.               catch (Exception e)
  120.               {
  121.                 e.printStackTrace();
  122.               }
  123.         }
  124.         else if (actualCommand.equalsIgnoreCase("TopLvl"))
  125.         {            player.sendMessage("OLOLO3");
  126.               java.sql.Connection con = null;
  127.               try
  128.               {
  129.                 con = L2DatabaseFactory.getInstance().getConnection();
  130.                 PreparedStatement statement;
  131.                 statement = con.prepareStatement("SELECT char_name,level FROM characters where accesslevel = 0 order by level DESC LIMIT 10;");
  132.                 ResultSet rset = statement.executeQuery();
  133.                 while(rset.next())
  134.                 {
  135.                     NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  136.                     TextBuilder sb = new TextBuilder();
  137.                     sb.append ("Character: "+rset.getString("char_name")+" ("+rset.getInt("level")+" level");
  138.                     html.setHtml(sb.toString());
  139.                     player.sendPacket(html);
  140.                 }
  141.                 rset.close();
  142.               statement.close();
  143.               con.close();
  144.               }
  145.               catch (Exception e)
  146.               {
  147.                 e.printStackTrace();
  148.               }
  149.         }
  150.         else
  151.         {
  152.             // this class dont know any other commands, let forward
  153.             // the command to the parent class
  154.  
  155.             super.onBypassFeedback(player, command);
  156.         }
  157.     }
  158.       public void showMessageWindow(L2PcInstance player)
  159.     {
  160.  NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  161.  
  162.         StringBuilder sb = new StringBuilder("<html><title>Статистика</title><body><br>");
  163.         sb.append("<font color=\"00FF00\"><a action=\"bypass -h npc_%objectId%_TopPvp\">TopPvp</a></font><br>");
  164.         sb.append("<font color=\"00FF00\"><a action=\"bypass -h npc_%objectId%_TopPk\">TopPk</a></font><br>");
  165.         sb.append("<font color=\"00FF00\"><a action=\"bypass -h npc_%objectId%_TopLvl\">TopLvl</a></font><br>");
  166.         sb.append("</body></html>");
  167.  
  168.         html.setHtml(sb.toString());
  169.         player.sendPacket(html);
  170.     }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement