Jump to content
  • 0

[Help] Vote Reward


Question

Posted

Hi, i am triying to make it works but.. nothing can help me plz?.

 

dibujogim.jpg

 

Uploaded with ImageShack.us

 

package L2j.Infinity.gameserver.model.entity;

 

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.net.URL;

import java.util.ArrayList;

import java.util.Collection;

import java.net.URLConnection;

 

import L2j.Infinity.ExternalConfig;

import L2j.Infinity.gameserver.Announcements;

import L2j.Infinity.gameserver.ThreadPoolManager;

import L2j.Infinity.gameserver.model.L2ItemInstance;

import L2j.Infinity.gameserver.model.L2World;

import L2j.Infinity.gameserver.model.actor.instance.L2PcInstance;

 

public class AutoVoteRewardHandler

{

private final String HOPZONE = ExternalConfig.WEBSITE_SERVER_LINK;

// 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 = {ExternalConfig.ITEM_ID};

private final int[] itemCount = {ExternalConfig.ITEM_COUNT};

private final int[] maxStack = { 1 };

private final int votesRequiredForReward = ExternalConfig.REQUIREDVOTES;

// 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);

if (item == null || item.getCount() < maxStack)

{

String host = player.getClient().getConnection().getInetAddress().getHostAddress();

if (host != null && !_listedIps.contains(host))

_listedIps.add(host);

else

return;

 

player.addItem("reward", itemId, itemCount, 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 = url.openConnection();

con.addRequestProperty("User-Agent", "Mozilla/4.76");

isr = new InputStreamReader(con.getInputStream());

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();

}

}

 

Thx everyone!

10 answers to this question

Recommended Posts

  • 0
Posted
Index: /trunk/***/java/com/***/gameserver/handler/AutoVoteRewardHandler.java
===================================================================
--- /trunk/***/java/com/***/gameserver/handler/AutoVoteRewardHandler.java
+++ /trunk/***/java/com/***/gameserver/handler/AutoVoteRewardHandler.java	
@@ -235,7 +235,7 @@
			while ((inputLine = in.readLine()) != null)
			{
-				if (inputLine.contains("moreinfo_total_rank_text"))
+				if (inputLine.contains("rank anonymous tooltip"))
				{
-					votes = Integer.valueOf(inputLine.split(">")[2].replace("</div", ""));
+					votes = Integer.valueOf(inputLine.split(">")[2].replace("</span", ""));
					break;
				}

  • 0
Posted

Change:

while ((inputLine = in.readLine()) != null)
{
if (inputLine.contains("moreinfo_total_rank_text"))
{
	return Integer.valueOf(inputLine.split(">")[2].replace("</div", ""));
}
}

 

For:

while ((inputLine = in.readLine()) != null)
{
if (inputLine.contains("Anonymous User Votes"))
{
	try
	{
		return Integer.parseInt(inputLine.substring(inputLine.indexOf("Votes") + 7, inputLine.indexOf("<", inputLine.indexOf("Votes"))));
	}
	catch (Exception e)
	{
		return -1;
	}
}
}

 

Hope that helps.

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.



×
×
  • Create New...