Hmm I can share with you my code, I use it as script in DataPack side.
/*
* 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/>.
*/
package custom.AutoVoteEngine;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.Event;
/**
* @author Sirpaypi~
* @version 2.7
*/
public class AutoVoteRewardHandler
{
protected static final Logger _log = Logger.getLogger(AutoVoteRewardHandler.class.getName());
private final static String _url = "YOUR VOTE SCRIPT";
private final int _votesRequiredForReward = 5;
private final int initialCheck = 5;
private final int delayForCheck = 10;
private final static int[][] ITEMs =
{
{ 57, 200 },
};
private int _lastVoteCount = 0;
private AutoVoteRewardHandler()
{
_log.info("[AutoVoteReward]: AUTO Vote Reward Started.");
ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), initialCheck * 60000, delayForCheck * 60000);
}
private class AutoReward implements Runnable
{
public void run()
{
int votes = getVotes();
int rewardedPlayers = 0;
if (votes > -1)
{
if ((getLastVoteCount() != 0) && (votes >= (getLastVoteCount() + _votesRequiredForReward)))
{
for (L2PcInstance player : L2World.getInstance().getAllPlayersArray())
{
if ((player != null) && !player.getClient().isDetached())
{
for (int[] reward : ITEMs)
{
if (player.getInventory().validateCapacityByItemId(reward[0]))
{
player.addItem("reward", reward[0], player, true);
}
}
rewardedPlayers++;
}
}
setLastVoteCount(getLastVoteCount() + _votesRequiredForReward);
}
else if (getLastVoteCount() == 0)
{
setLastVoteCount(votes);
}
_log.info("[AutoVoteReward]: Current Count : " + votes + ", Rewared Players : " + rewardedPlayers);
Event.getInstance().eventToAll("L2Cataclysm's Current vote count is " + votes + " , Next Reward on " + (getLastVoteCount() + _votesRequiredForReward) + " Votes.");
}
else
{
_log.log(Level.WARNING, "[AutoVoteReward]: Oups Failled...");
}
}
}
private static int getVotes()
{
BufferedReader in = null;
int votes = -1;
try
{
in = new BufferedReader(new InputStreamReader(new URL(_url).openStream()));
String inputLine;
while (((inputLine = in.readLine()) != null) && (votes == -1))
{
if (inputLine.contains("moreinfo_total_rank_text"))
{
try
{
votes = Integer.valueOf(inputLine.split(">")[2].replace("</div", ""));
}
catch (Exception e)
{
}
}
}
in.close();
}
catch (Exception e)
{
_log.log(Level.WARNING, "[AutoVoteReward]: " + e.getMessage(), e);
}
return votes;
}
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();
}
public static void main(String[] args)
{
AutoVoteRewardHandler.getInstance();
}
}