Advertisement
l2TopgameserverNet

L2jMobius Interlude vote reward - l2.topgameserver.net

May 12th, 2020 (edited)
1,951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 91.58 KB | None | 0 0
  1. diff --git a/L2J_Mobius_C6_Interlude/dist/game/config/custom/votesystem.ini b/L2J_Mobius_C6_Interlude/dist/game/config/custom/votesystem.ini
  2. new file mode 100644
  3. index 0000000..3ea8d39
  4. --- /dev/null
  5. +++ b/L2J_Mobius_C6_Interlude/dist/game/config/custom/votesystem.ini
  6. @@ -0,0 +1,95 @@
  7. +EnableVoteSystem = True
  8. +
  9. +EnableGlobalVote = True
  10. +
  11. +EnableIndividualVote = True
  12. +
  13. +## Time to Update table totalVotes from DB
  14. +NextTimeToAutoUpdateTotalVote = 2
  15. +
  16. +## Time to update table individualVotes
  17. +NextTimeToAutoUpdateIndividualVotes = 2
  18. +
  19. +NextTimeToAutoCleanInnecesaryVotes = 30
  20. +
  21. +NextTimeToCheckAutoGlobalVotesReward = 1
  22. +
  23. +IntervalTimeToNextVote = 12
  24. +
  25. +GlobalVotesAmountToNextReward = 1
  26. +
  27. +EnableVotingCommand = True
  28. +
  29. +VotingCommand = getreward
  30. +
  31. +## l2.topgameserver.net
  32. +VoteLinkTgs = http://l2.topgameserver.net/lineage/VoteApi/
  33. +
  34. +TgsApiKey =
  35. +
  36. +## l2top.co
  37. +VoteLinkTopCo = https://l2top.co/reward/
  38. +
  39. +TopCoSrvId =
  40. +
  41. +## ITopz.com
  42. +VoteLinkItopz = https://itopz.com/check/
  43. +
  44. +ItopzZpiKey =
  45. +
  46. +ItopzSrvId =
  47. +
  48. +## l2votes.com
  49. +VoteLinkVts = https://l2votes.com/
  50. +
  51. +VtsApiKey =
  52. +
  53. +VtsSid =
  54. +
  55. +## Hopzone.net
  56. +VoteLinkHz = https://api.hopzone.net/lineage2/
  57. +
  58. +HzApiKey =
  59. +
  60. +## l2network.eu
  61. +VoteNetworkLink = https://l2network.eu/api.php
  62. +
  63. +VoteNetworkUserName =
  64. +
  65. +VoteNetworkApiKey =
  66. +
  67. +## L2TopServer.com
  68. +VoteLinkTss = https://l2topservers.com/votes?
  69. +
  70. +TssApiToken =
  71. +
  72. +TsSrvId = 453
  73. +
  74. +TsDomainName= l2catgang
  75. +
  76. +## top.l2jbrasil.com
  77. +BrasilVoteLink = https://top.l2jbrasil.com/votesystem/index.php?
  78. +
  79. +BrasilUserName = julioguzman
  80. +
  81. +## l2jtop.com
  82. +VoteLinkMmotop = https://l2jtop.com/api/
  83. +
  84. +MmotopApiKey =
  85. +
  86. +## L2TopZone.com
  87. +VoteLinkTz = https://api.l2topzone.com/v1/
  88. +
  89. +TzApiKey =
  90. +
  91. +## L2Servers.com
  92. +VoteLinkServers = https://www.l2servers.com/api/
  93. +
  94. +ServersHashCode =
  95. +
  96. +ServersSrvId =
  97. +
  98. +
  99. +## for local test
  100. +TestIp =
  101. +
  102. diff --git a/L2J_Mobius_C6_Interlude/dist/game/data/html/mods/votesystem/50009.html b/L2J_Mobius_C6_Interlude/dist/game/data/html/mods/votesystem/50009.html
  103. new file mode 100644
  104. index 0000000..b2a5624
  105. --- /dev/null
  106. +++ b/L2J_Mobius_C6_Interlude/dist/game/data/html/mods/votesystem/50009.html
  107. @@ -0,0 +1,19 @@
  108. +<html>
  109. +<title>Voting panel</title>
  110. +<body><center>
  111. +   <br><img src="L2UI_CH3.herotower_deco" width=256 height=32><br>
  112. +   <table cellpadding=2 width=280>
  113. +       <tr><td width="280">Hello <font color="C6AF00">%accountName%</font>, welcome to the voting rewards dashboard, please help us by voting by server every <font color="C6AF00">%everyXtime% hours</font> in all voting sites.</td></tr>
  114. +   </table>
  115. +   <table width="290"><tr><td width="290" align="center">You can vote: </td></tr></table>
  116. +   <br><img src="l2ui.SquareWhite" width=290 height=1><br>
  117. +
  118. +   %enablevote%
  119. +
  120. +   <br>
  121. +   <img src="l2ui.SquareWhite" width=290 height=1><br>
  122. +
  123. +
  124. +
  125. +</center></body>
  126. +</html>
  127. \ No newline at end of file
  128. diff --git a/L2J_Mobius_C6_Interlude/dist/game/data/votesystem.json b/L2J_Mobius_C6_Interlude/dist/game/data/votesystem.json
  129. new file mode 100644
  130. index 0000000..dabcc63
  131. --- /dev/null
  132. +++ b/L2J_Mobius_C6_Interlude/dist/game/data/votesystem.json
  133. @@ -0,0 +1,14 @@
  134. +[
  135. +   {"votesite":{"ordinal":"0","name":"l2.topgameserver.net","timezone":"GMT+2", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  136. +   {"votesite":{"ordinal":"1","name":"Itopz.com","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  137. +   {"votesite":{"ordinal":"2","name":"L2Top.co","timezone":"GMT+2", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  138. +   {"votesite":{"ordinal":"3","name":"L2Votes.com","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  139. +   {"votesite":{"ordinal":"4","name":"Hopzone.net","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  140. +   {"votesite":{"ordinal":"5","name":"L2Network.eu","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  141. +   {"votesite":{"ordinal":"6","name":"L2Topservers.com","timezone":"Asia/Tokyo", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  142. +   {"votesite":{"ordinal":"7","name":"top.l2jbrasil.com","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  143. +   {"votesite":{"ordinal":"8","name":"l2jtop.com","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  144. +   {"votesite":{"ordinal":"9","name":"L2Topzone.com","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  145. +   {"votesite":{"ordinal":"10","name":"L2Servers.com","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  146. +   {"votesite":{"ordinal":"11","name":"globalVotes","timezone":"", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}}
  147. +]
  148. \ No newline at end of file
  149. diff --git a/L2J_Mobius_C6_Interlude/dist/libs/json-simple-1.1.1.jar b/L2J_Mobius_C6_Interlude/dist/libs/json-simple-1.1.1.jar
  150. new file mode 100644
  151. index 0000000..66347a6
  152. --- /dev/null
  153. +++ b/L2J_Mobius_C6_Interlude/dist/libs/json-simple-1.1.1.jar
  154. Binary files differ
  155. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java
  156. index b126291..876bcaf 100644
  157. --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java
  158. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java
  159. @@ -33,6 +33,7 @@
  160.  import java.util.List;
  161.  import java.util.Map;
  162.  import java.util.Properties;
  163. +import java.util.concurrent.TimeUnit;
  164.  import java.util.logging.Level;
  165.  import java.util.logging.Logger;
  166.  
  167. @@ -98,6 +99,7 @@
  168.     private static final String SCHEME_BUFFER_CONFIG_FILE = "./config/custom/SchemeBuffer.ini";
  169.     private static final String EVENT_REBIRTH_CONFIG_FILE = "./config/custom/Rebirth.ini";
  170.     private static final String EVENT_WEDDING_CONFIG_FILE = "./config/custom/Wedding.ini";
  171. +   private static final String VOTE_SYSTEM_FILE = "./config/custom/votesystem.ini";
  172.     // login
  173.     private static final String LOGIN_CONFIG_FILE = "./config/main/LoginServer.ini";
  174.     // others
  175. @@ -509,6 +511,50 @@
  176.     public static boolean GIVE_CUPID_BOW;
  177.     public static boolean ANNOUNCE_WEDDING;
  178.    
  179. +   // ---------------------------------------------------
  180. +   // VOTE SYSTEM
  181. +   // ---------------------------------------------------
  182. +   public static boolean ENABLE_VOTE_SYSTEM;
  183. +   public static boolean ENABLE_INDIVIDUAL_VOTE;
  184. +   public static boolean ENABLE_GLOBAL_VOTE;
  185. +   public static long NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE;
  186. +   public static long NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES;
  187. +   public static long NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES;
  188. +   public static long NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD;
  189. +   public static long INTERVAL_TO_NEXT_VOTE;
  190. +   public static int GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD;
  191. +   public static boolean ENABLE_VOTING_COMMAND;
  192. +   public static String VOTING_COMMAND;
  193. +   public static String VOTE_LINK_TGS;
  194. +   public static String TGS_API_KEY;
  195. +   public static String VOTE_LINK_TOP_CO;
  196. +   public static String TOP_CO_SRV_ID;
  197. +   public static String VOTE_LINK_ITOPZ;
  198. +   public static String ITOPZ_API_KEY;
  199. +   public static String ITOPZ_SRV_ID;
  200. +   public static String VOTE_LINK_VTS;
  201. +   public static String VTS_API_KEY;
  202. +   public static String VTS_SID;
  203. +   public static String VOTE_LINK_HZ;
  204. +   public static String HZ_API_KEY;
  205. +   public static String VOTE_NETWORK_LINK;
  206. +   public static String VOTE_NETWORK_USER_NAME;
  207. +   public static String VOTE_NETWORK_API_KEY;
  208. +   public static String VOTE_LINK_TSS;
  209. +   public static String TSS_API_TOKEN;
  210. +   public static String TS_SRV_ID;
  211. +   public static String TS_DOMAIN_NAME;
  212. +   public static String BRASIL_VOTE_LINK;
  213. +   public static String BRASIL_USER_NAME;
  214. +   public static String VOTE_LINK_MMOTOP;
  215. +   public static String MMOTOP_API_KEY;
  216. +   public static String VOTE_LINK_TZ;
  217. +   public static String TZ_API_KEY;
  218. +   public static String VOTE_LINK_SERVERS;
  219. +   public static String SERVERS_HASH_CODE;
  220. +   public static String SERVERS_SRV_ID;
  221. +   public static String TEST_IP;
  222. +  
  223.     public static String TVT_EVEN_TEAMS;
  224.     public static boolean TVT_ALLOW_INTERFERENCE;
  225.     public static boolean TVT_ALLOW_POTIONS;
  226. @@ -1758,6 +1804,53 @@
  227.         ANNOUNCE_WEDDING = weddingConfig.getBoolean("AnnounceWedding", true);
  228.     }
  229.    
  230. +   public static void loadVoteConfig()
  231. +   {
  232. +       // Load vote system settings
  233. +       final PropertiesParser votesystem = new PropertiesParser(VOTE_SYSTEM_FILE);
  234. +      
  235. +       ENABLE_VOTE_SYSTEM = votesystem.getBoolean("EnableVoteSystem", true);
  236. +       ENABLE_INDIVIDUAL_VOTE = votesystem.getBoolean("EnableIndividualVote", true);
  237. +       ENABLE_GLOBAL_VOTE = votesystem.getBoolean("EnableGlobalVote", true);
  238. +       NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE = TimeUnit.MINUTES.toMillis(votesystem.getInt("NextTimeToAutoUpdateTotalVote", 60));// -> minutes
  239. +       NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES = TimeUnit.MINUTES.toMillis(votesystem.getInt("NextTimeToAutoUpdateIndividualVotes", 60));// -> minutes
  240. +       NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES = TimeUnit.MINUTES.toMillis(votesystem.getInt("NextTimeToAutoCleanInnecesaryVotes", 30));// -> minutes
  241. +       NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD = TimeUnit.MINUTES.toMillis(votesystem.getInt("NextTimeToCheckAutoGlobalVotesReward", 5));// -> minutes
  242. +       INTERVAL_TO_NEXT_VOTE = TimeUnit.HOURS.toMillis(votesystem.getInt("IntervalTimeToNextVote", 12)); // -> hours
  243. +       GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD = votesystem.getInt("GlobalVotesAmountToNextReward", 50);
  244. +       ENABLE_VOTING_COMMAND = votesystem.getBoolean("EnableVotingCommand", true);
  245. +       VOTING_COMMAND = votesystem.getString("VotingCommand", "getreward");
  246. +       VOTE_LINK_TGS = votesystem.getString("VoteLinkTgs", "");
  247. +       TGS_API_KEY = votesystem.getString("TgsApiKey", "");
  248. +       VOTE_LINK_TOP_CO = votesystem.getString("VoteLinkTopCo", "");
  249. +       TOP_CO_SRV_ID = votesystem.getString("TopCoSrvId", "");
  250. +       VOTE_LINK_ITOPZ = votesystem.getString("VoteLinkItopz", "");
  251. +       ITOPZ_API_KEY = votesystem.getString("ItopzZpiKey", "");
  252. +       ITOPZ_SRV_ID = votesystem.getString("ItopzSrvId", "");
  253. +       VOTE_LINK_VTS = votesystem.getString("VoteLinkVts", "");
  254. +       VTS_API_KEY = votesystem.getString("VtsApiKey", "");
  255. +       VTS_SID = votesystem.getString("VtsSid", "");
  256. +       VOTE_LINK_HZ = votesystem.getString("VoteLinkHz", "");
  257. +       HZ_API_KEY = votesystem.getString("HzApiKey", "");
  258. +       VOTE_NETWORK_LINK = votesystem.getString("VoteNetworkLink", "");
  259. +       VOTE_NETWORK_USER_NAME = votesystem.getString("VoteNetworkUserName", "");
  260. +       VOTE_NETWORK_API_KEY = votesystem.getString("VoteNetworkApiKey", "");
  261. +       VOTE_LINK_TSS = votesystem.getString("VoteLinkTss", "");
  262. +       TSS_API_TOKEN = votesystem.getString("TssApiToken", "");
  263. +       TS_SRV_ID = votesystem.getString("TsSrvId", "");
  264. +       TS_DOMAIN_NAME = votesystem.getString("TsDomainName", "");
  265. +       BRASIL_VOTE_LINK = votesystem.getString("BrasilVoteLink", "");
  266. +       BRASIL_USER_NAME = votesystem.getString("BrasilUserName", "");
  267. +       VOTE_LINK_MMOTOP = votesystem.getString("VoteLinkMmotop", "");
  268. +       MMOTOP_API_KEY = votesystem.getString("MmotopApiKey", "");
  269. +       VOTE_LINK_TZ = votesystem.getString("VoteLinkTz", "");
  270. +       TZ_API_KEY = votesystem.getString("TzApiKey", "");
  271. +       VOTE_LINK_SERVERS = votesystem.getString("VoteLinkServers", "");
  272. +       SERVERS_HASH_CODE = votesystem.getString("ServersHashCode", "");
  273. +       SERVERS_SRV_ID = votesystem.getString("ServersSrvId", "");
  274. +       TEST_IP = votesystem.getString("TestIp", "");
  275. +   }
  276. +  
  277.     public static void loadTVTConfig()
  278.     {
  279.         final PropertiesParser tvtConfig = new PropertiesParser(EVENT_TVT_CONFIG_FILE);
  280. @@ -3190,6 +3283,7 @@
  281.             loadAutoPotionsConfig();
  282.             loadCustomMailManagerConfig();
  283.             loadMerchantZeroPriceConfig();
  284. +           loadVoteConfig();
  285.             loadWeddingConfig();
  286.             loadRebirthConfig();
  287.             loadBankingConfig();
  288. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/util/StatsSet.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/util/StatsSet.java
  289. new file mode 100644
  290. index 0000000..cb54758
  291. --- /dev/null
  292. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/util/StatsSet.java
  293. @@ -0,0 +1,91 @@
  294. +/*
  295. + * This file is part of the L2J Mobius project.
  296. + *
  297. + * This program is free software: you can redistribute it and/or modify
  298. + * it under the terms of the GNU General Public License as published by
  299. + * the Free Software Foundation, either version 3 of the License, or
  300. + * (at your option) any later version.
  301. + *
  302. + * This program is distributed in the hope that it will be useful,
  303. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  304. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  305. + * General Public License for more details.
  306. + *
  307. + * You should have received a copy of the GNU General Public License
  308. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  309. + */
  310. +package org.l2jmobius.commons.util;
  311. +
  312. +import java.util.HashMap;
  313. +
  314. +/**
  315. + * @author escor
  316. + */
  317. +public class StatsSet extends HashMap<String, Object>
  318. +{
  319. +  
  320. +   public StatsSet()
  321. +   {
  322. +       super();
  323. +   }
  324. +  
  325. +   public StatsSet(final StatsSet set)
  326. +   {
  327. +       super(set);
  328. +   }
  329. +  
  330. +   public void set(final String key, final Object value)
  331. +   {
  332. +       put(key, value);
  333. +   }
  334. +  
  335. +   public void set(final String key, final int value)
  336. +   {
  337. +       put(key, value);
  338. +   }
  339. +  
  340. +   public void set(final String key, final int[] value)
  341. +   {
  342. +       put(key, value);
  343. +   }
  344. +  
  345. +   public int getInteger(final String key)
  346. +   {
  347. +       final Object val = get(key);
  348. +      
  349. +       if (val instanceof Number)
  350. +       {
  351. +           return ((Number) val).intValue();
  352. +       }
  353. +       if (val instanceof String)
  354. +       {
  355. +           return Integer.parseInt((String) val);
  356. +       }
  357. +       if (val instanceof Boolean)
  358. +       {
  359. +           return (Boolean) val ? 1 : 0;
  360. +       }
  361. +      
  362. +       throw new IllegalArgumentException("StatsSet : Integer value required, but found: " + val + " for key: " + key + ".");
  363. +   }
  364. +  
  365. +   public int getInteger(final String key, final int defaultValue)
  366. +   {
  367. +       final Object val = get(key);
  368. +      
  369. +       if (val instanceof Number)
  370. +       {
  371. +           return ((Number) val).intValue();
  372. +       }
  373. +       if (val instanceof String)
  374. +       {
  375. +           return Integer.parseInt((String) val);
  376. +       }
  377. +       if (val instanceof Boolean)
  378. +       {
  379. +           return (Boolean) val ? 1 : 0;
  380. +       }
  381. +      
  382. +       return defaultValue;
  383. +   }
  384. +}
  385. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java
  386. index 72f2e67..806f612 100644
  387. --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java
  388. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java
  389. @@ -131,6 +131,8 @@
  390.  import org.l2jmobius.gameserver.scripting.ScriptEngineManager;
  391.  import org.l2jmobius.gameserver.taskmanager.TaskManager;
  392.  import org.l2jmobius.gameserver.ui.Gui;
  393. +import org.l2jmobius.gameserver.votesystem.Handler.voteManager;
  394. +import org.l2jmobius.gameserver.votesystem.VoteUtil.ReadJson;
  395.  import org.l2jmobius.telnet.TelnetStatusThread;
  396.  
  397.  public class GameServer
  398. @@ -331,6 +333,18 @@
  399.         FortSiegeManager.getInstance();
  400.         CrownManager.getInstance();
  401.        
  402. +       Util.printSection("Vote Reward System");
  403. +       if (Config.ENABLE_VOTE_SYSTEM)
  404. +       {
  405. +           voteManager.getInatance();
  406. +           LOGGER.info("======================Vote System Enabled=========================");
  407. +           ReadJson.getInstance();
  408. +       }
  409. +       else
  410. +       {
  411. +           LOGGER.info("======================Vote System Disabled=========================");
  412. +       }
  413. +      
  414.         Util.printSection("Boat");
  415.         BoatData.getInstance();
  416.        
  417. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/Shutdown.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/Shutdown.java
  418. index c040922..569a5d9 100644
  419. --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/Shutdown.java
  420. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/Shutdown.java
  421. @@ -42,6 +42,7 @@
  422.  import org.l2jmobius.gameserver.network.gameserverpackets.ServerStatus;
  423.  import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
  424.  import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
  425. +import org.l2jmobius.gameserver.votesystem.Handler.voteManager;
  426.  
  427.  /**
  428.   * This class provides the functions for shutting down and restarting the server.<br>
  429. @@ -453,6 +454,14 @@
  430.         FishingChampionshipManager.getInstance().shutdown();
  431.         LOGGER.info("Fishing Championship data have been saved!!");
  432.        
  433. +       // Save invidual votes data
  434. +      
  435. +       if (Config.ENABLE_VOTE_SYSTEM)
  436. +       {
  437. +           voteManager.getInatance().Shutdown();
  438. +           LOGGER.info("Vote data have been saved!!");
  439. +       }
  440. +      
  441.         // Schemes save.
  442.         SchemeBufferTable.getInstance().saveSchemes();
  443.         LOGGER.info("BufferTable data has been saved!!");
  444. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/VoicedCommandHandler.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/VoicedCommandHandler.java
  445. index 9236561..c5b807b 100644
  446. --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/VoicedCommandHandler.java
  447. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/VoicedCommandHandler.java
  448. @@ -31,6 +31,7 @@
  449.  import org.l2jmobius.gameserver.handler.voicedcommandhandlers.Online;
  450.  import org.l2jmobius.gameserver.handler.voicedcommandhandlers.StatsCmd;
  451.  import org.l2jmobius.gameserver.handler.voicedcommandhandlers.TvTCmd;
  452. +import org.l2jmobius.gameserver.handler.voicedcommandhandlers.VoteReward;
  453.  import org.l2jmobius.gameserver.handler.voicedcommandhandlers.Wedding;
  454.  
  455.  public class VoicedCommandHandler
  456. @@ -97,6 +98,11 @@
  457.             registerVoicedCommandHandler(new AutoPotion());
  458.         }
  459.        
  460. +       if (Config.ENABLE_VOTE_SYSTEM && Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTING_COMMAND)
  461. +       {
  462. +           registerVoicedCommandHandler(new VoteReward());
  463. +       }
  464. +      
  465.         LOGGER.info("VoicedCommandHandler: Loaded " + _datatable.size() + " handlers.");
  466.     }
  467.    
  468. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/voicedcommandhandlers/VoteReward.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/voicedcommandhandlers/VoteReward.java
  469. new file mode 100644
  470. index 0000000..ade580a
  471. --- /dev/null
  472. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/voicedcommandhandlers/VoteReward.java
  473. @@ -0,0 +1,80 @@
  474. +/*
  475. + * This file is part of the L2J Mobius project.
  476. + *
  477. + * This program is free software: you can redistribute it and/or modify
  478. + * it under the terms of the GNU General Public License as published by
  479. + * the Free Software Foundation, either version 3 of the License, or
  480. + * (at your option) any later version.
  481. + *
  482. + * This program is distributed in the hope that it will be useful,
  483. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  484. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  485. + * General Public License for more details.
  486. + *
  487. + * You should have received a copy of the GNU General Public License
  488. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  489. + */
  490. +package org.l2jmobius.gameserver.handler.voicedcommandhandlers;
  491. +
  492. +import org.l2jmobius.Config;
  493. +import org.l2jmobius.gameserver.handler.IVoicedCommandHandler;
  494. +import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
  495. +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
  496. +import org.l2jmobius.gameserver.votesystem.Handler.voteManager;
  497. +
  498. +/**
  499. + * @author l2.topgameserver.net
  500. + */
  501. +public class VoteReward implements IVoicedCommandHandler
  502. +{
  503. +  
  504. +   @Override
  505. +   public boolean useVoicedCommand(String command, PlayerInstance player, String params)
  506. +   {
  507. +       if (command.equalsIgnoreCase(Config.VOTING_COMMAND))
  508. +       {
  509. +           if (player.isInJail())
  510. +           {
  511. +               player.sendMessage("You cannot use this function while you are jailed");
  512. +               return false;
  513. +           }
  514. +           if (!Config.ENABLE_VOTE_SYSTEM)
  515. +           {
  516. +               player.sendMessage("The rewards system has been disabled by your administrator");
  517. +               return false;
  518. +           }
  519. +           if (!Config.ENABLE_INDIVIDUAL_VOTE)
  520. +           {
  521. +               player.sendMessage("The individual reward system is disabled");
  522. +               return false;
  523. +           }
  524. +           if (!Config.ENABLE_VOTING_COMMAND)
  525. +           {
  526. +               player.sendMessage("Voting command reward is disabled");
  527. +               return false;
  528. +           }
  529. +          
  530. +           for (voteSite vs : voteSite.values())
  531. +           {
  532. +               new Thread(() ->
  533. +               {
  534. +                   voteManager.getInatance().getReward(player, vs.ordinal());
  535. +               }).start();
  536. +           }
  537. +          
  538. +           return true;
  539. +          
  540. +       }
  541. +       return false;
  542. +   }
  543. +  
  544. +   @Override
  545. +   public String[] getVoicedCommandList()
  546. +   {
  547. +       return new String[]
  548. +       {
  549. +           Config.VOTING_COMMAND,
  550. +       };
  551. +   }
  552. +  
  553. +}
  554. \ No newline at end of file
  555. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/NpcVoteRewardInstance.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/NpcVoteRewardInstance.java
  556. new file mode 100644
  557. index 0000000..42b55bd
  558. --- /dev/null
  559. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/NpcVoteRewardInstance.java
  560. @@ -0,0 +1,112 @@
  561. +/*
  562. + * This file is part of the L2J Mobius project.
  563. + *
  564. + * This program is free software: you can redistribute it and/or modify
  565. + * it under the terms of the GNU General Public License as published by
  566. + * the Free Software Foundation, either version 3 of the License, or
  567. + * (at your option) any later version.
  568. + *
  569. + * This program is distributed in the hope that it will be useful,
  570. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  571. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  572. + * General Public License for more details.
  573. + *
  574. + * You should have received a copy of the GNU General Public License
  575. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  576. + */
  577. +package org.l2jmobius.gameserver.model.actor.instance;
  578. +
  579. +import org.l2jmobius.Config;
  580. +import org.l2jmobius.gameserver.datatables.ItemTable;
  581. +import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
  582. +import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
  583. +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
  584. +import org.l2jmobius.gameserver.votesystem.Handler.voteManager;
  585. +import org.l2jmobius.gameserver.votesystem.Model.Reward;
  586. +import org.l2jmobius.gameserver.votesystem.VoteUtil.ReadJson;
  587. +
  588. +/**
  589. + * @author l2.topgameserver.net
  590. + */
  591. +public class NpcVoteRewardInstance extends NpcInstance
  592. +{
  593. +  
  594. +   /**
  595. +    * @param objectId
  596. +    * @param template
  597. +    */
  598. +   public NpcVoteRewardInstance(int objectId, NpcTemplate template)
  599. +   {
  600. +       super(objectId, template);
  601. +   }
  602. +  
  603. +   @Override
  604. +   public void onBypassFeedback(PlayerInstance player, String command)
  605. +   {
  606. +       if (command == null)
  607. +       {
  608. +           return;
  609. +       }
  610. +       int Ordinalsite = Integer.parseInt(command);
  611. +       voteManager.getInatance().getReward(player, Ordinalsite);
  612. +       showChatWindow(player, 0);
  613. +       super.onBypassFeedback(player, command);
  614. +   }
  615. +  
  616. +   @Override
  617. +   public void showChatWindow(PlayerInstance player, int val)
  618. +   {
  619. +       final NpcHtmlMessage html = new NpcHtmlMessage(0);
  620. +       StringBuilder sb = new StringBuilder();
  621. +       html.setFile(getHtmlPath(getNpcId(), 0));
  622. +       for (voteSite vs : voteSite.values())
  623. +       {
  624. +           sb.append("<table bgcolor=000000 width=280><tr>");
  625. +           sb.append("<td width=42><img src=\"icon.etc_treasure_box_i08\" width=32 height=32></td>");
  626. +           sb.append("<td width=220><table width=220>");
  627. +           sb.append("<tr><td><table width=220><tr><td width=145>On " + String.format("%s", ReadJson.getInstance().getRecordSite(vs.ordinal()).getSiteName()) + "</td>");
  628. +           if (voteManager.getInatance().checkIndividualAvailableVote(player, vs.ordinal()))
  629. +           {
  630. +               sb.append("<td width=75>" + String.format("<button value=\"Get reward\" action=\"bypass -h vote_%s_site %s\" height=17 width=64 back=\"sek.cbui94\" fore=\"sek.cbui92\">", getObjectId(), vs.ordinal()) + "</td>");
  631. +           }
  632. +           else
  633. +           {
  634. +               sb.append(String.format("<td width=75 align=center><font color=C68E00>%s</font></td>", voteManager.getInatance().getTimeRemainingWithSampleFormat(player, vs.ordinal())));
  635. +           }
  636. +           sb.append("</tr></table></td></tr>");
  637. +           sb.append("<tr><td><table width=220><tr>");
  638. +           int i = 0;
  639. +           for (Reward r : ReadJson.getInstance().getRewards(vs.ordinal()))
  640. +           {
  641. +               sb.append(String.format("<td width=110 height=32 align=center><font color=BFAF00>%s x%s</font></td>", ItemTable.getInstance().getTemplate(r.getItemId()).getName(), r.getItemCount()));
  642. +               i++;
  643. +               if ((i % 2) == 0)
  644. +               {
  645. +                   sb.append("</tr><tr>");
  646. +               }
  647. +           }
  648. +           sb.append("</tr></table></td></tr></table></td></tr></table><br>");
  649. +       }
  650. +       html.replace("%everyXtime%", Config.INTERVAL_TO_NEXT_VOTE / (3600 * 1000));
  651. +       html.replace("%enablevote%", sb.toString());
  652. +       html.replace("%accountName%", player.getName());
  653. +       player.sendPacket(html);
  654. +   }
  655. +  
  656. +   @Override
  657. +   public String getHtmlPath(int npcId, int val)
  658. +   {
  659. +       String filename = "";
  660. +       if (val == 0)
  661. +       {
  662. +           filename = "" + npcId;
  663. +       }
  664. +       else
  665. +       {
  666. +           filename = npcId + "-" + val;
  667. +       }
  668. +      
  669. +       return "data/html/mods/votesystem/" + filename + ".html";
  670. +   }
  671. +  
  672. +}
  673. \ No newline at end of file
  674. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/SchemeBufferInstance.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/SchemeBufferInstance.java
  675. index 93288b1..5cf052a 100644
  676. --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/SchemeBufferInstance.java
  677. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/SchemeBufferInstance.java
  678. @@ -28,10 +28,11 @@
  679.  import org.l2jmobius.gameserver.model.actor.Creature;
  680.  import org.l2jmobius.gameserver.model.actor.Summon;
  681.  import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
  682. +import org.l2jmobius.gameserver.network.serverpackets.MagicSkillUse;
  683.  import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
  684.  import org.l2jmobius.gameserver.util.Util;
  685.  
  686. -public class SchemeBufferInstance extends FolkInstance
  687. +public class SchemeBufferInstance extends NpcInstance
  688.  {
  689.     private static final int PAGE_LIMIT = 6;
  690.    
  691. @@ -40,6 +41,40 @@
  692.         super(objectId, template);
  693.     }
  694.    
  695. +   public String getSpecialSkills(String groupType)
  696. +   {
  697. +       List<Integer> skills = SchemeBufferTable.getInstance().getSkillsIdsByType(groupType);
  698. +      
  699. +       if (skills.isEmpty())
  700. +       {
  701. +           return "That group doesn't contain any skills.";
  702. +       }
  703. +      
  704. +       final StringBuilder sb = new StringBuilder(skills.size() * 150);
  705. +       int row = 0;
  706. +      
  707. +       for (int skillId : skills)
  708. +       {
  709. +           sb.append(((row % 2) == 0 ? "<table width=\"280\" bgcolor=\"000000\"><tr>" : "<table width=\"280\"><tr>"));
  710. +           if ((skillId > 0) && (skillId < 100))
  711. +           {
  712. +               StringUtil.append(sb, "<td height=40 width=40><img src=\"icon.skill00", skillId, "\" width=32 height=32></td><td width=190>", SkillTable.getInstance().getSkill(skillId, 1).getName(), "<br1><font color=\"B09878\">", SchemeBufferTable.getInstance().getAvailableBuff(skillId).getDescription(), "</font></td><td><button action=\"bypass npc_", getObjectId(), "_getSpecialBuff;", skillId, "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomin2\" fore=\"L2UI_CH3.mapbutton_zoomin1\"></td>");
  713. +           }
  714. +           else if ((skillId >= 100) && (skillId < 1000))
  715. +           {
  716. +               StringUtil.append(sb, "<td height=40 width=40><img src=\"icon.skill0", skillId, "\" width=32 height=32></td><td width=190>", SkillTable.getInstance().getSkill(skillId, 1).getName(), "<br1><font color=\"B09878\">", SchemeBufferTable.getInstance().getAvailableBuff(skillId).getDescription(), "</font></td><td><button action=\"bypass npc_", getObjectId(), "_getSpecialBuff;", skillId, "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomin2\" fore=\"L2UI_CH3.mapbutton_zoomin1\"></td>");
  717. +           }
  718. +           else if (skillId >= 1000)
  719. +           {
  720. +               StringUtil.append(sb, "<td height=40 width=40><img src=\"icon.skill", skillId, "\" width=32 height=32></td><td width=190>", SkillTable.getInstance().getSkill(skillId, 1).getName(), "<br1><font color=\"B09878\">", SchemeBufferTable.getInstance().getAvailableBuff(skillId).getDescription(), "</font></td><td><button action=\"bypass npc_", getObjectId(), "_getSpecialBuff;", skillId, "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomin2\" fore=\"L2UI_CH3.mapbutton_zoomin1\"></td>");
  721. +           }
  722. +           sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=277 height=1>");
  723. +           row++;
  724. +       }
  725. +      
  726. +       return sb.toString();
  727. +   }
  728. +  
  729.     @Override
  730.     public void onBypassFeedback(PlayerInstance player, String commandValue)
  731.     {
  732. @@ -48,7 +83,68 @@
  733.        
  734.         final StringTokenizer st = new StringTokenizer(command, ";");
  735.         final String currentCommand = st.nextToken();
  736. -       if (currentCommand.startsWith("menu"))
  737. +      
  738. +       if (currentCommand.startsWith("specialbuff"))
  739. +       {
  740. +           final String ncommand = st.nextToken();
  741. +           final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  742. +           html.setFile(getHtmlPath(getNpcId(), 3));
  743. +           if (ncommand.startsWith("Resist"))
  744. +           {
  745. +               html.replace("%specialbuff%", getSpecialSkills("Resist"));
  746. +           }
  747. +           else if (ncommand.startsWith("Summon_buffs"))
  748. +           {
  749. +               html.replace("%specialbuff%", getSpecialSkills("Summon_buffs"));
  750. +           }
  751. +           else if (ncommand.startsWith("Malarias"))
  752. +           {
  753. +               html.replace("%specialbuff%", getSpecialSkills("Malarias"));
  754. +           }
  755. +           html.replace("%objectId%", getObjectId());
  756. +           player.sendPacket(html);
  757. +       }
  758. +      
  759. +       else if (currentCommand.startsWith("getSpecialBuff"))
  760. +       {
  761. +           final int skillid = Integer.parseInt(st.nextToken());
  762. +           final int price = SchemeBufferTable.getInstance().getAvailableBuff(skillid).getPrice();
  763. +           if (player.getInventory().getInventoryItemCount(7164, -1) >= 1)
  764. +           {
  765. +              
  766. +           }
  767. +           else if (player.getInventory().getInventoryItemCount(7569, -1) > price)
  768. +           {
  769. +               player.destroyItemByItemId("Buffer: ", 7569, price, player, true);
  770. +           }
  771. +           else
  772. +           {
  773. +               player.sendMessage("You don't have the necessary items to continue this action.");
  774. +               return;
  775. +           }
  776. +           Creature target = null;
  777. +           if (st.hasMoreTokens())
  778. +           {
  779. +               final String targetType = st.nextToken();
  780. +               if ((targetType != null) && targetType.equalsIgnoreCase("pet"))
  781. +               {
  782. +                   target = player.getPet();
  783. +               }
  784. +           }
  785. +           else
  786. +           {
  787. +               target = player;
  788. +           }
  789. +          
  790. +           if (target == null)
  791. +           {
  792. +               player.sendMessage("You don't have a pet.");
  793. +           }
  794. +           this.broadcastPacket(new MagicSkillUse(this, target, skillid, SchemeBufferTable.getInstance().getAvailableBuff(skillid).getLevel(), 0, 0));
  795. +           SkillTable.getInstance().getSkill(skillid, SchemeBufferTable.getInstance().getAvailableBuff(skillid).getLevel()).getEffects(this, target);
  796. +           player.sendMessage("You have acquired " + SkillTable.getInstance().getSkill(skillid, 1).getName());
  797. +       }
  798. +       else if (currentCommand.startsWith("menu"))
  799.         {
  800.             final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  801.             html.setFile(getHtmlPath(getNpcId(), 0));
  802. @@ -388,6 +484,10 @@
  803.         int count = 0;
  804.         for (String type : SchemeBufferTable.getInstance().getSkillTypes())
  805.         {
  806. +           if ((type.equalsIgnoreCase("Resist")) || (type.equalsIgnoreCase("Summon_buffs")) || (type.equalsIgnoreCase("Malarias")))
  807. +           {
  808. +               continue;
  809. +           }
  810.             if (count == 0)
  811.             {
  812.                 sb.append("<tr>");
  813. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java
  814. index 528e895..84fc800 100644
  815. --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java
  816. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java
  817. @@ -109,6 +109,30 @@
  818.                
  819.                 ach.useAdminCommand(_command, player);
  820.             }
  821. +           else if (_command.startsWith("vote_"))
  822. +           {
  823. +              
  824. +               int endOfId = _command.indexOf('_', 6);
  825. +               String id;
  826. +               if (endOfId > 0)
  827. +               {
  828. +                   id = _command.substring(5, endOfId);
  829. +               }
  830. +               else
  831. +               {
  832. +                   id = _command.substring(5);
  833. +               }
  834. +              
  835. +               if (_command.split(" ")[1].toString() != null)
  836. +               {
  837. +                   final WorldObject object = World.getInstance().findObject(Integer.parseInt(id));
  838. +                   if ((Config.ALLOW_CLASS_MASTERS && Config.ALLOW_REMOTE_CLASS_MASTERS && (object instanceof ClassMasterInstance)) //
  839. +                       || ((object instanceof NpcInstance) && (endOfId > 0) && player.isInsideRadius(object, NpcInstance.INTERACTION_DISTANCE, false, false)))
  840. +                   {
  841. +                       ((NpcInstance) object).onBypassFeedback(player, _command.split(" ")[1].toString());
  842. +                   }
  843. +               }
  844. +           }
  845.             else if (_command.equals("come_here") && player.isGM())
  846.             {
  847.                 final WorldObject obj = player.getTarget();
  848. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/CreatureSay.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/CreatureSay.java
  849. index 66c4ddd..0365268 100644
  850. --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/CreatureSay.java
  851. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/CreatureSay.java
  852. @@ -25,7 +25,7 @@
  853.  public class CreatureSay extends GameServerPacket
  854.  {
  855.     private final int _objectId;
  856. -   private final ChatType _chatType;
  857. +   private final int _chatType;
  858.     private final String _charName;
  859.     private final String _text;
  860.    
  861. @@ -38,6 +38,14 @@
  862.     public CreatureSay(int objectId, ChatType chatType, String charName, String text)
  863.     {
  864.         _objectId = objectId;
  865. +       _chatType = chatType.getClientId();
  866. +       _charName = charName;
  867. +       _text = text;
  868. +   }
  869. +  
  870. +   public CreatureSay(int objectId, int chatType, String charName, String text)
  871. +   {
  872. +       _objectId = objectId;
  873.         _chatType = chatType;
  874.         _charName = charName;
  875.         _text = text;
  876. @@ -48,14 +56,14 @@
  877.     {
  878.         writeC(0x4a);
  879.         writeD(_objectId);
  880. -       writeD(_chatType.getClientId());
  881. +       writeD(_chatType);
  882.         writeS(_charName);
  883.         writeS(_text);
  884.        
  885.         final PlayerInstance player = getClient().getPlayer();
  886.         if (player != null)
  887.         {
  888. -           player.broadcastSnoop(_chatType, _charName, _text, this);
  889. +           player.broadcastSnoop(ChatType.values()[_chatType], _charName, _text, this);
  890.         }
  891.     }
  892.  }
  893. \ No newline at end of file
  894. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/util/Broadcast.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/util/Broadcast.java
  895. index 308ab18..ccf7ad6 100644
  896. --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/util/Broadcast.java
  897. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/util/Broadcast.java
  898. @@ -17,11 +17,13 @@
  899.  package org.l2jmobius.gameserver.util;
  900.  
  901.  import org.l2jmobius.gameserver.datatables.xml.ZoneData;
  902. +import org.l2jmobius.gameserver.enums.ChatType;
  903.  import org.l2jmobius.gameserver.model.World;
  904.  import org.l2jmobius.gameserver.model.actor.Creature;
  905.  import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
  906.  import org.l2jmobius.gameserver.model.zone.ZoneType;
  907.  import org.l2jmobius.gameserver.network.serverpackets.CharInfo;
  908. +import org.l2jmobius.gameserver.network.serverpackets.CreatureSay;
  909.  import org.l2jmobius.gameserver.network.serverpackets.GameServerPacket;
  910.  import org.l2jmobius.gameserver.network.serverpackets.RelationChanged;
  911.  
  912. @@ -194,6 +196,11 @@
  913.         }
  914.     }
  915.    
  916. +   public static void toAllOnlinePlayers(String text, boolean isCritical)
  917. +   {
  918. +       toAllOnlinePlayers(new CreatureSay(0, isCritical ? ChatType.CRITICAL_ANNOUNCE.ordinal() : ChatType.ANNOUNCEMENT.ordinal(), "", text));
  919. +   }
  920. +  
  921.     /**
  922.      * Send a packet to all players in a specific zone type.
  923.      * @param <T> ZoneType.
  924. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/DB/globalVoteDB.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/DB/globalVoteDB.java
  925. new file mode 100644
  926. index 0000000..899b19c
  927. --- /dev/null
  928. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/DB/globalVoteDB.java
  929. @@ -0,0 +1,123 @@
  930. +package org.l2jmobius.gameserver.votesystem.DB;
  931. +
  932. +import java.sql.Connection;
  933. +import java.sql.PreparedStatement;
  934. +import java.sql.ResultSet;
  935. +import java.sql.SQLException;
  936. +import java.sql.Statement;
  937. +import java.util.logging.Logger;
  938. +
  939. +import org.l2jmobius.commons.database.DatabaseFactory;
  940. +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
  941. +import org.l2jmobius.gameserver.votesystem.Model.globalVote;
  942. +
  943. +/**
  944. + * @author l2.topgameserver.net
  945. + */
  946. +public class globalVoteDB
  947. +{
  948. +   public static final Logger LOGGER = Logger.getLogger(globalVoteDB.class.getName());
  949. +   private Statement st;
  950. +   private Connection con;
  951. +   private final globalVote[] _globalVotes;
  952. +  
  953. +   private globalVoteDB()
  954. +   {
  955. +       _globalVotes = new globalVote[voteSite.values().length];
  956. +       loadGlobalVotes();
  957. +   }
  958. +  
  959. +   public void loadGlobalVotes()
  960. +   {
  961. +       con = DatabaseFactory.getConnection();
  962. +       try (PreparedStatement ps = con.prepareStatement("Select voteSite,lastRewardVotes from globalvotes");
  963. +           ResultSet rs = ps.executeQuery();)
  964. +       {
  965. +           if (rs.getRow() == 0)
  966. +           {
  967. +               for (voteSite vs : voteSite.values())
  968. +               {
  969. +                   globalVote gv = new globalVote();
  970. +                   gv.setVoteSite(vs.ordinal());
  971. +                   gv.setVotesLastReward(0);
  972. +                   _globalVotes[gv.getVoyeSite()] = gv;
  973. +               }
  974. +               return;
  975. +           }
  976. +           while (rs.next())
  977. +           {
  978. +               globalVote gv = new globalVote();
  979. +               gv.setVoteSite(rs.getInt("voteSite"));
  980. +               gv.setVotesLastReward(rs.getInt("lastRewardVotes"));
  981. +               _globalVotes[gv.getVoyeSite()] = gv;
  982. +           }
  983. +           ps.close();
  984. +           con.close();
  985. +          
  986. +       }
  987. +       catch (SQLException e)
  988. +       {
  989. +           e.printStackTrace();
  990. +       }
  991. +   }
  992. +  
  993. +   public void saveGlobalVote(globalVote gb)
  994. +   {
  995. +       try (Connection con = DatabaseFactory.getConnection();
  996. +           PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)"))
  997. +      
  998. +       {
  999. +           ps.setInt(1, gb.getVoyeSite());
  1000. +           ps.setInt(2, gb.getVotesLastReward());
  1001. +           ps.executeUpdate();
  1002. +          
  1003. +           ps.close();
  1004. +           con.close();
  1005. +          
  1006. +       }
  1007. +       catch (SQLException e)
  1008. +       {
  1009. +           e.printStackTrace();
  1010. +       }
  1011. +   }
  1012. +  
  1013. +   public void saveGlobalVotes(globalVote[] globalVotes)
  1014. +   {
  1015. +       try (Connection con = DatabaseFactory.getConnection();
  1016. +           PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)"))
  1017. +      
  1018. +       {
  1019. +           for (voteSite vs : voteSite.values())
  1020. +           {
  1021. +               globalVote gb = globalVotes[vs.ordinal()];
  1022. +               ps.setInt(1, gb.getVoyeSite());
  1023. +               ps.setInt(2, gb.getVotesLastReward());
  1024. +               ps.addBatch();
  1025. +           }
  1026. +           ps.executeBatch();
  1027. +          
  1028. +           ps.close();
  1029. +           con.close();
  1030. +          
  1031. +       }
  1032. +       catch (SQLException e)
  1033. +       {
  1034. +           e.printStackTrace();
  1035. +       }
  1036. +   }
  1037. +  
  1038. +   public globalVote[] getGlobalVotes()
  1039. +   {
  1040. +       return _globalVotes;
  1041. +   }
  1042. +  
  1043. +   public static final globalVoteDB getInstance()
  1044. +   {
  1045. +       return SingleHolder.INSTANCE;
  1046. +   }
  1047. +  
  1048. +   private static final class SingleHolder
  1049. +   {
  1050. +       protected static final globalVoteDB INSTANCE = new globalVoteDB();
  1051. +   }
  1052. +}
  1053. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/DB/individualVoteDB.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/DB/individualVoteDB.java
  1054. new file mode 100644
  1055. index 0000000..a3cfbbe
  1056. --- /dev/null
  1057. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/DB/individualVoteDB.java
  1058. @@ -0,0 +1,180 @@
  1059. +package org.l2jmobius.gameserver.votesystem.DB;
  1060. +
  1061. +import java.sql.Connection;
  1062. +import java.sql.PreparedStatement;
  1063. +import java.sql.ResultSet;
  1064. +import java.sql.SQLException;
  1065. +import java.sql.Statement;
  1066. +import java.util.HashMap;
  1067. +import java.util.HashSet;
  1068. +import java.util.Map;
  1069. +import java.util.logging.Logger;
  1070. +
  1071. +import org.l2jmobius.commons.database.DatabaseFactory;
  1072. +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
  1073. +import org.l2jmobius.gameserver.votesystem.Model.individualVote;
  1074. +
  1075. +/**
  1076. + * @author l2.topgameserver.net
  1077. + */
  1078. +public class individualVoteDB
  1079. +{
  1080. +   private static final Logger LOGGER = Logger.getLogger(individualVoteDB.class.getName());
  1081. +   private final Map<String, individualVote[]> _votes;
  1082. +   private Statement st;
  1083. +   private Connection con;
  1084. +  
  1085. +   private individualVoteDB()
  1086. +   {
  1087. +       _votes = new HashMap<>();
  1088. +       loadVotes();
  1089. +   }
  1090. +  
  1091. +   public void loadVotes()
  1092. +   {
  1093. +      
  1094. +       _votes.clear();
  1095. +       try (Connection con = DatabaseFactory.getConnection();
  1096. +           PreparedStatement ps = con.prepareStatement("SELECT voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded FROM individualvotes");
  1097. +           ResultSet rs = ps.executeQuery();)
  1098. +       {
  1099. +           individualVote[] ivs = new individualVote[voteSite.values().length];
  1100. +           while (rs.next())
  1101. +           {
  1102. +               individualVote iv = new individualVote();
  1103. +               iv.setVoterIp(rs.getString("voterIp"));
  1104. +               iv.setVoteSite(rs.getInt("voteSite"));
  1105. +               iv.setVotingTimeSite(rs.getLong("votingTimeSite"));
  1106. +               iv.setAlreadyRewarded(rs.getBoolean("alreadyRewarded"));
  1107. +              
  1108. +               if (_votes.containsKey(iv.getVoterIp()))
  1109. +               {
  1110. +                   if (_votes.get(iv.getVoterIp())[iv.getVoteSite()] == null)
  1111. +                   {
  1112. +                       ivs[iv.getVoteSite()] = iv;
  1113. +                       _votes.replace(iv.getVoterIp(), ivs);
  1114. +                   }
  1115. +               }
  1116. +               else
  1117. +               {
  1118. +                   ivs[iv.getVoteSite()] = iv;
  1119. +                   _votes.put(iv.getVoterIp(), ivs);
  1120. +                  
  1121. +               }
  1122. +           }
  1123. +          
  1124. +       }
  1125. +       catch (SQLException e)
  1126. +       {
  1127. +           e.printStackTrace();
  1128. +       }
  1129. +      
  1130. +   }
  1131. +  
  1132. +   public void SaveVotes(Map<String, individualVote[]> votes)
  1133. +   {
  1134. +      
  1135. +       if (votes == null)
  1136. +       {
  1137. +           return;
  1138. +       }
  1139. +       if (votes.size() == 0)
  1140. +       {
  1141. +           return;
  1142. +       }
  1143. +       try (Connection con = DatabaseFactory.getConnection();
  1144. +           PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?) ON DUPLICATE KEY UPDATE " + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), votingTimeSite = VALUES(votingTimeSite),alreadyRewarded = VALUES(alreadyRewarded)");)
  1145. +       {
  1146. +          
  1147. +           for (Map.Entry<String, individualVote[]> ivm : votes.entrySet())
  1148. +           {
  1149. +               for (individualVote iv : ivm.getValue())
  1150. +               {
  1151. +                   if (iv == null)
  1152. +                   {
  1153. +                       continue;
  1154. +                   }
  1155. +                   ps.setString(1, iv.getVoterIp());
  1156. +                   ps.setInt(2, iv.getVoteSite());
  1157. +                   ps.setLong(4, iv.getVotingTimeSite());
  1158. +                   ps.setBoolean(5, iv.getAlreadyRewarded());
  1159. +                   ps.addBatch();
  1160. +               }
  1161. +           }
  1162. +           ps.executeBatch();
  1163. +       }
  1164. +       catch (SQLException e)
  1165. +       {
  1166. +           e.printStackTrace();
  1167. +       }
  1168. +   }
  1169. +  
  1170. +   public void SaveVote(individualVote vote)
  1171. +   {
  1172. +      
  1173. +       if (vote == null)
  1174. +       {
  1175. +           return;
  1176. +       }
  1177. +      
  1178. +       try (Connection con = DatabaseFactory.getConnection();
  1179. +           PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?) ON DUPLICATE KEY UPDATE" + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), votingTimeSite = VALUES(votingTimeSite), alreadyRewarded = VALUES(alreadyRewarded)");)
  1180. +       {
  1181. +           ps.setString(1, vote.getVoterIp());
  1182. +           ps.setInt(2, vote.getVoteSite());
  1183. +           ps.setLong(4, vote.getVotingTimeSite());
  1184. +           ps.setBoolean(5, vote.getAlreadyRewarded());
  1185. +           ps.executeUpdate();
  1186. +       }
  1187. +       catch (SQLException e)
  1188. +       {
  1189. +           e.printStackTrace();
  1190. +       }
  1191. +   }
  1192. +  
  1193. +   public void DeleteVotes(HashSet<individualVote> deleteVotes)
  1194. +   {
  1195. +       if (deleteVotes == null)
  1196. +       {
  1197. +           return;
  1198. +       }
  1199. +       if (deleteVotes.size() == 0)
  1200. +       {
  1201. +           return;
  1202. +       }
  1203. +       try
  1204. +       {
  1205. +           con = DatabaseFactory.getConnection();
  1206. +           st = con.createStatement();
  1207. +           for (individualVote iv : deleteVotes)
  1208. +           {
  1209. +               String sql = String.format("Delete from individualvotes where voterIp = '%s' AND voteSite = %s", iv.getVoterIp(), iv.getVoteSite());
  1210. +               st.addBatch(sql);
  1211. +           }
  1212. +           int[] result = st.executeBatch();
  1213. +           st.close();
  1214. +           con.close();
  1215. +           LOGGER.info(result.length + " Innecesary votes has been deleted");
  1216. +          
  1217. +       }
  1218. +       catch (SQLException e)
  1219. +       {
  1220. +           e.printStackTrace();
  1221. +       }
  1222. +   }
  1223. +  
  1224. +   public Map<String, individualVote[]> getVotesDB()
  1225. +   {
  1226. +       return _votes;
  1227. +   }
  1228. +  
  1229. +   public static final individualVoteDB getInstance()
  1230. +   {
  1231. +       return SingleHolder.INSTANCE;
  1232. +   }
  1233. +  
  1234. +   private static final class SingleHolder
  1235. +   {
  1236. +       protected static final individualVoteDB INSTANCE = new individualVoteDB();
  1237. +   }
  1238. +}
  1239. \ No newline at end of file
  1240. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Enum/voteSite.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Enum/voteSite.java
  1241. new file mode 100644
  1242. index 0000000..9218452
  1243. --- /dev/null
  1244. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Enum/voteSite.java
  1245. @@ -0,0 +1,19 @@
  1246. +package org.l2jmobius.gameserver.votesystem.Enum;
  1247. +
  1248. +/**
  1249. + * @author l2.topgameserver.net
  1250. + */
  1251. +public enum voteSite
  1252. +{
  1253. +   L2TOPGAMESERVER, // 0
  1254. +   ITOPZ, // 1
  1255. +   L2TOPCO, // 2
  1256. +   L2VOTES, // 3
  1257. +   HOPZONE, // 4
  1258. +   L2NETWORK, // 5
  1259. +   L2TOPSERVERS, // 6
  1260. +   TOPL2JBRASIL, // 7
  1261. +   MMOTOP, // 8
  1262. +   TOPZONE, // 9
  1263. +   L2SERVERS,// 10
  1264. +}
  1265. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Handler/voteHandler.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Handler/voteHandler.java
  1266. new file mode 100644
  1267. index 0000000..d74419c
  1268. --- /dev/null
  1269. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Handler/voteHandler.java
  1270. @@ -0,0 +1,500 @@
  1271. +package org.l2jmobius.gameserver.votesystem.Handler;
  1272. +
  1273. +import java.io.BufferedReader;
  1274. +import java.io.DataOutputStream;
  1275. +import java.io.InputStreamReader;
  1276. +import java.net.HttpURLConnection;
  1277. +import java.net.URL;
  1278. +import java.nio.charset.Charset;
  1279. +import java.text.ParseException;
  1280. +import java.text.SimpleDateFormat;
  1281. +import java.util.logging.Logger;
  1282. +
  1283. +import org.l2jmobius.Config;
  1284. +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
  1285. +import org.l2jmobius.gameserver.votesystem.Model.individualVoteResponse;
  1286. +import org.l2jmobius.gameserver.votesystem.VoteUtil.ReadJson;
  1287. +import org.l2jmobius.gameserver.votesystem.VoteUtil.VoteUtil;
  1288. +
  1289. +/**
  1290. + * @author l2.topgameserver.net
  1291. + */
  1292. +public class voteHandler
  1293. +{
  1294. +   public static final Logger LOGGER = Logger.getLogger(voteHandler.class.getName());
  1295. +  
  1296. +   protected static String getNetWorkResponse(String URL, int ordinal)
  1297. +   {
  1298. +       if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME)))
  1299. +       {
  1300. +           return "";
  1301. +       }
  1302. +      
  1303. +       StringBuffer response = new StringBuffer();
  1304. +       try
  1305. +       {
  1306. +           String API_URL = Config.VOTE_NETWORK_LINK;
  1307. +           String detail = URL;
  1308. +           String postParameters = "";
  1309. +           postParameters += "apiKey=" + VoteUtil.between("apiKey=", detail, "&type=");
  1310. +           postParameters += "&type=" + VoteUtil.between("&type=", detail, "&player");
  1311. +           String beginIndexPlayer = "&player=";
  1312. +           String player = detail.substring(detail.indexOf(beginIndexPlayer) + beginIndexPlayer.length());
  1313. +          
  1314. +           if ((player != null) && !player.equals(""))
  1315. +           {
  1316. +               postParameters += "&player=" + player;
  1317. +           }
  1318. +          
  1319. +           byte[] postData = postParameters.getBytes(Charset.forName("UTF-8"));
  1320. +           URL url = new URL(API_URL);
  1321. +           HttpURLConnection con = (HttpURLConnection) url.openConnection();
  1322. +           con.setConnectTimeout(5000);
  1323. +           con.setRequestMethod("POST");
  1324. +           con.setRequestProperty("Content-Length", Integer.toString(postData.length));
  1325. +           con.setRequestProperty("User-Agent", "Mozilla/5.0");
  1326. +           con.setDoOutput(true);
  1327. +          
  1328. +           DataOutputStream os = new DataOutputStream(con.getOutputStream());
  1329. +           os.write(postData);
  1330. +           os.flush();
  1331. +           os.close();
  1332. +          
  1333. +           BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  1334. +           String inputLine;
  1335. +          
  1336. +           while ((inputLine = in.readLine()) != null)
  1337. +           {
  1338. +               response.append(inputLine);
  1339. +           }
  1340. +           in.close();
  1341. +          
  1342. +           return response.toString();
  1343. +          
  1344. +       }
  1345. +       catch (Exception e)
  1346. +       {
  1347. +           LOGGER.warning(VoteUtil.Sites[ordinal] + " Say: An error ocurred " + e.getCause());
  1348. +           return "";
  1349. +       }
  1350. +   }
  1351. +  
  1352. +   protected static String getResponse(String Url, int ordinal)
  1353. +   {
  1354. +       if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME)))
  1355. +       {
  1356. +           return "";
  1357. +       }
  1358. +      
  1359. +       try
  1360. +       {
  1361. +           int responseCode = 0;
  1362. +           URL objUrl = new URL(Url);
  1363. +           HttpURLConnection con = (HttpURLConnection) objUrl.openConnection();
  1364. +           con.setRequestMethod("GET");
  1365. +           con.setRequestProperty("User-Agent", "Mozilla/5.0");
  1366. +           con.setConnectTimeout(5000);
  1367. +           responseCode = con.getResponseCode();
  1368. +           if (responseCode == HttpURLConnection.HTTP_OK)
  1369. +           {
  1370. +               String inputLine;
  1371. +               StringBuffer response = new StringBuffer();
  1372. +               BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  1373. +               while ((inputLine = in.readLine()) != null)
  1374. +               {
  1375. +                   response.append(inputLine);
  1376. +               }
  1377. +               in.close();
  1378. +               return response.toString();
  1379. +           }
  1380. +          
  1381. +       }
  1382. +       catch (Exception e)
  1383. +       {
  1384. +           LOGGER.warning(ReadJson.getInstance().getRecordSite(ordinal).getSiteName() + " Say: An error ocurred " + e.getCause());
  1385. +           return "";
  1386. +       }
  1387. +      
  1388. +       return "";
  1389. +   }
  1390. +  
  1391. +   public static individualVoteResponse getIndividualVoteResponse(int ordinal, String ip, String AccountName)
  1392. +   {
  1393. +       String response = "";
  1394. +       boolean isVoted = false;
  1395. +       long voteSiteTime = 0L, diffTime = 0L;
  1396. +       SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1397. +       individualVoteResponse ivr = new individualVoteResponse();
  1398. +      
  1399. +       switch (ordinal)
  1400. +       {
  1401. +           case 0:
  1402. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1403. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"already_voted\":", response, ",\"vote_time\""));
  1404. +               if (isVoted)
  1405. +               {
  1406. +                   try
  1407. +                   {
  1408. +                       voteSiteTime = format.parse(VoteUtil.between("\"vote_time\":\"", response, "\",\"server_time\"")).getTime();
  1409. +                   }
  1410. +                   catch (ParseException e)
  1411. +                   {
  1412. +                       e.printStackTrace();
  1413. +                   }
  1414. +               }
  1415. +               break;
  1416. +          
  1417. +           case 1:
  1418. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1419. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isvoted\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"votetime").replaceAll("\"", ""));
  1420. +               if (isVoted)
  1421. +               {
  1422. +                   try
  1423. +                   {
  1424. +                       voteSiteTime = (Long.parseLong(VoteUtil.between("\"votetime\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"servertime"))) * 1000;
  1425. +                   }
  1426. +                   catch (Exception e)
  1427. +                   {
  1428. +                       e.printStackTrace();
  1429. +                   }
  1430. +               }
  1431. +               break;
  1432. +          
  1433. +           case 2:
  1434. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1435. +               isVoted = (response == "") ? false : Boolean.parseBoolean(response);
  1436. +               if (isVoted)
  1437. +               {
  1438. +                   voteSiteTime = System.currentTimeMillis() - (VoteUtil.getTimeZoneVotingSite(ordinal));
  1439. +               }
  1440. +               break;
  1441. +          
  1442. +           case 3:
  1443. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1444. +               isVoted = ((VoteUtil.between("\"status\":\"", response, "\",\"date\"") != "") && (Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"date\"")) == 1)) ? true : false;
  1445. +               if (isVoted)
  1446. +               {
  1447. +                   String dateString = VoteUtil.between("\"date\":\"", response, "\"}]");
  1448. +                   try
  1449. +                   {
  1450. +                       voteSiteTime = format.parse(String.format("%s-%s-%s %s:%s:%s", dateString.substring(0, 4), dateString.substring(4, 6), dateString.substring(6, 8), dateString.substring(8, 10), dateString.substring(10, 12), dateString.substring(12, 14))).getTime();
  1451. +                   }
  1452. +                   catch (ParseException e1)
  1453. +                   {
  1454. +                       e1.printStackTrace();
  1455. +                   }
  1456. +                  
  1457. +               }
  1458. +               break;
  1459. +          
  1460. +           case 4:
  1461. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1462. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\""));
  1463. +               if (isVoted)
  1464. +               {
  1465. +                   try
  1466. +                   {
  1467. +                       voteSiteTime = format.parse(VoteUtil.between("\"voteTime\":\"", response, "\",\"hopzoneServerTime\"")).getTime();
  1468. +                   }
  1469. +                   catch (ParseException e)
  1470. +                   {
  1471. +                       e.printStackTrace();
  1472. +                   }
  1473. +               }
  1474. +               break;
  1475. +          
  1476. +           case 5:
  1477. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1478. +               isVoted = (!"".equals(response) && (Integer.parseInt(response) == 1)) ? true : false;
  1479. +               if (isVoted)
  1480. +               {
  1481. +                   voteSiteTime = System.currentTimeMillis() - (VoteUtil.getTimeZoneVotingSite(ordinal));
  1482. +               }
  1483. +               break;
  1484. +          
  1485. +           case 6:
  1486. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1487. +               isVoted = ("".equals(response)) ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\""));
  1488. +               if (isVoted)
  1489. +               {
  1490. +                   try
  1491. +                   {
  1492. +                       voteSiteTime = format.parse(VoteUtil.between("\"voteTime\":\"", response, "\",\"l2topserversServerTime\"")).getTime();
  1493. +                   }
  1494. +                   catch (Exception e)
  1495. +                   {
  1496. +                       e.printStackTrace();
  1497. +                   }
  1498. +                  
  1499. +               }
  1500. +               break;
  1501. +          
  1502. +           case 7:
  1503. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1504. +               isVoted = ((VoteUtil.between("\"status\":\"", response, "\",\"server_time\"") != "") && (Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"server_time\"")) == 1)) ? true : false;
  1505. +               if (isVoted)
  1506. +               {
  1507. +                   try
  1508. +                   {
  1509. +                       voteSiteTime = format.parse(VoteUtil.between("\"date\":\"", response, "\",\"status\"")).getTime();
  1510. +                   }
  1511. +                   catch (Exception e)
  1512. +                   {
  1513. +                       e.printStackTrace();
  1514. +                   }
  1515. +               }
  1516. +               break;
  1517. +          
  1518. +           case 8:
  1519. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1520. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"is_voted\":", response, ",\"vote_time\""));
  1521. +               if (isVoted)
  1522. +               {
  1523. +                   try
  1524. +                   {
  1525. +                       voteSiteTime = (Long.parseLong(VoteUtil.between("\"vote_time\":", response, ",\"server_time\""))) * 1000;
  1526. +                   }
  1527. +                   catch (Exception e)
  1528. +                   {
  1529. +                       e.printStackTrace();
  1530. +                   }
  1531. +               }
  1532. +               break;
  1533. +          
  1534. +           case 9:
  1535. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1536. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isVoted\": ", response, ",\"voteTime\""));
  1537. +               if (isVoted)
  1538. +               {
  1539. +                   voteSiteTime = Long.parseLong(VoteUtil.between("\"voteTime\": \"", response, "\",\"serverTime\"")) * 1000;
  1540. +               }
  1541. +               break;
  1542. +          
  1543. +           case 10:
  1544. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1545. +               isVoted = (response == "") ? false : Boolean.parseBoolean(response);
  1546. +               if (isVoted)
  1547. +               {
  1548. +                   voteSiteTime = System.currentTimeMillis() - (VoteUtil.getTimeZoneVotingSite(ordinal));
  1549. +               }
  1550. +               break;
  1551. +          
  1552. +           default:
  1553. +               return null;
  1554. +       }
  1555. +       if (!response.equals("") && isVoted)
  1556. +       {
  1557. +           ivr.setIsVoted(isVoted);
  1558. +           ivr.setDiffTime(diffTime);
  1559. +           ivr.setVoteSiteTime(voteSiteTime);
  1560. +           return ivr;
  1561. +       }
  1562. +       return null;
  1563. +   }
  1564. +  
  1565. +   public int getGlobalVotesResponse(int ordinal)
  1566. +   {
  1567. +      
  1568. +       String response = "";
  1569. +       int totalVotes = 0;
  1570. +      
  1571. +       switch (ordinal)
  1572. +       {
  1573. +           case 0:
  1574. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1575. +               response = VoteUtil.between("\"getVotes\":", response, "}");
  1576. +               totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
  1577. +               break;
  1578. +          
  1579. +           case 1:
  1580. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1581. +               response = VoteUtil.between("server_votes\":", response.replace(" ", ""), ",\"server_rank");
  1582. +               totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
  1583. +               break;
  1584. +          
  1585. +           case 2:
  1586. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1587. +               totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
  1588. +               break;
  1589. +          
  1590. +           case 3:
  1591. +               response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
  1592. +               response = VoteUtil.between("Votes:</th><th><a class='votes'>", response, "</a></th></tr><tr><th>Clicks:");
  1593. +               totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
  1594. +               break;
  1595. +          
  1596. +           case 4:
  1597. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1598. +               response = VoteUtil.between("\"totalvotes\":", response, ",\"status_code\"");
  1599. +               totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
  1600. +               break;
  1601. +          
  1602. +           case 5:
  1603. +               String responseNetwork = getNetWorkResponse(getGlobalUrl(ordinal), ordinal);
  1604. +               totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
  1605. +               break;
  1606. +          
  1607. +           case 6:
  1608. +               response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
  1609. +               response = VoteUtil.between("VOTE <span>", response.toString().replaceAll("\n", ""), "</span>");
  1610. +              
  1611. +               totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
  1612. +               break;
  1613. +          
  1614. +           case 7:
  1615. +               response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
  1616. +               response = VoteUtil.between("nicas:</b> ", response, "<br /><br />");
  1617. +               totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
  1618. +               break;
  1619. +          
  1620. +           case 8:
  1621. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1622. +               response = VoteUtil.between("\"monthly_votes\":", response, "}}");
  1623. +               totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
  1624. +               break;
  1625. +          
  1626. +           case 9:
  1627. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1628. +               response = VoteUtil.between("\"totalVotes\":\"", response, "\",\"serverRank\"");
  1629. +               totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
  1630. +               break;
  1631. +          
  1632. +           case 10:
  1633. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1634. +               totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
  1635. +               break;
  1636. +       }
  1637. +      
  1638. +       return totalVotes;
  1639. +   }
  1640. +  
  1641. +   public static String getIndividualUrl(int ordinal, String ip, String AccountName)
  1642. +   {
  1643. +       String url = "";
  1644. +       ip = (Config.TEST_IP.equalsIgnoreCase("off") || Config.TEST_IP.equalsIgnoreCase("")) ? ip : Config.TEST_IP;
  1645. +       switch (ordinal)
  1646. +       {
  1647. +           case 0:
  1648. +               // l2.topgameserver.net
  1649. +               url = String.format("%sAPI_KEY=%s/getData/%s", Config.VOTE_LINK_TGS, Config.TGS_API_KEY, ip);
  1650. +               break;
  1651. +          
  1652. +           case 1:
  1653. +               // itopz.com
  1654. +               url = String.format("%s%s/%s/%s", Config.VOTE_LINK_ITOPZ, Config.ITOPZ_API_KEY, Config.ITOPZ_SRV_ID, ip);
  1655. +               break;
  1656. +          
  1657. +           case 2:
  1658. +               // l2top.co
  1659. +               url = String.format("%sVoteCheck.php?id=%s&ip=%s", Config.VOTE_LINK_TOP_CO, Config.TOP_CO_SRV_ID, ip);
  1660. +               break;
  1661. +          
  1662. +           case 3:
  1663. +               // l2votes.com
  1664. +               url = String.format("%sapi.php?apiKey=%s&ip=%s", Config.VOTE_LINK_VTS, Config.VTS_API_KEY, ip);
  1665. +               break;
  1666. +          
  1667. +           case 4:
  1668. +               // hopzone.net
  1669. +               url = String.format("%svote?token=%s&ip_address=%s", Config.VOTE_LINK_HZ, Config.HZ_API_KEY, ip);
  1670. +               break;
  1671. +          
  1672. +           case 5:
  1673. +               // l2network.eu
  1674. +               url = String.format("https://l2network.eu/index.php?a=in&u=%s&ipc=%s", Config.VOTE_NETWORK_USER_NAME, ip);
  1675. +               break;
  1676. +          
  1677. +           case 6:
  1678. +               // l2topservers.com
  1679. +               url = String.format("%stoken=%s&ip=%s", Config.VOTE_LINK_TSS, Config.TSS_API_TOKEN, ip);
  1680. +               break;
  1681. +          
  1682. +           case 7:
  1683. +               // top.l2jbrasil.com
  1684. +               url = String.format("%susername=%s&ip=%s&type=json", Config.BRASIL_VOTE_LINK, Config.BRASIL_USER_NAME, ip);
  1685. +               break;
  1686. +          
  1687. +           case 8:
  1688. +               // l2jtop
  1689. +               url = String.format("%s%s/ip/%s", Config.VOTE_LINK_MMOTOP, Config.MMOTOP_API_KEY, ip);
  1690. +               break;
  1691. +          
  1692. +           case 9:
  1693. +               // topzone.com
  1694. +               url = String.format("%svote?token=%s&ip=%s", Config.VOTE_LINK_TZ, Config.TZ_API_KEY, ip);
  1695. +               break;
  1696. +          
  1697. +           case 10:
  1698. +               // l2servers.com
  1699. +               url = String.format("%scheckip.php?hash=%s&server_id=%s&ip=%s", Config.VOTE_LINK_SERVERS, Config.SERVERS_HASH_CODE, Config.SERVERS_SRV_ID, ip);
  1700. +               break;
  1701. +       }
  1702. +      
  1703. +       return url;
  1704. +   }
  1705. +  
  1706. +   public String getGlobalUrl(int ordinal)
  1707. +   {
  1708. +       String url = "";
  1709. +      
  1710. +       switch (ordinal)
  1711. +       {
  1712. +           case 0:
  1713. +               // l2.topgameserver.net
  1714. +               url = String.format("%sAPI_KEY=%s/getData", Config.VOTE_LINK_TGS, Config.TGS_API_KEY);
  1715. +               break;
  1716. +          
  1717. +           case 1:
  1718. +               // itopz.com
  1719. +               url = String.format("%s%s/%s", Config.VOTE_LINK_ITOPZ, Config.ITOPZ_API_KEY, Config.ITOPZ_SRV_ID);
  1720. +               break;
  1721. +          
  1722. +           case 2:
  1723. +               // l2top.co
  1724. +               url = String.format("%sVoteCheck_Total.php?id=%s", Config.VOTE_LINK_TOP_CO, Config.TOP_CO_SRV_ID);
  1725. +               break;
  1726. +          
  1727. +           case 3:
  1728. +               // l2votes.com
  1729. +               url = String.format("%sserverPage.php?sid=%s", Config.VOTE_LINK_VTS, Config.VTS_SID);
  1730. +               break;
  1731. +          
  1732. +           case 4:
  1733. +               // hopzone.net
  1734. +               url = String.format("%svotes?token=%s", Config.VOTE_LINK_HZ, Config.HZ_API_KEY);
  1735. +               break;
  1736. +          
  1737. +           case 5:
  1738. +               // l2network.eu
  1739. +               url = String.format("apiKey=%s&type=%s&player=", Config.VOTE_NETWORK_API_KEY, 1);
  1740. +               break;
  1741. +          
  1742. +           case 6:
  1743. +               // l2topservers
  1744. +               url = String.format("https://l2topservers.com/l2top/%s/%s", Config.TS_SRV_ID, Config.TS_DOMAIN_NAME);
  1745. +               break;
  1746. +          
  1747. +           case 7:
  1748. +               // top.l2jbrasil.com
  1749. +               url = String.format("https://top.l2jbrasil.com/index.php?a=stats&u=%s", Config.BRASIL_USER_NAME);
  1750. +               break;
  1751. +          
  1752. +           case 8:
  1753. +               // l2jtop.com
  1754. +               url = String.format("%s%s/info/", Config.VOTE_LINK_MMOTOP, Config.MMOTOP_API_KEY);
  1755. +               break;
  1756. +          
  1757. +           case 9:
  1758. +               // l2topzone.com
  1759. +               url = String.format("%sserver_%s/getServerData", Config.VOTE_LINK_TZ, Config.TZ_API_KEY);
  1760. +               break;
  1761. +          
  1762. +           case 10:
  1763. +               // l2servers.com
  1764. +               url = String.format("%syearlyvotes.php?server_id=%s", Config.VOTE_LINK_SERVERS, Config.SERVERS_SRV_ID);
  1765. +               break;
  1766. +       }
  1767. +      
  1768. +       return url;
  1769. +   }
  1770. +}
  1771. \ No newline at end of file
  1772. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Handler/voteManager.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Handler/voteManager.java
  1773. new file mode 100644
  1774. index 0000000..651ecde
  1775. --- /dev/null
  1776. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Handler/voteManager.java
  1777. @@ -0,0 +1,395 @@
  1778. +package org.l2jmobius.gameserver.votesystem.Handler;
  1779. +
  1780. +import java.util.HashSet;
  1781. +import java.util.Map;
  1782. +import java.util.concurrent.ConcurrentHashMap;
  1783. +import java.util.concurrent.ScheduledFuture;
  1784. +
  1785. +import org.l2jmobius.Config;
  1786. +import org.l2jmobius.commons.concurrent.ThreadPool;
  1787. +import org.l2jmobius.gameserver.model.World;
  1788. +import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
  1789. +import org.l2jmobius.gameserver.network.GameClient;
  1790. +import org.l2jmobius.gameserver.network.SystemMessageId;
  1791. +import org.l2jmobius.gameserver.network.serverpackets.ItemList;
  1792. +import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
  1793. +import org.l2jmobius.gameserver.util.Broadcast;
  1794. +import org.l2jmobius.gameserver.votesystem.DB.globalVoteDB;
  1795. +import org.l2jmobius.gameserver.votesystem.DB.individualVoteDB;
  1796. +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
  1797. +import org.l2jmobius.gameserver.votesystem.Model.Reward;
  1798. +import org.l2jmobius.gameserver.votesystem.Model.globalVote;
  1799. +import org.l2jmobius.gameserver.votesystem.Model.individualVote;
  1800. +import org.l2jmobius.gameserver.votesystem.Model.individualVoteResponse;
  1801. +import org.l2jmobius.gameserver.votesystem.VoteUtil.ReadJson;
  1802. +import org.l2jmobius.gameserver.votesystem.VoteUtil.VoteUtil;
  1803. +
  1804. +/**
  1805. + * @author l2.topgameserver.net
  1806. + */
  1807. +public final class voteManager extends voteHandler
  1808. +{
  1809. +   private ScheduledFuture<?> _saveGlobalVotes;
  1810. +   private ScheduledFuture<?> _updateIndividualVotes;
  1811. +   private ScheduledFuture<?> _autoGlobalVotesReward;
  1812. +  
  1813. +   private HashSet<individualVote> _votes;
  1814. +   private Map<String, individualVote[]> _foundVoters;
  1815. +   private globalVote[] _globalVotes = new globalVote[voteSite.values().length];
  1816. +  
  1817. +   public voteManager()
  1818. +   {
  1819. +       _foundVoters = new ConcurrentHashMap<>();
  1820. +       loadVotes();
  1821. +       loadGlobalVotes();
  1822. +       checkAllResponseGlobalVotes();
  1823. +       stopAutoTasks();
  1824. +      
  1825. +       if (Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTE_SYSTEM)
  1826. +       {
  1827. +           _updateIndividualVotes = ThreadPool.scheduleAtFixedRate(new AutoUpdateIndividualVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES);
  1828. +       }
  1829. +       if (Config.ENABLE_GLOBAL_VOTE && Config.ENABLE_VOTE_SYSTEM)
  1830. +       {
  1831. +           _autoGlobalVotesReward = ThreadPool.scheduleAtFixedRate(new AutoGlobalVoteRewardTask(), 10000, Config.NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD);
  1832. +           _saveGlobalVotes = ThreadPool.scheduleAtFixedRate(new AutoSaveGlobalVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE);
  1833. +       }
  1834. +   }
  1835. +  
  1836. +   private void stopAutoTasks()
  1837. +   {
  1838. +       if (_saveGlobalVotes != null)
  1839. +       {
  1840. +           _saveGlobalVotes.cancel(true);
  1841. +           _saveGlobalVotes = null;
  1842. +       }
  1843. +       if (_updateIndividualVotes != null)
  1844. +       {
  1845. +           _updateIndividualVotes.cancel(true);
  1846. +           _updateIndividualVotes = null;
  1847. +       }
  1848. +       if (_autoGlobalVotesReward != null)
  1849. +       {
  1850. +           _autoGlobalVotesReward.cancel(true);
  1851. +           _autoGlobalVotesReward = null;
  1852. +       }
  1853. +   }
  1854. +  
  1855. +   public void getReward(PlayerInstance player, int ordinalSite)
  1856. +   {
  1857. +       String ip = existIp(player);
  1858. +       if (ip == null)
  1859. +       {
  1860. +           return;
  1861. +       }
  1862. +       individualVoteResponse ivr = getIndividualVoteResponse(ordinalSite, ip, player.getAccountName());
  1863. +       if (ivr == null)
  1864. +       {
  1865. +           player.sendMessage("We were unable to verify your vote with: " + ReadJson.getInstance().getRecordSite(ordinalSite).getSiteName() + ", please try again");
  1866. +           return;
  1867. +       }
  1868. +
  1869. +       if (getTimeRemaining(new individualVote(ip, ivr.getVoteSiteTime(), ordinalSite, false)) < 0)
  1870. +       {
  1871. +           player.sendMessage("We were unable to verify your vote with: " + ReadJson.getInstance().getRecordSite(ordinalSite).getSiteName() + ", please try again");
  1872. +           return;
  1873. +       }
  1874. +       if (!ivr.getIsVoted())
  1875. +       {
  1876. +           player.sendMessage(String.format("You haven't vote on %s yet!", ReadJson.getInstance().getRecordSite(ordinalSite).getSiteName()));
  1877. +           return;
  1878. +       }
  1879. +       if (!checkIndividualAvailableVote(player, ordinalSite))
  1880. +       {
  1881. +           player.sendMessage(String.format("You can get the reward again on %s at %s", ReadJson.getInstance().getRecordSite(ordinalSite).getSiteName(), getTimeRemainingWithSampleFormat(player, ordinalSite)));
  1882. +           return;
  1883. +       }
  1884. +       individualVote iv = new individualVote(ip, ivr.getVoteSiteTime(), ordinalSite, false);
  1885. +      
  1886. +       individualVote[] aiv;
  1887. +       if (!_foundVoters.containsKey(ip))
  1888. +       {
  1889. +           aiv = new individualVote[voteSite.values().length];
  1890. +           iv.setAlreadyRewarded(true);
  1891. +           aiv[ordinalSite] = iv;
  1892. +           _foundVoters.put(ip, aiv);
  1893. +       }
  1894. +       else
  1895. +       {
  1896. +           aiv = _foundVoters.get(ip);
  1897. +           iv.setAlreadyRewarded(true);
  1898. +           aiv[ordinalSite] = iv;
  1899. +           _foundVoters.replace(ip, aiv);
  1900. +          
  1901. +       }
  1902. +       for (Reward reward : ReadJson.getInstance().getRewards(ordinalSite))
  1903. +       {
  1904. +           player.getInventory().addItem("VoteSystem", reward.getItemId(), reward.getItemCount(), player, null);
  1905. +           player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_EARNED_S2_S1_S).addItemName(reward.getItemId()).addNumber(reward.getItemCount()));
  1906. +       }
  1907. +       player.sendMessage(String.format("%s: Thank you for voting for our server, your reward has been delivered.", ReadJson.getInstance().getRecordSite(ordinalSite).getSiteName()));
  1908. +       player.sendPacket(new ItemList(player, true));
  1909. +   }
  1910. +  
  1911. +   public boolean checkIndividualAvailableVote(PlayerInstance player, int ordinalSite)
  1912. +   {
  1913. +       String ip = existIp(player);
  1914. +       if (_foundVoters.containsKey(ip))
  1915. +       {
  1916. +           individualVote[] ivs = _foundVoters.get(ip);
  1917. +           if (ivs[ordinalSite] == null)
  1918. +           {
  1919. +               return true;
  1920. +           }
  1921. +           if (ivs[ordinalSite] != null)
  1922. +           {
  1923. +               individualVote iv = ivs[ordinalSite];
  1924. +               if (getTimeRemaining(iv) < 0)
  1925. +               {
  1926. +                   return true;
  1927. +               }
  1928. +           }
  1929. +       }
  1930. +       else
  1931. +       {
  1932. +           return true;
  1933. +       }
  1934. +      
  1935. +       return false;
  1936. +   }
  1937. +  
  1938. +   public long getTimeRemaining(individualVote iv)
  1939. +   {
  1940. +       long timeRemaining = 0L;
  1941. +       long diff = VoteUtil.getTimeZoneVotingSite(iv.getVoteSite());
  1942. +       long nexttime = ReadJson.getInstance().getRecordSite(iv.getVoteSite()).getNextVoteTime();
  1943. +       timeRemaining = (iv.getVotingTimeSite() + nexttime) - (System.currentTimeMillis() - diff);
  1944. +       return timeRemaining;
  1945. +   }
  1946. +  
  1947. +   public String getTimeRemainingWithSampleFormat(PlayerInstance player, int ordinalSite)
  1948. +   {
  1949. +       String ip = existIp(player);
  1950. +      
  1951. +       String timeRemainingWithSampleFormat = "";
  1952. +       if (_foundVoters.containsKey(ip))
  1953. +       {
  1954. +           individualVote[] ivs = _foundVoters.get(ip);
  1955. +           if (ivs[ordinalSite] != null)
  1956. +           {
  1957. +               individualVote iv = ivs[ordinalSite];
  1958. +               long timeRemaining = getTimeRemaining(iv);
  1959. +               if (timeRemaining > 0)
  1960. +               {
  1961. +                   timeRemainingWithSampleFormat = CalculateTimeRemainingWithSampleDateFormat(timeRemaining);
  1962. +                   return timeRemainingWithSampleFormat;
  1963. +               }
  1964. +           }
  1965. +       }
  1966. +       return timeRemainingWithSampleFormat;
  1967. +   }
  1968. +  
  1969. +   public String CalculateTimeRemainingWithSampleDateFormat(long timeRemaining)
  1970. +   {
  1971. +       long t = timeRemaining / 1000;
  1972. +       int hours = Math.round(((t / 3600) % 24));
  1973. +       int minutes = Math.round((t / 60) % 60);
  1974. +       int seconds = Math.round(t % 60);
  1975. +       return String.format("%sH:%sm:%ss", hours, minutes, seconds);
  1976. +   }
  1977. +  
  1978. +   public String existIp(PlayerInstance p)
  1979. +   {
  1980. +      
  1981. +       GameClient client = p.getClient();
  1982. +       if ((client.getConnection().getInetAddress() != null) && (client.getPlayer() != null) && !client.isDetached())
  1983. +       {
  1984. +           try
  1985. +           {
  1986. +               return client.getIpAddress();
  1987. +           }
  1988. +           catch (Exception e)
  1989. +           {
  1990. +               e.printStackTrace();
  1991. +           }
  1992. +       }
  1993. +       return null;
  1994. +      
  1995. +   }
  1996. +  
  1997. +   public final void loadVotes()
  1998. +   {
  1999. +       _foundVoters = individualVoteDB.getInstance().getVotesDB();
  2000. +   }
  2001. +  
  2002. +   protected void loadGlobalVotes()
  2003. +   {
  2004. +       _globalVotes = globalVoteDB.getInstance().getGlobalVotes();
  2005. +   }
  2006. +  
  2007. +   public void saveVotes()
  2008. +   {
  2009. +       individualVoteDB.getInstance().SaveVotes(_foundVoters);
  2010. +   }
  2011. +  
  2012. +   protected void AutoGlobalVoteReward()
  2013. +   {
  2014. +       HashSet<String> ipList = new HashSet<>();
  2015. +       for (voteSite vs : voteSite.values())
  2016. +       {
  2017. +           new Thread(() ->
  2018. +           {
  2019. +               checkNewUpdate(vs.ordinal());
  2020. +               if (_globalVotes[vs.ordinal()].getCurrentVotes() >= (_globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)))
  2021. +               {
  2022. +                   _globalVotes[vs.ordinal()].setVotesLastReward(_globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD));
  2023. +                   for (PlayerInstance player : World.getInstance().getAllPlayers())
  2024. +                   {
  2025. +                       String ip = existIp(player);
  2026. +                       if (ip == null)
  2027. +                       {
  2028. +                           continue;
  2029. +                       }
  2030. +                       if (ipList.contains(ip))
  2031. +                       {
  2032. +                           continue;
  2033. +                       }
  2034. +                       for (Reward reward : ReadJson.getInstance().getRewards(11))
  2035. +                       {
  2036. +                           player.getInventory().addItem("VoteSystem: ", reward.getItemId(), reward.getItemCount(), player, null);
  2037. +                           player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_EARNED_S2_S1_S).addItemName(reward.getItemId()).addNumber(reward.getItemCount()));
  2038. +                       }
  2039. +                       ipList.add(ip);
  2040. +                       player.sendPacket(new ItemList(player, true));
  2041. +                   }
  2042. +                   Broadcast.toAllOnlinePlayers(VoteUtil.Sites[vs.ordinal()] + ": All players has been rewarded, please check your inventory", true);
  2043. +               }
  2044. +               else
  2045. +               {
  2046. +                   String encourage = "";
  2047. +                   int nextReward = _globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD);
  2048. +                   encourage = String.format("Vote for %s current Votes: %s, next quantity of votes to reward : %s, need votes to next reward: %s", VoteUtil.Sites[vs.ordinal()], _globalVotes[vs.ordinal()].getCurrentVotes(), nextReward, nextReward - _globalVotes[vs.ordinal()].getCurrentVotes());
  2049. +                   Broadcast.toAllOnlinePlayers(encourage, true);
  2050. +               }
  2051. +           }).start();
  2052. +          
  2053. +       }
  2054. +   }
  2055. +  
  2056. +   protected void AutoSaveGlobalVotes()
  2057. +   {
  2058. +       globalVoteDB.getInstance().saveGlobalVotes(_globalVotes);
  2059. +   }
  2060. +  
  2061. +   protected synchronized void AutoUpdateIndividualVotes()
  2062. +   {
  2063. +       AutoCleanInnecesaryIndividualVotes();
  2064. +       individualVoteDB.getInstance().SaveVotes(_foundVoters);
  2065. +   }
  2066. +  
  2067. +   protected synchronized void AutoCleanInnecesaryIndividualVotes()
  2068. +   {
  2069. +       HashSet<individualVote> removeVotes = new HashSet<>();
  2070. +       for (Map.Entry<String, individualVote[]> ivs : _foundVoters.entrySet())
  2071. +       {
  2072. +           for (individualVote individualvote : ivs.getValue())
  2073. +           {
  2074. +               if (individualvote == null)
  2075. +               {
  2076. +                   continue;
  2077. +               }
  2078. +               if (getTimeRemaining(individualvote) < 0)
  2079. +               {
  2080. +                   removeVotes.add(individualvote);
  2081. +                   if (_foundVoters.containsKey(individualvote.getVoterIp()))
  2082. +                   {
  2083. +                       if (_foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] != null)
  2084. +                       {
  2085. +                           _foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] = null;
  2086. +                       }
  2087. +                   }
  2088. +               }
  2089. +           }
  2090. +       }
  2091. +       individualVoteDB.getInstance().DeleteVotes(removeVotes);
  2092. +   }
  2093. +  
  2094. +   public void checkAllResponseGlobalVotes()
  2095. +   {
  2096. +       for (voteSite vs : voteSite.values())
  2097. +       {
  2098. +           new Thread(() ->
  2099. +           {
  2100. +               checkNewUpdate(vs.ordinal());
  2101. +           });
  2102. +       }
  2103. +   }
  2104. +  
  2105. +   public void checkNewUpdate(int ordinalSite)
  2106. +   {
  2107. +       int globalVotesResponse = getGlobalVotesResponse(ordinalSite);
  2108. +       if (globalVotesResponse == -1)
  2109. +       {
  2110. +           return;
  2111. +       }
  2112. +       _globalVotes[ordinalSite].setCurrentVotes(globalVotesResponse);
  2113. +       int last = globalVotesResponse - (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD);
  2114. +       if (last < 0)
  2115. +       {
  2116. +           _globalVotes[ordinalSite].setVotesLastReward(0);
  2117. +           return;
  2118. +       }
  2119. +       if ((_globalVotes[ordinalSite].getVotesLastReward() + (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)) < globalVotesResponse)
  2120. +       {
  2121. +           _globalVotes[ordinalSite].setVotesLastReward(globalVotesResponse);
  2122. +           return;
  2123. +       }
  2124. +   }
  2125. +  
  2126. +   public void Shutdown()
  2127. +   {
  2128. +       AutoSaveGlobalVotes();
  2129. +       AutoCleanInnecesaryIndividualVotes();
  2130. +       AutoUpdateIndividualVotes();
  2131. +   }
  2132. +  
  2133. +   protected class AutoGlobalVoteRewardTask implements Runnable
  2134. +   {
  2135. +      
  2136. +       @Override
  2137. +       public void run()
  2138. +       {
  2139. +           AutoGlobalVoteReward();
  2140. +          
  2141. +       }
  2142. +      
  2143. +   }
  2144. +  
  2145. +   protected class AutoSaveGlobalVotesTask implements Runnable
  2146. +   {
  2147. +      
  2148. +       @Override
  2149. +       public void run()
  2150. +       {
  2151. +           AutoSaveGlobalVotes();
  2152. +          
  2153. +       }
  2154. +      
  2155. +   }
  2156. +  
  2157. +   protected class AutoUpdateIndividualVotesTask implements Runnable
  2158. +   {
  2159. +      
  2160. +       @Override
  2161. +       public void run()
  2162. +       {
  2163. +           AutoUpdateIndividualVotes();
  2164. +          
  2165. +       }
  2166. +      
  2167. +   }
  2168. +  
  2169. +   public static voteManager getInatance()
  2170. +   {
  2171. +       return SingleHolder.INSTANCE;
  2172. +   }
  2173. +  
  2174. +   private static class SingleHolder
  2175. +   {
  2176. +       protected static final voteManager INSTANCE = new voteManager();
  2177. +   }
  2178. +}
  2179. \ No newline at end of file
  2180. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/Reward.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/Reward.java
  2181. new file mode 100644
  2182. index 0000000..d0cda74
  2183. --- /dev/null
  2184. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/Reward.java
  2185. @@ -0,0 +1,36 @@
  2186. +package org.l2jmobius.gameserver.votesystem.Model;
  2187. +
  2188. +/**
  2189. + * @author l2.topgameserver.net
  2190. + */
  2191. +public class Reward
  2192. +{
  2193. +   private int _itemId;
  2194. +   private int _itemCount;
  2195. +  
  2196. +   public Reward(int itemId, int itemCount)
  2197. +   {
  2198. +       _itemId = itemId;
  2199. +       _itemCount = itemCount;
  2200. +   }
  2201. +  
  2202. +   public void setItemId(int itemId)
  2203. +   {
  2204. +       _itemId = itemId;
  2205. +   }
  2206. +  
  2207. +   public void setItemCount(int itemCount)
  2208. +   {
  2209. +       _itemCount = itemCount;
  2210. +   }
  2211. +  
  2212. +   public int getItemId()
  2213. +   {
  2214. +       return _itemId;
  2215. +   }
  2216. +  
  2217. +   public int getItemCount()
  2218. +   {
  2219. +       return _itemCount;
  2220. +   }
  2221. +}
  2222. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/VoteSite.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/VoteSite.java
  2223. new file mode 100644
  2224. index 0000000..b17237b
  2225. --- /dev/null
  2226. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/VoteSite.java
  2227. @@ -0,0 +1,76 @@
  2228. +package org.l2jmobius.gameserver.votesystem.Model;
  2229. +
  2230. +import java.util.ArrayList;
  2231. +import java.util.List;
  2232. +import java.util.concurrent.TimeUnit;
  2233. +
  2234. +/**
  2235. + * @author l2.topgameserver.net
  2236. + */
  2237. +public class VoteSite
  2238. +{
  2239. +   private int _siteOrdinal;
  2240. +   private String _siteName;
  2241. +   private String _timeZone;
  2242. +   private long _nextVoteTime;
  2243. +   private final List<Reward> _rewards = new ArrayList<>();
  2244. +  
  2245. +   public VoteSite()
  2246. +   {
  2247. +      
  2248. +   }
  2249. +  
  2250. +   public void setSiteOrdinal(int siteOrdinal)
  2251. +   {
  2252. +       _siteOrdinal = siteOrdinal;
  2253. +   }
  2254. +  
  2255. +   public void setTimeZone(String timeZone)
  2256. +   {
  2257. +       _timeZone = timeZone;
  2258. +   }
  2259. +  
  2260. +   public void setNextVoteTime(int nextVoteTime)
  2261. +   {
  2262. +       _nextVoteTime = nextVoteTime;
  2263. +   }
  2264. +  
  2265. +   public void setSiteName(String siteName)
  2266. +   {
  2267. +       _siteName = siteName;
  2268. +   }
  2269. +  
  2270. +   public void setRewardList(List<Reward> rewards)
  2271. +   {
  2272. +       for (Reward r : rewards)
  2273. +       {
  2274. +           _rewards.add(r);
  2275. +       }
  2276. +   }
  2277. +  
  2278. +   public String getTimeZone()
  2279. +   {
  2280. +       return _timeZone;
  2281. +   }
  2282. +  
  2283. +   public long getNextVoteTime()
  2284. +   {
  2285. +       return TimeUnit.HOURS.toMillis(_nextVoteTime);
  2286. +   }
  2287. +  
  2288. +   public int getSiteOrdinal()
  2289. +   {
  2290. +       return _siteOrdinal;
  2291. +   }
  2292. +  
  2293. +   public String getSiteName()
  2294. +   {
  2295. +       return _siteName;
  2296. +   }
  2297. +  
  2298. +   public List<Reward> getRewardList()
  2299. +   {
  2300. +       return _rewards;
  2301. +   }
  2302. +  
  2303. +}
  2304. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/globalVote.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/globalVote.java
  2305. new file mode 100644
  2306. index 0000000..6ed7b6b
  2307. --- /dev/null
  2308. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/globalVote.java
  2309. @@ -0,0 +1,53 @@
  2310. +package org.l2jmobius.gameserver.votesystem.Model;
  2311. +
  2312. +/**
  2313. + * @author l2.topgameserver.net
  2314. + */
  2315. +public class globalVote
  2316. +{
  2317. +   private int _voteSite;
  2318. +   private int _votesLastReward;
  2319. +   private int _currentVotes;
  2320. +  
  2321. +   public globalVote()
  2322. +   {
  2323. +      
  2324. +   }
  2325. +  
  2326. +   public globalVote(int voteSite, int votesLastReward)
  2327. +   {
  2328. +       _voteSite = voteSite;
  2329. +       _votesLastReward = votesLastReward;
  2330. +   }
  2331. +  
  2332. +   public void setVoteSite(int voteSite)
  2333. +   {
  2334. +       _voteSite = voteSite;
  2335. +   }
  2336. +  
  2337. +   public void setVotesLastReward(int votesLastReward)
  2338. +   {
  2339. +       _votesLastReward = votesLastReward;
  2340. +   }
  2341. +  
  2342. +   public void setCurrentVotes(int currentVotes)
  2343. +   {
  2344. +       _currentVotes = currentVotes;
  2345. +   }
  2346. +  
  2347. +   public int getVoyeSite()
  2348. +   {
  2349. +       return _voteSite;
  2350. +   }
  2351. +  
  2352. +   public int getVotesLastReward()
  2353. +   {
  2354. +       return _votesLastReward;
  2355. +   }
  2356. +  
  2357. +   public int getCurrentVotes()
  2358. +   {
  2359. +       return _currentVotes;
  2360. +   }
  2361. +  
  2362. +}
  2363. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/individualVote.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/individualVote.java
  2364. new file mode 100644
  2365. index 0000000..e0d227e
  2366. --- /dev/null
  2367. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/individualVote.java
  2368. @@ -0,0 +1,66 @@
  2369. +package org.l2jmobius.gameserver.votesystem.Model;
  2370. +
  2371. +/**
  2372. + * @author l2.topgameserver.net
  2373. + */
  2374. +public class individualVote
  2375. +{
  2376. +   private String _voterIp;
  2377. +   private long _votingTimeSite;
  2378. +   private int _voteSite;
  2379. +   private boolean _alreadyRewarded;
  2380. +  
  2381. +   public individualVote(String voterIp, long votingTimeSite, int voteSite, boolean alreadyRewarded)
  2382. +   {
  2383. +       _voterIp = voterIp;
  2384. +       _votingTimeSite = votingTimeSite;
  2385. +       _voteSite = voteSite;
  2386. +       _alreadyRewarded = alreadyRewarded;
  2387. +   }
  2388. +  
  2389. +   public individualVote()
  2390. +   {
  2391. +      
  2392. +   }
  2393. +  
  2394. +   public void setVoterIp(String voterIp)
  2395. +   {
  2396. +       _voterIp = voterIp;
  2397. +   }
  2398. +  
  2399. +   public void setVotingTimeSite(long votingTimeSite)
  2400. +   {
  2401. +       _votingTimeSite = votingTimeSite;
  2402. +   }
  2403. +  
  2404. +   public void setVoteSite(int voteSite)
  2405. +   {
  2406. +       _voteSite = voteSite;
  2407. +   }
  2408. +  
  2409. +   public void setAlreadyRewarded(boolean alreadyRewarded)
  2410. +   {
  2411. +       _alreadyRewarded = alreadyRewarded;
  2412. +   }
  2413. +  
  2414. +   public String getVoterIp()
  2415. +   {
  2416. +       return _voterIp;
  2417. +   }
  2418. +  
  2419. +   public long getVotingTimeSite()
  2420. +   {
  2421. +       return _votingTimeSite;
  2422. +   }
  2423. +  
  2424. +   public int getVoteSite()
  2425. +   {
  2426. +       return _voteSite;
  2427. +   }
  2428. +  
  2429. +   public boolean getAlreadyRewarded()
  2430. +   {
  2431. +       return _alreadyRewarded;
  2432. +   }
  2433. +  
  2434. +}
  2435. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/individualVoteResponse.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/individualVoteResponse.java
  2436. new file mode 100644
  2437. index 0000000..6707e1b
  2438. --- /dev/null
  2439. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/individualVoteResponse.java
  2440. @@ -0,0 +1,46 @@
  2441. +package org.l2jmobius.gameserver.votesystem.Model;
  2442. +
  2443. +/**
  2444. + * @author l2.topgameserver.net
  2445. + */
  2446. +public class individualVoteResponse
  2447. +{
  2448. +   private boolean _isVoted;
  2449. +   private long _diffTime;
  2450. +   private long _voteSiteTime;
  2451. +  
  2452. +   public individualVoteResponse()
  2453. +   {
  2454. +      
  2455. +   }
  2456. +  
  2457. +   public void setIsVoted(boolean isVoted)
  2458. +   {
  2459. +       _isVoted = isVoted;
  2460. +   }
  2461. +  
  2462. +   public void setDiffTime(long diffTime)
  2463. +   {
  2464. +       _diffTime = diffTime;
  2465. +   }
  2466. +  
  2467. +   public void setVoteSiteTime(long voteSiteTime)
  2468. +   {
  2469. +       _voteSiteTime = voteSiteTime;
  2470. +   }
  2471. +  
  2472. +   public boolean getIsVoted()
  2473. +   {
  2474. +       return _isVoted;
  2475. +   }
  2476. +  
  2477. +   public long getDiffTime()
  2478. +   {
  2479. +       return _diffTime;
  2480. +   }
  2481. +  
  2482. +   public long getVoteSiteTime()
  2483. +   {
  2484. +       return _voteSiteTime;
  2485. +   }
  2486. +}
  2487. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/VoteUtil/ReadJson.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/VoteUtil/ReadJson.java
  2488. new file mode 100644
  2489. index 0000000..0196c2a
  2490. --- /dev/null
  2491. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/VoteUtil/ReadJson.java
  2492. @@ -0,0 +1,126 @@
  2493. +/*
  2494. + * This file is part of the L2J Mobius project.
  2495. + *
  2496. + * This program is free software: you can redistribute it and/or modify
  2497. + * it under the terms of the GNU General Public License as published by
  2498. + * the Free Software Foundation, either version 3 of the License, or
  2499. + * (at your option) any later version.
  2500. + *
  2501. + * This program is distributed in the hope that it will be useful,
  2502. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2503. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2504. + * General Public License for more details.
  2505. + *
  2506. + * You should have received a copy of the GNU General Public License
  2507. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  2508. + */
  2509. +package org.l2jmobius.gameserver.votesystem.VoteUtil;
  2510. +
  2511. +import java.io.FileNotFoundException;
  2512. +import java.io.FileReader;
  2513. +import java.io.IOException;
  2514. +import java.util.Collection;
  2515. +import java.util.HashMap;
  2516. +import java.util.Map;
  2517. +import java.util.concurrent.TimeUnit;
  2518. +import java.util.logging.Logger;
  2519. +
  2520. +import org.json.simple.JSONArray;
  2521. +import org.json.simple.JSONObject;
  2522. +import org.json.simple.parser.JSONParser;
  2523. +
  2524. +import org.l2jmobius.Config;
  2525. +import org.l2jmobius.gameserver.votesystem.Model.Reward;
  2526. +import org.l2jmobius.gameserver.votesystem.Model.VoteSite;
  2527. +
  2528. +public class ReadJson
  2529. +{
  2530. +   Logger LOGGER = Logger.getLogger(ReadJson.class.getName());
  2531. +   private final static Map<Integer, VoteSite> _voteSites = new HashMap<>();
  2532. +  
  2533. +   public ReadJson()
  2534. +   {
  2535. +       load();
  2536. +   }
  2537. +  
  2538. +   @SuppressWarnings("unchecked")
  2539. +   public void load()
  2540. +   {
  2541. +       JSONParser jsonParser = new JSONParser();
  2542. +      
  2543. +       try (FileReader reader = new FileReader(parseDatapackFile("/data/votesystem.json")))
  2544. +       {
  2545. +           Object obj = jsonParser.parse(reader);
  2546. +          
  2547. +           JSONArray rewardSiteList = (JSONArray) obj;
  2548. +           rewardSiteList.forEach(emp -> parseRewardSites((JSONObject) emp));
  2549. +           LOGGER.info("Loaded " + _voteSites.size() + " reward sites");
  2550. +          
  2551. +       }
  2552. +       catch (FileNotFoundException e)
  2553. +       {
  2554. +           e.printStackTrace();
  2555. +       }
  2556. +       catch (IOException e)
  2557. +       {
  2558. +           e.printStackTrace();
  2559. +       }
  2560. +       catch (Exception e)
  2561. +       {
  2562. +           e.printStackTrace();
  2563. +       }
  2564. +   }
  2565. +  
  2566. +   private void parseRewardSites(JSONObject site)
  2567. +   {
  2568. +       VoteSite votesite = new VoteSite();
  2569. +       JSONObject rewardsite = (JSONObject) site.get("votesite");
  2570. +      
  2571. +       votesite.setSiteOrdinal(Integer.parseInt((String) rewardsite.get("ordinal")));
  2572. +       votesite.setSiteName((String) rewardsite.get("name"));
  2573. +       votesite.setNextVoteTime(Integer.parseInt((String) rewardsite.get("nextvotetime")));
  2574. +       votesite.setTimeZone((String) rewardsite.get("timezone"));
  2575. +      
  2576. +       JSONArray rewardList = (JSONArray) rewardsite.get("rewards");
  2577. +       for (int i = 0; i < rewardList.size(); i++)
  2578. +       {
  2579. +           JSONObject object = (JSONObject) rewardList.get(i);
  2580. +           votesite.getRewardList().add(new Reward(Integer.parseInt((String) object.get("item_id")), Integer.parseInt((String) object.get("item_count"))));
  2581. +          
  2582. +       }
  2583. +      
  2584. +       _voteSites.put(votesite.getSiteOrdinal(), votesite);
  2585. +   }
  2586. +  
  2587. +   private String parseDatapackFile(String path)
  2588. +   {
  2589. +       String p = Config.DATAPACK_ROOT + path;
  2590. +       return p;
  2591. +   }
  2592. +  
  2593. +   public VoteSite getRecordSite(int ordinal)
  2594. +   {
  2595. +       return _voteSites.get(ordinal);
  2596. +   }
  2597. +  
  2598. +   public long getNextVoteTime(int ordinal)
  2599. +   {
  2600. +       return TimeUnit.HOURS.toMillis(_voteSites.get(ordinal).getNextVoteTime());
  2601. +   }
  2602. +  
  2603. +   public Collection<Reward> getRewards(int ordinal)
  2604. +   {
  2605. +       return _voteSites.get(ordinal).getRewardList();
  2606. +   }
  2607. +  
  2608. +   public static final ReadJson getInstance()
  2609. +   {
  2610. +       return SingletonHolder.INSTANCE;
  2611. +   }
  2612. +  
  2613. +   private static final class SingletonHolder
  2614. +   {
  2615. +       protected static final ReadJson INSTANCE = new ReadJson();
  2616. +   }
  2617. +  
  2618. +}
  2619. diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/VoteUtil/VoteUtil.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/VoteUtil/VoteUtil.java
  2620. new file mode 100644
  2621. index 0000000..8feba1f
  2622. --- /dev/null
  2623. +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/VoteUtil/VoteUtil.java
  2624. @@ -0,0 +1,130 @@
  2625. +package org.l2jmobius.gameserver.votesystem.VoteUtil;
  2626. +
  2627. +import java.io.BufferedReader;
  2628. +import java.io.InputStreamReader;
  2629. +import java.net.HttpURLConnection;
  2630. +import java.net.URL;
  2631. +import java.text.ParseException;
  2632. +import java.text.SimpleDateFormat;
  2633. +import java.time.ZoneId;
  2634. +import java.time.ZonedDateTime;
  2635. +import java.time.format.DateTimeFormatter;
  2636. +import java.util.Date;
  2637. +import java.util.TimeZone;
  2638. +import java.util.logging.Logger;
  2639. +
  2640. +/**
  2641. + * @author l2.topgameserver.net
  2642. + */
  2643. +public final class VoteUtil
  2644. +{
  2645. +   public static final Logger LOGGER = Logger.getLogger(VoteUtil.class.getName());
  2646. +  
  2647. +   public static final long getTimeZoneVotingSite(int ordinalSite)
  2648. +   {
  2649. +       try
  2650. +       {
  2651. +           String id = TimeZone.getDefault().getID();
  2652. +           String myDate = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(ZonedDateTime.now(ZoneId.of(ReadJson.getInstance().getRecordSite(ordinalSite).getTimeZone()))).toString();
  2653. +           SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  2654. +           Date date = sdf.parse(myDate);
  2655. +           String myDate2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(ZonedDateTime.now(ZoneId.of(id))).toString();
  2656. +           SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  2657. +           Date date2 = sdf2.parse(myDate2);
  2658. +           return (date2.getTime() - date.getTime());
  2659. +          
  2660. +       }
  2661. +       catch (ParseException pe)
  2662. +       {
  2663. +           pe.printStackTrace();
  2664. +           return 0L;
  2665. +       }
  2666. +      
  2667. +   }
  2668. +  
  2669. +   public static final String Sites[] =
  2670. +   {
  2671. +       "L2.TopGameServer.net",
  2672. +       "ITopZ.com",
  2673. +       "L2Top.co",
  2674. +       "L2Votes.com",
  2675. +       "L2.Hopzone.net",
  2676. +       "L2Network.eu",
  2677. +       "L2TopServers.com",
  2678. +       "top.l2jbrasil.com",
  2679. +       "MMOTOP.eu",
  2680. +       "L2Topzone.com",
  2681. +       "L2Servers.com",
  2682. +       "GolbalVotes"
  2683. +   };
  2684. +  
  2685. +   public static final String getResponse(String Url, int ordinal)
  2686. +   {
  2687. +      
  2688. +       try
  2689. +       {
  2690. +           int responseCode = 0;
  2691. +           URL objUrl = new URL(Url);
  2692. +           HttpURLConnection con = (HttpURLConnection) objUrl.openConnection();
  2693. +           con.setRequestMethod("GET");
  2694. +           con.setRequestProperty("User-Agent", "Mozilla/5.0");
  2695. +           con.setConnectTimeout(5000);
  2696. +           responseCode = con.getResponseCode();
  2697. +           if (responseCode == HttpURLConnection.HTTP_OK)
  2698. +           {
  2699. +              
  2700. +               String inputLine;
  2701. +               StringBuffer response = new StringBuffer();
  2702. +               BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  2703. +               while ((inputLine = in.readLine()) != null)
  2704. +               {
  2705. +                   if (ordinal == 3)
  2706. +                   {
  2707. +                       if (inputLine.contains("Votes:"))
  2708. +                       {
  2709. +                           response.append(inputLine);
  2710. +                           break;
  2711. +                       }
  2712. +                   }
  2713. +                   if (ordinal == 7)
  2714. +                   {
  2715. +                       if (inputLine.contains("<b>Entradas "))
  2716. +                       {
  2717. +                           response.append(inputLine);
  2718. +                           break;
  2719. +                       }
  2720. +                   }
  2721. +               }
  2722. +               in.close();
  2723. +               return response.toString();
  2724. +           }
  2725. +          
  2726. +       }
  2727. +       catch (Exception e)
  2728. +       {
  2729. +           LOGGER.warning(VoteUtil.Sites[ordinal] + " Say: An error ocurred " + e.getStackTrace());
  2730. +           return "";
  2731. +       }
  2732. +      
  2733. +       return "";
  2734. +   }
  2735. +  
  2736. +   public static final String between(String p1, String str, String p2)
  2737. +   {
  2738. +       String returnValue = "";
  2739. +       int i1 = str.indexOf(p1);
  2740. +       int i2 = str.indexOf(p2);
  2741. +       if ((i1 != -1) && (i2 != -1))
  2742. +       {
  2743. +           i1 = i1 + p1.length();
  2744. +           returnValue = str.substring(i1, i2);
  2745. +       }
  2746. +       return returnValue;
  2747. +   }
  2748. +  
  2749. +   public static final boolean isNumeric(String text)
  2750. +   {
  2751. +       return text.matches("[+-]?\\d*(\\.\\d+)?");
  2752. +   }
  2753. +  
  2754. +}
  2755.  
  2756. -- ----------------------------
  2757. -- Table structure for globalvotes
  2758. -- ----------------------------
  2759. DROP TABLE IF EXISTS `globalvotes`;
  2760. CREATE TABLE `globalvotes`  (
  2761.   `voteSite` tinyint(2) NOT NULL,
  2762.   `lastRewardVotes` int(11) NULL DEFAULT NULL,
  2763.   PRIMARY KEY (`voteSite`) USING BTREE
  2764. ) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
  2765.  
  2766. -- ----------------------------
  2767. -- Records of globalvotes
  2768. -- ----------------------------
  2769. INSERT INTO `globalvotes` VALUES (0, 13);
  2770. INSERT INTO `globalvotes` VALUES (1, 68);
  2771. INSERT INTO `globalvotes` VALUES (2, 0);
  2772. INSERT INTO `globalvotes` VALUES (3, 3);
  2773. INSERT INTO `globalvotes` VALUES (4, 2);
  2774. INSERT INTO `globalvotes` VALUES (5, 0);
  2775. INSERT INTO `globalvotes` VALUES (6, 0);
  2776. INSERT INTO `globalvotes` VALUES (7, 2);
  2777. INSERT INTO `globalvotes` VALUES (8, 3);
  2778. INSERT INTO `globalvotes` VALUES (9, 0);
  2779. INSERT INTO `globalvotes` VALUES (10, 75);
  2780.  
  2781. -- ----------------------------
  2782. -- Table structure for individualvotes
  2783. -- ----------------------------
  2784. DROP TABLE IF EXISTS `individualvotes`;
  2785. CREATE TABLE `individualvotes`  (
  2786.   `voterIp` varchar(40) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  2787.   `voteSite` tinyint(3) NOT NULL,
  2788.   `votingTimeSite` bigint(20) NULL DEFAULT NULL,
  2789.   `alreadyRewarded` tinyint(3) NULL DEFAULT NULL,
  2790.   PRIMARY KEY (`voterIp`, `voteSite`) USING BTREE
  2791. ) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
  2792.  
  2793. -- ----------------------------
  2794. -- Records of npc
  2795. -- ----------------------------
  2796. INSERT INTO `l2jmobiusc6`.`npc`(`id`, `idTemplate`, `name`, `serverSideName`, `title`, `serverSideTitle`, `class`, `collision_radius`, `collision_height`, `level`, `sex`, `type`, `attackrange`, `hp`, `mp`, `hpreg`, `mpreg`, `str`, `con`, `dex`, `int`, `wit`, `men`, `exp`, `sp`, `patk`, `pdef`, `matk`, `mdef`, `atkspd`, `aggro`, `matkspd`, `rhand`, `lhand`, `armor`, `walkspd`, `runspd`, `faction_id`, `faction_range`, `isUndead`, `absorb_level`, `absorb_type`) VALUES (75014, 35587, 'Kaaya', 1, 'Vote Reward System', 0, 'NPC.a_traderC_Fhuman', 8.00, 21.00, 70, 'female', 'NpcVoteReward', 40, 3862, 1493, 11.85, 2.78, 40, 43, 30, 21, 20, 10, 0, 0, 1314, 470, 780, 382, 278, 0, 333, 0, 0, 0, 88, 132, NULL, 0, 0, 0, 'LAST_HIT');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement