hello there can u make this code check works for hopzone
/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/packageExtensions.Vote;import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import java.net.URL;import java.net.URLConnection;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.logging.Level;import java.util.logging.Logger;importExtensions.Vote.Tasks.MonthlyResetTask;importExtensions.Vote.Tasks.TriesResetTask;import com.l2jfrozen.Config;import com.l2jfrozen.gameserver.thread.ThreadPoolManager;import com.l2jfrozen.gameserver.model.L2World;import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;import com.l2jfrozen.util.database.L2DatabaseFactory;publicclassVoteManager{protectedstaticfinalLogger _log =Logger.getLogger(VoteManager.class.getName());privatestaticboolean hasVotedHop;privatestaticboolean hasVotedTop;publicVoteManager(){}publicstaticvoid load(){
_log.log(Level.INFO,"VoteManager: initialized.");TriesResetTask.getInstance();MonthlyResetTask.getInstance();}protectedstaticint getHopZoneVotes(){int votes =-1;StringHopzonelink=Config.VOTE_LINK_HOPZONE;InputStreamReader isr =null;BufferedReader br =null;try{URLConnection con =new URL(Hopzonelink).openConnection();
con.addRequestProperty("User-Agent","Mozilla/4.76");
isr =newInputStreamReader(con.getInputStream());
br =newBufferedReader(isr);String line;while((line = br.readLine())!=null){if(line.contains("rank anonymous tooltip")){
votes =Integer.valueOf(line.split(">")[2].replace("</span",""));break;}}
br.close();
isr.close();}catch(Exception e){if(Config.DEVELOPER){
e.printStackTrace();}}return votes;}protectedstaticint getTopZoneVotes(){int votes =-1;
URL url =null;URLConnection con =null;InputStreamis=null;InputStreamReader isr =null;BufferedReaderin=null;try{
url =new URL(Config.VOTE_LINK_TOPZONE);
con = url.openConnection();
con.addRequestProperty("User-Agent","L2TopZone");is= con.getInputStream();
isr =newInputStreamReader(is);in=newBufferedReader(isr);String inputLine;while((inputLine =in.readLine())!=null){if(inputLine.contains("Votes")){String votesLine = inputLine;
votes =Integer.valueOf(votesLine.split(">")[3].replace("</div",""));break;}}}catch(Exception e){if(Config.DEVELOPER){
e.printStackTrace();}}return votes;}publicstaticString hopCd(L2PcInstance player){long hopCdMs =0;long voteDelay =43200000L;PreparedStatement statement =null;Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT lastVoteHopzone FROM characters WHERE obj_Id=?");
statement.setInt(1, player.getObjectId());ResultSet rset = statement.executeQuery();while(rset.next()){
hopCdMs = rset.getLong("lastVoteHopzone");}}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}SimpleDateFormat sdf =newSimpleDateFormat("MMM dd,yyyy HH:mm");Date resultdate =newDate(hopCdMs + voteDelay);return sdf.format(resultdate);}publicstaticString topCd(L2PcInstance player){long topCdMs =0;long voteDelay =43200000L;PreparedStatement statement =null;Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT lastVoteTopzone FROM characters WHERE obj_Id=?");
statement.setInt(1, player.getObjectId());ResultSet rset = statement.executeQuery();while(rset.next()){
topCdMs = rset.getLong("lastVoteTopzone");}}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}SimpleDateFormat sdf =newSimpleDateFormat("MMM dd,yyyy HH:mm");Date resultdate =newDate(topCdMs + voteDelay);return sdf.format(resultdate);}publicstaticString whosVoting(){for(L2PcInstance voter : L2World.getInstance().getAllPlayers()){if(voter.isVoting()){return voter.getName();}}return"None";}publicstaticvoid hopvote(final L2PcInstance player){long lastVoteHopzone =0L;long voteDelay =43200000L;finalint firstvoteshop;
firstvoteshop = getHopZoneVotes();class hopvotetask implementsRunnable{privatefinal L2PcInstance p;public hopvotetask(L2PcInstance player){
p = player;}@Overridepublicvoid run(){if(firstvoteshop < getHopZoneVotes()){
p.setIsVoting(false);
p.setIsImobilised(false);VoteManager.setHasVotedHop(player);
p.sendMessage("Thank you for voting for us!");VoteManager.updateLastVoteHopzone(p);VoteManager.updateVotes(p);}else{
p.setIsVoting(false);
p.setIsImobilised(false);
p.sendMessage("You did not vote.Please try again.");VoteManager.setTries(player,VoteManager.getTries(p)-1);}}}PreparedStatement statement =null;Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT lastVoteHopzone FROM characters WHERE obj_Id=?");
statement.setInt(1, player.getObjectId());ResultSet rset = statement.executeQuery();while(rset.next()){
lastVoteHopzone = rset.getLong("lastVoteHopzone");}}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}if(getTries(player)<=0){
player.sendMessage("Due to your multiple failures in voting you lost your chance to vote today");}elseif(((lastVoteHopzone + voteDelay)<System.currentTimeMillis())&&(getTries(player)>0)){for(L2PcInstance j : L2World.getInstance().getAllPlayers()){if(j.isVoting()){
player.sendMessage("Someone is already voting.Wait for your turn please!");return;}}
player.setIsVoting(true);
player.setIsImobilised(true);
player.sendMessage("Go fast on the site and vote on the hopzone banner!");
player.sendMessage("You have "+Config.SECS_TO_VOTE +" seconds.Hurry!");ThreadPoolManager.getInstance().scheduleGeneral(new hopvotetask(player),Config.SECS_TO_VOTE *1000);}elseif((getTries(player)<=0)&&((lastVoteHopzone + voteDelay)<System.currentTimeMillis())){for(L2PcInstance j : L2World.getInstance().getAllPlayers()){if(j.isVoting()){
player.sendMessage("Someone is already voting.Wait for your turn please!");return;}}
player.setIsVoting(true);
player.setIsImobilised(true);
player.sendMessage("Go fast on the site and vote on the hopzone banner!");
player.sendMessage("You have "+Config.SECS_TO_VOTE +" seconds.Hurry!");ThreadPoolManager.getInstance().scheduleGeneral(new hopvotetask(player),Config.SECS_TO_VOTE *1000);}else{
player.sendMessage("12 hours have to pass till you are able to vote again.");}}publicstaticvoid topvote(final L2PcInstance player){long lastVoteTopzone =0L;long voteDelay =43200000L;finalint firstvotestop;
firstvotestop = getTopZoneVotes();class topvotetask implementsRunnable{privatefinal L2PcInstance p;public topvotetask(L2PcInstance player){
p = player;}@Overridepublicvoid run(){if(firstvotestop < getTopZoneVotes()){
p.setIsVoting(false);
p.setIsImobilised(false);VoteManager.setHasVotedTop(p);
p.sendMessage("Thank you for voting for us!");VoteManager.updateLastVoteTopzone(p);VoteManager.updateVotes(p);}else{
p.setIsVoting(false);
p.setIsImobilised(false);
p.sendMessage("You did not vote.Please try again.");VoteManager.setTries(p,VoteManager.getTries(p)-1);}}}PreparedStatement statement =null;Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT lastVoteTopzone FROM characters WHERE obj_Id=?");
statement.setInt(1, player.getObjectId());ResultSet rset = statement.executeQuery();while(rset.next()){
lastVoteTopzone = rset.getLong("lastVoteTopzone");}}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}if(getTries(player)<=0){
player.sendMessage("Due to your multiple failures in voting you lost your chance to vote today");}elseif((getTries(player)<=0)&&((lastVoteTopzone + voteDelay)<System.currentTimeMillis())){for(L2PcInstance j : L2World.getInstance().getAllPlayers()){if(j.isVoting()){
player.sendMessage("Someone is already voting.Wait for your turn please!");return;}}
player.setIsVoting(true);
player.setIsImobilised(true);
player.sendMessage("Go fast on the site and vote on the topzone banner!");
player.sendMessage((newStringBuilder()).append("You have ").append(Config.SECS_TO_VOTE).append(" seconds.Hurry!").toString());ThreadPoolManager.getInstance().scheduleGeneral(new topvotetask(player),Config.SECS_TO_VOTE *1000);}elseif(((lastVoteTopzone + voteDelay)<System.currentTimeMillis())&&(getTries(player)>0)){for(L2PcInstance j : L2World.getInstance().getAllPlayers()){if(j.isVoting()){
player.sendMessage("Someone is already voting.Wait for your turn please!");return;}}
player.setIsVoting(true);
player.setIsImobilised(true);
player.sendMessage("Go fast on the site and vote on the topzone banner!");
player.sendMessage((newStringBuilder()).append("You have ").append(Config.SECS_TO_VOTE).append(" seconds.Hurry!").toString());ThreadPoolManager.getInstance().scheduleGeneral(new topvotetask(player),Config.SECS_TO_VOTE *1000);}else{
player.sendMessage("12 hours have to pass till you are able to vote again.");}}publicstaticvoid hasVotedHop(L2PcInstance player){int hasVotedHop =-1;Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("SELECT hasVotedHop FROM characters WHERE obj_Id=?");
statement.setInt(1, player.getObjectId());ResultSet rset = statement.executeQuery();while(rset.next()){
hasVotedHop = rset.getInt("hasVotedHop");}if(hasVotedHop ==1){
setHasVotedHop(true);}elseif(hasVotedHop ==0){
setHasVotedHop(false);}}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}}publicstaticvoid hasVotedTop(L2PcInstance player){int hasVotedTop =-1;Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("SELECT hasVotedTop FROM characters WHERE obj_Id=?");
statement.setInt(1, player.getObjectId());ResultSet rset = statement.executeQuery();while(rset.next()){
hasVotedTop = rset.getInt("hasVotedTop");}if(hasVotedTop ==1){
setHasVotedTop(true);}elseif(hasVotedTop ==0){
setHasVotedTop(false);}}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}}publicstaticvoid updateVotes(L2PcInstance activeChar){Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("UPDATE characters SET monthVotes=?, totalVotes=? WHERE obj_Id=?");
statement.setInt(1, getMonthVotes(activeChar)+1);
statement.setInt(2, getTotalVotes(activeChar)+1);
statement.setInt(3, activeChar.getObjectId());
statement.execute();
statement.close();}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}}publicstaticvoid setHasVotedHop(L2PcInstance activeChar){Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("UPDATE characters SET hasVotedHop=? WHERE obj_Id=?");
statement.setInt(1,1);
statement.setInt(2, activeChar.getObjectId());
statement.execute();
statement.close();}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}}publicstaticvoid setHasVotedTop(L2PcInstance activeChar){Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("UPDATE characters SET hasVotedTop=? WHERE obj_Id=?");
statement.setInt(1,1);
statement.setInt(2, activeChar.getObjectId());
statement.execute();
statement.close();}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}}publicstaticvoid setHasNotVotedHop(L2PcInstance activeChar){Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("UPDATE characters SET hasVotedHop=? WHERE obj_Id=?");
statement.setInt(1,0);
statement.setInt(2, activeChar.getObjectId());
statement.execute();
statement.close();}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}}publicstaticvoid setHasNotVotedTop(L2PcInstance activeChar){Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("UPDATE characters SET hasVotedTop=? WHERE obj_Id=?");
statement.setInt(1,0);
statement.setInt(2, activeChar.getObjectId());
statement.execute();
statement.close();}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}}publicstaticint getTries(L2PcInstance player){int tries =-1;Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("SELECT tries FROM characters WHERE obj_Id=?");
statement.setInt(1, player.getObjectId());for(ResultSet rset = statement.executeQuery(); rset.next();){
tries = rset.getInt("tries");}}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}return tries;}publicstaticvoid setTries(L2PcInstance player,int tries){Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("UPDATE characters SET tries=? WHERE obj_Id=?");
statement.setInt(1, tries);
statement.setInt(2, player.getObjectId());
statement.execute();
statement.close();}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}}publicstaticint getMonthVotes(L2PcInstance player){int monthVotes =-1;Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("SELECT monthVotes FROM characters WHERE obj_Id=?");
statement.setInt(1, player.getObjectId());for(ResultSet rset = statement.executeQuery(); rset.next();){
monthVotes = rset.getInt("monthVotes");}}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}return monthVotes;}publicstaticint getTotalVotes(L2PcInstance player){int totalVotes =-1;Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("SELECT totalVotes FROM characters WHERE obj_Id=?");
statement.setInt(1, player.getObjectId());for(ResultSet rset = statement.executeQuery(); rset.next();){
totalVotes = rset.getInt("totalVotes");}}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}return totalVotes;}publicstaticint getBigTotalVotes(L2PcInstance player){int bigTotalVotes =-1;Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("SELECT SUM(totalVotes) FROM characters");for(ResultSet rset = statement.executeQuery(); rset.next();){
bigTotalVotes = rset.getInt("SUM(totalVotes)");}}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}return bigTotalVotes;}publicstaticint getBigMonthVotes(L2PcInstance player){int bigMonthVotes =-1;Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("SELECT SUM(monthVotes) FROM characters");for(ResultSet rset = statement.executeQuery(); rset.next();){
bigMonthVotes = rset.getInt("SUM(monthVotes)");}}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}return bigMonthVotes;}publicstaticvoid updateLastVoteHopzone(L2PcInstance player){Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("UPDATE characters SET lastVoteHopzone=? WHERE obj_Id=?");
statement.setLong(1,System.currentTimeMillis());
statement.setInt(2, player.getObjectId());
statement.execute();}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}}publicstaticvoid updateLastVoteTopzone(L2PcInstance player){Connection con =null;try{
con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement("UPDATE characters SET lastVoteTopzone=? WHERE obj_Id=?");
statement.setLong(1,System.currentTimeMillis());
statement.setInt(2, player.getObjectId());
statement.execute();}catch(Exception e){
_log.warning(" ");}finally{try{if(con !=null)
con.close();}catch(SQLException e){
_log.warning("Failed to close database connection!");}}}// Getters and Setterspublicstaticboolean hasVotedHop(){return hasVotedHop;}publicstaticvoid setHasVotedHop(boolean hasVotedHop){VoteManager.hasVotedHop = hasVotedHop;}publicstaticboolean hasVotedTop(){return hasVotedTop;}publicstaticvoid setHasVotedTop(boolean hasVotedTop){VoteManager.hasVotedTop = hasVotedTop;}}
Question
iAlreadyExist
hello there can u make this code check works for hopzone
Edited by haskovo20 answers to this question
Recommended Posts