Author Topic: High Five Vote Reward Fix For Hopzone.  (Read 53 times)

Offline JMD

  • Heir
  • **
  • Posts: 40
Vote Reward Fix For Hopzone.
« on: April 06, 2021, 09:27:45 PM »
I really hope Mobius makes these work in a proper way sometime.

Im not really interested in making the other topsites work so feel free to use this method for the others if its applicable and share it.

I dont use any version control atm so im not able to make a proper patch, you will have to do it manually, its just a copy paste job even a monkey like me can do so it shouldnt be difficult.

Go into java/org/l2jmobius/gameserver/model/votereward and open the Hopzone.java file.

Find this
Code: [Select]
@Override
public int getVotes()
{
InputStreamReader isr = null;
BufferedReader br = null;

try
{
final URLConnection con = new URL(Config.HOPZONE_SERVER_LINK).openConnection();
con.addRequestProperty("User-Agent", "Mozilla/5.0");
isr = new InputStreamReader(con.getInputStream());
br = new BufferedReader(isr);

String line;
while ((line = br.readLine()) != null)
{
if (line.contains("<span class=\"rank tooltip\" title"))
{
return Integer.parseInt(line.split(">")[2].replace("</span", ""));
}
}

br.close();
isr.close();
}
catch (Exception e)
{
LOGGER.warning("VoteSystem: Error while getting server vote count from " + getSiteName() + ".");
}

return -1;
}

and replace it with this:
Code: [Select]
@Override
public int getVotes()
{

int votes = -1;
try
{
HttpURLConnection con = (HttpURLConnection) new URL(Config.HOPZONE_SERVER_LINK).openConnection();
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream())))
{
String keyWord = "<span class=\"rank tooltip hidden\" title=\"Total Votes\">";

String line;
while ((line = br.readLine()) != null)
{
if (line.contains(keyWord))
{
votes = Integer.parseInt(line.split(keyWord)[1].split("</span>")[0]);
break;
}
}
}
con.disconnect();
}
catch (Exception e)
{
LOGGER.warning("VoteSystem: Error while getting server vote count from " + getSiteName() + ".");
}

return votes;
}

You will also need to add the following import if your IDE doesnt add it automatically. (Eclipse does for me)
Code: [Select]
import java.net.HttpURLConnection;
Here it is working properly at last using a random server for votes.


Feel free to report any problems or offer improvements.