| Mazokista |
28-12-2010 08:02 PM |
Vote System Config
1 Anexo(s)
Citação:
com.it.br.gameserver.instancemanager.AutoVoteRewar dHandler.java
|
Código:
/*
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
*/
package com.it.br.gameserver.instancemanager;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.it.br.Config;
import com.it.br.L2DatabaseFactory;
import com.it.br.gameserver.Announcements;
import com.it.br.gameserver.ThreadPoolManager;
import com.it.br.gameserver.model.L2ItemInstance;
import com.it.br.gameserver.model.L2World;
import com.it.br.gameserver.model.actor.instance.L2PcInstance;
/**
* @author Issle - Updater Kinho! V1.0
*
*/
public class AutoVoteRewardHandler
{
private final String HOPZONE = "Config.HopZone_ID";
// 60 * 1000(1000milliseconds = 1 second) = 60seconds
private final int initialCheck = 60 * 1000;
// 1800 * 1000(1000milliseconds = 1 second) = 1800seconds = 30minutes
private final int delayForCheck = Config.Delay_for_check * 1000;
private final int[] itemId = {Config.Item_ID};
private final int[] itemCount = {Config.Item_Count};
private final int[] maxStack = {Config.Max_Stack};
private final int votesRequiredForReward = Config.Votes_Required;
// do not change
private int lastVoteCount = 0;
private AutoVoteRewardHandler()
{
System.out.println("Vote Reward System Initiated.");
ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), initialCheck, delayForCheck);
}
private class AutoReward implements Runnable
{
public void run()
{
int votes = getVotes();
System.out.println("Server Votes: " + votes);
if (votes != 0 && getLastVoteCount() != 0 && votes >= getLastVoteCount() + votesRequiredForReward)
{
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("" +
"SELECT" +
" characters.obj_Id," +
" characters.char_name" +
"FROM" +
" characters.account_name = accounts.login" +
"WHERE" +
" characters.online > 0" +
"GROUP BY" +
" accounts.lastIP" +
"ORDER BY" +
" characters.level" +
"DESC");
ResultSet rset = statement.executeQuery();
L2PcInstance player = null;
L2ItemInstance item = null;
while (rset.next())
{
player = L2World.getInstance().getPlayer("charId");
if (player != null && !player.getClient().isDetached())
{
for (int i = 0; i < itemId.length; i++)
{
item = player.getInventory().getItemByItemId(itemId[i]);
if (item == null || item.getCount() < maxStack[i])
player.addItem("reward", itemId[i], itemCount, player, true);
}
}
}
statement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
try { if (con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); }
}
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);
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();
}
}
Código:
Index: com/it/br/Config.java
===================================================================
--- com/it/br/Config.java (revision 1793)
+++ com/it/br/Config.java (working copy)
@@ -273,7 +273,13 @@
public static int GM_DONT_TAKE_AGGRO;
public static int GM_REPAIR = 75;
public static int GM_VIP;
public static int GM_AIO;
+ public static String HopZone_ID;
+ public static int Delay_for_check;
+ public static int Item_ID;
+ public static int Item_Count;
+ public static int Max_Stack;
+ public static int Votes_Required;
/* Rate control */
public static float RATE_XP;
public static float RATE_SP;
@@ -1094,6 +1105,17 @@
*********.load(is);
is.close();
+ HopZone_ID = *********.getProperty("HopZoneID", "www.google.com");
+ Delay_for_check = Integer.parseInt(*********.getProperty("Delayforcheck", "600"));
+ Item_ID = Integer.parseInt(*********.getProperty("ItemID", "3470"));
+ Item_Count = Integer.parseInt(*********.getProperty("ItemCount", "1"));
+ Max_Stack = Integer.parseInt(*********.getProperty("MaxStack", "1"));
+ Votes_Required = Integer.parseInt(*********.getProperty("VotesRequired", "10"));
CHARS_TITLE = Boolean.parseBoolean(*********.getProperty("NewCharTitle", "False"));
ANNOUNCE_CASTLE_LORDS = Boolean.parseBoolean(*********.getProperty("AnnounceCastleLords", "False"));
DISPLAY_SERVER_VERSION = Boolean.parseBoolean(*********.getProperty("DisplayServerRevision","True"));
Index: com/it/br/gameserver/GameServer.java
===================================================================
--- com/it/br/gameserver/GameServer.java (revision 1793)
+++ com/it/br/gameserver/GameServer.java (working copy)
@@ -174,6 +174,7 @@
import com.it.br.gameserver.handler.voicedcommandhandlers.tradeoff;
import com.it.br.gameserver.idfactory.IdFactory;
import com.it.br.gameserver.instancemanager.AuctionManager;
+import com.it.br.gameserver.instancemanager.AutoVoteRewardHandler;
import com.it.br.gameserver.instancemanager.BoatManager;
import com.it.br.gameserver.instancemanager.CastleManager;
import com.it.br.gameserver.instancemanager.CastleManorManager;
@@ -380,6 +381,8 @@
if (Config.SAVE_DROPPED_ITEM)
ItemsOnGroundManager.getInstance();
+ AutoVoteRewardHandler.getInstance();
+
if (Config.AUTODESTROY_ITEM_AFTER > 0 || Config.HERB_AUTO_DESTROY_TIME > 0)
ItemsAutoDestroy.getInstance();
Citação:
config/*********.properties
|
Código:
+# ============================= #
+#l2jmods HopZone Java Vote Reward
+# ============================= #
+# Hopzone Url
+#For example http://l2.hopzone.net/lineage2/moreinfo/L2Gang/82066.html
+HopZoneID = www.google.com
+
+# Dealy Check
+#This means in every x seconds the Handler will check for vote count
+Delayforcheck = 600
+
+# Item id
+# The reward of your choice
+ItemID = 3470
+
+# Item Count
+# The Count of your choice
+ItemCount = 1
+
+# MaxStack
+# Recommended 1
+MaxStack = 1
+
+# Votes Required
+# Votes required between rewards
+VotesRequired = 10
Download PhP :
|