Guest User

L2jbrasil autovotereward

a guest
Aug 28th, 2016
176
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- Código: ---
  2. ### Eclipse Workspace Patch 1.0
  3. #P L2jFrozen_GameServer
  4. Index: head-src/com/l2jfrozen/Config.java
  5. ===================================================================
  6. --- head-src/com/l2jfrozen/Config.java (revision 1004)
  7. +++ head-src/com/l2jfrozen/Config.java (working copy)
  8. @@ -2398,7 +2398,20 @@
  9. public static String FARM2_CUSTOM_MESSAGE;
  10. public static String PVP1_CUSTOM_MESSAGE;
  11. public static String PVP2_CUSTOM_MESSAGE;
  12. -
  13. +
  14. + // Vote Reward System Configs
  15. + public static int VOTES_FOR_REWARD;
  16. +
  17. + public static String VOTES_REWARDS;
  18. + public static String VOTES_SITE_L2JBrasil_URL;
  19. + public static String VOTES_SITE_Adminsprol2_URL;
  20. + public static FastMap VOTES_REWARDS_LIST;
  21. +
  22. + public static int VOTES_SYSYEM_INITIAL_DELAY;
  23. + public static int VOTES_SYSYEM_STEP_DELAY;
  24. +
  25. + public static String SERVER_WEB_SITE;
  26. + public static boolean AUTOVOTEREWARD_ENABLED;
  27. //============================================================
  28. public static void loadL2JFrozenConfig()
  29. {
  30. @@ -2517,6 +2530,33 @@
  31. FARM2_CUSTOM_MESSAGE = L2JFrozenSettings.getProperty("Farm2CustomMeesage", "You have been teleported to Farm Zone 2!");
  32. PVP1_CUSTOM_MESSAGE = L2JFrozenSettings.getProperty("PvP1CustomMeesage", "You have been teleported to PvP Zone 1!");
  33. PVP2_CUSTOM_MESSAGE = L2JFrozenSettings.getProperty("PvP2CustomMeesage", "You have been teleported to PvP Zone 2!");
  34. + AUTOVOTEREWARD_ENABLED = Boolean.parseBoolean(L2JFrozenSettings.getProperty("VoteRewardSystem", "true"));
  35. + VOTES_FOR_REWARD = Integer.parseInt(L2JFrozenSettings.getProperty("VotesRequiredForReward", "100"));
  36. + VOTES_SYSYEM_INITIAL_DELAY = Integer.parseInt(L2JFrozenSettings.getProperty("VotesSystemInitialDelay", "60000"));
  37. + VOTES_SYSYEM_STEP_DELAY = Integer.parseInt(L2JFrozenSettings.getProperty("VotesSystemStepDelay", "1800000"));
  38. + VOTES_SITE_Adminsprol2_URL = L2JFrozenSettings.getProperty("VotesSiteAdminsprol2Url", "");
  39. + VOTES_SITE_L2JBrasil_URL = L2JFrozenSettings.getProperty("VotesSiteL2JBrasilUrl", "");
  40. + SERVER_WEB_SITE = L2JFrozenSettings.getProperty("ServerWebSite", "");
  41. + VOTES_REWARDS = L2JFrozenSettings.getProperty("VotesRewards", "");
  42. + VOTES_REWARDS_LIST = new FastMap();
  43. +
  44. + String[] splitted_VOTES_REWARDS = VOTES_REWARDS.split(";");
  45. +
  46. + for (String reward : splitted_VOTES_REWARDS)
  47. + {
  48. +
  49. + String[] item_count = reward.split(",");
  50. +
  51. + if (item_count.length != 2)
  52. + {
  53. + System.out.println("[VotesRewards]: invalid config property -> VotesRewards \"" + VOTES_REWARDS + "\"");
  54. + }
  55. + else
  56. + {
  57. + VOTES_REWARDS_LIST.put(Integer.parseInt(item_count[0]), Integer.parseInt(item_count[1]));
  58. + }
  59. +
  60. + }
  61. }
  62. catch(Exception e)
  63. {
  64. Index: head-src/com/l2jfrozen/gameserver/handler/AutoVoteRewardCaFi.java
  65. ===================================================================
  66. --- head-src/com/l2jfrozen/gameserver/handler/AutoVoteRewardCaFi.java (revision 0)
  67. +++ head-src/com/l2jfrozen/gameserver/handler/AutoVoteRewardCaFi.java (working copy)
  68. @@ -0,0 +1,361 @@
  69. +package com.l2jfrozen.gameserver.handler;
  70. +
  71. +import java.io.BufferedReader;
  72. +import java.io.IOException;
  73. +import java.io.InputStream;
  74. +import java.io.InputStreamReader;
  75. +import java.net.URL;
  76. +import java.net.URLConnection;
  77. +import java.util.ArrayList;
  78. +import java.util.Collection;
  79. +import java.util.List;
  80. +import java.util.Set;
  81. +import java.util.logging.Logger;
  82. +
  83. +import com.l2jfrozen.Config;
  84. +import com.l2jfrozen.gameserver.model.L2World;
  85. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  86. +import com.l2jfrozen.gameserver.model.entity.Announcements;
  87. +import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
  88. +
  89. +/*************************************
  90. + * @author* Fissban * Adaptacion CaFi*
  91. + ************************************/
  92. +
  93. +public class AutoVoteRewardCaFi
  94. +{
  95. + protected static final Logger _log = Logger.getLogger(AutoVoteRewardCaFi.class.getName());
  96. +
  97. + private int Adminsprol2VotesCount = 0;
  98. + private int L2JBrasilVotesCount = 0;
  99. + protected List already_rewarded;
  100. +
  101. + protected static boolean L2JBrasil = false;
  102. + protected static boolean Adminsprol2 = false;
  103. +
  104. + private AutoVoteRewardCaFi()
  105. + {
  106. + _log.info("Vote Reward System Initiated.");
  107. +
  108. + if (Adminsprol2)
  109. + {
  110. + int Adminsprol2_votes = getAdminsprol2Votes();
  111. +
  112. + if (Adminsprol2_votes == -1)
  113. + {
  114. + Adminsprol2_votes = 0;
  115. + }
  116. +
  117. + setAdminsprol2VoteCount(Adminsprol2_votes);
  118. + }
  119. +
  120. + if (L2JBrasil)
  121. + {
  122. + int L2JBrasil_votes = getL2JBrasilVotes();
  123. +
  124. + if (L2JBrasil_votes == -1)
  125. + {
  126. + L2JBrasil_votes = 0;
  127. + }
  128. +
  129. + setL2JBrasilVoteCount(L2JBrasil_votes);
  130. + }
  131. +
  132. + ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), Config.VOTES_SYSYEM_INITIAL_DELAY, Config.VOTES_SYSYEM_STEP_DELAY);
  133. + }
  134. +
  135. + protected class AutoReward implements Runnable
  136. + {
  137. + @Override
  138. + public void run()
  139. + {
  140. + int minutes = (Config.VOTES_SYSYEM_STEP_DELAY / 1000) / 60;
  141. +
  142. + if (Adminsprol2)
  143. + {
  144. + int Adminsprol2_votes = getAdminsprol2Votes();
  145. +
  146. + if (Adminsprol2_votes != -1)
  147. + {
  148. + _log.info("[AutoVoteReward] Server Adminsprol2 Votes: " + Adminsprol2_votes);
  149. + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Actual Adminsprol2 Votes are " + Adminsprol2_votes + "...");
  150. +
  151. + if ((Adminsprol2_votes != 0) && (Adminsprol2_votes >= (getAdminsprol2VoteCount() + Config.VOTES_FOR_REWARD)))
  152. + {
  153. + already_rewarded = new ArrayList();
  154. +
  155. + Collection pls = L2World.getInstance().getAllPlayers();
  156. +
  157. + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Great Work! Check your inventory for Reward!!");
  158. +
  159. + // L2ItemInstance item;
  160. + for (L2PcInstance player : pls)
  161. + {
  162. + if ((player != null) && !player.isOffline() && (player.isOnline() == 1))
  163. + {
  164. + if ((player._active_boxes <= 1) || ((player._active_boxes > 1) && checkSingleBox(player)))
  165. + {
  166. +
  167. + Set items = Config.VOTES_REWARDS_LIST.keySet();
  168. + for (Integer i : items)
  169. + {
  170. + // item = player.getInventory().getItemByItemId(i);
  171. +
  172. + // TODO: check on maxstack for item
  173. + player.addItem("reward", i, Config.VOTES_REWARDS_LIST.get(i), player, true);
  174. +
  175. + }
  176. +
  177. + }
  178. + }
  179. + }
  180. + setAdminsprol2VoteCount(Adminsprol2_votes);
  181. + }
  182. + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Next Adminsprol2 Reward in " + minutes + " minutes at " + (getAdminsprol2VoteCount() + Config.VOTES_FOR_REWARD) + " Votes!!");
  183. + // site web
  184. + Announcements.getInstance().gameAnnounceToAll("[SiteWeb] " + Config.SERVER_WEB_SITE);
  185. +
  186. + }
  187. +
  188. + }
  189. +
  190. + if (L2JBrasil && Adminsprol2 && (Config.VOTES_SYSYEM_STEP_DELAY > 0))
  191. + {
  192. + try
  193. + {
  194. + Thread.sleep(Config.VOTES_SYSYEM_STEP_DELAY / 2);
  195. + }
  196. + catch (InterruptedException e)
  197. + {
  198. + if (Config.ENABLE_ALL_EXCEPTIONS)
  199. + {
  200. + e.printStackTrace();
  201. + }
  202. + }
  203. + }
  204. +
  205. + if (L2JBrasil)
  206. + {
  207. + int L2JBrasil_votes = getL2JBrasilVotes();
  208. +
  209. + if (L2JBrasil_votes != -1)
  210. + {
  211. +
  212. + _log.info("[AutoVoteReward] Server L2JBrasil Votes: " + L2JBrasil_votes);
  213. + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Actual L2JBrasil Votes are " + L2JBrasil_votes + "...");
  214. +
  215. + if ((L2JBrasil_votes != 0) && (L2JBrasil_votes >= (getL2JBrasilVoteCount() + Config.VOTES_FOR_REWARD)))
  216. + {
  217. + already_rewarded = new ArrayList();
  218. +
  219. + Collection pls = L2World.getInstance().getAllPlayers();
  220. +
  221. + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Great Work! Check your inventory for Reward!!");
  222. +
  223. + // L2ItemInstance item;
  224. + for (L2PcInstance player : pls)
  225. + {
  226. + if ((player != null) && !player.isOffline() && (player.isOnline() == 1))
  227. + {
  228. + if ((player._active_boxes <= 1) || ((player._active_boxes > 1) && checkSingleBox(player)))
  229. + {
  230. +
  231. + Set items = Config.VOTES_REWARDS_LIST.keySet();
  232. + for (Integer i : items)
  233. + {
  234. + // item = player.getInventory().getItemByItemId(i);
  235. +
  236. + // TODO: check on maxstack for item
  237. + player.addItem("reward", i, Config.VOTES_REWARDS_LIST.get(i), player, true);
  238. +
  239. + }
  240. +
  241. + }
  242. + }
  243. + }
  244. + setL2JBrasilVoteCount(L2JBrasil_votes);
  245. + }
  246. +
  247. + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Next L2JBrasil Reward in " + minutes + " minutes at " + (getL2JBrasilVoteCount() + Config.VOTES_FOR_REWARD) + " Votes!!");
  248. + // site web
  249. + Announcements.getInstance().gameAnnounceToAll("[SiteWeb] " + Config.SERVER_WEB_SITE);
  250. +
  251. + }
  252. +
  253. + }
  254. +
  255. + }
  256. + }
  257. +
  258. + protected boolean checkSingleBox(L2PcInstance player)
  259. + {
  260. +
  261. + if(player.getClient()!=null && player.getClient().getConnection()!=null && !player.getClient().getConnection().isClosed() && !player.isOffline()){
  262. +
  263. + String playerip = player.getClient().getConnection().getInetAddress().getHostAddress();
  264. +
  265. + if(already_rewarded.contains(playerip))
  266. + return false;
  267. + already_rewarded.add(playerip);
  268. + return true;
  269. + }
  270. +
  271. + // if no connection (maybe offline shop) dnt reward
  272. + return false;
  273. + }
  274. +
  275. + protected int getAdminsprol2Votes()
  276. + {
  277. + int votes = -1;
  278. + URL url = null;
  279. + URLConnection con = null;
  280. + InputStream is = null;
  281. + InputStreamReader isr = null;
  282. + BufferedReader in = null;
  283. + try
  284. + {
  285. + url = new URL("http://hopzone.com.e...omServer.php?ID=" + Config.VOTES_SITE_Adminsprol2_URL);
  286. + con = url.openConnection();
  287. + con.addRequestProperty("User-Agent", "Mozilla/4.76");
  288. + is = con.getInputStream();
  289. + isr = new InputStreamReader(is);
  290. + in = new BufferedReader(isr);
  291. + String inputLine;
  292. + while ((inputLine = in.readLine()) != null)
  293. + {
  294. + return Integer.parseInt(inputLine);
  295. + }
  296. + }
  297. + catch (Exception e)
  298. + {
  299. + _log.info("[AutoVoteReward] Server Adminsprol2 is offline or something is wrong in link");
  300. + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Adminsprol2 is offline. We will check reward as it will be online again");
  301. + // e.printStackTrace();
  302. + }
  303. + finally
  304. + {
  305. + if (in != null)
  306. + {
  307. + try
  308. + {
  309. + in.close();
  310. + }
  311. + catch (IOException e1)
  312. + {
  313. + e1.printStackTrace();
  314. + }
  315. + }
  316. + if (isr != null)
  317. + {
  318. + try
  319. + {
  320. + isr.close();
  321. + }
  322. + catch (IOException e1)
  323. + {
  324. + e1.printStackTrace();
  325. + }
  326. + }
  327. + if (is != null)
  328. + {
  329. + try
  330. + {
  331. + is.close();
  332. + }
  333. + catch (IOException e1)
  334. + {
  335. + e1.printStackTrace();
  336. + }
  337. + }
  338. +
  339. + }
  340. + return votes;
  341. + }
  342. +
  343. + protected int getL2JBrasilVotes()
  344. + {
  345. + try
  346. + {
  347. + URL url = new URL(Config.VOTES_SITE_L2JBrasil_URL);
  348. + URLConnection con = url.openConnection();
  349. + con.addRequestProperty("User-Agent", "Mozilla/4.76");
  350. + InputStreamReader isr = new InputStreamReader(con.getInputStream());
  351. + BufferedReader in = new BufferedReader(isr);
  352. + String inputLine;
  353. +
  354. + boolean search = false;
  355. + int count = 0;
  356. + while ((inputLine = in.readLine()) != null)
  357. + {
  358. + if (inputLine.contains("Este M"))
  359. + {
  360. + search = true;
  361. + }
  362. + else if (search && inputLine.contains(""))
  363. + {
  364. + if (count > 0)
  365. + {
  366. + String votes = inputLine.replace("", "");
  367. + votes = votes.replace("", "");
  368. + votes = votes.trim();
  369. + return Integer.parseInt(votes);
  370. + }
  371. + count++;
  372. + }
  373. + }
  374. + }
  375. + catch (IOException e)
  376. + {
  377. + _log.warning("AutoVoteBrasil: " + e);
  378. + }
  379. + finally
  380. + {
  381. + }
  382. + return 0;
  383. + }
  384. +
  385. + protected void setAdminsprol2VoteCount(int voteCount)
  386. + {
  387. + Adminsprol2VotesCount = voteCount;
  388. + }
  389. +
  390. + protected int getAdminsprol2VoteCount()
  391. + {
  392. + return Adminsprol2VotesCount;
  393. + }
  394. +
  395. + protected void setL2JBrasilVoteCount(int voteCount)
  396. + {
  397. + L2JBrasilVotesCount = voteCount;
  398. + }
  399. +
  400. + protected int getL2JBrasilVoteCount()
  401. + {
  402. + return L2JBrasilVotesCount;
  403. + }
  404. +
  405. + public static AutoVoteRewardCaFi getInstance()
  406. + {
  407. + if ((Config.VOTES_SITE_Adminsprol2_URL != null) && !Config.VOTES_SITE_Adminsprol2_URL.equals(""))
  408. + {
  409. + Adminsprol2 = true;
  410. + }
  411. +
  412. + if ((Config.VOTES_SITE_L2JBrasil_URL != null) && !Config.VOTES_SITE_L2JBrasil_URL.equals(""))
  413. + {
  414. + L2JBrasil = true;
  415. + }
  416. +
  417. + if (L2JBrasil || Adminsprol2)
  418. + {
  419. + return SingletonHolder._instance;
  420. + }
  421. + return null;
  422. + }
  423. +
  424. + @SuppressWarnings("synthetic-access")
  425. + private static class SingletonHolder
  426. + {
  427. + protected static final AutoVoteRewardCaFi _instance = new AutoVoteRewardCaFi();
  428. + }
  429. +}
  430. \ No newline at end of file
  431. Index: head-src/com/l2jfrozen/gameserver/GameServer.java
  432. ===================================================================
  433. --- head-src/com/l2jfrozen/gameserver/GameServer.java (revision 1004)
  434. +++ head-src/com/l2jfrozen/gameserver/GameServer.java (working copy)
  435. @@ -81,6 +81,7 @@
  436. import com.l2jfrozen.gameserver.handler.AdminCommandHandler;
  437. import com.l2jfrozen.gameserver.handler.AutoAnnouncementHandler;
  438. import com.l2jfrozen.gameserver.handler.AutoChatHandler;
  439. +import com.l2jfrozen.gameserver.handler.AutoVoteRewardCaFi;
  440. import com.l2jfrozen.gameserver.handler.ItemHandler;
  441. import com.l2jfrozen.gameserver.handler.SkillHandler;
  442. import com.l2jfrozen.gameserver.handler.UserCommandHandler;
  443. @@ -230,6 +231,7 @@
  444. MapRegionTable.getInstance();
  445. Announcements.getInstance();
  446. AutoAnnouncementHandler.getInstance();
  447. + AutoVoteRewardCaFi.getInstance();
  448. if (!IdFactory.getInstance().isInitialized())
  449. {
  450. _log.info("Could not read object IDs from DB. Please Check Your Data.");
  451. Index: config/functions/l2jfrozen.properties
  452. ===================================================================
  453. --- config/functions/l2jfrozen.properties (revision 1004)
  454. +++ config/functions/l2jfrozen.properties (working copy)
  455. @@ -280,4 +280,17 @@
  456. ProtectorSkillLevel = 13
  457. ProtectorSkillTime = 600
  458. # Npc Protector Message
  459. -ProtectorMessage = Hey You!, Never Kill On This Area, Go Read The Rules!
  460. \ No newline at end of file
  461. +ProtectorMessage = Hey You!, Never Kill On This Area, Go Read The Rules!
  462. +
  463. +# Automatic Vote Reward System
  464. +VoteRewardSystem= True
  465. +VotesRequiredForReward = 10
  466. +VotesSystemInitialDelay= 60000
  467. +VotesSystemStepDelay= 1800000
  468. +VotesRewards= 3470,20;
  469. +
  470. +#Leave empty to disable one site
  471. +#if you need just one of these
  472. +VotesSiteAdminsprol2Url=
  473. +VotesSiteL2JBrasilUrl=
  474. +ServerWebSite= http://www.l2jbrasil.com
  475. \ No newline at end of file
RAW Paste Data