Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package custom;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.logging.Logger;
- import net.sf.l2j.Config;
- import net.sf.l2j.gameserver.Announcements;
- public class VoteRead
- {
- private static final Logger _log = Logger.getLogger(VoteRead.class.getName());
- public static int getL2NetworkVotes()
- {
- int votes = -1;
- URL url = null;
- URLConnection con = null;
- InputStream is = null;
- InputStreamReader isr = null;
- BufferedReader in = null;
- try
- {
- url = new URL(Config.VOTES_SITE_L2NETWORK_URL);
- con = url.openConnection();
- con.addRequestProperty("User-Agent", "L2Network");
- is = con.getInputStream();
- isr = new InputStreamReader(is);
- in = new BufferedReader(isr);
- String inputLine;
- while ((inputLine = in.readLine()) != null)
- {
- if (inputLine.contains("color:#e7ebf2"))
- {
- votes = Integer.valueOf(inputLine.split(">")[2].replace("</b", ""));
- break;
- }
- }
- }
- catch (final Exception e)
- {
- _log.info("[AutoVoteReward] Server L2NETWORK is offline or something is wrong in link");
- Announcements.gameAnnounceToAll("[AutoVoteReward] L2Network is offline. We will check reward as it will be online again");
- // e.printStackTrace();
- }
- finally
- {
- if (in != null)
- try
- {
- in.close();
- }
- catch (final IOException e1)
- {
- e1.printStackTrace();
- }
- if (isr != null)
- try
- {
- isr.close();
- }
- catch (final IOException e1)
- {
- e1.printStackTrace();
- }
- if (is != null)
- try
- {
- is.close();
- }
- catch (final IOException e1)
- {
- e1.printStackTrace();
- }
- }
- return votes;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment