Guest User

Untitled

a guest
Nov 23rd, 2015
2,682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.59 KB | None | 0 0
  1. Index: config/events.properties
  2. ===================================================================
  3. --- config/events.properties (revision 2)
  4. +++ config/events.properties (working copy)
  5. @@ -241,4 +241,61 @@
  6. AltFishChampionshipReward2 = 500000
  7. AltFishChampionshipReward3 = 300000
  8. AltFishChampionshipReward4 = 200000
  9. -AltFishChampionshipReward5 = 100000
  10. \ No newline at end of file
  11. +AltFishChampionshipReward5 = 100000
  12. +
  13. +# Vote reward for Network.
  14. +AllowNetworkVoteReward = False
  15. +# Vote reward server link. (IMPORTANT!!!! Always add .html at the end of the link)
  16. +NetworkServerLink =
  17. +# Votes for next reward needed.
  18. +NetworkVotesDifference = 4
  19. +# Minutes between rewards.
  20. +# Eg. You put 5 it checks every 5 minutes for reward.
  21. +NetworkRewardCheckTime = 5
  22. +# Reward(s).
  23. +NetworkReward = 3481,5;
  24. +# Network reward max dual boxes reward.
  25. +# For example if you put 2 and someone has 3 boxes open 2 will be rewarded.
  26. +NetworkDuaboxesAllowed = 1
  27. +# Game server console report.
  28. +# If set to true, game server console will get a report of
  29. +# current vote count, votes needed for next reward and votes needed for first page.
  30. +AllowNetworkGameServerReport = False
  31. +
  32. +# Vote reward for Topzone.
  33. +AllowTopzoneVoteReward = False
  34. +# Vote reward server link. (IMPORTANT!!!! Always add .html at the end of the link)
  35. +TopzoneServerLink =
  36. +# Votes for next reward needed.
  37. +TopzoneVotesDifference = 4
  38. +# Minutes between rewards.
  39. +# Eg. You put 5 it checks every 5 minutes for reward.
  40. +TopzoneRewardCheckTime = 5
  41. +# Reward(s).
  42. +TopzoneReward = 3481,5;
  43. +# Topzone reward max dual boxes reward.
  44. +# For example if you put 2 and someone has 3 boxes open 2 will be rewarded.
  45. +TopzoneDuaboxesAllowed = 1
  46. +# Game server console report.
  47. +# If set to true, game server console will get a report of
  48. +# current vote count, votes needed for next reward and votes needed for first page.
  49. +AllowTopzoneGameServerReport = False
  50. +
  51. +# Vote reward for Hopzone.
  52. +AllowHopzoneVoteReward = False
  53. +# Vote reward server link. (IMPORTANT!!!! Always add .html at the end of the link)
  54. +HopzoneServerLink =
  55. +# Votes for next reward needed.
  56. +HopzoneVotesDifference = 4
  57. +# Minutes between rewards.
  58. +# Eg. You put 5 it checks every 5 minutes for reward.
  59. +HopzoneRewardCheckTime = 5
  60. +# Reward(s).
  61. +HopzoneReward = 3481,5;
  62. +# Topzone reward max dual boxes reward.
  63. +# For example if you put 2 and someone has 3 boxes open 2 will be rewarded.
  64. +HopzoneDuaboxesAllowed = 1
  65. +# Game server console report.
  66. +# If set to true, game server console will get a report of
  67. +# current vote count, votes needed for next reward and votes needed for first page.
  68. +AllowHopzoneGameServerReport = False
  69. \ No newline at end of file
  70. Index: java/net/sf/l2j/Config.java
  71. ===================================================================
  72. --- java/net/sf/l2j/Config.java (revision 6)
  73. +++ java/net/sf/l2j/Config.java (working copy)
  74. @@ -222,6 +222,29 @@
  75. public static int ALT_FISH_CHAMPIONSHIP_REWARD_4;
  76. public static int ALT_FISH_CHAMPIONSHIP_REWARD_5;
  77.  
  78. + /** Vote reward */
  79. + public static boolean ALLOW_NETWORK_VOTE_REWARD;
  80. + public static String NETWORK_SERVER_LINK;
  81. + public static int NETWORK_VOTES_DIFFERENCE;
  82. + public static int NETWORK_REWARD_CHECK_TIME;
  83. + public static Map<Integer, Integer> NETWORK_REWARD = new HashMap<>();
  84. + public static int NETWORK_DUALBOXES_ALLOWED;
  85. + public static boolean ALLOW_NETWORK_GAME_SERVER_REPORT;
  86. + public static boolean ALLOW_TOPZONE_VOTE_REWARD;
  87. + public static String TOPZONE_SERVER_LINK;
  88. + public static int TOPZONE_VOTES_DIFFERENCE;
  89. + public static int TOPZONE_REWARD_CHECK_TIME;
  90. + public static Map<Integer, Integer> TOPZONE_REWARD = new HashMap<>();
  91. + public static int TOPZONE_DUALBOXES_ALLOWED;
  92. + public static boolean ALLOW_TOPZONE_GAME_SERVER_REPORT;
  93. + public static boolean ALLOW_HOPZONE_VOTE_REWARD;
  94. + public static String HOPZONE_SERVER_LINK;
  95. + public static int HOPZONE_VOTES_DIFFERENCE;
  96. + public static int HOPZONE_REWARD_CHECK_TIME;
  97. + public static Map<Integer, Integer> HOPZONE_REWARD = new HashMap<>();
  98. + public static int HOPZONE_DUALBOXES_ALLOWED;
  99. + public static boolean ALLOW_HOPZONE_GAME_SERVER_REPORT;
  100. +
  101. // --------------------------------------------------
  102. // GeoEngine
  103. // --------------------------------------------------
  104. @@ -911,6 +934,46 @@
  105. ALT_FISH_CHAMPIONSHIP_REWARD_3 = events.getProperty("AltFishChampionshipReward3", 300000);
  106. ALT_FISH_CHAMPIONSHIP_REWARD_4 = events.getProperty("AltFishChampionshipReward4", 200000);
  107. ALT_FISH_CHAMPIONSHIP_REWARD_5 = events.getProperty("AltFishChampionshipReward5", 100000);
  108. +
  109. + ALLOW_NETWORK_VOTE_REWARD = events.getProperty("AllowNetworkVoteReward", false);
  110. + NETWORK_SERVER_LINK = events.getProperty("NetworkServerLink", "");
  111. + NETWORK_VOTES_DIFFERENCE = events.getProperty("NetworkVotesDifference", 5);
  112. + NETWORK_REWARD_CHECK_TIME = events.getProperty("NetworkRewardCheckTime", 5);
  113. + String NETWORK_SMALL_REWARD_VALUE = events.getProperty("NetworkReward", "57,100000000;");
  114. + String[] NETWORK_small_reward_splitted_1 = NETWORK_SMALL_REWARD_VALUE.split(";");
  115. + for (String i : NETWORK_small_reward_splitted_1)
  116. + {
  117. + String[] NETWORK_small_reward_splitted_2 = i.split(",");
  118. + NETWORK_REWARD.put(Integer.parseInt(NETWORK_small_reward_splitted_2[0]), Integer.parseInt(NETWORK_small_reward_splitted_2[1]));
  119. + }
  120. + NETWORK_DUALBOXES_ALLOWED = events.getProperty("NetworkDualboxesAllowed", 1);
  121. + ALLOW_NETWORK_GAME_SERVER_REPORT = events.getProperty("AllowNetworkGameServerReport", false);
  122. + ALLOW_TOPZONE_VOTE_REWARD = events.getProperty("AllowTopzoneVoteReward", false);
  123. + TOPZONE_SERVER_LINK = events.getProperty("TopzoneServerLink", "");
  124. + TOPZONE_VOTES_DIFFERENCE = events.getProperty("TopzoneVotesDifference", 5);
  125. + TOPZONE_REWARD_CHECK_TIME = events.getProperty("TopzoneRewardCheckTime", 5);
  126. + String TOPZONE_SMALL_REWARD_VALUE = events.getProperty("TopzoneReward", "57,100000000;");
  127. + String[] topzone_small_reward_splitted_1 = TOPZONE_SMALL_REWARD_VALUE.split(";");
  128. + for (String i : topzone_small_reward_splitted_1)
  129. + {
  130. + String[] topzone_small_reward_splitted_2 = i.split(",");
  131. + TOPZONE_REWARD.put(Integer.parseInt(topzone_small_reward_splitted_2[0]), Integer.parseInt(topzone_small_reward_splitted_2[1]));
  132. + }
  133. + TOPZONE_DUALBOXES_ALLOWED = events.getProperty("TopzoneDualboxesAllowed", 1);
  134. + ALLOW_TOPZONE_GAME_SERVER_REPORT = events.getProperty("AllowTopzoneGameServerReport", false);
  135. + ALLOW_HOPZONE_VOTE_REWARD = events.getProperty("AllowHopzoneVoteReward", false);
  136. + HOPZONE_SERVER_LINK = events.getProperty("HopzoneServerLink", "");
  137. + HOPZONE_VOTES_DIFFERENCE = events.getProperty("HopzoneVotesDifference", 5);
  138. + HOPZONE_REWARD_CHECK_TIME = events.getProperty("HopzoneRewardCheckTime", 5);
  139. + String HOPZONE_SMALL_REWARD_VALUE = events.getProperty("HopzoneReward", "57,100000000;");
  140. + String[] hopzone_small_reward_splitted_1 = HOPZONE_SMALL_REWARD_VALUE.split(";");
  141. + for (String i : hopzone_small_reward_splitted_1)
  142. + {
  143. + String[] hopzone_small_reward_splitted_2 = i.split(",");
  144. + HOPZONE_REWARD.put(Integer.parseInt(hopzone_small_reward_splitted_2[0]), Integer.parseInt(hopzone_small_reward_splitted_2[1]));
  145. + }
  146. + HOPZONE_DUALBOXES_ALLOWED = events.getProperty("HopzoneDualboxesAllowed", 1);
  147. + ALLOW_HOPZONE_GAME_SERVER_REPORT = events.getProperty("AllowHopzoneGameServerReport", false);
  148. }
  149.  
  150. /**
  151. Index: java/net/sf/l2j/gameserver/GameServer.java
  152. ===================================================================
  153. --- java/net/sf/l2j/gameserver/GameServer.java (revision 5)
  154. +++ java/net/sf/l2j/gameserver/GameServer.java (working copy)
  155. @@ -120,6 +120,7 @@
  156. import net.sf.l2j.gameserver.taskmanager.ShadowItemTaskManager;
  157. import net.sf.l2j.gameserver.taskmanager.TaskManager;
  158. import net.sf.l2j.gameserver.taskmanager.WaterTaskManager;
  159. +import net.sf.l2j.gameserver.votereward.VoteSystem;
  160. import net.sf.l2j.gameserver.xmlfactory.XMLDocumentFactory;
  161. import net.sf.l2j.util.DeadLockDetector;
  162. import net.sf.l2j.util.IPv4Filter;
  163. @@ -290,6 +291,9 @@
  164. if (Config.ALT_FISH_CHAMPIONSHIP_ENABLED)
  165. FishingChampionshipManager.getInstance();
  166.  
  167. + StringUtil.printSection("Vote Reward");
  168. + VoteSystem.initialize();
  169. +
  170. StringUtil.printSection("System");
  171. TaskManager.getInstance();
  172. Runtime.getRuntime().addShutdownHook(Shutdown.getInstance());
  173. Index: java/net/sf/l2j/gameserver/votereward/Hopzone.java
  174. ===================================================================
  175. --- java/net/sf/l2j/gameserver/votereward/Hopzone.java (revision 0)
  176. +++ java/net/sf/l2j/gameserver/votereward/Hopzone.java (revision 0)
  177. @@ -0,0 +1,82 @@
  178. +/*
  179. + * This program is free software: you can redistribute it and/or modify it under
  180. + * the terms of the GNU General Public License as published by the Free Software
  181. + * Foundation, either version 3 of the License, or (at your option) any later
  182. + * version.
  183. + *
  184. + * This program is distributed in the hope that it will be useful, but WITHOUT
  185. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  186. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  187. + * details.
  188. + *
  189. + * You should have received a copy of the GNU General Public License along with
  190. + * this program. If not, see <http://www.gnu.org/licenses/>.
  191. + */
  192. +package net.sf.l2j.gameserver.votereward;
  193. +
  194. +import java.io.BufferedReader;
  195. +import java.io.InputStreamReader;
  196. +import java.net.URL;
  197. +import java.net.URLConnection;
  198. +import java.util.Map;
  199. +
  200. +import net.sf.l2j.Config;
  201. +
  202. +/**
  203. + * @author Anarchy
  204. + *
  205. + */
  206. +public class Hopzone extends VoteSystem
  207. +{
  208. + public Hopzone(int votesDiff, boolean allowReport, int boxes, Map<Integer, Integer> rewards, int checkMins)
  209. + {
  210. + super(votesDiff, allowReport, boxes, rewards, checkMins);
  211. + }
  212. +
  213. + @Override
  214. + public void run()
  215. + {
  216. + reward();
  217. + }
  218. +
  219. + @Override
  220. + public int getVotes()
  221. + {
  222. + InputStreamReader isr = null;
  223. + BufferedReader br = null;
  224. +
  225. + try
  226. + {
  227. + URLConnection con = new URL(Config.HOPZONE_SERVER_LINK).openConnection();
  228. + con.addRequestProperty("User-Agent", "Mozilla/4.76");
  229. + isr = new InputStreamReader(con.getInputStream());
  230. + br = new BufferedReader(isr);
  231. +
  232. + String line;
  233. + while ((line = br.readLine()) != null)
  234. + {
  235. + if (line.contains("<li><span class=\"rank anonymous tooltip\" title"))
  236. + {
  237. + int votes = Integer.valueOf(line.split(">")[2].replace("</span", ""));
  238. + return votes;
  239. + }
  240. + }
  241. +
  242. + br.close();
  243. + isr.close();
  244. + }
  245. + catch (Exception e)
  246. + {
  247. + e.printStackTrace();
  248. + System.out.println("Error while getting server vote count from "+getSiteName()+".");
  249. + }
  250. +
  251. + return -1;
  252. + }
  253. +
  254. + @Override
  255. + public String getSiteName()
  256. + {
  257. + return "Hopzone";
  258. + }
  259. +}
  260. Index: java/net/sf/l2j/gameserver/votereward/Network.java
  261. ===================================================================
  262. --- java/net/sf/l2j/gameserver/votereward/Network.java (revision 0)
  263. +++ java/net/sf/l2j/gameserver/votereward/Network.java (revision 0)
  264. @@ -0,0 +1,82 @@
  265. +/*
  266. + * This program is free software: you can redistribute it and/or modify it under
  267. + * the terms of the GNU General Public License as published by the Free Software
  268. + * Foundation, either version 3 of the License, or (at your option) any later
  269. + * version.
  270. + *
  271. + * This program is distributed in the hope that it will be useful, but WITHOUT
  272. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  273. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  274. + * details.
  275. + *
  276. + * You should have received a copy of the GNU General Public License along with
  277. + * this program. If not, see <http://www.gnu.org/licenses/>.
  278. + */
  279. +package net.sf.l2j.gameserver.votereward;
  280. +
  281. +import java.io.BufferedReader;
  282. +import java.io.InputStreamReader;
  283. +import java.net.URL;
  284. +import java.net.URLConnection;
  285. +import java.util.Map;
  286. +
  287. +import net.sf.l2j.Config;
  288. +
  289. +/**
  290. + * @author Anarchy
  291. + *
  292. + */
  293. +public class Network extends VoteSystem
  294. +{
  295. + public Network(int votesDiff, boolean allowReport, int boxes, Map<Integer, Integer> rewards, int checkMins)
  296. + {
  297. + super(votesDiff, allowReport, boxes, rewards, checkMins);
  298. + }
  299. +
  300. + @Override
  301. + public void run()
  302. + {
  303. + reward();
  304. + }
  305. +
  306. + @Override
  307. + public int getVotes()
  308. + {
  309. + InputStreamReader isr = null;
  310. + BufferedReader br = null;
  311. +
  312. + try
  313. + {
  314. + URLConnection con = new URL(Config.NETWORK_SERVER_LINK).openConnection();
  315. + con.addRequestProperty("User-L2Network", "Mozilla/4.76");
  316. + isr = new InputStreamReader(con.getInputStream());
  317. + br = new BufferedReader(isr);
  318. +
  319. + String line;
  320. + while ((line = br.readLine()) != null)
  321. + {
  322. + if (line.contains("<div class=\"tls-in-sts\"><b style"))
  323. + {
  324. + int votes = Integer.valueOf(line.split(">")[2].replace("</b", ""));
  325. + return votes;
  326. + }
  327. + }
  328. +
  329. + br.close();
  330. + isr.close();
  331. + }
  332. + catch (Exception e)
  333. + {
  334. + e.printStackTrace();
  335. + System.out.println("Error while getting server vote count from "+getSiteName()+".");
  336. + }
  337. +
  338. + return -1;
  339. + }
  340. +
  341. + @Override
  342. + public String getSiteName()
  343. + {
  344. + return "Network";
  345. + }
  346. +}
  347. Index: java/net/sf/l2j/gameserver/votereward/Topzone.java
  348. ===================================================================
  349. --- java/net/sf/l2j/gameserver/votereward/Topzone.java (revision 0)
  350. +++ java/net/sf/l2j/gameserver/votereward/Topzone.java (revision 0)
  351. @@ -0,0 +1,82 @@
  352. +/*
  353. + * This program is free software: you can redistribute it and/or modify it under
  354. + * the terms of the GNU General Public License as published by the Free Software
  355. + * Foundation, either version 3 of the License, or (at your option) any later
  356. + * version.
  357. + *
  358. + * This program is distributed in the hope that it will be useful, but WITHOUT
  359. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  360. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  361. + * details.
  362. + *
  363. + * You should have received a copy of the GNU General Public License along with
  364. + * this program. If not, see <http://www.gnu.org/licenses/>.
  365. + */
  366. +package net.sf.l2j.gameserver.votereward;
  367. +
  368. +import java.io.BufferedReader;
  369. +import java.io.InputStreamReader;
  370. +import java.net.URL;
  371. +import java.net.URLConnection;
  372. +import java.util.Map;
  373. +
  374. +import net.sf.l2j.Config;
  375. +
  376. +/**
  377. + * @author Anarchy
  378. + *
  379. + */
  380. +public class Topzone extends VoteSystem
  381. +{
  382. + public Topzone(int votesDiff, boolean allowReport, int boxes, Map<Integer, Integer> rewards, int checkMins)
  383. + {
  384. + super(votesDiff, allowReport, boxes, rewards, checkMins);
  385. + }
  386. +
  387. + @Override
  388. + public void run()
  389. + {
  390. + reward();
  391. + }
  392. +
  393. + @Override
  394. + public int getVotes()
  395. + {
  396. + InputStreamReader isr = null;
  397. + BufferedReader br = null;
  398. +
  399. + try
  400. + {
  401. + URLConnection con = new URL(Config.TOPZONE_SERVER_LINK).openConnection();
  402. + con.addRequestProperty("User-Agent", "L2TopZone");
  403. + isr = new InputStreamReader(con.getInputStream());
  404. + br = new BufferedReader(isr);
  405. +
  406. + String line;
  407. + while ((line = br.readLine()) != null)
  408. + {
  409. + if (line.contains("</span></small>"))
  410. + {
  411. + int votes = Integer.valueOf(line.split(">")[9].replace("</span", ""));
  412. + return votes;
  413. + }
  414. + }
  415. +
  416. + br.close();
  417. + isr.close();
  418. + }
  419. + catch (Exception e)
  420. + {
  421. + e.printStackTrace();
  422. + System.out.println("Error while getting server vote count from "+getSiteName()+".");
  423. + }
  424. +
  425. + return -1;
  426. + }
  427. +
  428. + @Override
  429. + public String getSiteName()
  430. + {
  431. + return "Topzone";
  432. + }
  433. +}
  434. Index: java/net/sf/l2j/gameserver/votereward/VoteSystem.java
  435. ===================================================================
  436. --- java/net/sf/l2j/gameserver/votereward/VoteSystem.java (revision 0)
  437. +++ java/net/sf/l2j/gameserver/votereward/VoteSystem.java (revision 0)
  438. @@ -0,0 +1,163 @@
  439. +/*
  440. + * This program is free software: you can redistribute it and/or modify it under
  441. + * the terms of the GNU General Public License as published by the Free Software
  442. + * Foundation, either version 3 of the License, or (at your option) any later
  443. + * version.
  444. + *
  445. + * This program is distributed in the hope that it will be useful, but WITHOUT
  446. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  447. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  448. + * details.
  449. + *
  450. + * You should have received a copy of the GNU General Public License along with
  451. + * this program. If not, see <http://www.gnu.org/licenses/>.
  452. + */
  453. +package net.sf.l2j.gameserver.votereward;
  454. +
  455. +import java.util.ArrayList;
  456. +import java.util.Collection;
  457. +import java.util.HashMap;
  458. +import java.util.List;
  459. +import java.util.Map;
  460. +
  461. +import net.sf.l2j.Config;
  462. +import net.sf.l2j.gameserver.ThreadPoolManager;
  463. +import net.sf.l2j.gameserver.model.L2World;
  464. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  465. +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  466. +import net.sf.l2j.gameserver.util.Broadcast;
  467. +
  468. +/**
  469. + * @author Anarchy
  470. + *
  471. + */
  472. +public abstract class VoteSystem implements Runnable
  473. +{
  474. + private static List<VoteSystem> voteSystems = new ArrayList<>();
  475. +
  476. + protected int votesDiff;
  477. + protected boolean allowReport;
  478. + protected int boxes;
  479. + protected Map<Integer, Integer> rewards;
  480. + protected int checkMins;
  481. + protected int lastVotes = 0;
  482. + private Map<String, Integer> playerIps = new HashMap<>();
  483. +
  484. + public static void initialize()
  485. + {
  486. + System.out.println("Vote System: Loaded");
  487. + if (Config.ALLOW_NETWORK_VOTE_REWARD)
  488. + voteSystems.add(new Network(Config.NETWORK_VOTES_DIFFERENCE, Config.ALLOW_NETWORK_GAME_SERVER_REPORT, Config.NETWORK_DUALBOXES_ALLOWED, Config.NETWORK_REWARD, Config.NETWORK_REWARD_CHECK_TIME));
  489. + if (Config.ALLOW_TOPZONE_VOTE_REWARD)
  490. + voteSystems.add(new Topzone(Config.TOPZONE_VOTES_DIFFERENCE, Config.ALLOW_TOPZONE_GAME_SERVER_REPORT, Config.TOPZONE_DUALBOXES_ALLOWED, Config.TOPZONE_REWARD, Config.TOPZONE_REWARD_CHECK_TIME));
  491. + if (Config.ALLOW_HOPZONE_VOTE_REWARD)
  492. + voteSystems.add(new Hopzone(Config.HOPZONE_VOTES_DIFFERENCE, Config.ALLOW_HOPZONE_GAME_SERVER_REPORT, Config.HOPZONE_DUALBOXES_ALLOWED, Config.HOPZONE_REWARD, Config.HOPZONE_REWARD_CHECK_TIME));
  493. + }
  494. +
  495. + public static VoteSystem getVoteSystem(String name)
  496. + {
  497. + for (VoteSystem vs : voteSystems)
  498. + if (vs.getSiteName().equals(name))
  499. + return vs;
  500. +
  501. + return null;
  502. + }
  503. +
  504. + public VoteSystem(int votesDiff, boolean allowReport, int boxes, Map<Integer, Integer> rewards, int checkMins)
  505. + {
  506. + this.votesDiff = votesDiff;
  507. + this.allowReport = allowReport;
  508. + this.boxes = boxes;
  509. + this.rewards = rewards;
  510. + this.checkMins = checkMins;
  511. +
  512. + ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(this, checkMins*1000*60, checkMins*1000*60);
  513. + }
  514. +
  515. + protected void reward()
  516. + {
  517. + int currentVotes = getVotes();
  518. +
  519. + if (currentVotes == -1)
  520. + {
  521. + System.out.println("There was a problem on getting server votes.");
  522. + return;
  523. + }
  524. +
  525. + if (lastVotes == 0)
  526. + {
  527. + lastVotes = currentVotes;
  528. + announce(getSiteName()+": Current vote count is "+currentVotes+".");
  529. + announce(getSiteName()+": We need "+((lastVotes+votesDiff)-currentVotes)+" vote(s) for reward.");
  530. + if (allowReport)
  531. + {
  532. + System.out.println("Server votes on "+getSiteName()+": "+currentVotes);
  533. + System.out.println("Votes needed for reward: "+((lastVotes+votesDiff)-currentVotes));
  534. + }
  535. + return;
  536. + }
  537. +
  538. + if (currentVotes >= lastVotes+votesDiff)
  539. + {
  540. + Collection<L2PcInstance> pls = L2World.getInstance().getPlayers();
  541. + if (allowReport)
  542. + {
  543. + System.out.println("Server votes on "+getSiteName()+": "+currentVotes);
  544. + System.out.println("Votes needed for next reward: "+((currentVotes+votesDiff)-currentVotes));
  545. + }
  546. + announce(getSiteName()+": Everyone has been rewarded.");
  547. + announce(getSiteName()+": Current vote count is "+currentVotes+".");
  548. + announce(getSiteName()+": We need "+votesDiff+" vote(s) for next reward.");
  549. + for (L2PcInstance p : pls)
  550. + {
  551. + if (p.getClient() == null || p.getClient().isDetached()) // offline shops protection
  552. + continue;
  553. +
  554. + boolean canReward = false;
  555. + String pIp = p.getClient().getConnection().getInetAddress().getHostAddress();
  556. + if (playerIps.containsKey(pIp))
  557. + {
  558. + int count = playerIps.get(pIp);
  559. + if (count < boxes)
  560. + {
  561. + playerIps.remove(pIp);
  562. + playerIps.put(pIp, count+1);
  563. + canReward = true;
  564. + }
  565. + }
  566. + else
  567. + {
  568. + canReward = true;
  569. + playerIps.put(pIp, 1);
  570. + }
  571. + if (canReward)
  572. + for (int i : rewards.keySet())
  573. + p.addItem("Vote reward.", i, rewards.get(i), p, true);
  574. + else
  575. + p.sendMessage("Already "+boxes+" character(s) of your ip have been rewarded, so this character won't be rewarded.");
  576. + }
  577. + playerIps.clear();
  578. +
  579. + lastVotes = currentVotes;
  580. + }
  581. + else
  582. + {
  583. + if (allowReport)
  584. + {
  585. + System.out.println("Server votes on "+getSiteName()+": "+currentVotes);
  586. + System.out.println("Votes needed for next reward: "+((lastVotes+votesDiff)-currentVotes));
  587. + }
  588. + announce(getSiteName()+": Current vote count is "+currentVotes+".");
  589. + announce(getSiteName()+": We need "+((lastVotes+votesDiff)-currentVotes)+" vote(s) for reward.");
  590. + }
  591. + }
  592. +
  593. + private static void announce(String msg)
  594. + {
  595. + CreatureSay cs = new CreatureSay(0, 18, "", msg);
  596. + Broadcast.toAllOnlinePlayers(cs);
  597. + }
  598. +
  599. + public abstract int getVotes();
  600. + public abstract String getSiteName();
  601. +}
Advertisement
Add Comment
Please, Sign In to add comment