· 8 years ago · Aug 26, 2018, 05:58 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
5package net.sf.l2j.gameserver.handler.voicedcommandhandlers;
6
7import java.net.InetAddress;
8import java.sql.Connection;
9import java.sql.PreparedStatement;
10import java.sql.ResultSet;
11import net.sf.l2j.Config;
12import net.sf.l2j.L2DatabaseFactory;
13import net.sf.l2j.commons.mmocore.MMOConnection;
14import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
15import net.sf.l2j.gameserver.model.actor.instance.Player;
16import net.sf.l2j.gameserver.network.L2GameClient;
17
18public class VoteReward
19 implements IVoicedCommandHandler
20{
21 private static final String[] VOICED_COMMANDS = { "reward" };
22
23 public boolean useVoicedCommand(String command, Player activeChar, String params)
24 {
25 String IP = activeChar.getClient().getConnection().getInetAddress().getHostAddress();
26 long milis = activeChar.getVoteTimeReward() + 43200000L;
27 boolean canGetVoteReward = milis < System.currentTimeMillis();
28 boolean isRewarded = false;
29 if (canGetVoteReward)
30 {
31 try
32 {
33 Connection con = L2DatabaseFactory.getInstance().getConnection();Throwable localThrowable3 = null;
34 try
35 {
36 PreparedStatement statement = con.prepareStatement("SELECT timestamp,rewarded FROM vote_system WHERE vote_ip=?");
37 statement.setString(1, IP);
38 ResultSet rset = statement.executeQuery();
39 if (rset.next())
40 {
41 canGetVoteReward = milis < rset.getLong("timestamp");
42 isRewarded = rset.getInt("rewarded") != 0;
43 }
44 else
45 {
46 canGetVoteReward = false;
47 }
48 if (!isRewarded)
49 {
50 if (canGetVoteReward)
51 {
52 activeChar.addItem("Vote Reward", Config.VOTE_REWARD_ITEM_ID, Config.VOTE_REWARD_ITEM_COUNT, activeChar, true);
53
54 statement = con.prepareStatement("Update vote_system SET rewarded=1 WHERE vote_ip=?");
55 statement.setString(1, IP);
56 statement.executeUpdate();
57 activeChar.setVoteTimeReward(System.currentTimeMillis());
58 }
59 else
60 {
61 activeChar.sendMessage("You have to vote in order to be rewarded!");
62 }
63 }
64 else
65 {
66 activeChar.sendMessage("You have already been rewarded!");
67 }
68 statement.close();
69 rset.close();
70 }
71 catch (Throwable localThrowable1)
72 {
73 localThrowable3 = localThrowable1;throw localThrowable1;
74 }
75 finally
76 {
77 if (con != null)
78 {
79 if (localThrowable3 != null)
80 {
81 try
82 {
83 con.close();
84 }
85 catch (Throwable localThrowable2)
86 {
87 localThrowable3.addSuppressed(localThrowable2);
88 }
89 } else {
90 con.close();
91 }
92 }
93 }
94 }
95 catch (Exception ex)
96 {
97 ex.printStackTrace();
98 }
99 } else
100 {
101 activeChar.sendMessage("You have to wait time to pass and vote again!");
102 }
103 return true;
104 }
105
106 public String[] getVoicedCommandList()
107 {
108 return VOICED_COMMANDS;
109 }
110}
111
112===================================================================
113--- java/net/sf/l2j/Config.java (revision 0)
114+++ java/net/sf/l2j/Config.java (revision 0)
115
116 public static int SOCIAL_TIME;
117 public static int SCHEDULED_THREAD_POOL_COUNT;
118 public static int THREADS_PER_SCHEDULED_THREAD_POOL;
119 public static int INSTANT_THREAD_POOL_COUNT;
120 public static int THREADS_PER_INSTANT_THREAD_POOL;
121 public static boolean L2WALKER_PROTECTION;
122
123+ public static int VOTE_REWARD_ITEM_ID;
124+ public static int VOTE_REWARD_ITEM_COUNT;
125
126
127 DIVINE_SP_BOOK_NEEDED = players.getProperty("DivineInspirationSpBookNeeded", true);
128 ALT_GAME_SUBCLASS_WITHOUT_QUESTS = players.getProperty("AltSubClassWithoutQuests", false);
129 ALL_SUBCLASS = Boolean.parseBoolean(players.getProperty("AllowAllSubclassesChange", "False"));
130
131 BUFFS_MAX_AMOUNT = players.getProperty("MaxBuffsAmount", 20);
132 STORE_SKILL_COOLTIME = players.getProperty("StoreSkillCooltime", true);
133
134 + VOTE_REWARD_ITEM_ID = players.getProperty("VoteRewardItemId", 57);
135 + VOTE_REWARD_ITEM_COUNT = players.getProperty("VoteRewardItemCount", 57);
136
137===================================================================
138--- players.properties (revision 0)
139+++ players.properties (revision 0)
140
141#=============================================================
142# Buffs config
143#=============================================================
144
145# Maximum number of buffs.
146# Remember that Divine Inspiration will give 4 additional buff slots on top of the number specified.
147# Default: 20
148MaxBuffsAmount = 46
149
150# Store buffs/debuffs on user logout?
151StoreSkillCooltime = True
152
153+ #=============================================================
154+ # Site Vote config
155+ #=============================================================
156+ #Vote reward system.
157+ #Vote reward item ID
158+ VoteRewardItemId = 57
159+ #Vote reward item count
160+ VoteRewardItemCount = 57
161
162
163===================================================================
164--- vote_system.sql (revision 0)
165+++ vote_system.sql (revision 0)
166
167SET FOREIGN_KEY_CHECKS=0;
168
169-- ----------------------------
170-- Table structure for vote_system
171-- ----------------------------
172DROP TABLE IF EXISTS `vote_system`;
173CREATE TABLE `vote_system` (
174 `vote_ip` char(15) NOT NULL,
175 `timestamp` bigint(15) unsigned NOT NULL DEFAULT '0',
176 `account` varchar(45) NOT NULL,
177 `rewarded` int(3) DEFAULT '0',
178 PRIMARY KEY (`vote_ip`)
179) ENGINE=InnoDB DEFAULT CHARSET=latin1;