Advertisement
goldenglory

Ranking

Apr 27th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.11 KB | None | 0 0
  1. package net.sf.l2j.gameserver.model.actor.instance;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6.  
  7. import net.sf.l2j.L2DatabaseFactory;
  8. import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  9. import net.sf.l2j.gameserver.network.SystemMessageId;
  10. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  11. import net.sf.l2j.gameserver.network.serverpackets.EnchantResult;
  12. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  13.  
  14. public class L2RankingInstance extends L2NpcInstance
  15. {
  16.     public L2RankingInstance(int objectId, NpcTemplate template)
  17.     {
  18.         super(objectId, template);
  19.     }
  20.    
  21.     @Override
  22.     public void onBypassFeedback(L2PcInstance player, String command)
  23.     {
  24.         if (player.isProcessingTransaction())
  25.         {
  26.             player.sendPacket(SystemMessageId.ALREADY_TRADING);
  27.             return;
  28.         }
  29.        
  30.         if (player.getActiveEnchantItem() != null)
  31.         {
  32.             player.setActiveEnchantItem(null);
  33.             player.sendPacket(EnchantResult.CANCELLED);
  34.             player.sendPacket(SystemMessageId.ENCHANT_SCROLL_CANCELLED);
  35.         }
  36.        
  37.         else if (command.startsWith("topPvp"))
  38.         {
  39.             NpcHtmlMessage htm = new NpcHtmlMessage(0);
  40.             StringBuilder sb = new StringBuilder("<html><body>");
  41.             sb.append("<center><br>Top 15 PvP:<br><br1>");
  42.             try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  43.             {
  44.                 PreparedStatement stm = con.prepareStatement("SELECT char_name,pvpkills,accesslevel,online FROM characters ORDER BY pvpkills DESC LIMIT 15");
  45.                 ResultSet rSet = stm.executeQuery();
  46.                 while (rSet.next())
  47.                 {
  48.                     int accessLevel = rSet.getInt("accesslevel");
  49.                     if (accessLevel > 0)
  50.                     {
  51.                         continue;
  52.                     }
  53.                     int pvpKills = rSet.getInt("pvpkills");
  54.                     if (pvpKills == 0)
  55.                     {
  56.                         continue;
  57.                     }
  58.                     String pl = rSet.getString("char_name");
  59.                     int online = rSet.getInt("online");
  60.                     String status = online == 1 ? "<font color=\"00FF00\">Online</font>" : "<font color=\"FF0000\">Offline</font>";
  61.                     sb.append("Player: <font color=\"LEVEL\">" + pl + "</font> PvPs: <font color=\"LEVEL\">" + pvpKills + "</font> Status: <font color=\"LEVEL\">" + status + "</font><br1>");
  62.                 }
  63.             }
  64.             catch (Exception e)
  65.             {
  66.                 System.out.println("Error while selecting top 15 pvp from database.");
  67.             }
  68.            
  69.             sb.append("</body></html>");
  70.             htm.setHtml(sb.toString());
  71.             player.sendPacket(htm);
  72.         }
  73.         else if (command.startsWith("topPk"))
  74.         {
  75.             NpcHtmlMessage htm = new NpcHtmlMessage(0);
  76.             StringBuilder sb = new StringBuilder("<html><body>");
  77.             sb.append("<center><br>Top 15 PK:<br><br1>");
  78.             try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  79.             {
  80.                 PreparedStatement stm = con.prepareStatement("SELECT char_name,pkkills,accesslevel,online FROM characters ORDER BY pkkills DESC LIMIT 15");
  81.                 ResultSet rSet = stm.executeQuery();
  82.                 while (rSet.next())
  83.                 {
  84.                     int accessLevel = rSet.getInt("accesslevel");
  85.                     if (accessLevel > 0)
  86.                     {
  87.                         continue;
  88.                     }
  89.                     int pkKills = rSet.getInt("pkkills");
  90.                     if (pkKills == 0)
  91.                     {
  92.                         continue;
  93.                     }
  94.                     String pl = rSet.getString("char_name");
  95.                     int online = rSet.getInt("online");
  96.                     String status = online == 1 ? "<font color=\"00FF00\">Online</font>" : "<font color=\"FF0000\">Offline</font>";
  97.                     sb.append("Player: <font color=\"LEVEL\">" + pl + "</font> PKs: <font color=\"LEVEL\">" + pkKills + "</font> Status: <font color=\"LEVEL\">" + status + "</font><br1>");
  98.                 }
  99.             }
  100.             catch (Exception e)
  101.             {
  102.                 System.out.println("Error while selecting top 15 pk from database.");
  103.             }
  104.             sb.append("</body></html>");
  105.             htm.setHtml(sb.toString());
  106.             player.sendPacket(htm);
  107.         }
  108.     }
  109.    
  110.     @Override
  111.     public void showChatWindow(L2PcInstance player, int val)
  112.     {
  113.         player.sendPacket(ActionFailed.STATIC_PACKET);
  114.         String filename = "data/html/npc/ranking-no.htm";
  115.        
  116.         filename = "data/html/npc/ranking.htm";
  117.        
  118.         NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  119.         html.setFile(filename);
  120.         html.replace("%objectId%", String.valueOf(getObjectId()));
  121.         html.replace("%playerName%", player.getName());
  122.         player.sendPacket(html);
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement