Jump to content

[Share]AutoVoteReward Topzone


Recommended Posts

Hallo This Java Code In By Vampirekiller L2Shax  Server

 

net.sf.l2j.gameserver.model

add New Class Name AutoVoteRewardHandler.java

 

package net.sf.l2j.gameserver.model;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import net.sf.l2j.Config;
import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.datatables.ItemTable;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.network.SystemMessageId;
import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
import net.sf.l2j.gameserver.util.Broadcast;

public class AutoVoteRewardHandler
{
  private final int initialCheck = Config.VOTE_INIT_CHECK;

  private final int delayForCheck = Config.VOTE_DELAY;

  private String server_name = "";

  private final int votesRequiredForReward = Config.VOTE_DIFF;

  private static int lastVoteCount = 0;

  private AutoVoteRewardHandler(Object object)
  {
    System.out.println("Vote Reward System Initiated.");
    ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(null), initialCheck, delayForCheck);
  }

  private int getVotes()
  {
    URL url = null;
    InputStreamReader isr = null;
    BufferedReader in = null;
    try
    {
      url = new URL(Config.VOTE_URL);

      if (Config.VOTE_DEBUG_PARSE) System.out.println("HTML Parse-------------------------------------");

      isr = new InputStreamReader(url.openStream());
      in = new BufferedReader(isr);
      String inputLine;
      while ((inputLine = in.readLine()) != null)
      {
        if (Config.VOTE_DEBUG_PARSE) System.out.println(inputLine);
        if (inputLine.contains(">Votes<")) {
          inputLine = in.readLine();
          if (Config.VOTE_DEBUG_PARSE) System.out.println("-------------->" + inputLine.split(">")[5].replace("</font", ""));
          int i = Integer.valueOf(inputLine.split(">")[5].replace("</font", "")).intValue();
          return i;
        }
      }
    }
    catch (IOException e)
    {
      ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(null), initialCheck, delayForCheck);
      System.out.println("Server Votes: Site Down");
      if (Config.VOTE_DEBUG) e.printStackTrace();
    }
    finally
    {
      try
      {
        in.close();
      }
      catch (IOException e)
      {
      }
      try {
        isr.close();
      }
      catch (IOException e) {
      }
    }
    return 0;
  }

  private int getVotesForFirstPage(int topn)
  {
    URL url = null;
    InputStreamReader isr = null;
    BufferedReader in = null;
    try
    {
      url = new URL(Config.VOTE_LIST);
      isr = new InputStreamReader(url.openStream());
      in = new BufferedReader(isr);

      if (Config.VOTE_DEBUG_PARSE) System.out.println("HTML First Page Parse-------------------------------------");
      String inputLine;
      while ((inputLine = in.readLine()) != null)
      {
        if (Config.VOTE_DEBUG_PARSE) System.out.println(inputLine);
        if (inputLine.contains("<td><div align=\"center\">" + topn + "</div></td>")) {
          for (int i = 0; i < 3; i++) inputLine = in.readLine();
          server_name = inputLine.split("\"")[1];
          if (Config.VOTE_DEBUG_PARSE) System.out.println("First page parse ServerName-->" + server_name);
          for (int i = 0; i < 2; i++) inputLine = in.readLine();
          if (Config.VOTE_DEBUG_PARSE) System.out.println("First page parse FirstPage Last Server Votes-->" + inputLine.split(">")[2].replace("</div", ""));
          int i = Integer.valueOf(inputLine.split(">")[2].replace("</div", "")).intValue();
          return i;
        }
      }
    }
    catch (IOException e)
    {
      ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(null), initialCheck, delayForCheck);
      System.out.println("Server Votes: Site Down");
      if (Config.VOTE_DEBUG) e.printStackTrace();
    }
    finally
    {
      try
      {
        in.close();
      }
      catch (IOException e)
      {
      }
      try {
        isr.close();
      }
      catch (IOException e) {
      }
    }
    return 0;
  }

  public static void setLastVoteCount(int voteCount)
  {
    lastVoteCount = voteCount;
  }

  public static void onShutdown() throws SQLException {
    Connection con = null;
    try
    {
      con = L2DatabaseFactory.getInstance().getConnection();
      PreparedStatement statement = con.prepareStatement("UPDATE Votes SET count = " + lastVoteCount);

      statement.execute();
      statement.close();
    }
    catch (SQLException e)
    {
      e.printStackTrace();
    }
    finally
    {
    	con.close();
    }
  }

  public static int getLastVoteCount()
  {
    return lastVoteCount;
  }

  public static void onStartup() throws SQLException {
    int count = 0;
    Connection con = null;
    try
    {
      con = L2DatabaseFactory.getInstance().getConnection();
      PreparedStatement statement = con.prepareStatement("SELECT * FROM Votes");

      ResultSet rset = statement.executeQuery();
      while (rset.next())
      {
        count = rset.getInt("count");
      }

      rset.close();
      statement.close();
    }
    catch (SQLException e)
    {
      e.printStackTrace();
    }
    finally
    {
    	con.close();
    }

    setLastVoteCount(count);
  }

  public static AutoVoteRewardHandler getInstance()
  {
    return SingletonHolder._instance;
  }

  private static class SingletonHolder
  {
    protected static final AutoVoteRewardHandler _instance = new AutoVoteRewardHandler(null);
  }

  private class AutoReward
    implements Runnable
  {
    private AutoReward(Object object)
    {
    }

    public void run()
    {
      int votes = AutoVoteRewardHandler.this.getVotes();
      int votes_frs = AutoVoteRewardHandler.this.getVotesForFirstPage(Config.VOTE_TOP);
      if ((votes < AutoVoteRewardHandler.getLastVoteCount()) || (AutoVoteRewardHandler.getLastVoteCount() <= 0)) {
        AutoVoteRewardHandler.setLastVoteCount(votes);
      }
      System.out.println("Server Votes: " + votes + " - For First Page: " + (votes_frs - votes));
      if (Config.VOTE_DEBUG) {
        System.out.println("URL: " + Config.VOTE_URL);
        System.out.println("vote diff: " + AutoVoteRewardHandler.this.votesRequiredForReward);
        for (int[] reward : Config.VOTE_REWARDS)
          System.out.println("Reward Low : " + reward[0] + "-" + reward[1]);
        for (int[] reward : Config.VOTE_REWARDS_FIRST_PAGE)
          System.out.println("Reward High : " + reward[0] + "-" + reward[1]);
      }
      if (!Config.VOTE_DEBUG) {
        if ((votes != 0) && (AutoVoteRewardHandler.getLastVoteCount() != 0) && (votes >= AutoVoteRewardHandler.getLastVoteCount() + AutoVoteRewardHandler.this.votesRequiredForReward))
        {
          Connection con = null;
          try
          {
            con = L2DatabaseFactory.getInstance().getConnection();
            PreparedStatement statement = con.prepareStatement("SELECT\tc.obj_Id,\tc.char_name FROM \tcharacters AS c LEFT JOIN \taccounts AS a ON \tc.account_name = a.login WHERE \tc.online > 0 ORDER BY \tc.level DESC");

            ResultSet rset = statement.executeQuery();
            L2PcInstance player = null;

            if ((votes < votes_frs) || ((votes == votes_frs) && (!Config.VOTE_URL.equals(AutoVoteRewardHandler.this.server_name)))) {
              Broadcast.toAllOnlinePlayers(new CreatureSay(1, 3, "Vote System", Config.VOTE_TEXT_SMALL_WIN));
              System.out.println("Server Votes: SMALL Rewarded at " + votes);
            }while (rset.next())
            {
              player = L2World.getInstance().getPlayer(rset.getInt("obj_Id"));
              if ((player == null) ||
             (player.isOffline())) continue;
              for (int[] reward : Config.VOTE_REWARDS)
              {
                player.addItem("Vote Reward", reward[0], reward[1], player, false);
                SystemMessage systemMessage = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
                systemMessage.addItemName(reward[0]);
                systemMessage.addNumber(reward[1]);
                player.sendPacket(systemMessage);
              continue;
              
              }
              if ((votes <= votes_frs) && ((votes != votes_frs) || (!Config.VOTE_URL.equals(AutoVoteRewardHandler.this.server_name)))) break;
              Broadcast.toAllOnlinePlayers(new CreatureSay(1, 3, "Vote System", Config.VOTE_TEXT_BIG_WIN));
              System.out.println("Server Votes: BIG Rewarded at " + votes);
              while (rset.next())
              {
                player = L2World.getInstance().getPlayer(rset.getInt("obj_Id"));
                if ((player == null) || 
                  (player.isOffline())) continue;
                for (int[] reward : Config.VOTE_REWARDS_FIRST_PAGE)
                {
                  player.addItem("Vote Reward", reward[0], reward[1], player, false);
                  SystemMessage systemMessage = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
                  systemMessage.addItemName(reward[0]);
                  systemMessage.addNumber(reward[1]);
                  player.sendPacket(systemMessage);
                }

              }

            }

            rset.close();
            statement.close();
          }
          catch (SQLException e)
          {
            e.printStackTrace();
          }
          finally
          {
			try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

          }

          AutoVoteRewardHandler.setLastVoteCount(AutoVoteRewardHandler.getLastVoteCount() + AutoVoteRewardHandler.this.votesRequiredForReward);
        }

        if ((votes < votes_frs) || ((votes == votes_frs) && (!Config.VOTE_URL.equals(AutoVoteRewardHandler.this.server_name))))
        {
          String msg = Config.VOTE_TEXT_CURRENT;
          msg = msg.replaceAll("%votes%", Integer.toString(votes));
          msg = msg.replaceAll("%votesRequiredForReward%", Integer.toString(AutoVoteRewardHandler.getLastVoteCount() + AutoVoteRewardHandler.this.votesRequiredForReward - votes));
          int count = 0;
          for (int[] reward : Config.VOTE_REWARDS)
          {
            msg = msg + reward[1] + " " + ItemTable.getInstance().getTemplate(reward[0]).getName();
            count++;
            if (count != Config.VOTE_REWARDS.size())
              msg = msg + ", ";
          }
          msg = msg + ")";

          Broadcast.toAllOnlinePlayers(new CreatureSay(1, 3, "Vote System", msg));

          msg = Config.VOTE_TEXT_FOR_FIRSTPAGE;
          msg = msg.replaceAll("%votes_frs%", Integer.toString(votes_frs - votes + 1));
          count = 0;
          for (int[] reward : Config.VOTE_REWARDS_FIRST_PAGE)
          {
            msg = msg + reward[1] + " " + ItemTable.getInstance().getTemplate(reward[0]).getName();
            count++;
            if (count != Config.VOTE_REWARDS_FIRST_PAGE.size())
              msg = msg + ", ";
          }
          msg = msg + ")";
          Broadcast.toAllOnlinePlayers(new CreatureSay(1, 3, "Vote System", msg));
        }
        else if ((votes > votes_frs) || ((votes == votes_frs) && (Config.VOTE_URL.equals(AutoVoteRewardHandler.this.server_name)))) {
          String msg = "Votes now: " + votes + ". " + (AutoVoteRewardHandler.getLastVoteCount() + AutoVoteRewardHandler.this.votesRequiredForReward - votes) + " Votes left at TopZone until next reward (";

          int count = 0;
          for (int[] reward : Config.VOTE_REWARDS_FIRST_PAGE)
          {
            msg = msg + reward[1] + " " + ItemTable.getInstance().getTemplate(reward[0]).getName();
            count++;
            if (count != Config.VOTE_REWARDS_FIRST_PAGE.size())
              msg = msg + ", ";
          }
          msg = msg + ")";

          Broadcast.toAllOnlinePlayers(new CreatureSay(1, 3, "Vote System", msg));
        }
      }
    }
  }
}

 

net.sf.l2j Config.java

  public static boolean VOTE_ENABLE;
  public static boolean VOTE_DEBUG;
  public static boolean VOTE_DEBUG_PARSE;
  public static String VOTE_URL;
  public static int VOTE_INIT_CHECK;
  public static int VOTE_DELAY;
  public static int VOTE_DIFF;
  public static List<int[]> VOTE_REWARDS;
  public static int VOTE_TOP;
  public static String VOTE_LIST;
  public static List<int[]> VOTE_REWARDS_FIRST_PAGE;
  public static String VOTE_TEXT_SMALL_WIN;
  public static String VOTE_TEXT_BIG_WIN;
  public static String VOTE_TEXT_CURRENT;
  public static String VOTE_TEXT_FOR_FIRSTPAGE;

 

    		      VOTE_ENABLE = Boolean.parseBoolean(votereward.getProperty("VoteEnable", "false"));
    		      VOTE_DEBUG = Boolean.parseBoolean(votereward.getProperty("VoteDebug", "false"));
    		      VOTE_DEBUG_PARSE = Boolean.parseBoolean(votereward.getProperty("VoteDebugParse", "false"));
    		      VOTE_URL = votereward.getProperty("VoteUrl", "");
    		      VOTE_INIT_CHECK = Integer.parseInt(votereward.getProperty("InitCheck", "0"));
    		      VOTE_DELAY = Integer.parseInt(votereward.getProperty("Delay", "0"));
    		      VOTE_DIFF = Integer.parseInt(votereward.getProperty("VoteDiff", "10"));
    		      VOTE_TOP = Integer.parseInt(votereward.getProperty("VoteTop", "10"));
    		      VOTE_REWARDS = new ArrayList<int[]>();

    		      VOTE_TEXT_SMALL_WIN = votereward.getProperty("VoteTextSmallWin", "");
    		      VOTE_TEXT_BIG_WIN = votereward.getProperty("VoteTextBigWin", "");
    		      VOTE_TEXT_CURRENT = votereward.getProperty("VoteCurrent", "");
    		      VOTE_TEXT_FOR_FIRSTPAGE = votereward.getProperty("VoteTextForFirstpage", "");

    		      VOTE_LIST = votereward.getProperty("VoteList", "");
    		      VOTE_REWARDS_FIRST_PAGE = new ArrayList<int[]>();

    		      String[] propertySplit = votereward.getProperty("VoteRewards", "100001,50").split(";");
    		      for (String reward : propertySplit)
    		      {
    		        String[] rewardSplit = reward.split(",");
    		        if (rewardSplit.length != 2) {
    		          _log.warning(StringUtil.concat(new String[] { "VoteEngine[Config.load()]: invalid config property -> VoteReward \"", reward, "\"" }));
    		        }
    		        else {
    		          try
    		          {
    		            VOTE_REWARDS.add(new int[] { Integer.parseInt(rewardSplit[0]), Integer.parseInt(rewardSplit[1]) });
    		          }
    		          catch (NumberFormatException nfe)
    		          {
    		            if (!reward.isEmpty()) {
    		              _log.warning(StringUtil.concat(new String[] { "VoteEngine[Config.load()]: invalid config property -> VoteReward \"", reward, "\"" }));
    		            }
    		          }
    		        }
    		      }
    		      propertySplit = votereward.getProperty("VoteRewardsFirstPage", "100001,50").split(";");
    		      for (String reward : propertySplit)
    		      {
    		        String[] rewardSplit = reward.split(",");
    		        if (rewardSplit.length != 2) {
    		          _log.warning(StringUtil.concat(new String[] { "VoteEngine[Config.load()]: invalid config property -> VoteReward \"", reward, "\"" }));
    		        }
    		        else {
    		          try
    		          {
    		            VOTE_REWARDS_FIRST_PAGE.add(new int[] { Integer.parseInt(rewardSplit[0]), Integer.parseInt(rewardSplit[1]) });
    		          }
    		          catch (NumberFormatException nfe)
    		          {
    		            if (!reward.isEmpty()) {
    		              _log.warning(StringUtil.concat(new String[] { "VoteEngine[Config.load()]: invalid config property -> VoteReward \"", reward, "\"" }));
    		            }
    		          }
    		        }
    		      }

Custom Config

 

#Big Reward TopZone
#Vote Reward System By L2Shax

VoteEnable = False

VoteDebug = false

VoteDebugParse = false

#url to hopzone page
VoteUrl = http://l2topzone.com/lineage2/server-info/6764/L2Luxury.html

#60 * 1000(1000milliseconds = 1 second) = 60seconds
InitCheck = 300000

Working I Test
Delay = 600000

VoteDiff = 1

VoteRewards = 813,5;

VoteTop = 1

VoteList = http://l2topzone.com/lineage2/server-list/top.html

VoteRewardsFirstPage = 813,25;


VoteTextSmallWin = Votes achieved! We are not in first page of TopZone. You will get the SMALL reward in few seconds.

VoteTextBigWin = Votes achieved! We are in first page of TopZone!!! You will get the BIG reward in few seconds.

VoteCurrent = Votes now: %votes%. %votesRequiredForReward% Votes left at TopZone until next reward (

VoteTextForFirstpage = %votes_frs% Votes left at TopZone until the server be on first page and the rewards will be (

Link to comment
Share on other sites

  • 5 weeks later...
  • 3 weeks later...

put the rightful credits that guy only adapted it.

That's the code i took the idea from Setekh. Then re-coded it in a more illegible and cleaner way.

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...
  • 5 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • 2 Factor Authentication Code for 100% secure login. Account provided with full information (email, password, dob, gender, etc).
    • ready server for sale, also available for testing with ready and beautiful npc zone pvp with custom 2 epic core orfen lvl2 with all maps ready all quests work at 100% ready comm  board with buffer teleport gm shop service anyone interested send me a pm many more that I forget  Exp/Sp : x30 (Premium: x40)    Adena : x7 (Premium: x10)   Drop : x7 (Premium: 10)   Spoil : x7 (Premium: 10)   Seal Stones : x7 (Premium: 10)   Raid Boss EXP/SP : x10   Raid Boss Drop : x3 (Premium: x5)   Epic Boss Drop : x1 Enchants   Safe Enchant : +3   Max Enchant : +16   Normal Scroll of Enchant Chance : 55%   Blessed Scroll of Enchant Chance : 60% Game Features   GMShop (Max. B-Grade)   Mana Potions (1000 MP, 10 sec Cooldown)   NPC Buffer (Include all buffs, 2h duration)   Auto-learn skills (Except Divine Inspiration)   Global Gatekeeper   Skill Escape: 15 seconds or /unstuck   1st Class Transfer (Free)   2nd Class Transfer (Free)   3rd Class Transfer (700 halisha mark)   Subclass (Items required from Cabrio / Hallate / Kernon / Golkonda + Top B Weapon + 984 Cry B)   Subclass 5 Subclasses + Main (Previous subclasses to level 75 to add new one)   Noblesse (Full Retail Quest)   Buff Slots: 24 (28 with Divine Inspiration LVL 4)   Skill Sweeper Festival added (Scavenger level 36)   Skill Block Buff added   Maximum delevel to keep Skills: 10 Levels   Shift + Click to see Droplist   Global Shout & Trade Chat   Retail Geodata and Pathnodes   Seven Signs Retail   Merchant and Blacksmith of Mammon at towns   Dimensional Rift (Min. 3 people in party to enter - Instance)   Tyrannosaurus drop Top LS with fixed 50% chance   Fast Augmentation System (Using Life Stones from Inventory)   Chance of getting skills (Normal 1%, Mid 3%, High 5%, Top 10%)   Wedding System with 30 seconds teleport to husband/wife Olympiad & Siege   Olympiad circle 14 days. (Maximum Enchant +6)   Olympiads time 18:00 - 00:00 (GMT +3)   Non-class 5 minimum participants to begin   Class based disabled   Siege every week.   To gain the reward you need to keep the Castle 2 times. Clans, Alliances & Limits   Max Clients/PC: 2   Max Clan Members: 36   Alliances allowed (Max 1 Clans)   24H Clan Penalties   Alliance penalty reset at daily restart (3-5 AM)   To bid for a Clan Hall required Clan Level 6 Quests x3   Alliance with the Ketra Orcs   Alliance with the Varka Silenos   War with Ketra Orcs   War with the Varka Silenos   The Finest Food   A Powerful Primeval Creature   Legacy of Insolence   Exploration of Giants Cave Part 1   Exploration of Giants Cave Part 2   Seekers of the Holy Grail   Guardians of the Holy Grail   Hunt of the Golden Ram Mercenary Force   The Zero Hour   Delicious Top Choice Meat   Heart in Search of Power   Rise and Fall of the Elroki Tribe   Yoke of the Past     Renegade Boss (Monday to Friday 20:00)   All Raid Boss 18+1 hours random respawn   Core (Jewel +1 STR +1 DEX) Monday, Wednesday and Friday 20:00 - 21:00 (Maximum level allowed to enter Cruma Tower: 80)   Orfen (Jewel +1 INT +1 WIT) Monday to Friday, 20:00 - 21:00 (Maximum level allowed to enter Sea of Spores: 80)   Ant Queen Monday and Friday 21:00 - 22:00 (Maximum level allowed to enter Ant Nest: 80)   Zaken Monday,Wednesday,Friday 22:00 - 23:00 (Maximum level allowed to enter Devil's Isle: 80)   Frintezza Tuesday, Thursday and Sunday 22:00 – 23:00 (Need CC of 4 party and 7 people in each party min to join the lair, max is 8 party of 9 people each)   Baium (lvl80) Saturday 22:00 – 23:00   Antharas Every 2 Saturdays 22:00 - 23:00 Every 2 Sundays (alternating with Valakas) 22:00 – 23:00   Valakas Every 2 Saturdays 22:00 - 23:00 Every 2 Sundays (alternating with Antharas) 22:00 – 23:00   Subclass Raids (Cabrio, Kernon, Hallate, Golkonda) 18hours + 1 random   Noblesse Raid (Barakiel) 6 hours + 15min random   Varka’s Hero Shadith 8 hours + 30 mins random (4th lvl of alliance with Ketra)   Ketra’s Hero Hekaton 8 hours + 30 mins random (4th lvl of alliance with Varka)   Varka’s Commander Mos 8 hours + 30 mins random (5th lvl of alliance with Ketra)   Ketra’s Commander Tayr 8 hours + 30 mins random (5th lvl of alliance with Varka)
    • Have a great day! Unfortunately, we can not give you the codes at the moment, but they will be distributed as soon as trial is back online, thanks for understanding! Other users also can reply there for codes, we will send them out some time after.
    • Ok mates i would like to play a pridestyle server (interluide, gracie w/ever) Is there any such server online and worth playing?
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock