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 ?
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.
Excellent seller! Super helpful.
The code runs on Java 11, but it’s really stable and easy to work with. It already has a bunch of PvP-ready features that can save you weeks of work.
I’ve managed to add an AI model (DeepSeek and ChatGPT) to help run the server as GMGod. Also upgraded the Autobots — now they can accept parties, follow the leader across different spots, and even kite properly.
Really happy so far. Big vouch for @IcathiaLord!
When everything works — life is easier.
Vibe SMS is a service where using it is simple and stress-free.
No unnecessary complications: you get a number, complete your task, and move on.
We design our service so you can focus on what really matters and not waste time on small details.
We’re against unnecessary complexity; we’re for calm and confident work.
Website link — https://vibe-sms.net/
Our Telegram channel — https://t.me/vibe_sms
Hello!
Can you please elaborate about what is exactly, how it works, maybe some pictures would be nice!
Also, when sharing files, it would be awesome to scan them for viruses first so nobody downloads any malicious.
Question
TouchAndDie
hello :) i have this vote reward:
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 ?
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.
Note: Your post will require moderator approval before it will be visible.