· 8 years ago · Aug 26, 2018, 08:10 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 private final void sendInfoFrom(L2Object object)
111 {
112 if (object.getPolyType() == L2Object.PolyType.ITEM)
113 {
114 sendPacket(new SpawnItem(object));
115 }
116 else
117 {
118 object.sendInfo(this);
119 if ((object instanceof L2Character))
120 {
121 L2Character obj = (L2Character)object;
122 if (obj.hasAI()) {
123 obj.getAI().describeStateToPlayer(this);
124 }
125 }
126 }
127 }
128
129+ private long _voteTimeReward = 0L;
130
131+ public long getVoteTimeReward()
132+ {
133+ return this._voteTimeReward;
134+ }
135+
136+ public void setVoteTimeReward(long voteTimeReward)
137+ {
138+ this._voteTimeReward = voteTimeReward;
139+ }
140
141===================================================================
142--- java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java (revision 0)
143+++ java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java (revision 0)
144
145 import java.util.logging.Logger;
146+ import net.sf.l2j.gameserver.handler.voicedcommandhandlers.VoteReward;
147
148
149 protected VoicedCommandHandler()
150 {
151 _datatable = new TIntObjectHashMap<>();
152+ registerHandler(new VoteReward());
153
154 }
155
156===================================================================
157--- java/net/sf/l2j/Config.java (revision 0)
158+++ java/net/sf/l2j/Config.java (revision 0)
159
160 public static int SOCIAL_TIME;
161 public static int SCHEDULED_THREAD_POOL_COUNT;
162 public static int THREADS_PER_SCHEDULED_THREAD_POOL;
163 public static int INSTANT_THREAD_POOL_COUNT;
164 public static int THREADS_PER_INSTANT_THREAD_POOL;
165 public static boolean L2WALKER_PROTECTION;
166
167+ public static int VOTE_REWARD_ITEM_ID;
168+ public static int VOTE_REWARD_ITEM_COUNT;
169
170
171 DIVINE_SP_BOOK_NEEDED = players.getProperty("DivineInspirationSpBookNeeded", true);
172 ALT_GAME_SUBCLASS_WITHOUT_QUESTS = players.getProperty("AltSubClassWithoutQuests", false);
173 ALL_SUBCLASS = Boolean.parseBoolean(players.getProperty("AllowAllSubclassesChange", "False"));
174
175 BUFFS_MAX_AMOUNT = players.getProperty("MaxBuffsAmount", 20);
176 STORE_SKILL_COOLTIME = players.getProperty("StoreSkillCooltime", true);
177
178 + VOTE_REWARD_ITEM_ID = players.getProperty("VoteRewardItemId", 57);
179 + VOTE_REWARD_ITEM_COUNT = players.getProperty("VoteRewardItemCount", 57);
180
181
182===================================================================
183--- players.properties (revision 0)
184+++ players.properties (revision 0)
185
186
187#=============================================================
188# Buffs config
189#=============================================================
190
191# Maximum number of buffs.
192# Remember that Divine Inspiration will give 4 additional buff slots on top of the number specified.
193# Default: 20
194MaxBuffsAmount = 46
195
196# Store buffs/debuffs on user logout?
197StoreSkillCooltime = True
198
199+ #=============================================================
200+ # Site Vote config
201+ #=============================================================
202+ #Vote reward system.
203+ #Vote reward item ID
204+ VoteRewardItemId = 57
205+ #Vote reward item count
206+ VoteRewardItemCount = 57
207
208
209===================================================================
210--- vote_system.sql (revision 0)
211+++ vote_system.sql (revision 0)
212
213DROP TABLE IF EXISTS `vote_system`;
214CREATE TABLE `vote_system` (
215 `vote_ip` char(15) NOT NULL,
216 `timestamp` bigint(15) unsigned NOT NULL DEFAULT '0',
217 `account` varchar(45) NOT NULL,
218 `rewarded` int(3) DEFAULT '0',
219 PRIMARY KEY (`vote_ip`)
220) ENGINE=InnoDB DEFAULT CHARSET=latin1;