Jump to content
  • 0

HELP pls Java


cutitarii

Question

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

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

-			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 :)

Link to comment
Share on other sites

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.

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.



  • Posts

    • rename the l2.bin into l2.exe
    • L2LIVE.PRO- Dynamic Mid-rates Essence Seven Signs GRAND OPENING - July 5, 20:00 GMT+3 (EEST) TEST SERVER IS OPEN - COME AND CHECK IT OUT TODAY! Join our community and be part of it at: https://www.l2live.pro https://discord.gg/k3NMgR4Dmu   Server description * EXP/SP: Dynamic (x1- x100 based on your level, *before* Sayha and EXP buffs * Adena: x50 / Item Drop: x10 / Fishing EXP increased / Attribute EXP increased * Simplified gameplay to stay in the loop while not spending hours and hours farming * Starter Pack containing very useful items for beginners * MP replenishing potions with auto-consumption * No overpowered donations L2LIVE shop * All spellbook coupons, pet spellbook coupons and master books are sold via Game Assistant * Additionally you can buy SP pouches, enchanted talismans, pet training guides and various other consumables for Adena and L-Coin * More items such as cloaks, more talismans, agathions, belts, pendants, enchantment scrolls of various grades, evolution stones, etc will be added! Shop server as a shortcut, and all retail-like ways of earning items are still here! L-Coins * Drops with small change and in random amounts from Lv60+ monsters  * All raidbosses drop random amount of L-Coin Pouches generating up to 420 Lcoin per unit. **Grand Olympiad and Events** * Grand Olympiad is held week day * Format is 1v1, unlimited weekly fights  * Heroes are declared weekly at Sunday * There are three automated events - TvT, CTF and Deathmatch, running at evenings * Orc Fortress, Battle with Balok, Keber Hunter, Archievements Box, Daily Gift Calendar provisional events are active too Custom user commands * .offlineplay command, your character will keep playing till death or server restart * .offlineshop command, keeps your shop sitting until all items are purchased * .apon / .apoff - enable/disable HP/MP autoconsume And lots of other small improvements are waiting for you!   Join our community and be part of it at: https://www.l2live.pro https://discord.gg/k3NMgR4Dmu
    • I can use this folder system for High Five offline server?   The folder does not have a l2.exe file.   Thank you very much if anyone can help me.   https://drive.google.com/file/d/13kU-g_4JJ-sP-kg2F7pqkUOVKmQdubFm/view
  • Topics

×
×
  • Create New...