i found a file for l2jfrozen.. but i trying to do it for l2jserver:
location: scripts\custom\votereward\AutoVoteRewardHandler.java
Code:
package custom.AutoVoteRewardHandler;
import java.util.regex.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.Announcements;
import com.l2jserver.gameserver.ThreadPoolManager;
public class AutoVoteRewardHandler
{
private static Logger _log = Logger.getLogger(AutoVoteRewardHandler.class.getName());
private final static String SERVER_WEB_SITE = "http://myWeb.tk";
private final static String SiteUrl = "http://myWeb/findVotes.php";
private final static int VOTES_FOR_REWARD = 10;
private final static int _INITIAL_DELAY = 1*60000;
private final static int _STEP_DELAY = 10*60000;
//Item Id, Amount.
private final static int RW_ITEM = 14721;
private final static int RW_COUNT = 1;
private int hopzoneVotesCount = 0;
private List<String> already_rewarded;
private static boolean hopzone = false;
private final boolean ALL_EXCEPTIONS = true;
private AutoVoteRewardHandler()
{
_log.info("Vote Reward System Initiated.");
if(hopzone){
int hopzone_votes = getHopZoneVotes();
if(hopzone_votes == -1){
hopzone_votes = 0;
}
setHopZoneVoteCount(hopzone_votes);
}
ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), _INITIAL_DELAY , _STEP_DELAY );
}
private class AutoReward implements Runnable
{
@Override
public void run()
{
int minutes = ( _STEP_DELAY / 1000 ) / 60;
if(hopzone){
int hopzone_votes = getHopZoneVotes();
if(hopzone_votes != -1){
_log.info("[AutoVoteReward] Server HOPZONE Votes: " + hopzone_votes);
Announcements.getInstance().announceToAll("[AutoVoteReward] Actual HOPZONE Votes are " + hopzone_votes + "...");
if (hopzone_votes != 0 && hopzone_votes >= getHopZoneVoteCount() + VOTES_FOR_REWARD)
{
already_rewarded = new ArrayList<String>();
Announcements.getInstance().announceToAll("[AutoVoteReward] Great Work! Check your inventory for Reward!!");
L2PcInstance[] pls = L2World.getInstance().getAllPlayers().getValues(new L2PcInstance[0]);
//L2ItemInstance item;
for (L2PcInstance player : pls)
{
if (player != null && !player.getClient().isDetached())
{
if(player.isOnline() && checkSingleBox(player)){
if(player.getInventory().validateCapacityByItemId(RW_ITEM))
{
player.addItem("reward", RW_ITEM, RW_COUNT, player, true);
}
}
}
}
setHopZoneVoteCount(hopzone_votes);
}
Announcements.getInstance().announceToAll("[AutoVoteReward] Next HOPZONE Reward in "+minutes+" minutes at " + (getHopZoneVoteCount() + VOTES_FOR_REWARD) + " Votes!!");
//site web
Announcements.getInstance().announceToAll("[SiteWeb] "+SERVER_WEB_SITE);
}
}
if(hopzone && _STEP_DELAY > 0)
try
{
Thread.sleep(_INITIAL_DELAY/2);
}
catch(InterruptedException e)
{
if(ALL_EXCEPTIONS)
e.printStackTrace();
}
}
}
private boolean checkSingleBox(L2PcInstance player){
if(player.getClient()!=null && player.getClient().getConnection()!=null && !player.getClient().getConnection().isClosed() && !player.getClient().isDetached()){
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;
}
private int getHopZoneVotes()
{
int votes = -1;
URL url = null;
InputStreamReader isr = null;
BufferedReader in = null;
try
{
url = new URL(SiteUrl);
URLConnection con = url.openConnection();
con.addRequestProperty("User-Agent", "Mozilla/4.76");
isr = new InputStreamReader(con.getInputStream());
in = new BufferedReader(isr);
String inputLine;
inputLine = in.readLine();
Pattern p = Pattern.compile("[0-9]");
Matcher m = p.matcher(inputLine);
if ( m.find() ){
int o = Integer.parseInt(inputLine);
votes = Integer.valueOf(o);
}
}
catch (Exception e)
{
_log.info("[AutoVoteReward] Server HOPZONE is offline or something is wrong in link");
Announcements.getInstance().announceToAll("[AutoVoteReward] HOPZONE is offline. We will check reward as it will be online again");
//e.printStackTrace();
}
finally
{
try
{
if(in!=null)
in.close();
}
catch (Exception e)
{
if(ALL_EXCEPTIONS)
e.printStackTrace();
}
try
{
if(isr!=null)
isr.close();
}
catch (Exception e)
{
if(ALL_EXCEPTIONS)
e.printStackTrace();
}
}
return votes;
}
private void setHopZoneVoteCount(int voteCount)
{
hopzoneVotesCount = voteCount;
}
private int getHopZoneVoteCount()
{
return hopzoneVotesCount;
}
public static AutoVoteRewardHandler getInstance()
{
if(SiteUrl != null && !SiteUrl.equals("")){
hopzone = true;
}
if(hopzone)
return SingletonHolder._instance;
return null;
}
@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
protected static final AutoVoteRewardHandler _instance = new AutoVoteRewardHandler();
}
}
findVotes.php:
PHP Code:
<?php
//here vote url:
$url = 'http://l2.hopzone.net/lineage2/details/YourIDHopzone/NameServer';
function Obtener_contenidos($url,$inicio='',$final){
$source = @file_get_contents($url)or die('se ha producido un error');
$posicion_inicio = strpos($source, $inicio) + strlen($inicio);
$posicion_final = strpos($source, $final) - $posicion_inicio;
$found_text = substr($source, $posicion_inicio, $posicion_final);
return $inicio . $found_text .$final;
}
function Obtener_contenidos2($url,$inicio='',$final){
$posicion_inicio = strpos($url, $inicio) + strlen($inicio);
$posicion_final = strpos($url, $final) - $posicion_inicio;
$found_text = substr($url, $posicion_inicio, $posicion_final);
return $inicio . $found_text .$final;
}
$startFind="<span class=\"rank anonymous tooltip\" title=\"Anonymous User Votes\">";
$EndFind="[0-9]+</span>";
//take part of hopzone html code
$obtenido = Obtener_contenidos($url, $startFind, $EndFind);
$startFind2="<span";
$EndFind2="</span>";
//clean all HTML/text/others to print only votes. (numbres)
echo preg_replace("/[^0-9]/", "", Obtener_contenidos2($obtenido, $startFind2, $EndFind2));
?>
error log from AutoVoteRewardHandler.java:
Code:
Error on: D:\server\game\data\scripts\custom\votereward\AutoVoteRewardHandler.java.error.log
Line: -1 - Column: -1
java.lang.ClassNotFoundException: custom.VoteEngine.AutoVoteRewardHandler
whats wrong?..
i edited that code from: here