Jump to content

[Share] Topzone vote reward


Recommended Posts

As l2topzone.com updated it's source and hopzone's vote reward does not work for topzone too here is a vote reward,

 

 package net.sf.l2j.gameserver.model;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Collection;

import javolution.util.FastList;

import net.sf.l2j.Config;
import net.sf.l2j.gameserver.Announcements;
import net.sf.l2j.gameserver.GmListTable;
import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.model.L2ItemInstance;
import net.sf.l2j.gameserver.model.L2World;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.serverpackets.ExShowScreenMessage;
import net.sf.l2j.gameserver.serverpackets.ExShowScreenMessage.SMPOS;


public class TopzoneVoteRewardHandler
{
private int	lastVoteCount = 0;
private int	initialCheck = 60 * 1000;														
private int	delayForCheck = 300 * 1000;														
private int	votesForReward = 5;
private int	maxRewardStack = 500;

@SuppressWarnings("synthetic-access")
private TopzoneVoteRewardHandler()
{
	System.out.println("Topzone Vote Reward System activated.");
	ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), initialCheck, delayForCheck);
}

private class AutoReward implements Runnable
{
	public void run()
	{
		System.out.println("Topzone Vote Count Check.");
		if (Config.TOPZONE_VOTE_REWARD1_ID == 0 || Config.TOPZONE_VOTE_REWARD1_COUNT == 0)
		{
			GmListTable.broadcastMessageToGMs("The rewards aren't Identified. Please take a look.");
			return;
		}
		int newVoteCount = getVotes(Config.TOPZONE_VOTE_HTML_PATCH);
		System.out.println("newVoteCount:"+newVoteCount);
		System.out.println("getLastVoteCount:"+getLastVoteCount());
		if (newVoteCount != 0 && getLastVoteCount() != 0 && newVoteCount >= getLastVoteCount() + votesForReward)
		{
			FastList<InetAddress> ip = new FastList<InetAddress>();
			Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers();
			for (L2PcInstance player : pls)
			{
				if (player != null)
				{
					L2ItemInstance item1 = player.getInventory().getItemByItemId(Config.TOPZONE_VOTE_REWARD1_ID);
					if (item1 == null || item1.getCount() < maxRewardStack)
					{
						InetAddress ipc = player.getClient().getConnection().getSocketChannel().socket().getInetAddress();

						if(ip.contains(ipc))
							continue;

						ip.add(ipc);
						player.addItem("reward", Config.TOPZONE_VOTE_REWARD1_ID, Config.TOPZONE_VOTE_REWARD1_COUNT, player, true);
						player.sendMessage("Keep Voting For Us.Rewards given.");
					}
				}
			}	
			setLastVoteCount(getLastVoteCount()+ votesForReward);
		}

		Announcements.getInstance().announceToAll("L2Godrich TopZone : " + newVoteCount + " Votes.");
		Announcements.getInstance().announceToAll("Next reward will be on : " + (getLastVoteCount()+ votesForReward) + " Votes.");
		Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers();

		if (getLastVoteCount() == 0)
		{
			setLastVoteCount(newVoteCount);
		}
	}
}

static int getVotes(String urlString)
{
	String htmlText = "";
	boolean startAdd = false;
	int voteCount = 0;
	boolean ok = false;
	try
	{
		URL pageToDisplay;
		pageToDisplay = new URL(urlString);
		URLConnection conn = pageToDisplay.openConnection();
		conn.connect();				
		InputStream in = conn.getInputStream();
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		htmlText = "";
		while(!ok)
		{
			String newLine = br.readLine();
			if (newLine == null)
			{
				ok = true;
			}
			else 
			{
				if (htmlText.length() < 110000)
				{
					if (!startAdd && newLine.indexOf(">Votes<") > 0) 
						startAdd = true;
					if (startAdd && newLine.indexOf(">Uptime<") > 0) 
						startAdd = false;
					if (startAdd) 
						htmlText = htmlText+newLine;
					if (htmlText.length() > 10 && !startAdd) 
						ok = true;					     
				}
			}
		}
		br.close();
	}
	catch (MalformedURLException mfe)
	{
	} 
	catch (IOException e)
	{ 
	}
	htmlText = htmlText.substring(htmlText.indexOf("font-size")+ 31);
	htmlText = htmlText.substring(0,htmlText.indexOf("</font>"));
	try
	{
		voteCount = Integer.parseInt(htmlText);
	}
	catch (NumberFormatException a)
	{
		voteCount = 0;
	}
        return voteCount;
}

private void setLastVoteCount(int voteCount)
{
	lastVoteCount = voteCount;
}

private int getLastVoteCount()
{
	return lastVoteCount;
}

public static TopzoneVoteRewardHandler getInstance()
{
	return SingletonHolder._instance;
}

@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
	protected static final TopzoneVoteRewardHandler _instance = new TopzoneVoteRewardHandler();
}
}

 

Config.java

public static boolean TOPZONE_VOTE_ENABLE;
public static String TOPZONE_VOTE_HTML_PATCH;
public static int TOPZONE_VOTE_REWARD1_ID;
public static int TOPZONE_VOTE_REWARD2_ID;
public static int TOPZONE_VOTE_REWARD1_COUNT;
public static int TOPZONE_VOTE_REWARD2_COUNT;




TOPZONE_VOTE_ENABLE = Boolean.parseBoolean(Customs.getProperty("TopzoneVoteEnable", "False"));
    			PROTECTED_GAMESERVER = Boolean.parseBoolean(Customs.getProperty("ProtectGameServerWithPassword", "False"));
                TOPZONE_VOTE_HTML_PATCH = Customs.getProperty("TopzoneVoteHtmlPatch", "Null");
			TOPZONE_VOTE_REWARD1_COUNT = Integer.parseInt(Customs.getProperty("TopzoneVoteReward1Count", "1000"));
			TOPZONE_VOTE_REWARD2_COUNT = Integer.parseInt(Customs.getProperty("TopzoneVoteReward2Count", "1000"));
			TOPZONE_VOTE_REWARD1_ID = Integer.parseInt(Customs.getProperty("TopzoneVoteReward1Id", "57"));
			TOPZONE_VOTE_REWARD2_ID = Integer.parseInt(Customs.getProperty("TopzoneVoteReward2Id", "57"));
    			

Do not forget to register this on gameserver.

 

Credits: me

 

PS: it's tested.

Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...

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
Reply to this topic...

×   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

    • amigo como eu coloco pra mostra os icone enchant no inventory  vc pode da essa ajuda @ShooterLineage2 ?
    • 📢 𝐖𝐞 𝐚𝐫𝐞 𝐢𝐧 𝐛𝐞𝐭𝐚 𝐭𝐞𝐬𝐭, 𝐰𝐞 𝐰𝐢𝐥𝐥 𝐬𝐭𝐚𝐫𝐭 𝐨𝐧 𝐉𝐮𝐧𝐞 𝟐𝟎 𝐚𝐭 𝟏𝟖:𝟎𝟎 𝐦𝐨𝐫𝐞 𝐢𝐧𝐟𝐨𝐬 𝐢𝐧 https://l2bless.online/infos.html ⚔️ 𝗥𝗮𝘁𝗲𝘀: 𝗫𝗣 𝟐𝟎𝐗, 𝗔𝗱𝗲𝗻𝗮 𝟐𝟎𝐗, 𝗦𝗽𝗼𝗶𝗹 𝟐𝟎𝐗, 𝗗𝗿𝗼𝗽 𝟐𝟎𝐗, 💬 𝗠𝗮𝘅 𝗲𝗻𝗰𝗵𝗮𝗻𝘁 +𝟭𝟲 𝘄𝗶𝘁𝗵 𝟲𝟱% 𝗻𝗼𝗿𝗺𝗮𝗹 𝗮𝗻𝗱 𝟳𝟬% 𝗯𝗹𝗲𝘀𝘀𝗲𝗱, 👉 𝟳𝟬+ 𝗔𝘂𝘁𝗼 𝗲𝘃𝗲𝗻𝘁𝘀, 𝗖𝘂𝘀𝘁𝗼𝗺 𝗥𝗮𝗶𝗱𝘀, 𝟱𝟱 𝗻𝗲𝘄𝘀 𝗖𝗹𝗼𝗮𝗸𝘀, 🌍 𝗪𝗲𝗯𝗦𝗶𝘁𝗲: https://l2bless.online/
    • What unique features ? 
    • Welcome to SmurfsZone   Buy League of Legends accounts across all servers and jump straight into Ranked Games with amazing quality and support.   Why Choose SmurfsZone? 24/7 Instant Delivery: Get your full access LoL smurf account immediately. 100% Hand-Leveled: High-quality accounts leveled by hand. Versatile MMR Options: High MMR, Standard MMR, Fresh MMR (ARAMs), and Ranked accounts available. Valorant Accounts: Expand your gaming experience. Our Commitment to You: Unopened Loot: Customize your champion pool. Lifetime Warranty: Valid if you change the email, username, and password upon purchase. Password Changeable: Ensure your account's security. Full Recovery Information: Complete access to account recovery details. Unverified and Changeable Email: Easy to personalize and secure your account. Completely Unranked: Fresh start with no ranked history in any season. Responsive Customer Support: Our dedicated team is available to assist you 24/7.   Experience the best place to buy League of Legends accounts with exceptional quality and dedicated support. We're here for YOU!
    • Thanks! I'll take a second look and let you know if my implementation of the clearCircle() helps with the stuttering once I find time for some extensive testing.
  • Topics

×
×
  • Create New...