Skip to content

HELP pls Java

Featured Replies

Hello... i have problem with Vote Reward...

 

i have this code:

package com.l2jserver.gameserver.instancemanager;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collection;


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;

public class AutoVoteRewardHandler
{
private final String HOPZONE = "http://l2.hopzone.net/lineage2/moreinfo/L2-NeXtGeN/92153.html";
// 60 * 1000(1000milliseconds = 1 second) = 60seconds
private final int initialCheck = 60 * 1000;
// 1800 * 1000(1000milliseconds = 1 second) = 1800seconds = 30minutes
private final int delayForCheck = 600 * 1000;
private final int[] itemId = {33399, 33340 };
private final int[] itemCount = { 5, 2};
private final int[] maxStack = { 1, 1 };
private final int votesRequiredForReward = 10;
// do not change
private int lastVoteCount = 0;
private static ArrayList<String> _listedIps;

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

private class AutoReward implements Runnable
{
	@Override
	public void run()
	{
		int votes = getVotes();
		System.out.println("Server Votes: " + votes);
		if (votes != 0 && getLastVoteCount() != 0 && votes >= getLastVoteCount() + votesRequiredForReward)
		{
			Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().values();
			int onlinePlayers = 0;
			for (L2PcInstance pl : pls)
			{
				if (pl.isOnline() && !pl.getClient().isDetached())
				{
					onlinePlayers++;
				}
			}
			_listedIps = new ArrayList<String>(onlinePlayers);
			L2ItemInstance item;
			for (L2PcInstance player : pls)
			{
				if (player != null && player.isOnline() && !player.getClient().isDetached())
				{
					for (int i = 0; i < itemId.length; i++)
					{
						item = player.getInventory().getItemByItemId(itemId[i]);
						if (item == null || item.getCount() < maxStack[i])
						{
							String host = player.getClient().getConnection().getInetAddress().getHostAddress();
							if (host != null && !_listedIps.contains(host))
								_listedIps.add(host);
							else
								return;

							player.addItem("reward", itemId[i], itemCount[i], player, true);
						}
					}
				}
			}
			setLastVoteCount(getLastVoteCount() + votesRequiredForReward);
		}
		Announcements.getInstance().announceToAll("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(HOPZONE);
		URLConnection con = (URLConnection) url.openConnection();
		con.addRequestProperty("User-Agent", "Mozilla/4.76"); 
		isr = new InputStreamReader(con.getInputStream());
		//isr = new InputStreamReader(url.openStream());
		in = new BufferedReader(isr);
		String inputLine;
		while ((inputLine = in.readLine()) != null)
		{
			if (inputLine.contains("moreinfo_total_rank_text"))
			{
				return Integer.valueOf(inputLine.split(">")[2].replace("</div", ""));
			}
		}
	}
	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();
}
}

no have error ... nothing...

 

have one problem:

I voted in hopzone and in server result is:

Server Votes: 0    |  Next Reward on: 10    votes

 

please help me... :| no counting votes on hopzone

-			while ((inputLine = in.readLine()) != null)
-			{
-				if (inputLine.contains("moreinfo_total_rank_text"))
-				{
-					return Integer.valueOf(inputLine.split(">")[2].replace("</div", ""));
-				}
-			}
+			while ((inputLine = in.readLine()) != null)
+			{
+				//topzone
+				while ((inputLine = in.readLine()) != null)
+				{
+					if (inputLine.contains("								<tr><td><div align=\"center\"><b><font style=\"font-size:14px;color:#018BC1;\">"))
+					{
+						return Integer.valueOf(inputLine.replace("								<tr><td><div align=\"center\"><b><font style=\"font-size:14px;color:#018BC1;\">", "").replace("</font></b></div></td></tr>", ""));
+					}
+				}
+			}

 

it should work :)

  • Author

im need for hopzone no topzone

and teste your code... not working

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.