Guest User

Untitled

a guest
Oct 16th, 2016
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. package custom;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.net.URL;
  8. import java.net.URLConnection;
  9. import java.util.logging.Logger;
  10.  
  11. import net.sf.l2j.Config;
  12. import net.sf.l2j.gameserver.Announcements;
  13.  
  14. public class VoteRead
  15. {
  16. private static final Logger _log = Logger.getLogger(VoteRead.class.getName());
  17.  
  18. public static int getL2NetworkVotes()
  19. {
  20. int votes = -1;
  21. URL url = null;
  22. URLConnection con = null;
  23. InputStream is = null;
  24. InputStreamReader isr = null;
  25. BufferedReader in = null;
  26.  
  27. try
  28. {
  29. url = new URL(Config.VOTES_SITE_L2NETWORK_URL);
  30. con = url.openConnection();
  31. con.addRequestProperty("User-Agent", "L2Network");
  32. is = con.getInputStream();
  33. isr = new InputStreamReader(is);
  34. in = new BufferedReader(isr);
  35. String inputLine;
  36. while ((inputLine = in.readLine()) != null)
  37. {
  38. if (inputLine.contains("color:#e7ebf2"))
  39. {
  40. votes = Integer.valueOf(inputLine.split(">")[2].replace("</b", ""));
  41. break;
  42. }
  43. }
  44. }
  45. catch (final Exception e)
  46. {
  47. _log.info("[AutoVoteReward] Server L2NETWORK is offline or something is wrong in link");
  48. Announcements.gameAnnounceToAll("[AutoVoteReward] L2Network is offline. We will check reward as it will be online again");
  49. // e.printStackTrace();
  50. }
  51. finally
  52. {
  53. if (in != null)
  54. try
  55. {
  56. in.close();
  57. }
  58. catch (final IOException e1)
  59. {
  60. e1.printStackTrace();
  61. }
  62. if (isr != null)
  63. try
  64. {
  65. isr.close();
  66. }
  67. catch (final IOException e1)
  68. {
  69. e1.printStackTrace();
  70. }
  71. if (is != null)
  72. try
  73. {
  74. is.close();
  75. }
  76. catch (final IOException e1)
  77. {
  78. e1.printStackTrace();
  79. }
  80. }
  81. return votes;
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment