· 8 years ago · Aug 26, 2018, 08:24 PM
1===================================================================
2--- java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/VoteReward.java (revision 0)
3+++ java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/VoteReward.java (revision 0)
4
5/*
6 * This program is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
9 * version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19package net.sf.l2j.gameserver.handler.voicedcommandhandlers;
20
21import java.sql.Connection;
22import java.sql.PreparedStatement;
23import java.sql.ResultSet;
24
25import net.sf.l2j.Config;
26import net.sf.l2j.L2DatabaseFactory;
27import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
28import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
29
30public class VoteReward implements IVoicedCommandHandler
31{
32 private static final String[] VOICED_COMMANDS =
33 {
34 "reward"
35 };
36
37 @Override
38 public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
39 {
40
41 // if (activeChar.getInventory().getInventoryItemCount(Config.VOTE_REWARD_ITEM_ID, -1, true) != 0)
42 // {
43 // activeChar.sendMessage("You can't be rewarded again.");
44 // }
45 // else
46 {
47 String IP = activeChar.getClient().getConnection().getInetAddress().getHostAddress();
48 long milis = activeChar.getVoteTimeReward() + (12 * 60 * 60 * 1000L);
49 boolean canGetVoteReward = (milis < System.currentTimeMillis());
50 boolean isRewarded = false;
51 if (canGetVoteReward)
52 {
53 try (Connection con = L2DatabaseFactory.getInstance().getConnection())
54 {
55 PreparedStatement statement = con.prepareStatement("SELECT timestamp,rewarded FROM vote_system WHERE vote_ip=?");
56 statement.setString(1, IP);
57 ResultSet rset = statement.executeQuery();
58 if (rset.next())
59 {
60 canGetVoteReward = milis < rset.getLong("timestamp");
61 isRewarded = rset.getInt("rewarded") == 0 ? false : true;
62 }
63 else
64 canGetVoteReward = false;
65 if (!isRewarded)
66 {
67 if (canGetVoteReward)
68 {
69 activeChar.addItem("Vote Reward", Config.VOTE_REWARD_ITEM_ID, Config.VOTE_REWARD_ITEM_COUNT, activeChar, true);
70 // activeChar.setVoteRewarded(true);
71 statement = con.prepareStatement("Update vote_system SET rewarded=1 WHERE vote_ip=?");
72 statement.setString(1, IP);
73 statement.executeUpdate();
74 activeChar.setVoteTimeReward(System.currentTimeMillis());
75 }
76 else
77 activeChar.sendMessage("You have to vote in order to be rewarded!");
78 }
79 else
80 activeChar.sendMessage("You have already been rewarded!");
81 statement.close();
82 rset.close();
83 }
84 catch (Exception ex)
85 {
86 ex.printStackTrace();
87 }
88 }
89 else
90 {
91 activeChar.sendMessage("You have to wait time to pass and vote again!");
92 }
93 }
94 return true;
95
96 }
97
98 @Override
99 public String[] getVoicedCommandList()
100 {
101 return VOICED_COMMANDS;
102 }
103
104}
105
106===================================================================
107--- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 0)
108+++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 0)
109
110
111 statement.setLong(49, getDeathPenaltyBuffLevel());
112+ statement.setLong(50, getVoteTimeReward());
113
114 player.setKarma(rset.getInt("karma"));
115 player.setPvpKills(rset.getInt("pvpkills"));
116 player.setPkKills(rset.getInt("pkkills"));
117 player.setOnlineTime(rset.getLong("onlinetime"));
118 player.setNoble(rset.getInt("nobless") == 1, false);
119+ player.setVoteTimeReward(rset.getLong("voterewardTime"));
120
121
122 private final void sendInfoFrom(L2Object object)
123 {
124 if (object.getPolyType() == L2Object.PolyType.ITEM)
125 {
126 sendPacket(new SpawnItem(object));
127 }
128 else
129 {
130 object.sendInfo(this);
131 if ((object instanceof L2Character))
132 {
133 L2Character obj = (L2Character)object;
134 if (obj.hasAI()) {
135 obj.getAI().describeStateToPlayer(this);
136 }
137 }
138 }
139 }
140
141+ private long _voteTimeReward = 0L;
142
143+ public long getVoteTimeReward()
144+ {
145+ return this._voteTimeReward;
146+ }
147+
148+ public void setVoteTimeReward(long voteTimeReward)
149+ {
150+ this._voteTimeReward = voteTimeReward;
151+ }
152
153===================================================================
154--- java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java (revision 0)
155+++ java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java (revision 0)
156
157 import java.util.logging.Logger;
158+ import net.sf.l2j.gameserver.handler.voicedcommandhandlers.VoteReward;
159
160
161 protected VoicedCommandHandler()
162 {
163 _datatable = new TIntObjectHashMap<>();
164+ registerHandler(new VoteReward());
165
166 }
167
168===================================================================
169--- java/net/sf/l2j/Config.java (revision 0)
170+++ java/net/sf/l2j/Config.java (revision 0)
171
172 public static int SOCIAL_TIME;
173 public static int SCHEDULED_THREAD_POOL_COUNT;
174 public static int THREADS_PER_SCHEDULED_THREAD_POOL;
175 public static int INSTANT_THREAD_POOL_COUNT;
176 public static int THREADS_PER_INSTANT_THREAD_POOL;
177 public static boolean L2WALKER_PROTECTION;
178
179+ public static int VOTE_REWARD_ITEM_ID;
180+ public static int VOTE_REWARD_ITEM_COUNT;
181
182
183 DIVINE_SP_BOOK_NEEDED = players.getProperty("DivineInspirationSpBookNeeded", true);
184 ALT_GAME_SUBCLASS_WITHOUT_QUESTS = players.getProperty("AltSubClassWithoutQuests", false);
185 ALL_SUBCLASS = Boolean.parseBoolean(players.getProperty("AllowAllSubclassesChange", "False"));
186
187 BUFFS_MAX_AMOUNT = players.getProperty("MaxBuffsAmount", 20);
188 STORE_SKILL_COOLTIME = players.getProperty("StoreSkillCooltime", true);
189
190 + VOTE_REWARD_ITEM_ID = players.getProperty("VoteRewardItemId", 57);
191 + VOTE_REWARD_ITEM_COUNT = players.getProperty("VoteRewardItemCount", 57);
192
193
194===================================================================
195--- players.properties (revision 0)
196+++ players.properties (revision 0)
197
198
199#=============================================================
200# Buffs config
201#=============================================================
202
203# Maximum number of buffs.
204# Remember that Divine Inspiration will give 4 additional buff slots on top of the number specified.
205# Default: 20
206MaxBuffsAmount = 46
207
208# Store buffs/debuffs on user logout?
209StoreSkillCooltime = True
210
211+ #=============================================================
212+ # Site Vote config
213+ #=============================================================
214+ #Vote reward system.
215+ #Vote reward item ID
216+ VoteRewardItemId = 57
217+ #Vote reward item count
218+ VoteRewardItemCount = 57
219
220
221===================================================================
222--- vote_system.sql (revision 0)
223+++ vote_system.sql (revision 0)
224
225DROP TABLE IF EXISTS `vote_system`;
226CREATE TABLE `vote_system` (
227 `vote_ip` char(15) NOT NULL,
228 `timestamp` bigint(15) unsigned NOT NULL DEFAULT '0',
229 `account` varchar(45) NOT NULL,
230 `rewarded` int(3) DEFAULT '0',
231 PRIMARY KEY (`vote_ip`)
232) ENGINE=InnoDB DEFAULT CHARSET=latin1;