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