Advertisement
Guest User

Untitled

a guest
Feb 17th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.25 KB | None | 0 0
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. * This program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  9. * details.
  10. * You should have received a copy of the GNU General Public License along with
  11. * this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. package Extensions.Vote;
  14.  
  15.  
  16. import java.io.BufferedReader;
  17. import java.io.InputStream;
  18. import java.io.InputStreamReader;
  19. import java.net.URL;
  20. import java.net.URLConnection;
  21. import java.sql.Connection;
  22. import java.sql.PreparedStatement;
  23. import java.sql.ResultSet;
  24. import java.sql.SQLException;
  25. import java.text.SimpleDateFormat;
  26. import java.util.Date;
  27. import java.util.logging.Level;
  28. import java.util.logging.Logger;
  29.  
  30.  
  31. import Extensions.Vote.Tasks.MonthlyResetTask;
  32. import Extensions.Vote.Tasks.TriesResetTask;
  33.  
  34.  
  35. import com.l2jfrozen.Config;
  36. import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
  37. import com.l2jfrozen.gameserver.model.L2World;
  38. import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  39. import com.l2jfrozen.util.database.L2DatabaseFactory;
  40.  
  41.  
  42. public class VoteManager
  43. {
  44. protected static final Logger _log = Logger.getLogger(VoteManager.class.getName());
  45.  
  46.  
  47. private static boolean hasVotedHop;
  48. private static boolean hasVotedTop;
  49.  
  50.  
  51. public VoteManager()
  52. {
  53. }
  54.  
  55.  
  56. public static void load()
  57. {
  58. _log.log(Level.INFO, "VoteManager: initialized.");
  59. TriesResetTask.getInstance();
  60. MonthlyResetTask.getInstance();
  61. }
  62.  
  63.  
  64. protected static int getHopZoneVotes()
  65. {
  66. int votes = -1;
  67. URL url = null;
  68. URLConnection con = null;
  69. InputStream is = null;
  70. InputStreamReader isr = null;
  71. BufferedReader in = null;
  72.  
  73.  
  74. try
  75. {
  76. url = new URL(Config.VOTE_LINK_HOPZONE);
  77. con = url.openConnection();
  78. con.addRequestProperty("User-Agent", "L2HopZone");
  79. is = con.getInputStream();
  80. isr = new InputStreamReader(is);
  81. in = new BufferedReader(isr);
  82.  
  83.  
  84. String line;
  85. while ((line = br.readLine()) != null)
  86. {
  87. if (line.contains("rank anonymous tooltip"))
  88. {
  89. votes = Integer.valueOf(line.split(">")[2].replace("</span", ""));
  90. break;
  91. }
  92. }
  93.  
  94.  
  95. br.close();
  96. isr.close();
  97. }
  98. catch (Exception e)
  99. {
  100. if (Config.DEVELOPER)
  101. {
  102. e.printStackTrace();
  103. }
  104. }
  105. return votes;
  106. }
  107.  
  108.  
  109. protected static int getTopZoneVotes()
  110. {
  111. int votes = -1;
  112. URL url = null;
  113. URLConnection con = null;
  114. InputStream is = null;
  115. InputStreamReader isr = null;
  116. BufferedReader in = null;
  117. try
  118. {
  119. url = new URL(Config.VOTE_LINK_TOPZONE);
  120. con = url.openConnection();
  121. con.addRequestProperty("User-Agent", "L2TopZone");
  122. is = con.getInputStream();
  123. isr = new InputStreamReader(is);
  124. in = new BufferedReader(isr);
  125. String inputLine;
  126. while ((inputLine = in.readLine()) != null)
  127. {
  128. if (inputLine.contains("Votes"))
  129. {
  130. String votesLine = inputLine;
  131.  
  132.  
  133. votes = Integer.valueOf(votesLine.split(">")[3].replace("</div", ""));
  134. break;
  135. }
  136. }
  137. }
  138. catch (Exception e)
  139. {
  140. if (Config.DEVELOPER)
  141. {
  142. e.printStackTrace();
  143. }
  144. }
  145. return votes;
  146. }
  147.  
  148.  
  149. public static String hopCd(L2PcInstance player)
  150. {
  151. long hopCdMs = 0;
  152. long voteDelay = 43200000L;
  153. PreparedStatement statement = null;
  154. Connection con = null;
  155. try
  156. {
  157. con = L2DatabaseFactory.getInstance().getConnection();
  158. statement = con.prepareStatement("SELECT lastVoteHopzone FROM characters WHERE obj_Id=?");
  159. statement.setInt(1, player.getObjectId());
  160.  
  161.  
  162. ResultSet rset = statement.executeQuery();
  163.  
  164.  
  165. while (rset.next())
  166. {
  167. hopCdMs = rset.getLong("lastVoteHopzone");
  168. }
  169. }
  170. catch (Exception e)
  171. {
  172. _log.warning(" ");
  173. }
  174. finally
  175. {
  176. try
  177. {
  178. if (con != null)
  179. con.close();
  180. }
  181. catch (SQLException e)
  182. {
  183. _log.warning("Failed to close database connection!");
  184. }
  185. }
  186.  
  187.  
  188. SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
  189.  
  190.  
  191. Date resultdate = new Date(hopCdMs + voteDelay);
  192. return sdf.format(resultdate);
  193. }
  194.  
  195.  
  196. public static String topCd(L2PcInstance player)
  197. {
  198. long topCdMs = 0;
  199. long voteDelay = 43200000L;
  200. PreparedStatement statement = null;
  201. Connection con = null;
  202. try
  203. {
  204. con = L2DatabaseFactory.getInstance().getConnection();
  205. statement = con.prepareStatement("SELECT lastVoteTopzone FROM characters WHERE obj_Id=?");
  206. statement.setInt(1, player.getObjectId());
  207.  
  208.  
  209. ResultSet rset = statement.executeQuery();
  210.  
  211.  
  212. while (rset.next())
  213. {
  214. topCdMs = rset.getLong("lastVoteTopzone");
  215. }
  216. }
  217. catch (Exception e)
  218. {
  219. _log.warning(" ");
  220. }
  221. finally
  222. {
  223. try
  224. {
  225. if (con != null)
  226. con.close();
  227. }
  228. catch (SQLException e)
  229. {
  230. _log.warning("Failed to close database connection!");
  231. }
  232. }
  233.  
  234.  
  235. SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
  236.  
  237.  
  238. Date resultdate = new Date(topCdMs + voteDelay);
  239. return sdf.format(resultdate);
  240. }
  241.  
  242.  
  243. public static String whosVoting()
  244. {
  245. for (L2PcInstance voter : L2World.getInstance().getAllPlayers())
  246. {
  247. if (voter.isVoting())
  248. {
  249. return voter.getName();
  250. }
  251. }
  252. return "None";
  253. }
  254.  
  255.  
  256. public static void hopvote(final L2PcInstance player)
  257. {
  258. long lastVoteHopzone = 0L;
  259. long voteDelay = 43200000L;
  260. final int firstvoteshop;
  261.  
  262.  
  263. firstvoteshop = getHopZoneVotes();
  264.  
  265.  
  266. class hopvotetask implements Runnable
  267. {
  268. private final L2PcInstance p;
  269.  
  270.  
  271. public hopvotetask(L2PcInstance player)
  272. {
  273. p = player;
  274. }
  275.  
  276.  
  277. @Override
  278. public void run()
  279. {
  280. if (firstvoteshop < getHopZoneVotes())
  281. {
  282. p.setIsVoting(false);
  283. p.setIsImobilised(false);
  284. VoteManager.setHasVotedHop(player);
  285. p.sendMessage("Thank you for voting for us!");
  286. VoteManager.updateLastVoteHopzone(p);
  287. VoteManager.updateVotes(p);
  288. }
  289. else
  290. {
  291. p.setIsVoting(false);
  292. p.setIsImobilised(false);
  293. p.sendMessage("You did not vote.Please try again.");
  294. VoteManager.setTries(player, VoteManager.getTries(p) - 1);
  295. }
  296. }
  297.  
  298.  
  299. }
  300.  
  301.  
  302. PreparedStatement statement = null;
  303. Connection con = null;
  304. try
  305. {
  306. con = L2DatabaseFactory.getInstance().getConnection();
  307. statement = con.prepareStatement("SELECT lastVoteHopzone FROM characters WHERE obj_Id=?");
  308. statement.setInt(1, player.getObjectId());
  309.  
  310.  
  311. ResultSet rset = statement.executeQuery();
  312.  
  313.  
  314. while (rset.next())
  315. {
  316. lastVoteHopzone = rset.getLong("lastVoteHopzone");
  317. }
  318. }
  319. catch (Exception e)
  320. {
  321. _log.warning(" ");
  322. }
  323. finally
  324. {
  325. try
  326. {
  327. if (con != null)
  328. con.close();
  329. }
  330. catch (SQLException e)
  331. {
  332. _log.warning("Failed to close database connection!");
  333. }
  334. }
  335.  
  336.  
  337. if (getTries(player) <= 0)
  338. {
  339. player.sendMessage("Due to your multiple failures in voting you lost your chance to vote today");
  340. }
  341. else if (((lastVoteHopzone + voteDelay) < System.currentTimeMillis()) && (getTries(player) > 0))
  342. {
  343. for (L2PcInstance j : L2World.getInstance().getAllPlayers())
  344. {
  345. if (j.isVoting())
  346. {
  347. player.sendMessage("Someone is already voting.Wait for your turn please!");
  348. return;
  349. }
  350. }
  351.  
  352.  
  353. player.setIsVoting(true);
  354. player.setIsImobilised(true);
  355. player.sendMessage("Go fast on the site and vote on the hopzone banner!");
  356. player.sendMessage("You have " + Config.SECS_TO_VOTE + " seconds.Hurry!");
  357. ThreadPoolManager.getInstance().scheduleGeneral(new hopvotetask(player), Config.SECS_TO_VOTE * 1000);
  358. }
  359. else if ((getTries(player) <= 0) && ((lastVoteHopzone + voteDelay) < System.currentTimeMillis()))
  360. {
  361. for (L2PcInstance j : L2World.getInstance().getAllPlayers())
  362. {
  363. if (j.isVoting())
  364. {
  365. player.sendMessage("Someone is already voting.Wait for your turn please!");
  366. return;
  367. }
  368. }
  369.  
  370.  
  371. player.setIsVoting(true);
  372. player.setIsImobilised(true);
  373. player.sendMessage("Go fast on the site and vote on the hopzone banner!");
  374. player.sendMessage("You have " + Config.SECS_TO_VOTE + " seconds.Hurry!");
  375. ThreadPoolManager.getInstance().scheduleGeneral(new hopvotetask(player), Config.SECS_TO_VOTE * 1000);
  376.  
  377.  
  378. }
  379. else
  380. {
  381. player.sendMessage("12 hours have to pass till you are able to vote again.");
  382. }
  383.  
  384.  
  385. }
  386.  
  387.  
  388. public static void topvote(final L2PcInstance player)
  389. {
  390. long lastVoteTopzone = 0L;
  391. long voteDelay = 43200000L;
  392. final int firstvotestop;
  393.  
  394.  
  395. firstvotestop = getTopZoneVotes();
  396.  
  397.  
  398. class topvotetask implements Runnable
  399. {
  400. private final L2PcInstance p;
  401.  
  402.  
  403. public topvotetask(L2PcInstance player)
  404. {
  405. p = player;
  406. }
  407.  
  408.  
  409. @Override
  410. public void run()
  411. {
  412. if (firstvotestop < getTopZoneVotes())
  413. {
  414. p.setIsVoting(false);
  415. p.setIsImobilised(false);
  416. VoteManager.setHasVotedTop(p);
  417. p.sendMessage("Thank you for voting for us!");
  418. VoteManager.updateLastVoteTopzone(p);
  419. VoteManager.updateVotes(p);
  420. }
  421. else
  422. {
  423. p.setIsImobilised(false);
  424. p.sendMessage("You did not vote.Please try again.");
  425. VoteManager.setTries(p, VoteManager.getTries(p) - 1);
  426. }
  427. }
  428.  
  429.  
  430. }
  431.  
  432.  
  433. PreparedStatement statement = null;
  434. Connection con = null;
  435. try
  436. {
  437. con = L2DatabaseFactory.getInstance().getConnection();
  438. statement = con.prepareStatement("SELECT lastVoteTopzone FROM characters WHERE obj_Id=?");
  439. statement.setInt(1, player.getObjectId());
  440.  
  441.  
  442. ResultSet rset = statement.executeQuery();
  443.  
  444.  
  445. while (rset.next())
  446. {
  447. lastVoteTopzone = rset.getLong("lastVoteTopzone");
  448. }
  449. }
  450. catch (Exception e)
  451. {
  452. _log.warning(" ");
  453. }
  454. finally
  455. {
  456. try
  457. {
  458. if (con != null)
  459. con.close();
  460. }
  461. catch (SQLException e)
  462. {
  463. _log.warning("Failed to close database connection!");
  464. }
  465. }
  466.  
  467.  
  468. if (getTries(player) <= 0)
  469. {
  470. player.sendMessage("Due to your multiple failures in voting you lost your chance to vote today");
  471. }
  472. else if ((getTries(player) <= 0) && ((lastVoteTopzone + voteDelay) < System.currentTimeMillis()))
  473. {
  474. for (L2PcInstance j : L2World.getInstance().getAllPlayers())
  475. {
  476. if (j.isVoting())
  477. {
  478. player.sendMessage("Someone is already voting.Wait for your turn please!");
  479. return;
  480. }
  481. }
  482. player.setIsVoting(true);
  483. player.setIsImobilised(true);
  484. player.sendMessage("Go fast on the site and vote on the topzone banner!");
  485. player.sendMessage((new StringBuilder()).append("You have ").append(Config.SECS_TO_VOTE).append(" seconds.Hurry!").toString());
  486. ThreadPoolManager.getInstance().scheduleGeneral(new topvotetask(player), Config.SECS_TO_VOTE * 1000);
  487. }
  488. else if (((lastVoteTopzone + voteDelay) < System.currentTimeMillis()) && (getTries(player) > 0))
  489. {
  490. for (L2PcInstance j : L2World.getInstance().getAllPlayers())
  491. {
  492. if (j.isVoting())
  493. {
  494. player.sendMessage("Someone is already voting.Wait for your turn please!");
  495. return;
  496. }
  497. }
  498. player.setIsVoting(true);
  499. player.setIsImobilised(true);
  500. player.sendMessage("Go fast on the site and vote on the topzone banner!");
  501. player.sendMessage((new StringBuilder()).append("You have ").append(Config.SECS_TO_VOTE).append(" seconds.Hurry!").toString());
  502. ThreadPoolManager.getInstance().scheduleGeneral(new topvotetask(player), Config.SECS_TO_VOTE * 1000);
  503. }
  504. else
  505. {
  506. player.sendMessage("12 hours have to pass till you are able to vote again.");
  507. }
  508.  
  509.  
  510. }
  511.  
  512.  
  513. public static void hasVotedHop(L2PcInstance player)
  514. {
  515. int hasVotedHop = -1;
  516. Connection con = null;
  517. try
  518. {
  519. con = L2DatabaseFactory.getInstance().getConnection();
  520. PreparedStatement statement = con.prepareStatement("SELECT hasVotedHop FROM characters WHERE obj_Id=?");
  521. statement.setInt(1, player.getObjectId());
  522.  
  523.  
  524. ResultSet rset = statement.executeQuery();
  525.  
  526.  
  527. while (rset.next())
  528. {
  529. hasVotedHop = rset.getInt("hasVotedHop");
  530. }
  531.  
  532.  
  533. if (hasVotedHop == 1)
  534. {
  535. setHasVotedHop(true);
  536. }
  537. else if (hasVotedHop == 0)
  538. {
  539. setHasVotedHop(false);
  540. }
  541. }
  542. catch (Exception e)
  543. {
  544. _log.warning(" ");
  545. }
  546. finally
  547. {
  548. try
  549. {
  550. if (con != null)
  551. con.close();
  552. }
  553. catch (SQLException e)
  554. {
  555. _log.warning("Failed to close database connection!");
  556. }
  557. }
  558. }
  559.  
  560.  
  561. public static void hasVotedTop(L2PcInstance player)
  562. {
  563. int hasVotedTop = -1;
  564. Connection con = null;
  565. try
  566. {
  567. con = L2DatabaseFactory.getInstance().getConnection();
  568. PreparedStatement statement = con.prepareStatement("SELECT hasVotedTop FROM characters WHERE obj_Id=?");
  569. statement.setInt(1, player.getObjectId());
  570.  
  571.  
  572. ResultSet rset = statement.executeQuery();
  573.  
  574.  
  575. while (rset.next())
  576. {
  577. hasVotedTop = rset.getInt("hasVotedTop");
  578. }
  579.  
  580.  
  581. if (hasVotedTop == 1)
  582. {
  583. setHasVotedTop(true);
  584. }
  585. else if (hasVotedTop == 0)
  586. {
  587. setHasVotedTop(false);
  588. }
  589. }
  590. catch (Exception e)
  591. {
  592. _log.warning(" ");
  593. }
  594. finally
  595. {
  596. try
  597. {
  598. if (con != null)
  599. con.close();
  600. }
  601. catch (SQLException e)
  602. {
  603. _log.warning("Failed to close database connection!");
  604. }
  605. }
  606. }
  607.  
  608.  
  609. public static void updateVotes(L2PcInstance activeChar)
  610. {
  611. Connection con = null;
  612. try
  613. {
  614. con = L2DatabaseFactory.getInstance().getConnection();
  615. PreparedStatement statement = con.prepareStatement("UPDATE characters SET monthVotes=?, totalVotes=? WHERE obj_Id=?");
  616.  
  617.  
  618. statement.setInt(1, getMonthVotes(activeChar) + 1);
  619. statement.setInt(2, getTotalVotes(activeChar) + 1);
  620. statement.setInt(3, activeChar.getObjectId());
  621. statement.execute();
  622. statement.close();
  623. }
  624. catch (Exception e)
  625. {
  626. _log.warning(" ");
  627. }
  628. finally
  629. {
  630. try
  631. {
  632. if (con != null)
  633. con.close();
  634. }
  635. catch (SQLException e)
  636. {
  637. _log.warning("Failed to close database connection!");
  638. }
  639. }
  640. }
  641.  
  642.  
  643. public static void setHasVotedHop(L2PcInstance activeChar)
  644. {
  645. activeChar.setHop(true);
  646. Connection con = null;
  647. try
  648. {
  649. con = L2DatabaseFactory.getInstance().getConnection();
  650. PreparedStatement statement = con.prepareStatement("UPDATE characters SET hasVotedHop=? WHERE obj_Id=?");
  651.  
  652.  
  653. statement.setInt(1, 1);
  654. statement.setInt(2, activeChar.getObjectId());
  655. statement.execute();
  656. statement.close();
  657. }
  658. catch (Exception e)
  659. {
  660. _log.warning(" ");
  661. }
  662. finally
  663. {
  664. try
  665. {
  666. if (con != null)
  667. con.close();
  668. }
  669. catch (SQLException e)
  670. {
  671. _log.warning("Failed to close database connection!");
  672. }
  673. }
  674. }
  675.  
  676.  
  677. public static void setHasVotedTop(L2PcInstance activeChar)
  678. {
  679. activeChar.setTop(true);
  680. Connection con = null;
  681. try
  682. {
  683. con = L2DatabaseFactory.getInstance().getConnection();
  684. PreparedStatement statement = con.prepareStatement("UPDATE characters SET hasVotedTop=? WHERE obj_Id=?");
  685.  
  686.  
  687. statement.setInt(1, 1);
  688. statement.setInt(2, activeChar.getObjectId());
  689. statement.execute();
  690. statement.close();
  691. }
  692. catch (Exception e)
  693. {
  694. _log.warning(" ");
  695. }
  696. finally
  697. {
  698. try
  699. {
  700. if (con != null)
  701. con.close();
  702. }
  703. catch (SQLException e)
  704. {
  705. _log.warning("Failed to close database connection!");
  706. }
  707. }
  708. }
  709.  
  710.  
  711. public static void setHasNotVotedHop(L2PcInstance activeChar)
  712. {
  713. activeChar.setHop(false);
  714. Connection con = null;
  715. try
  716. {
  717. con = L2DatabaseFactory.getInstance().getConnection();
  718. PreparedStatement statement = con.prepareStatement("UPDATE characters SET hasVotedHop=? WHERE obj_Id=?");
  719.  
  720.  
  721. statement.setInt(1, 0);
  722. statement.setInt(2, activeChar.getObjectId());
  723. statement.execute();
  724. statement.close();
  725. }
  726. catch (Exception e)
  727. {
  728. _log.warning(" ");
  729. }
  730. finally
  731. {
  732. try
  733. {
  734. if (con != null)
  735. con.close();
  736. }
  737. catch (SQLException e)
  738. {
  739. _log.warning("Failed to close database connection!");
  740. }
  741. }
  742. }
  743.  
  744.  
  745. public static void setHasNotVotedTop(L2PcInstance activeChar)
  746. {
  747. activeChar.setTop(false);
  748. Connection con = null;
  749. try
  750. {
  751. con = L2DatabaseFactory.getInstance().getConnection();
  752. PreparedStatement statement = con.prepareStatement("UPDATE characters SET hasVotedTop=? WHERE obj_Id=?");
  753.  
  754.  
  755. statement.setInt(1, 0);
  756. statement.setInt(2, activeChar.getObjectId());
  757. statement.execute();
  758. statement.close();
  759. }
  760. catch (Exception e)
  761. {
  762. _log.warning(" ");
  763. }
  764. finally
  765. {
  766. try
  767. {
  768. if (con != null)
  769. con.close();
  770. }
  771. catch (SQLException e)
  772. {
  773. _log.warning("Failed to close database connection!");
  774. }
  775. }
  776. }
  777.  
  778.  
  779. public static int getTries(L2PcInstance player)
  780. {
  781. int tries = -1;
  782. Connection con = null;
  783. try
  784. {
  785. con = L2DatabaseFactory.getInstance().getConnection();
  786. PreparedStatement statement = con.prepareStatement("SELECT tries FROM characters WHERE obj_Id=?");
  787. statement.setInt(1, player.getObjectId());
  788. for (ResultSet rset = statement.executeQuery(); rset.next();)
  789. {
  790. tries = rset.getInt("tries");
  791. }
  792. }
  793. catch (Exception e)
  794. {
  795. _log.warning(" ");
  796. }
  797. finally
  798. {
  799. try
  800. {
  801. if (con != null)
  802. con.close();
  803. }
  804. catch (SQLException e)
  805. {
  806. _log.warning("Failed to close database connection!");
  807. }
  808. }
  809. return tries;
  810. }
  811.  
  812.  
  813. public static void setTries(L2PcInstance player, int tries)
  814. {
  815. Connection con = null;
  816. try
  817. {
  818. con = L2DatabaseFactory.getInstance().getConnection();
  819. PreparedStatement statement = con.prepareStatement("UPDATE characters SET tries=? WHERE obj_Id=?");
  820.  
  821.  
  822. statement.setInt(1, tries);
  823. statement.setInt(2, player.getObjectId());
  824. statement.execute();
  825. statement.close();
  826. }
  827. catch (Exception e)
  828. {
  829. _log.warning(" ");
  830. }
  831. finally
  832. {
  833. try
  834. {
  835. if (con != null)
  836. con.close();
  837. }
  838. catch (SQLException e)
  839. {
  840. _log.warning("Failed to close database connection!");
  841. }
  842. }
  843. }
  844.  
  845.  
  846. public static int getMonthVotes(L2PcInstance player)
  847. {
  848. int monthVotes = -1;
  849. Connection con = null;
  850. try
  851. {
  852. con = L2DatabaseFactory.getInstance().getConnection();
  853. PreparedStatement statement = con.prepareStatement("SELECT monthVotes FROM characters WHERE obj_Id=?");
  854.  
  855.  
  856. statement.setInt(1, player.getObjectId());
  857. for (ResultSet rset = statement.executeQuery(); rset.next();)
  858. {
  859. monthVotes = rset.getInt("monthVotes");
  860. }
  861. }
  862. catch (Exception e)
  863. {
  864. _log.warning(" ");
  865. }
  866. finally
  867. {
  868. try
  869. {
  870. if (con != null)
  871. con.close();
  872. }
  873. catch (SQLException e)
  874. {
  875. _log.warning("Failed to close database connection!");
  876. }
  877. }
  878. return monthVotes;
  879. }
  880.  
  881.  
  882. public static int getTotalVotes(L2PcInstance player)
  883. {
  884. int totalVotes = -1;
  885. Connection con = null;
  886. try
  887. {
  888. con = L2DatabaseFactory.getInstance().getConnection();
  889. PreparedStatement statement = con.prepareStatement("SELECT totalVotes FROM characters WHERE obj_Id=?");
  890.  
  891.  
  892. statement.setInt(1, player.getObjectId());
  893. for (ResultSet rset = statement.executeQuery(); rset.next();)
  894. {
  895. totalVotes = rset.getInt("totalVotes");
  896. }
  897. }
  898. catch (Exception e)
  899. {
  900. _log.warning(" ");
  901. }
  902. finally
  903. {
  904. try
  905. {
  906. if (con != null)
  907. con.close();
  908. }
  909. catch (SQLException e)
  910. {
  911. _log.warning("Failed to close database connection!");
  912. }
  913. }
  914. return totalVotes;
  915. }
  916.  
  917.  
  918. public static int getBigTotalVotes(L2PcInstance player)
  919. {
  920. int bigTotalVotes = -1;
  921. Connection con = null;
  922. try
  923. {
  924. con = L2DatabaseFactory.getInstance().getConnection();
  925. PreparedStatement statement = con.prepareStatement("SELECT SUM(totalVotes) FROM characters");
  926.  
  927.  
  928. for (ResultSet rset = statement.executeQuery(); rset.next();)
  929. {
  930. bigTotalVotes = rset.getInt("SUM(totalVotes)");
  931. }
  932. }
  933. catch (Exception e)
  934. {
  935. _log.warning(" ");
  936. }
  937. finally
  938. {
  939. try
  940. {
  941. if (con != null)
  942. con.close();
  943. }
  944. catch (SQLException e)
  945. {
  946. _log.warning("Failed to close database connection!");
  947. }
  948. }
  949. return bigTotalVotes;
  950. }
  951.  
  952.  
  953. public static int getBigMonthVotes(L2PcInstance player)
  954. {
  955. int bigMonthVotes = -1;
  956. Connection con = null;
  957. try
  958. {
  959. con = L2DatabaseFactory.getInstance().getConnection();
  960. PreparedStatement statement = con.prepareStatement("SELECT SUM(monthVotes) FROM characters");
  961.  
  962.  
  963. for (ResultSet rset = statement.executeQuery(); rset.next();)
  964. {
  965. bigMonthVotes = rset.getInt("SUM(monthVotes)");
  966. }
  967. }
  968. catch (Exception e)
  969. {
  970. _log.warning(" ");
  971. }
  972. finally
  973. {
  974. try
  975. {
  976. if (con != null)
  977. con.close();
  978. }
  979. catch (SQLException e)
  980. {
  981. _log.warning("Failed to close database connection!");
  982. }
  983. }
  984. return bigMonthVotes;
  985. }
  986.  
  987.  
  988. public static void updateLastVoteHopzone(L2PcInstance player)
  989. {
  990. Connection con = null;
  991. try
  992. {
  993. con = L2DatabaseFactory.getInstance().getConnection();
  994. PreparedStatement statement = con.prepareStatement("UPDATE characters SET lastVoteHopzone=? WHERE obj_Id=?");
  995. statement.setLong(1, System.currentTimeMillis());
  996. statement.setInt(2, player.getObjectId());
  997. statement.execute();
  998. }
  999. catch (Exception e)
  1000. {
  1001. _log.warning(" ");
  1002. }
  1003. finally
  1004. {
  1005. try
  1006. {
  1007. if (con != null)
  1008. con.close();
  1009. }
  1010. catch (SQLException e)
  1011. {
  1012. _log.warning("Failed to close database connection!");
  1013. }
  1014. }
  1015. }
  1016.  
  1017.  
  1018. public static void updateLastVoteTopzone(L2PcInstance player)
  1019. {
  1020. Connection con = null;
  1021. try
  1022. {
  1023. con = L2DatabaseFactory.getInstance().getConnection();
  1024. PreparedStatement statement = con.prepareStatement("UPDATE characters SET lastVoteTopzone=? WHERE obj_Id=?");
  1025. statement.setLong(1, System.currentTimeMillis());
  1026. statement.setInt(2, player.getObjectId());
  1027. statement.execute();
  1028. }
  1029. catch (Exception e)
  1030. {
  1031. _log.warning(" ");
  1032. }
  1033. finally
  1034. {
  1035. try
  1036. {
  1037. if (con != null)
  1038. con.close();
  1039. }
  1040. catch (SQLException e)
  1041. {
  1042. _log.warning("Failed to close database connection!");
  1043. }
  1044. }
  1045. }
  1046.  
  1047.  
  1048. // Getters and Setters
  1049. public static boolean hasVotedHop()
  1050. {
  1051. return hasVotedHop;
  1052. }
  1053.  
  1054.  
  1055. public static void setHasVotedHop(boolean hasVotedHop)
  1056. {
  1057. VoteManager.hasVotedHop = hasVotedHop;
  1058. }
  1059.  
  1060.  
  1061. public static boolean hasVotedTop()
  1062. {
  1063. return hasVotedTop;
  1064. }
  1065.  
  1066.  
  1067. public static void setHasVotedTop(boolean hasVotedTop)
  1068. {
  1069. VoteManager.hasVotedTop = hasVotedTop;
  1070. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement