Jump to content
  • 0

[help] vote reward bugged


TouchAndDie
 Share

Question

hello :) i have this vote reward:

package com.l2jserver.gameserver.instancemanager;

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 com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.Announcements;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.clientpackets.Say2;
import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
import com.l2jserver.gameserver.util.Broadcast;

public class AutoVoteRewardHandler
{
private final String TOPZONE = "http://l2topzone.com/";
// 60 * 1000(1000milliseconds = 1 second) = 60seconds
private final int initialCheck = 60 * 1000;
// 1800 * 1000(1000milliseconds = 1 second) = 1800seconds = 30minutes
private final int delayForCheck = 1800 * 1000;
private final int[] itemId = { 9627, 9142 };
   private final int[] itemCount = { 2, 500 };
private final int[] maxStack = { 2, 500 };
private final int votesRequiredForReward = 10;
// do not change
private int lastVoteCount = 0;

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

private class AutoReward implements Runnable
{
	public void run()
	{
		int votes = getVotes();
		System.out.println("Server Votes: " + votes);
		if (votes != 0 && getLastVoteCount() != 0 && votes >= getLastVoteCount() + votesRequiredForReward)
		{
			Connection con = null;
			try
			{
				con = L2DatabaseFactory.getInstance().getConnection();
				PreparedStatement statement = con.prepareStatement("SELECT c.charId, c.char_name FROM characters AS c LEFT JOIN accounts AS a ON c.account_name = a.login WHERE c.online > 0 GROUP BY a.lastIP ORDER BY c.level DESC");
				ResultSet rset = statement.executeQuery();
				L2PcInstance player = null;
				L2ItemInstance item = null;
				while (rset.next())
				{
					player = L2World.getInstance().getPlayer(rset.getInt("charId"));
					if (player != null && !player.getClient().isDetached())
					{
						for (int i = 0; i < itemId.length; i++)
						{
							item = player.getInventory().getItemByItemId(itemId[i]);
							if (item == null || item.getCount() < maxStack[i])
								player.addItem("reward", itemId[i], itemCount[i], player, true);
						}
					}
				}
				statement.close();
		}
			catch (SQLException e)
		{
				e.printStackTrace();
			}
			finally
			{
				L2DatabaseFactory.close(con);
			}

			setLastVoteCount(getLastVoteCount() + votesRequiredForReward);
		}
		Broadcast.toAllOnlinePlayers(new CreatureSay(1, Say2.ANNOUNCEMENT, "Announcements:", "Server Votes: " + votes + " | Next Reward on " + (getLastVoteCount() + votesRequiredForReward) + " Votes.)"));
		if (getLastVoteCount() == 0)
			setLastVoteCount(votes);
	}
}

private int getVotes()
{
	URL url = null;
	InputStreamReader isr = null;
	BufferedReader in = null;
	try
	{
		url = new URL(TOPZONE);
		isr = new InputStreamReader(url.openStream());
		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)
	{
		e.printStackTrace();
	}
	finally
	{
		try
		{
			in.close();
		}
		catch (IOException e)
		{}
		try
		{
			isr.close();
		}
		catch (IOException e)
		{}
	}
	return 0;
}

private void setLastVoteCount(int voteCount)
{
	lastVoteCount = voteCount;
}

private int getLastVoteCount()
{
	return lastVoteCount;
}

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

@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
	protected static final AutoVoteRewardHandler _instance = new AutoVoteRewardHandler();
}
}

if the script check it and it has 10 votes i get vote reward but if the check is with 11 votes+ i don't get the reward.. i mean now i have 100 votes and after 2 mins i have 111 votes and i don't get the reward only if i have 110.. how can i fix that ?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   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.

 Share



×
×
  • 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 Disbaled AdBlock