Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AutoVoteRewardHandler.java
- -----------------------------------------------------------------------------------------------------------------
- public class AutoVoteRewardHandler
- {
- protected static final Logger _LOG = LoggerFactory.getLogger(AutoVoteRewardHandler.class.getName());
- private int _hopzoneVotesCount = 0;
- private int _l2jbrasilVotesCount = 0;
- protected List<String> already_rewarded;
- protected static boolean _l2jbrasil = false;
- protected static boolean _hopzone = false;
- private AutoVoteRewardHandler()
- {
- _LOG.info("Vote Reward System Initiated.");
- if (_hopzone)
- {
- int hopzone_votes = getHopZoneVotes();
- if (hopzone_votes == -1)
- {
- hopzone_votes = 0;
- }
- setHopZoneVoteCount(hopzone_votes);
- }
- if (_l2jbrasil)
- {
- int _l2jbrasil_votes = getL2jBrasilVotes();
- if (_l2jbrasil_votes == -1)
- {
- _l2jbrasil_votes = 0;
- }
- setL2jBrasilVoteCount(_l2jbrasil_votes);
- }
- ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), Config.VOTES_SYSYEM_INITIAL_DELAY, Config.VOTES_SYSYEM_STEP_DELAY);
- }
- protected class AutoReward implements Runnable
- {
- @SuppressWarnings("unused")
- @Override
- public void run()
- {
- final int minutes = (Config.VOTES_SYSYEM_STEP_DELAY / 1000) / 60;
- if (_hopzone)
- {
- final int _hotzone_votes = getHopZoneVotes();
- if (_hotzone_votes != -1)
- {
- _LOG.info("HOPZONE Votes: " + _hotzone_votes);
- // Announcements.getInstance().gameAnnounceToAll("Hopzone: Votes are " + _hotzone_votes + "...");
- if ((_hotzone_votes != 0) && (_hotzone_votes >= (getHopZoneVoteCount() + Config.VOTES_FOR_REWARD)))
- {
- already_rewarded = new ArrayList<>();
- final Collection<L2PcInstance> pls = L2World.getInstance().getPlayers();
- Announcements.getInstance().gameAnnounceToAll("Hopzone: Great Work! Check your inventory!!");
- // L2ItemInstance item;
- for (L2PcInstance player : pls)
- {
- if ((player != null) && !player.isInOfflineMode() && (player.isOnline() == 1))
- {
- if ((player._active_boxes <= 1) || ((player._active_boxes > 1) && checkSingleBox(player)))
- {
- final Set<Integer> items = Config.VOTES_REWARDS_LIST.keySet();
- for (Integer i : items)
- {
- player.addItem("reward", i, Config.VOTES_REWARDS_LIST.get(i), player, true);
- }
- }
- }
- }
- setHopZoneVoteCount(_hotzone_votes);
- }
- // Announcements.getInstance().gameAnnounceToAll("Hopzone: Reward in " + minutes + " minutes at " + (getHopZoneVoteCount() + Config.VOTES_FOR_REWARD) + " Votes!!");
- }
- }
- if (_l2jbrasil && _hopzone && (Config.VOTES_SYSYEM_STEP_DELAY > 0))
- {
- try
- {
- Thread.sleep(Config.VOTES_SYSYEM_STEP_DELAY / 2);
- }
- catch (InterruptedException e)
- {
- if (Config.ENABLE_ALL_EXCEPTIONS)
- {
- e.printStackTrace();
- }
- }
- }
- if (_l2jbrasil)
- {
- int _l2jbrasil_votes = getL2jBrasilVotes();
- if (_l2jbrasil_votes != -1)
- {
- _LOG.info("L2JBRASIL Votes: " + _l2jbrasil_votes);
- // Announcements.getInstance().gameAnnounceToAll("L2jBrasil: Votes are " + _l2jbrasil_votes + "...");
- if ((_l2jbrasil_votes != 0) && (_l2jbrasil_votes >= (getL2jBrasilVoteCount() + Config.VOTES_FOR_REWARD)))
- {
- already_rewarded = new ArrayList<>();
- final Collection<L2PcInstance> pls = L2World.getInstance().getPlayers();
- Announcements.getInstance().gameAnnounceToAll("L2jBrasil: Great Work! Check your inventory!!");
- // L2ItemInstance item;
- for (L2PcInstance player : pls)
- {
- if ((player != null) && !player.isInOfflineMode() && (player.isOnline() == 1))
- {
- if ((player._active_boxes <= 1) || ((player._active_boxes > 1) && checkSingleBox(player)))
- {
- final Set<Integer> items = Config.VOTES_REWARDS_LIST.keySet();
- for (Integer i : items)
- {
- player.addItem("reward", i, Config.VOTES_REWARDS_LIST.get(i), player, true);
- }
- }
- }
- }
- setL2jBrasilVoteCount(_l2jbrasil_votes);
- }
- // Announcements.getInstance().gameAnnounceToAll("L2jBrasil: Reward in " + minutes + " minutes at " + (getL2jBrasilVoteCount() + Config.VOTES_FOR_REWARD) + " Votes!!");
- }
- }
- }
- }
- protected boolean checkSingleBox(L2PcInstance player)
- {
- if (player.getClient() != null && player.getClient().getConnection() != null && !player.getClient().getConnection().isClosed() && !player.isInOfflineMode())
- {
- final String playerip = player.getClient().getConnection().getInetAddress().getHostAddress();
- if (already_rewarded.contains(playerip))
- {
- return false;
- }
- already_rewarded.add(playerip);
- return true;
- }
- // if no connection (maybe offline shop) dnt reward
- return false;
- }
- protected int getHopZoneVotes()
- {
- int votes = 0;
- try
- {
- URLConnection con = new URL(Config.VOTES_SITE_HOPZONE_URL).openConnection();
- con.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36");
- con.setConnectTimeout(5000);
- try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())))
- {
- String line;
- boolean encontrado = false;
- int contador = 0;
- while ((line = in.readLine()) != null)
- {
- if (line.contains("Total Votes\">"))
- {
- for (String inputLine : line.split(">"))
- {
- if (encontrado)
- {
- String inputLinefinal = inputLine.replace("</span", "");
- if (5 == inputLinefinal.length())
- {
- StringTokenizer st = new StringTokenizer(inputLinefinal, ",");
- String one = st.nextToken();
- String two = st.nextToken();
- inputLinefinal = one + "" + two;
- }
- votes = Integer.parseInt(inputLinefinal);
- contador++;
- break;
- }
- if (inputLine.contains("Total Votes\""))
- {
- encontrado = true;
- continue;
- }
- }
- if (encontrado && contador > 0)
- {
- break;
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- _LOG.info("HOPZONE is offline or something is wrong in link");
- // Announcements.getInstance().gameAnnounceToAll("Hopzone: is offline.");
- // e.printStackTrace();
- }
- return votes;
- }
- protected int getL2jBrasilVotes()
- {
- try
- {
- URLConnection con = new URL(Config.VOTES_SITE_L2JBRASIL_URL).openConnection();
- con.addRequestProperty("User-Agent", "Mozilla/5.0");
- InputStreamReader isr = new InputStreamReader(con.getInputStream());
- BufferedReader br = new BufferedReader(isr);
- String line;
- while ((line = br.readLine()) != null)
- {
- if (line.contains("<b>Entradas(Total):</b"))
- {
- String votesResult = String.valueOf(line.split(">")[2].replace("<br /", ""));
- int votes = Integer.valueOf(votesResult.replace(" ", ""));
- return votes;
- }
- }
- br.close();
- isr.close();
- }
- catch (Exception e)
- {
- _LOG.info("L2JBRASIL is offline or something is wrong in link");
- // Announcements.getInstance().gameAnnounceToAll("L2jBrasil: is offline.");
- }
- return 0;
- }
- protected void setHopZoneVoteCount(int voteCount)
- {
- _hopzoneVotesCount = voteCount;
- }
- protected int getHopZoneVoteCount()
- {
- return _hopzoneVotesCount;
- }
- protected void setL2jBrasilVoteCount(int voteCount)
- {
- _l2jbrasilVotesCount = voteCount;
- }
- protected int getL2jBrasilVoteCount()
- {
- return _l2jbrasilVotesCount;
- }
- public static AutoVoteRewardHandler getInstance()
- {
- if ((Config.VOTES_SITE_HOPZONE_URL != null) && !Config.VOTES_SITE_HOPZONE_URL.equals(""))
- {
- _hopzone = true;
- }
- if ((Config.VOTES_SITE_L2JBRASIL_URL != null) && !Config.VOTES_SITE_L2JBRASIL_URL.equals(""))
- {
- _l2jbrasil = true;
- }
- if (_l2jbrasil || _hopzone)
- {
- return SingletonHolder._instance;
- }
- return null;
- }
- @SuppressWarnings("synthetic-access")
- private static class SingletonHolder
- {
- protected static final AutoVoteRewardHandler _instance = new AutoVoteRewardHandler();
- }
- }
- -----------------------------------------------------------------------------------------------------------------
- config.java
- public static int VOTES_FOR_REWARD;
- public static String VOTES_REWARDS;
- public static String VOTES_SITE_L2JBRASIL_URL;
- public static String VOTES_SITE_HOPZONE_URL;
- public static FastMap<Integer, Integer> VOTES_REWARDS_LIST = new FastMap<>();
- public static int VOTES_SYSYEM_INITIAL_DELAY;
- public static int VOTES_SYSYEM_STEP_DELAY;
- public static boolean AUTOVOTEREWARD_ENABLED;
- AUTOVOTEREWARD_ENABLED = Boolean.parseBoolean(L2jOrionSettings.getProperty("VoteRewardSystem", "true"));
- VOTES_FOR_REWARD = Integer.parseInt(L2jOrionSettings.getProperty("VotesRequiredForReward", "100"));
- VOTES_SYSYEM_INITIAL_DELAY = Integer.parseInt(L2jOrionSettings.getProperty("VotesSystemInitialDelay", "60000"));
- VOTES_SYSYEM_STEP_DELAY = Integer.parseInt(L2jOrionSettings.getProperty("VotesSystemStepDelay", "1800000"));
- VOTES_SITE_HOPZONE_URL = L2jOrionSettings.getProperty("VotesSiteHopzoneUrl", "");
- VOTES_SITE_L2JBRASIL_URL = L2jOrionSettings.getProperty("VotesSiteL2JBrasilUrl", "");
- VOTES_REWARDS = L2jOrionSettings.getProperty("VotesRewards", "");
- VOTES_REWARDS_LIST = new FastMap<>();
- String[] splitted_VOTES_REWARDS = VOTES_REWARDS.split(";");
- for (String reward : splitted_VOTES_REWARDS)
- {
- String[] item_count = reward.split(",");
- if (item_count.length != 2)
- {
- System.out.println("[VotesRewards]: invalid config property -> VotesRewards \"" + VOTES_REWARDS + "\"");
- }
- else
- {
- VOTES_REWARDS_LIST.put(Integer.parseInt(item_count[0]), Integer.parseInt(item_count[1]));
- }
- }
- -----------------------------------------------------------------------------------------------------------------
- Gameserver.java
- if (Config.AUTOVOTEREWARD_ENABLED)
- {
- AutoVoteRewardHandler.getInstance();
- }
- -----------------------------------------------------------------------------------------------------------------
- config.ini
- # Automatic Global Vote Reward System
- VoteRewardSystem= False
- VotesRequiredForReward = 1
- VotesSystemInitialDelay= 60000
- VotesSystemStepDelay= 300000
- VotesRewards= 9143,10;
- #Leave empty to disable one site
- #if you need just one of these
- VotesSiteHopzoneUrl= https://l2.hopzone.net/lineage2/details/88242/Lineage2Argentina
- VotesSiteL2JBrasilUrl= https://top.l2jbrasil.com/index.php?a=stats&u=l2argentina
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement