Advertisement
Guest User

getTopzoneVotes

a guest
Apr 3rd, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1.     public static int getTopzoneVotes()
  2.     {
  3.         int votes = -1;
  4.         try
  5.         {
  6.             final URL obj = new URL(Config.VOTES_SITE_TOPZONE_URL);
  7.             final HttpURLConnection con = (HttpURLConnection) obj.openConnection();
  8.            
  9.             con.addRequestProperty("User-Agent", "L2TopZone");
  10.             con.setConnectTimeout(5000);
  11.            
  12.             final int responseCode = con.getResponseCode();
  13.             if (responseCode == 200)
  14.             {
  15.                 try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())))
  16.                 {
  17.                     String inputLine;
  18.                     while ((inputLine = in.readLine()) != null)
  19.                     {
  20.                         if (inputLine.contains("Votes:"))
  21.                         {
  22.                             votes = Integer.valueOf(inputLine.split("<br>")[1].replace("</div>", ""));
  23.                             break;
  24.                         }
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.         catch (Exception e)
  30.         {
  31.             announce("TOPZONE is offline. We will check reward as it will be online again.");
  32.         }
  33.         return votes;
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement