Jump to content

Recommended Posts

Posted (edited)


#=============================================================

# Auto Vote Reward

#=============================================================

# Enable vote system

EnableVoteSystem = False

 

# Enabled or Disabled Topzone

EnableTopzone = False

 

# Votes required for reward.

VotesRequiredForReward = 3

 

# Votes system initial delay.

VotesSystemInitialDelay = 100

 

# Votes system step delay.

VotesSystemStepDelay = 100

 

# Reward (item, count).

# Reward Hopzone

HopzoneRewardId = 4037

HopzoneRewardCount = 3

 

# Reward (item, count).

# Reward Topzone

TopzoneRewardId = 4037

TopzoneRewardCount = 3

 

# Site URL.

# Leave empty to disable one site if you need just one of these.

VotesSiteHopZoneUrl =

VotesSiteTopZoneUrl =  


/** Auto Vote */

public static boolean ENABLE_VOTE_SYSTEM;

public static int VOTES_FOR_REWARD;

public static int VOTES_SYSTEM_INITIAL_DELAY;

public static int VOTES_SYSTEM_STEP_DELAY;

public static int HOPZONE_REWARD_ID;

public static int HOPZONE_REWARD_COUNT;

public static int TOPZONE_REWARD_ID;

public static int TOPZONE_REWARD_COUNT;

public static String VOTES_HOPZONE_REWARDS;

public static String VOTES_TOPZONE_REWARDS;

public static String VOTES_SITE_HOPZONE_URL;

public static String VOTES_SITE_TOPZONE_URL;

public static boolean VOTE_TOPZONE_ENABLED;


/** Auto Vote */

ENABLE_VOTE_SYSTEM = Boolean.parseBoolean(tester.getProperty("EnableVoteSystem", "False"));

VOTE_TOPZONE_ENABLED = Boolean.parseBoolean(tester.getProperty("EnableTopzone", "False"));

VOTES_FOR_REWARD = Integer.parseInt(tester.getProperty("VotesRequiredForReward", "100"));

VOTES_SYSTEM_INITIAL_DELAY = Integer.parseInt(tester.getProperty("VotesSystemInitialDelay", "60000"));

VOTES_SYSTEM_STEP_DELAY = Integer.parseInt(tester.getProperty("VotesSystemStepDelay", "1800000"));

VOTES_HOPZONE_REWARDS = tester.getProperty("VotesHopZoneRewards", "");

VOTES_SYSTEM_INITIAL_DELAY = Integer.parseInt(tester.getProperty("VotesSystemInitialDelay", "60000"));

HOPZONE_REWARD_ID = Integer.parseInt(tester.getProperty("HopzoneRewardId", "3470"));

HOPZONE_REWARD_COUNT = Integer.parseInt(tester.getProperty("HopzoneRewardCount", "10"));

TOPZONE_REWARD_ID = Integer.parseInt(tester.getProperty("TopzoneRewardId", "3470"));

TOPZONE_REWARD_COUNT = Integer.parseInt(tester.getProperty("TopzoneRewardCount", "10"));

VOTES_SITE_HOPZONE_URL = tester.getProperty("VotesSiteHopZoneUrl", "");

VOTES_SITE_TOPZONE_URL = tester.getProperty("VotesSiteTopZoneUrl", "");


/*

* This program is free software; you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation; either version 2, or (at your option)

* any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program; if not, write to the Free Software

* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA

* 02111-1307, USA.

*

* http://www.gnu.org/copyleft/gpl.html

*/

package com.l2jfrozen.gameserver.custom;

 

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;

import java.util.ArrayList;

import java.util.Collection;

import java.util.List;

import java.util.logging.Logger;

 

import com.l2jfrozen.Config;

import com.l2jfrozen.gameserver.datatables.sql.ItemTable;

import com.l2jfrozen.gameserver.model.L2World;

import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;

import com.l2jfrozen.gameserver.model.entity.Announcements;

import com.l2jfrozen.gameserver.thread.ThreadPoolManager;

 

public class AutoVoteReward

{

public static Logger _log = Logger.getLogger(AutoVoteReward.class.getName());

 

private int hopzoneVotesCount = 0;

private int topzoneVotesCount = 0;

protected List<String> already_rewarded;

 

protected static boolean topzone = false;

protected static boolean hopzone = false;

 

private AutoVoteReward()

{

_log.info("VoteRewardSystem: Initialized.");

if(hopzone)

{

int hopzone_votes = getHopZoneVotes();

if(hopzone_votes == -1)

{

hopzone_votes = 0;

}

 

setHopZoneVoteCount(hopzone_votes);

}

 

if(Config.VOTE_TOPZONE_ENABLED)

{

if(topzone)

{

int topzone_votes = getTopZoneVotes();

if(topzone_votes == -1)

{

topzone_votes = 0;

}

 

setTopZoneVoteCount(topzone_votes);

}

}

 

ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), Config.VOTES_SYSTEM_INITIAL_DELAY, Config.VOTES_SYSTEM_STEP_DELAY);

}

 

protected class AutoReward implements Runnable

{

@Override

public void run()

{

if(hopzone)

{

int hopzone_votes = getHopZoneVotes();

if(hopzone_votes != -1)

{

_log.info("Hopzone Votes: " + hopzone_votes);

 

if(hopzone_votes != 0 && hopzone_votes >= getHopZoneVoteCount() + Config.VOTES_FOR_REWARD)

{

already_rewarded = new ArrayList<>();

 

Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers();

 

for(L2PcInstance player : pls)

{

if(player != null && !player.isOffline())

{

if(checkSingleBox(player))

{

player.addItem("reward", Config.HOPZONE_REWARD_ID, Config.HOPZONE_REWARD_COUNT, player, true);

}

}

}

 

setHopZoneVoteCount(hopzone_votes);

}

Announcements.voteAnnounce("Votes Now " + hopzone_votes + ". " + (getHopZoneVoteCount() + Config.VOTES_FOR_REWARD) + " Votes left at HOPZONE until next reward (" + Config.HOPZONE_REWARD_COUNT + " " + ItemTable.getInstance().getTemplate(Config.HOPZONE_REWARD_ID).getName() + ")");

}

}

if(Config.VOTE_TOPZONE_ENABLED)

{

if(topzone && hopzone && Config.VOTES_SYSTEM_STEP_DELAY > 0)

{

try

{

Thread.sleep(Config.VOTES_SYSTEM_STEP_DELAY / 2);

}

catch(InterruptedException e)

{

e.printStackTrace();

}

}

}

 

if(Config.VOTE_TOPZONE_ENABLED)

{

if(topzone)

{

int topzone_votes = getTopZoneVotes();

if(topzone_votes != -1)

{

_log.info("TopZone Votes: " + topzone_votes);

 

if(topzone_votes != 0 && topzone_votes >= getTopZoneVoteCount() + Config.VOTES_FOR_REWARD)

{

already_rewarded = new ArrayList<>();

 

Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers();

 

for(L2PcInstance player : pls)

{

if(player != null && !player.isOffline())

{

if(checkSingleBox(player))

{

player.addItem("reward", Config.TOPZONE_REWARD_ID, Config.TOPZONE_REWARD_COUNT, player, true);

}

}

}

 

setTopZoneVoteCount(topzone_votes);

}

Announcements.voteAnnounce("Votes Now " + topzone_votes + ". " + (getTopZoneVoteCount() + Config.VOTES_FOR_REWARD) + " Votes left at TOPZONE until next reward (" + Config.TOPZONE_REWARD_COUNT + " " + ItemTable.getInstance().getTemplate(Config.TOPZONE_REWARD_ID).getName() + ")");

}

}

}

}

}

 

protected boolean checkSingleBox(L2PcInstance player)

{

if(player.getClient()!=null && player.getClient().getConnection()!=null && !player.getClient().getConnection().isClosed() && !player.isOffline()){

 

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

 

if(already_rewarded.contains(playerip))

return false;

already_rewarded.add(playerip);

return true;

}

return false;

}

 

 

 

protected int getHopZoneVotes()

{

URL url = null;

InputStreamReader isr = null;

BufferedReader in = null;

 

try

{

if(!Config.VOTES_SITE_HOPZONE_URL.endsWith(".html"))

Config.VOTES_SITE_HOPZONE_URL+=".html";

 

url = new URL(Config.VOTES_SITE_HOPZONE_URL);

HttpURLConnection con = (HttpURLConnection) url.openConnection();

HttpURLConnection.setFollowRedirects(false);

con.setConnectTimeout(10 * 1000);

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

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

in = new BufferedReader(isr);

 

String line;

while ((line = in.readLine()) != null)

{

if (line.contains("no steal make love")||line.contains("no votes here")||line.contains("bang, you don't have votes")|| line.contains("la vita e bella"))

{

int votes = Integer.valueOf(line.split(">")[2].replace("</span", ""));

return votes;

}

}

}

catch (final Exception e)

{

_log.warning("[AutoVoteReward] Server L2Hopzone is offline or something is wrong in link");

Announcements.getInstance().AnnounceToAll("[AutoVoteReward] L2Hopzone is offline. We will check reward as it will be online again");

}

finally

{

if (in != null)

try

{

in.close();

}

catch (final IOException e1)

{

e1.printStackTrace();

}

if (isr != null)

try

{

isr.close();

}

catch (final IOException e1)

{

e1.printStackTrace();

}

}

return -1;

}

 

protected int getTopZoneVotes()

{

int votes = -1;

try

{

final URL obj = new URL(Config.VOTES_SITE_TOPZONE_URL);

final HttpURLConnection con = (HttpURLConnection) obj.openConnection();

 

con.addRequestProperty("User-Agent", "L2TopZone");

con.setConnectTimeout(5000);

 

final int responseCode = con.getResponseCode();

if (responseCode == 200) // OK

{

try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())))

{

String inputLine;

while ((inputLine = in.readLine()) != null)

{

if (inputLine.contains("Votes:"))

{

votes = Integer.valueOf(inputLine.split("<br>")[1].replace("</div>", ""));

break;

}

}

}

}

}

catch (Exception e)

{

if (topzone)

System.out.println("TOPZONE is offline. We will check reward as it will be online again.");

}

return votes;

}

 

protected void setHopZoneVoteCount(int voteCount)

{

hopzoneVotesCount = voteCount;

}

 

protected int getHopZoneVoteCount()

{

return hopzoneVotesCount;

}

 

protected void setTopZoneVoteCount(int voteCount)

{

topzoneVotesCount = voteCount;

}

 

protected int getTopZoneVoteCount()

{

return topzoneVotesCount;

}

 

public static AutoVoteReward getInstance()

{

if(Config.VOTES_SITE_HOPZONE_URL != null && !Config.VOTES_SITE_HOPZONE_URL.equals("")){

hopzone = true;

}

 

if(Config.VOTES_SITE_TOPZONE_URL != null && !Config.VOTES_SITE_TOPZONE_URL.equals("")){

topzone = true;

}

 

if(topzone || hopzone)

return SingletonHolder._instance;

return null;

}

 

@SuppressWarnings("synthetic-access")

private static class SingletonHolder

{

protected static final AutoVoteReward _instance = new AutoVoteReward();

}

 

}


Gameserver.java

 

 

import com.l2jfrozen.gameserver.custom.AutoVoteReward;

 

 

 

Util.printSection("Vote System - L2JFrozen");

if(Config.ENABLE_VOTE_SYSTEM)

{

AutoVoteReward.getInstance();

}

 

Edited by Harut
Posted

Topzone is ok. Since its method which I posted somewhere.

 

At least you could change hopzone to the same sexy style.. C/p since ages.

  • 1 month later...
Posted

i have error in tester.getProperty

Just throw the config java code in a already exist config.

Like "players.getProperty".

After change the tester.getProperty to players.getProperty

  • 3 weeks later...
Guest
This topic is now closed to further replies.


×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock