Jump to content

Question

Posted

γεια σας παίδες έχω πρόβλημα το  vot manager vazo link apo server mia fora to topzone doulepse menta den exei ksanadoulepsi to hopzone oute kapios na me help ti na kanw thex L2jFrozenShot00dfgdf000.jpg

Recommended Posts

  • 0
Posted

Hello, did you even read post i have provide you?

I have told exactly what you need to do there....

You must change in your config your link with the new link provided in your myhome section reward. Link must looks like this :  http://l2topzone.com/tv.php?id= YOUR SERVER ID

Then you must make your java code to read that link correctly.

This mean you need to replace few line in this code you have share with us.

protected int getTopZoneVotes()

{

int votes = -1;

URL url = null;

URLConnection con = null;

InputStream is = null;

InputStreamReader isr = null;

BufferedReader in = null;

try

{

url = new URL(PowerPakConfig.VOTES_SITE_TOPZONE_URL);

con = url.openConnection();

con.addRequestProperty("User-Agent", "L2TopZone");

is = con.getInputStream();

isr = new InputStreamReader(is);

in = new BufferedReader(isr);

String inputLine;

while ((inputLine = in.readLine()) != null)

{

if (inputLine.contains("Votes"))

{

votes = Integer.valueOf(inputLine.split(">")[3].replace("</div", ""));

break;

}

}

Replace with this one :

protected int getTopZoneVotes()

{

int votes = -1;

URL url = null;

URLConnection con = null;

InputStream is = null;

InputStreamReader isr = null;

BufferedReader in = null;

try

{

url = new URL(PowerPakConfig.VOTES_SITE_TOPZONE_URL);

con = url.openConnection();

con.addRequestProperty("User-Agent", "L2TopZone");

is = con.getInputStream();

isr = new InputStreamReader(is);

in = new BufferedReader(isr);

String inputLine;

while ((inputLine = in.readLine()) != null)

{

votes = Integer.valueOf(inputLine);

break;

}

Check again what is the difference between what you have share with us and what i have provide you. And make the same for all your code where you have get votes.

 

Good luck.

  • 0
Posted
package com.l2jfrozen.gameserver.handler;

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.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.l2jfrozen.Config;
import com.l2jfrozen.gameserver.model.L2World;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.model.entity.Announcements;
import com.l2jfrozen.gameserver.powerpak.PowerPakConfig;
import com.l2jfrozen.gameserver.thread.ThreadPoolManager;

public class AutoVoteRewardHandler
{
	protected static final Logger LOGGER = Logger.getLogger(AutoVoteRewardHandler.class);
	
	private int _l2networkVotesCount = 0;
	private int hopzoneVotesCount = 0;
	private int topzoneVotesCount = 0;
	protected List<String> already_rewarded;
	
	protected static boolean l2network = false;
	protected static boolean topzone = false;
	protected static boolean hopzone = false;
	
	private WebClient webClient;
	
	private AutoVoteRewardHandler()
	{
		LOGGER.info("Vote Reward System Initiated.");
		
		if (hopzone)
		{
			webClient = new WebClient(BrowserVersion.CHROME);
			webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
			webClient.getOptions().setThrowExceptionOnScriptError(false);
			webClient.getOptions().setPrintContentOnFailingStatusCode(false);
			
			int hopzone_votes = getHopZoneVotes();
			
			if (hopzone_votes == -1)
			{
				hopzone_votes = 0;
			}
			
			setHopZoneVoteCount(hopzone_votes);
		}
		
		if (l2network)
		{
			int l2network_votes = getL2NetworkVotes();
			
			if (l2network_votes == -1)
			{
				l2network_votes = 0;
			}
			
			setL2NetworkVoteCount(l2network_votes);
		}
		
		if (topzone)
		{
			int topzone_votes = getTopZoneVotes();
			
			if (topzone_votes == -1)
			{
				topzone_votes = 0;
			}
			
			setTopZoneVoteCount(topzone_votes);
		}
		
		ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), PowerPakConfig.VOTES_SYSYEM_INITIAL_DELAY, PowerPakConfig.VOTES_SYSYEM_STEP_DELAY);
	}
	
	protected class AutoReward implements Runnable
	{
		@Override
		public void run()
		{
			final int minutes = (PowerPakConfig.VOTES_SYSYEM_STEP_DELAY / 1000) / 60;
			
			if (hopzone)
			{
				final int hopzone_votes = getHopZoneVotes();
				
				if (hopzone_votes != -1)
				{
					LOGGER.info("Server Has on HopZone: " + hopzone_votes + " Votes!");
					Announcements.getInstance().gameAnnounceToAll("[VOTE] Votes on Hopzone " + hopzone_votes);

					if (hopzone_votes != 0 && hopzone_votes >= getHopZoneVoteCount() + PowerPakConfig.VOTES_FOR_REWARD)
					{
						already_rewarded = new ArrayList<>();
						
						final Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers();
						
						Announcements.getInstance().gameAnnounceToAll("[VOTE] Great Work! Check your inventory for Reward!!");
						
						// L2ItemInstance item;
						for (final 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 = PowerPakConfig.VOTES_REWARDS_LIST.keySet();
									for (final Integer i : items)
									{
										// item = player.getInventory().getItemByItemId(i);
										
										// TODO: check on maxstack for item
										player.addItem("reward", i, PowerPakConfig.VOTES_REWARDS_LIST.get(i), player, true);
										
									}
									
								}
							}
						}
						setHopZoneVoteCount(hopzone_votes);
					}
					Announcements.getInstance().gameAnnounceToAll("[VOTE] Next Reward in " + minutes + " minutes at " + (getHopZoneVoteCount() + PowerPakConfig.VOTES_FOR_REWARD) + " votes");
					Announcements.getInstance().gameAnnounceToAll("[VOTE] " + PowerPakConfig.SERVER_WEB_SITE);
				}
				
			}
			
			if (topzone && hopzone && PowerPakConfig.VOTES_SYSYEM_STEP_DELAY > 0)
				try
				{
					Thread.sleep(PowerPakConfig.VOTES_SYSYEM_STEP_DELAY / 2);
				}
				catch (final InterruptedException e)
				{
					if (Config.ENABLE_ALL_EXCEPTIONS)
						e.printStackTrace();
				}
			
			if (topzone)
			{
				final int topzone_votes = getTopZoneVotes();
				
				if (topzone_votes != -1)
				{
					
					LOGGER.info("Server on TopZone have: " + topzone_votes);
					
					Announcements.getInstance().gameAnnounceToAll("[VOTE] Votes on Topzone " + topzone_votes);
					
					if (topzone_votes != 0 && topzone_votes >= getTopZoneVoteCount() + PowerPakConfig.VOTES_FOR_REWARD)
					{
						already_rewarded = new ArrayList<>();
						
						final Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers();

						Announcements.getInstance().gameAnnounceToAll("[VOTE] Great Work! Check your inventory for Reward!!");
						
						// L2ItemInstance item;
						for (final 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 = PowerPakConfig.VOTES_REWARDS_LIST.keySet();
									for (final Integer i : items)
									{
										// item = player.getInventory().getItemByItemId(i);
										
										// TODO: check on maxstack for item
										player.addItem("reward", i, PowerPakConfig.VOTES_REWARDS_LIST.get(i), player, true);
										
									}
									
								}
							}
						}
						setTopZoneVoteCount(topzone_votes);
					}
						Announcements.getInstance().gameAnnounceToAll("[VOTE] Next Reward in " + minutes + " minutes at " + (getTopZoneVoteCount() + PowerPakConfig.VOTES_FOR_REWARD) + " votes");
						Announcements.getInstance().gameAnnounceToAll("[VOTE] " + PowerPakConfig.SERVER_WEB_SITE);
					}
				
			}
			
			if (topzone && hopzone && l2network && PowerPakConfig.VOTES_SYSYEM_STEP_DELAY > 0)
			{
				try
				{
					Thread.sleep(PowerPakConfig.VOTES_SYSYEM_STEP_DELAY / 2);
				}
				catch (final InterruptedException e)
				{
					if (Config.ENABLE_ALL_EXCEPTIONS)
						e.printStackTrace();
				}
			}
			
			if (l2network)
			{
				final int l2network_votes = getL2NetworkVotes();
				
				if (l2network_votes != -1)
				{
					LOGGER.info("Server L2NETWORK Votes: " + l2network_votes);
					
					Announcements.getInstance().gameAnnounceToAll("[VOTE] Votes on L2Network " + l2network_votes);
					
					if (l2network_votes != 0 && l2network_votes >= getL2NetworkVoteCount() + PowerPakConfig.VOTES_FOR_REWARD)
					{
						already_rewarded = new ArrayList<>();
						
						final Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers();
						
						Announcements.getInstance().gameAnnounceToAll("[VOTE] Great Work! Check your inventory for Reward!!");
						
						// L2ItemInstance item;
						for (final 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 = PowerPakConfig.VOTES_REWARDS_LIST.keySet();
									for (final Integer i : items)
									{
										// item = player.getInventory().getItemByItemId(i);
										
										// TODO: check on maxstack for item
										player.addItem("reward", i, PowerPakConfig.VOTES_REWARDS_LIST.get(i), player, true);
									}
								}
							}
						}
						setL2NetworkVoteCount(l2network_votes);
					}
						Announcements.getInstance().gameAnnounceToAll("[VOTE] Next Reward in " + minutes + " minutes at " + (getL2NetworkVoteCount() + PowerPakConfig.VOTES_FOR_REWARD) + " votes");
						Announcements.getInstance().gameAnnounceToAll("[VOTE] " + PowerPakConfig.SERVER_WEB_SITE);
				}
			}
			
		}
	}
	
	protected boolean checkSingleBox(final 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 = -1;
		try
		{
			final HtmlPage page = webClient.getPage(PowerPakConfig.VOTES_SITE_HOPZONE_URL);
			
			String fullPage = page.asXml();
			int constrainA = fullPage.indexOf("rank anonymous tooltip") + 24;
			String voteSection = fullPage.substring(constrainA);
			int constrainB = voteSection.indexOf("span") - 2;
			voteSection = voteSection.substring(0, constrainB).trim();
			votes = Integer.parseInt(voteSection);
			
		}
		catch (final Exception e)
		{
			LOGGER.warn("[AutoVoteReward] Server HOPZONE is offline or something is wrong in link", e);
			//Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] HOPZONE is offline. We will check reward as it will be online again");
		}
		finally
		{
			webClient.closeAllWindows();
		}
		return votes;
	}
	
	protected int getTopZoneVotes()
	{
		int votes = -1;
		URL url = null;
		URLConnection con = null;
		InputStream is = null;
		InputStreamReader isr = null;
		BufferedReader in = null;
		try
		{
			url = new URL(PowerPakConfig.VOTES_SITE_TOPZONE_URL);
			con = url.openConnection();
			con.addRequestProperty("User-Agent", "L2TopZone");
			is = con.getInputStream();
			isr = new InputStreamReader(is);
			in = new BufferedReader(isr);
			String inputLine;
			while ((inputLine = in.readLine()) != null)
			{
			votes = Integer.valueOf(inputLine);
			break;
			}
		}
		catch (final Exception e)
		{
			LOGGER.warn("[AutoVoteReward] Server TOPZONE is offline or something is wrong in link");
			//Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] TOPZONE 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;
	}
	
	protected int getL2NetworkVotes()
	{
		int votes = -1;
		URL url = null;
		URLConnection con = null;
		InputStream is = null;
		InputStreamReader isr = null;
		BufferedReader in = null;

		try
		{
			url = new URL(PowerPakConfig.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)
		{
			LOGGER.warn("[AutoVoteReward] Server L2NETWORK is offline or something is wrong in link");
			// 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;
	}
	
	protected void setHopZoneVoteCount(final int voteCount)
	{
		hopzoneVotesCount = voteCount;
	}
	
	protected int getHopZoneVoteCount()
	{
		return hopzoneVotesCount;
	}
	
	protected void setTopZoneVoteCount(final int voteCount)
	{
		topzoneVotesCount = voteCount;
	}
	
	protected int getTopZoneVoteCount()
	{
		return topzoneVotesCount;
	}
	
	protected void setL2NetworkVoteCount(final int voteCount)
	{
		_l2networkVotesCount = voteCount;
	}
	
	protected int getL2NetworkVoteCount()
	{
		return _l2networkVotesCount;
	}
	
	public static AutoVoteRewardHandler getInstance()
	{
		Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
		if (PowerPakConfig.VOTES_SITE_HOPZONE_URL != null && !PowerPakConfig.VOTES_SITE_HOPZONE_URL.equals(""))
		{
			hopzone = true;
		}
		
		if (PowerPakConfig.VOTES_SITE_TOPZONE_URL != null && !PowerPakConfig.VOTES_SITE_TOPZONE_URL.equals(""))
		{
			topzone = true;
		}
		
		if (PowerPakConfig.VOTES_SITE_L2NETWORK_URL != null && !PowerPakConfig.VOTES_SITE_L2NETWORK_URL.equals(""))
		{
			l2network = true;
		}
		if (topzone || hopzone || l2network)
			return SingletonHolder._instance;
		return null;
	}
	
	@SuppressWarnings("synthetic-access")
	private static class SingletonHolder
	{
		protected static final AutoVoteRewardHandler _instance = new AutoVoteRewardHandler();
	}
}
package com.l2jfrozen.gameserver.model.actor.instance;

import com.l2jfrozen.Config;
import com.l2jfrozen.gameserver.ai.CtrlIntention;
import com.l2jfrozen.gameserver.datatables.sql.ItemTable;
import com.l2jfrozen.gameserver.model.votereward.VoteMain;
import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
import com.l2jfrozen.gameserver.network.serverpackets.ItemList;
import com.l2jfrozen.gameserver.network.serverpackets.MyTargetSelected;
import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocation;
import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
import javolution.text.TextBuilder;

public class L2VoteManagerInstance
  extends L2FolkInstance
{
  public L2VoteManagerInstance(int objectId, L2NpcTemplate template)
  {
    super(objectId, template);
  }
  
  @Override
public void onBypassFeedback(L2PcInstance player, String command)
  {
    if (player == null) {
      return;
    }
    if (command.startsWith("votehopzone"))
    {
      VoteMain.hopvote(player);
    }
    if (command.startsWith("votetopzone"))
    {
      VoteMain.topvote(player);
    }
    if ((command.startsWith("rewards")) && VoteMain.hasVotedHop() && VoteMain.hasVotedTop())
    {
      showRewardsHtml(player);
    }
    
    if ((command.startsWith("reward1")) && VoteMain.hasVotedHop() && VoteMain.hasVotedTop())
    {
      player.getInventory().addItem("reward", Config.VOTE_REWARD_ID1, Config.VOTE_REWARD_AMOUNT1, player, null);
      player.sendMessage("Thanks you for votes. Take your reward.");
      player.sendPacket(new ItemList(player, true));
      VoteMain.setHasNotVotedHop(player);
      VoteMain.setHasNotVotedTop(player);
      VoteMain.setTries(player, VoteMain.getTries(player) + 1);
    }
    
    if ((command.startsWith("reward2")) && VoteMain.hasVotedHop() && VoteMain.hasVotedTop())
    {
      player.getInventory().addItem("reward", Config.VOTE_REWARD_ID2, Config.VOTE_REWARD_AMOUNT2, player, null);
      player.sendMessage("Thanks you for votes. Take your reward.");
      player.sendPacket(new ItemList(player, true));
      VoteMain.setHasNotVotedHop(player);
      VoteMain.setHasNotVotedTop(player);
      VoteMain.setTries(player, VoteMain.getTries(player) + 1);
    }
    
    if ((command.startsWith("reward3")) && VoteMain.hasVotedHop() && VoteMain.hasVotedTop())
    {
      player.getInventory().addItem("reward", Config.VOTE_REWARD_ID3, Config.VOTE_REWARD_AMOUNT3, player, null);
      player.sendMessage("Thanks you for votes. Take your reward.");
      player.sendPacket(new ItemList(player, true));
      VoteMain.setHasNotVotedHop(player);
      VoteMain.setHasNotVotedTop(player);
      VoteMain.setTries(player, VoteMain.getTries(player) + 1);
    }
    
    if ((command.startsWith("reward4")) && VoteMain.hasVotedHop() && VoteMain.hasVotedTop())
    {
      player.getInventory().addItem("reward", Config.VOTE_REWARD_ID4, Config.VOTE_REWARD_AMOUNT4, player, null);
      player.sendMessage("Thanks you for votes. Take your reward.");
      player.sendPacket(new ItemList(player, true));
      VoteMain.setHasNotVotedHop(player);
      VoteMain.setHasNotVotedTop(player);
      VoteMain.setTries(player, VoteMain.getTries(player) + 1);
    }
  }
  
  @Override
public void onAction(L2PcInstance player)
  {
    if (this != player.getTarget())
    {
      player.setTarget(this);
      
      player.sendPacket(new MyTargetSelected(getObjectId(), 0));
      
      player.sendPacket(new ValidateLocation(this));
    }
    else if (!canInteract(player))
    {
      player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
    }
    else
    {
      showHtmlWindow(player);
    }
    player.sendPacket(ActionFailed.STATIC_PACKET);
  }
  
  public void showHtmlWindow(L2PcInstance activeChar)
  {
    VoteMain.hasVotedHop(activeChar);
    VoteMain.hasVotedTop(activeChar);
    
    TextBuilder tb = new TextBuilder();
    NpcHtmlMessage html = new NpcHtmlMessage(1);
    
    tb.append("<html><head><title>Vote reward Panel</title></head><body><center><br><br>");
    tb.append("<table bgcolor=\"FFFFFF\"><tr><td align=\"center\"><font color=\"00ff99\">Who's voting now: </font>" + VoteMain.whosVoting() + "</td></tr>");
    tb.append("<tr><td align=\"center\"><font color=\"00ffff\">Tries left: </font>" + VoteMain.getTries(activeChar) + "</td></tr>");
    tb.append("<tr><td align=\"center\"><font color=\"00ffff\">Max seconds until vote: </font>" + Config.SECS_TO_VOTE + "(s)</td></tr>");
    if (Config.VOTE_REWARD_ID1 > 0)
    {
      tb.append("<tr><td align=\"center\"><font color=\"00ffff\">1) " + ItemTable.getInstance().getTemplate(Config.VOTE_REWARD_ID1).getName() + ":</font> " + Config.VOTE_REWARD_AMOUNT1 + "</td></tr>");
    }
    if (Config.VOTE_REWARD_ID2 > 0)
    {
      tb.append("<tr><td align=\"center\"><font color=\"00ffff\">2) " + ItemTable.getInstance().getTemplate(Config.VOTE_REWARD_ID2).getName() + ":</font> " + Config.VOTE_REWARD_AMOUNT2 + "</td></tr>");
    }
    if (Config.VOTE_REWARD_ID3 > 0)
    {
      tb.append("<tr><td align=\"center\"><font color=\"00ffff\">2) " + ItemTable.getInstance().getTemplate(Config.VOTE_REWARD_ID3).getName() + ":</font> " + Config.VOTE_REWARD_AMOUNT3 + "</td></tr>");
    }
    if (Config.VOTE_REWARD_ID4 > 0) 
    {
      tb.append("<tr><td align=\"center\"><font color=\"00ffff\">2) " + ItemTable.getInstance().getTemplate(Config.VOTE_REWARD_ID4).getName() + ":</font> " + Config.VOTE_REWARD_AMOUNT4 + "</td></tr>");
    }
    tb.append("<tr><td align=\"center\"><font color=\"FF6600\">You can vote in Hopzone at " + VoteMain.hopCd(activeChar) + "</font></td></tr>");
    tb.append("<tr><td align=\"center\"><font color=\"FF6600\">You can vote in Topzone at " + VoteMain.topCd(activeChar) + "</font></td></tr>");
    tb.append("</table>");
    tb.append("</center><br><br>");
    tb.append("<center>");
    if ((VoteMain.hasVotedHop()) && (!VoteMain.hasVotedTop()))
    {
      tb.append("<td><font color = \"00FF00\">For reward you must vote on TOPZONE TOO!</font></td>");
      tb.append("<td><button value=\"Vote Topzone\" action=\"bypass -h npc_" + getObjectId() + "_votetopzone\" width=\"94\" height=\"21\" back=\"L2UI_ch3.bigbutton_over\" fore=\"L2UI_ch3.bigbutton\"></td>");
    }
    else if ((!VoteMain.hasVotedHop()) && (VoteMain.hasVotedTop()))
    {
      tb.append("<td><font color = \"00FF00\">For reward you must vote on HOPZONE TOO!</font></td>");
      tb.append("<td><button value=\"Vote Hopzone\" action=\"bypass -h npc_" + getObjectId() + "_votehopzone\" width=\"94\" height=\"21\" back=\"L2UI_ch3.bigbutton_over\" fore=\"L2UI_ch3.bigbutton\"></td>");
    }
    else if ((!VoteMain.hasVotedHop()) && (!VoteMain.hasVotedTop()))
    {
      tb.append("<td><button value=\"Vote Hopzone\" action=\"bypass -h npc_" + getObjectId() + "_votehopzone\" width=\"94\" height=\"21\" back=\"L2UI_ch3.bigbutton_over\" fore=\"L2UI_ch3.bigbutton\"></td>");
      tb.append("<td><button value=\"Vote Topzone\" action=\"bypass -h npc_" + getObjectId() + "_votetopzone\" width=\"94\" height=\"21\" back=\"L2UI_ch3.bigbutton_over\" fore=\"L2UI_ch3.bigbutton\"></td>");
    }
    else
    {
      tb.append("<td><button value=\"Take The REWARD\" action=\"bypass -h npc_" + getObjectId() + "_rewards\" width=\"94\" height=\"21\" back=\"L2UI_ch3.bigbutton_over\" fore=\"L2UI_ch3.bigbutton\"></td>");
    }
    tb.append("<table width=200>");
    if (!VoteMain.hasVotedHop())
    {
      tb.append("<tr>");
      tb.append("<td align=\"center\"><font color=\"FF6600\">Hopzone Status: </font><font color=\"00FFFF\">NOT VOTED.</font></td>");
      tb.append("</tr>");
    }
    else
    {
      tb.append("<tr>");
      tb.append("<td align=\"center\"><font color=\"FF6600\">Hopzone Status: </font><font color=\"FF00FF\">VOTED.</font></td>");
      tb.append("</tr>");
    }
    if (!VoteMain.hasVotedTop())
    {
      tb.append("<tr>");
      tb.append("<td align=\"center\"><font color=\"FF6600\">Topzone Status: </font><font color=\"00FFFF\">NOT VOTED.</font></td>");
      tb.append("</tr>");
    }
    else
    {
      tb.append("<tr>");
      tb.append("<td align=\"center\"><font color=\"FF6600\">Topzone Status: </font><font color=\"FF00FF\">VOTED.</font></td>");
      tb.append("</tr>");
    }
    tb.append("</table>");
    tb.append("<br><br>");
    tb.append("<table width=200>");
    tb.append("<tr><td align=\"center\"><font color=\"FF6600\">Your total votes in general: </font>" + VoteMain.getTotalVotes(activeChar) + "</td></tr>");
    tb.append("<tr><td align=\"center\"><font color=\"FF6600\">Players voted in general: </font>" + VoteMain.getBigTotalVotes(activeChar) + "</td></tr>");
    tb.append("</table>");
    tb.append("</center>");
    tb.append("</body></html>");
    
    html.setHtml(tb.toString());
    activeChar.sendPacket(html);
  }
  
  public void showRewardsHtml(L2PcInstance player)
  {
    TextBuilder tb = new TextBuilder();
    NpcHtmlMessage html = new NpcHtmlMessage(1);
    
    tb.append("<html><head><title>Vote Reward Panel</title></head><body>");
    tb.append("<center>");
    tb.append("<table width=\"250\" cellpadding=\"5\" bgcolor=\"000000\">");
    tb.append("<tr>");
    tb.append("<td width=\"45\" valign=\"top\" align=\"center\"><img src=\"L2ui_ch3.menubutton4\" width=\"38\" height=\"38\"></td>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Vote Panel</font>");
    tb.append("<br1><font color=\"00FF00\">" + player.getName() + "</font>, get your reward here.</td>");
    tb.append("</tr>");
    tb.append("</table>");
    tb.append("</center>");
    tb.append("<center>");
    tb.append("<td valign=\"top\"><font color=\"FF6600\">Choose your reward " + player.getName() + ".</font>");
    if (Config.VOTE_REWARD_ID1 > 0) {
      tb.append("<button value=\"Item:" + ItemTable.getInstance().getTemplate(Config.VOTE_REWARD_ID1).getName() + "   Amount:" + Config.VOTE_REWARD_AMOUNT1 + "\" action=\"bypass -h npc_" + getObjectId() + "_reward1\" width=204 height=20>");
    }
    if (Config.VOTE_REWARD_ID2 > 0) {
      tb.append("<button value=\"Item:" + ItemTable.getInstance().getTemplate(Config.VOTE_REWARD_ID2).getName() + "   Amount:" + Config.VOTE_REWARD_AMOUNT2 + "\" action=\"bypass -h npc_" + getObjectId() + "_reward2\" width=204 height=20>");
    }
    if (Config.VOTE_REWARD_ID3 > 0) {
      tb.append("<button value=\"Item:" + ItemTable.getInstance().getTemplate(Config.VOTE_REWARD_ID3).getName() + "   Amount:" + Config.VOTE_REWARD_AMOUNT3 + "\" action=\"bypass -h npc_" + getObjectId() + "_reward3\" width=204 height=20>");
    }
    if (Config.VOTE_REWARD_ID4 > 0) {
      tb.append("<button value=\"Item:" + ItemTable.getInstance().getTemplate(Config.VOTE_REWARD_ID4).getName() + "   Amount:" + Config.VOTE_REWARD_AMOUNT4 + "\" action=\"bypass -h npc_" + getObjectId() + "_reward4\" width=204 height=20>");
    }
    tb.append("</center>");
    
    tb.append("</body></html>");
    
    html.setHtml(tb.toString());
    player.sendPacket(html);
  }
}

package com.l2jfrozen.gameserver.model.votereward;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.l2jfrozen.Config;
import com.l2jfrozen.gameserver.model.L2World;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.network.serverpackets.CreatureSay;
import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
import com.l2jfrozen.util.database.L2DatabaseFactory;

/**
 * @Rework Katara
 */
public class VoteMain
{
	private static boolean hasVotedHop;
	private static boolean hasVotedTop;
	static boolean Problemontop = false;
	static boolean Problemonhop = false;
	
	public VoteMain()
	{
	}
	
	public static void load()
	{
		System.out.println("Vote Reward Per Person Started Successfully.");
		TriesResetTask.getInstance();
	}
	
	protected static int getHopZoneVotes()
	{
		URL url = null;
		InputStreamReader isr = null;
		BufferedReader in = null;
		try
		{
			url = new URL(Config.VOTE_LINK_HOPZONE);
			HttpURLConnection con = (HttpURLConnection) url.openConnection();
			HttpURLConnection.setFollowRedirects(false);
			con.setConnectTimeout(10 * 1000);
			con.addRequestProperty("user-agent", "fake googlebot");
			con.connect();
			isr = new InputStreamReader(con.getInputStream());
			in = new BufferedReader(isr);
			String inputLine;
			while ((inputLine = in.readLine()) != null)
			{
				if (inputLine.contains("rank anonymous tooltip"))
				{
					return Integer.valueOf(inputLine.split(">")[2].replace("</span", ""));
				}
			}
		}
		catch (IOException e)
		{
			System.out.println("[Hopzone-Vote Manager] I can't connect on Hopzone site...");
			Problemonhop = true;
		}
		return 0;
	}
	
	protected static int getTopZoneVotes()
	{
		URL url = null;
		InputStreamReader isr = null;
		BufferedReader in = null;
		try
		{
			try
			{
				url = new URL(Config.VOTE_LINK_TOPZONE);
				HttpURLConnection con = (HttpURLConnection) url.openConnection();
				HttpURLConnection.setFollowRedirects(false);
				con.setConnectTimeout(5 * 1000);
				con.addRequestProperty("User-Agent", "L2TopZone");
				con.connect();
				isr = new InputStreamReader(con.getInputStream());
				in = new BufferedReader(isr);
			}
			catch (SocketTimeoutException e)
			{
				System.out.println("[Topzone-Vote Manager] I can't connect on TOPZONE site...");
				Problemontop = true;
				return 0;
			}
			 
			String inputLine;
			while ((inputLine = in.readLine()) != null)
			{
				if (inputLine.contains("Votes:"))
				{
					for (int i=-1; i>2; i++)
						inputLine = in.readLine();

					Problemontop = false;
					return Integer.valueOf(inputLine.split(">")[3].replace("</div", ""));
				}
			}
		}	
	catch (IOException e)
		{
			e.printStackTrace();
			System.out.println("[Topzone-Vote Manager] I can't connect on Topzone site...");
			Problemontop = true;
		}
		return 0;
	}
	
	public static String hopCd(L2PcInstance player)
	{
		long hopCdMs = 0;
		long voteDelay = 43200000L;
		PreparedStatement statement = null;
		try (Connection 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)
		{
			e.printStackTrace();
		}
		SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
		
		Date resultdate = new Date(hopCdMs + voteDelay);
		return sdf.format(resultdate);
	}
	
	public static String topCd(L2PcInstance player)
	{
		long topCdMs = 0;
		long voteDelay = 43200000L;
		PreparedStatement statement = null;
		try (Connection 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)
		{
			e.printStackTrace();
		}
		SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
		
		Date resultdate = new Date(topCdMs + voteDelay);
		return sdf.format(resultdate);
	}
	
	public static String whosVoting()
	{
		for (L2PcInstance voter : L2World.getInstance().getAllPlayers())
		{
			if (voter.isVoting())
			{
				return voter.getName();
			}
		}
		return "None";
	}
	
	public static void hopvote(final L2PcInstance player)
	{
		long lastVoteHopzone = 0L;
		long voteDelay = 43200000L;
		final int firstvoteshop;
		int votesmessage = 0;
		
		firstvoteshop = getHopZoneVotes();
		votesmessage = getHopZoneVotes();
		
		class hopvotetask implements Runnable
		{
			private final L2PcInstance p;
			
			public hopvotetask(L2PcInstance player)
			{
				p = player;
			}
			
			@Override
			public void run()
			{
				if(Problemonhop == true)
				{
					p.setIsVoting(false);
					VoteMain.setHasVotedHop(p);
					p.sendMessage("Thank you for voting for us!");
					//Announcements.getInstance().gameAnnounceToAll("[Vote Manager] Vote 4 Us on HOPZONE.");
					VoteMain.updateLastVoteHopzone(p);
					Problemonhop = false;
					System.out.println("I have error on topzone but i will give the reward... Please check me katara.");
				}
				else
				{
					if (firstvoteshop < getHopZoneVotes())
					{
						p.setIsVoting(false);
						VoteMain.setHasVotedHop(player);
						p.sendMessage("Thank you for voting for us!");
						//Announcements.getInstance().gameAnnounceToAll("[Vote Manager] Vote 4 Us on HOPZONE.");
						VoteMain.updateLastVoteHopzone(p);
						VoteMain.updateVotes(p);
					}
					else
					{
						p.setIsVoting(false);
						p.sendMessage("You did not vote on hopzone. Please try again later...");
						VoteMain.setTries(player, VoteMain.getTries(p) - 1);
					}
				}
			}
		}
		
		PreparedStatement statement = null;
		try (Connection 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)
		{
			e.printStackTrace();
		}
		
		if (getTries(player) <= 0)
		{
			player.sendMessage("Due to your multiple failures in voting you lost your chance to vote today");
		}
		else if (((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);
			//ExShowScreenMessageOnBroad screen = new ExShowScreenMessageOnBroad("GO at Website and vote on HOPZONE, " + player.getName(), 20000, SMPOS.TOP_CENTER, true);
			//player.sendPacket(screen);
			CreatureSay cs = new CreatureSay(player.getObjectId(), 3, "Hopzone system","Current votes are "+votesmessage+", careful with your vote!");
			player.sendPacket(cs);
			player.sendMessage("You have " + Config.SECS_TO_VOTE + " seconds.Hurry!");
			ThreadPoolManager.getInstance().scheduleGeneral(new hopvotetask(player), Config.SECS_TO_VOTE * 1000);
		}
		else if ((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);
			//ExShowScreenMessageOnBroad screen = new ExShowScreenMessageOnBroad("GO at Website and vote on HOPZONE, " + player.getName(), 20000, SMPOS.TOP_CENTER, true);
			//player.sendPacket(screen);
			CreatureSay cs = new CreatureSay(player.getObjectId(), 3, "Hopzone system","Current votes are "+votesmessage+", careful with your vote!");
			player.sendPacket(cs);
			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.");
		}
		
	}
	
	public static void topvote(final L2PcInstance player)
	{
		long lastVoteTopzone = 0L;
		long voteDelay = 43200000L;
		final int firstvotestop;
		int votesmessage = 0;
		
		firstvotestop = getTopZoneVotes();
		votesmessage = getTopZoneVotes();
		
		class topvotetask implements Runnable
		{
			private final L2PcInstance p;
			
			public topvotetask(L2PcInstance player)
			{
				p = player;
			}
			
			@Override
			public void run()
			{
				if(Problemontop == true)
				{
					p.setIsVoting(false);
					VoteMain.setHasVotedTop(p);
					p.sendMessage("Thank you for voting for us!");
					//Announcements.getInstance().gameAnnounceToAll("[Vote Manager] Vote 4 Us on TOPZONE.");
					VoteMain.updateLastVoteTopzone(p);
					Problemontop = false;
					System.out.println("I have error on topzone but i will give the reward... Please check me katara.");
				}
				else
				{
					if (firstvotestop < getTopZoneVotes())
					{
						p.setIsVoting(false);
						VoteMain.setHasVotedTop(p);
						p.sendMessage("Thank you for voting for us!");
						//Announcements.getInstance().gameAnnounceToAll("[Vote Manager] Vote 4 Us on TOPZONE.");
						VoteMain.updateLastVoteTopzone(p);
						VoteMain.updateVotes(p);
					}
					else
					{
						p.setIsVoting(false);
						p.sendMessage("You did not vote on topzone. Please try again later...");
						VoteMain.setTries(p, VoteMain.getTries(p) - 1);
					}
				}
			}
		}
		
		PreparedStatement statement = null;
		try (Connection 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)
		{
			e.printStackTrace();
		}
		
		if (getTries(player) <= 0)
		{
			player.sendMessage("Due to your multiple failures in voting you lost your chance to vote today");
		}
		else if ((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);
			//ExShowScreenMessageOnBroad screen = new ExShowScreenMessageOnBroad("GO at Website and vote on TOPZONE, " + player.getName(), 20000, SMPOS.TOP_CENTER, true);
			//player.sendPacket(screen);
			CreatureSay cs = new CreatureSay(player.getObjectId(), 3, "Topzone system","Current votes are "+votesmessage+", careful with your vote!");
			player.sendPacket(cs);
			player.sendMessage("You have " + Config.SECS_TO_VOTE + " seconds.Hurry!");
			ThreadPoolManager.getInstance().scheduleGeneral(new topvotetask(player), Config.SECS_TO_VOTE * 1000);
		}
		else if (((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);
			//ExShowScreenMessageOnBroad screen = new ExShowScreenMessageOnBroad("GO at Website and vote on TOPZONE, " + player.getName(), 20000, SMPOS.TOP_CENTER, true);
			//player.sendPacket(screen);
			CreatureSay cs = new CreatureSay(player.getObjectId(), 3, "Topzone system","Current votes are "+votesmessage+", careful with your vote!");
			player.sendPacket(cs);
			player.sendMessage("You have " + Config.SECS_TO_VOTE + " seconds.Hurry!");
			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.");
		}
		
	}
	
	public static void hasVotedHop(L2PcInstance player)
	{
		int hasVotedHop = -1;
		try (Connection 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);
			}
			else if (hasVotedHop == 0)
			{
				setHasVotedHop(false);
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public static void hasVotedTop(L2PcInstance player)
	{
		int hasVotedTop = -1;
		try (Connection 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);
			}
			else if (hasVotedTop == 0)
			{
				setHasVotedTop(false);
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public static void updateVotes(L2PcInstance activeChar)
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
		{
			PreparedStatement statement = con.prepareStatement("UPDATE characters SET totalVotes=? WHERE obj_Id=?");

			statement.setInt(1, getTotalVotes(activeChar) + 1);
			statement.setInt(2, activeChar.getObjectId());
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public static void setHasVotedHop(L2PcInstance activeChar)
	{
		try (Connection 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)
		{
			e.printStackTrace();
		}
	}
	
	public static void setHasVotedTop(L2PcInstance activeChar)
	{
		try (Connection 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)
		{
			e.printStackTrace();
	}
	}
	
	public static void setHasNotVotedHop(L2PcInstance activeChar)
	{
		try (Connection 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)
		{
			e.printStackTrace();
		}
	}
	
	public static void setHasNotVotedTop(L2PcInstance activeChar)
	{
		try (Connection 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)
		{
			e.printStackTrace();
		}
	}
	
	public static int getTries(L2PcInstance player)
	{
		int tries = -1;
		try (Connection 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)
		{
			e.printStackTrace();
		}
		return tries;
	}
	
	public static void setTries(L2PcInstance player, int tries)
	{
		try (Connection 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)
		{
			e.printStackTrace();
		}
	}
	
	public static int getTotalVotes(L2PcInstance player)
	{
		int totalVotes = 0;
		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
		{
			PreparedStatement statement = con.prepareStatement("SELECT totalVotes FROM characters WHERE obj_Id=?");
			statement.setInt(1, player.getObjectId());
			ResultSet rset = statement.executeQuery();
			while (rset.next())
			{	
				totalVotes = rset.getInt("totalVotes");
			}
			rset.close();
			statement.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return totalVotes;
	}
	
	public static int getBigTotalVotes(L2PcInstance player)
	{
		int bigTotalVotes = -1;
		try (Connection 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)
		{
			e.printStackTrace();
		}
		return bigTotalVotes;
	}
	
	public static void updateLastVoteHopzone(L2PcInstance player)
	{
		try (Connection 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)
		{
			e.printStackTrace();
		}
	}
	
	public static void updateLastVoteTopzone(L2PcInstance player)
	{
		try (Connection 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)
		{
			e.printStackTrace();
		}
	}
	
	// Getters and Setters
	public static boolean hasVotedHop()
	{
		return hasVotedHop;
	}
	
	public static void setHasVotedHop(boolean hasVotedHop)
	{
		VoteMain.hasVotedHop = hasVotedHop;
	}
	
	public static boolean hasVotedTop()
	{
		return hasVotedTop;
	}
	
	public static void setHasVotedTop(boolean hasVotedTop)
	{
		VoteMain.hasVotedTop = hasVotedTop;
	}
}
package com.l2jfrozen.gameserver.model.votereward;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Calendar;

import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
import com.l2jfrozen.util.database.L2DatabaseFactory;

public class TriesResetTask
{	
	public TriesResetTask()
	{
	}
	
	public static void getInstance()
	{
		ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
		{
			@Override
			public void run()
			{
				try (Connection con = L2DatabaseFactory.getInstance().getConnection())
				{
					PreparedStatement statement = con.prepareStatement("UPDATE characters SET tries=?");
					
					statement.setInt(1, 3);
					statement.execute();
					statement.close();
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		}, getValidationTime());
	}
	
	private static long getValidationTime()
	{
		Calendar cld = Calendar.getInstance();
		cld.set(11, 12);
		cld.set(12, 1);
		long time = cld.getTimeInMillis();
		if ((System.currentTimeMillis() - time) <= 0L)
		{
			long delay = cld.getTimeInMillis() - System.currentTimeMillis();
			return delay;
		}
		return 0L;
	}
}

that's all I have to clip than vote opium anyone desires to help thex

  • 0
Posted

I have also told you on private message what you need to do but seams that you are equal with 0 at java... you don't know even basic things.....

 

You have the same situation here what I replay above....

while ((inputLine = in.readLine()) != null)
			{
				if (inputLine.contains("Votes:"))
				{
					for (int i=-1; i>2; i++)
						inputLine = in.readLine();
 
					Problemontop = false;
					return Integer.valueOf(inputLine.split(">")[3].replace("</div", ""));
				}
			}

Replace it with  

while ((inputLine = in.readLine()) != null)
{
					Problemontop = false;
					return Integer.valueOf(inputLine);
}
  • 0
Posted

Locked .

 

Δεν νομιζω να νοιάζει κανέναν ποιανού είναι το pack .

Guest
This topic is now closed to further replies.


  • Posts

    • L2 Kings    Stage 1 – The Awakening Dynasty and Moirai Level Cap: 83 Gear: Dynasty -Moirai & Weapons (Shop for Adena + Drop from mobs/instances ) Masterwork System: Available (Neolithics S required with neolithics u can do armor parts foundation aswell) Class Cloaks: Level 1 - Masterwork sets such us moirai/dynasty stats are boosted also vesper(stage 2) Olf T-Shirt: +6 (fails don’t reset) safe is +2 Dolls: Level 1 Belts: Low & Medium Enchant: Safe +3 / Max +8 / Attribution Easy in Moirai-Dynasty . Main Zones: Varka Outpost: Easy farm, Adena, EXP for new players = > 80- 100kk hour Dragon Valley: Main farm zone — , 100–120kk/hour Weapon Weakness System active (all classes can farm efficiently) Archers get vampiric auto-hits vs mobs Dragon Valley Center: Main Party Zone — boosted drops (Blessed enchants, Neolithics chance) => farm like 150-200kk per hour. Dragon Valley North: Spoil Zone (Asofe + crafting materials for MW) Primeval Isle: Safe autofarm zone (low adena for casual players) ==> 50kk per hour Forge of the Gods & Imperial Tomb: Available from Stage 1 (lower Adena reward in compare with Dragon Valley) Hellbound also avaliable from stage 1 In few words all zones opened but MAIN farm zone with boosted adena and drops is Dragon valley also has more mobs Instances: Zaken (24h Reuse) → Instead of Vespers drop Moirai , 100% chance to drop 1 of 9 dolls lvl 1, Zaken 7-Day Jewelry Raid Bosses (7 RBs): Drop Moirai Parts + Neolithic S grade instead of Vespers parts that has 7 Rb Quest give Icarus Weapons Special Feature 7rb bosses level up soul crystals aswell. Closed Areas : Monaster of SIlence, LOA, ( It wont have mobs) / Mahum Quest/Lizardmen off) Grand Epics: Unlocked on Day 4 of Stage 1 → Antharas, Valakas, Baium, AQ, etc ================================================================================= Stage 2 – Rise of Vespers Level Cap: 85 Gear: Moirai Armors (Adena GM SHOP / Craft/ Drop) Weapons: Icarus Cloaks: Level 2 Olf: +8 Dolls: Level 2 Belts: High & Top Enchant: Safe +3 / Max +8 Masterwork can be with Neolithics S84 aswell but higher so craft will be usefull aswell. 7 Raid Boss Quest Updated: Now works retail give vesper weapons 7rb Bosses Drops : Vespers Instances: Zaken : Drops to retail vespers + the dolls and the extra items that we added on stage 1 New Freya Instance: Added — drops vespers and instead of mid s84 weapons will drop vespers . Extra drops Blessed Bottle of Freya - drops 100% chance 1 of 9 dolls. Farm Areas Dragon Valley remains main farm New Zone : Lair of Antharas (mobs nerfed and added drop Noble stone so solo players can farm too) New Party Zone : LOA Circle   ============================================================================   Stage 3 – The Vorpal ERA Gear: Vorpal Unclock Cloaks: Level 3 Olf: +10 (max cap) Dolls: Level 3 Enchant: Safe +3 / Max +12 Farm Zones : Dragon Valley Center Scorpions becomes a normal solo zone (no longer party zone) Drops:   LOA & Knorik → Mid Weapons avaliable in drop New Party Zone Kariks Instances: Easy Freya Drops Mid Weapons Frintezza Release =================================================================================     Stage 4 – Elegia Era (Final Stage) Elegia Unlock Gear: Elegia Weapons: Elegia TOP s84 ( farmed via H-Freya/ Drops ) Cloaks: Level 5 Dolls: Level 3 (final bonuses) Enchant: Safe +6 / Max +16 Instances: Hard Freya → Drops Elegia Weapons + => The Instance will drop 2-3 parts for sure and also will be able to Join with 7 people . Party Zone will have also drop chances for elegia armor parts and weapons but small   Events (Hourly): Win: 50 Event Medals + 3 GCM + morewards Lose: 25 Medals + 1 GCM + more rewards Tie: 30 Medals + 2 GCM + more rewards   ================================================================================ Epic Fragments Currency Participating in Daily Bosses mass rewarding all players Participating in Instances (zaken freya frintezza etc) all players get reward ================================================================================ Adena - Main server currency (all items in gm shop require adena ) Event Medals (Festival Adena) - Event shop currency Donation coins you can buy with them dressme,cosmetics and premium account Epic Fragments you can buy with them fake epic jewels Olympiad Tokens you can buy many items from olympiad shop (Hero Coin even items that are on next stages) Olympiad Win = 1000 Tokens / Lose = 500 Tokens ================================================================================= Offline Autofarm Allows limited Offline farming requires offline autofarm ticket that you get by voting etc ================================================================================= Grand Epics have Specific Custom NPC that can spawn Epics EU/LATIN TIME ZONE ================================================================================= First Olympiad Day 19 December First Heroes 22 December ( 21 December Last day of 1st Period) After that olympiad will be weekly. ================================================================================= Item price and economy Since adena is main coin of server and NOT donation coins we will always add new items in gm shop with adena in order to burn the adena of server and not be inflation . =================================================================================        
    • Hello, I'd like to change a title color for custom npc.  I created custom NPC, cloned existing. I put unique id for it in npcname-e, npcgrp and database. I have "0" to serverSideName in db, so that it would use npcname-e, but instead it has "NoNameNPC"and no title color change.
    • Trusted Guy 100% ,  I asked him for some work and he did it right away.
  • 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