Advertisement
tobaJK

Untitled

Feb 19th, 2017
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 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. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15.  
  16. package net.sf.l2j.gameserver.handler.voicedcommandhandlers;
  17.  
  18. import java.sql.Connection;
  19. import java.sql.PreparedStatement;
  20. import java.sql.ResultSet;
  21.  
  22. import net.sf.l2j.L2DatabaseFactory;
  23. import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  25.  
  26. /**
  27. * @author Melron
  28. */
  29.  
  30. public class RemindVotes implements IVoicedCommandHandler
  31. {
  32. private static final String[] VOICED_COMMANDS =
  33. {
  34. "votes"
  35. };
  36.  
  37. @Override
  38. public boolean useVoicedCommand(final String command, final L2PcInstance activeChar, final String target)
  39. {
  40. if (command.startsWith("votes"))
  41. getVoteRealTime(activeChar);
  42. return true;
  43. }
  44.  
  45. public static void getVoteRealTime(L2PcInstance activeChar)
  46. {
  47. if (activeChar == null)
  48. return;
  49.  
  50. long LastHZVote = 0L;
  51. long LastTZVote = 0L;
  52. long LastNZvote = 0L;
  53. long voteDelay = 43200000L;
  54.  
  55. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  56. {
  57. PreparedStatement statementHZ = con.prepareStatement("SELECT LastHZVote FROM characters WHERE obj_Id=?");
  58. statementHZ.setInt(1, activeChar.getObjectId());
  59. ResultSet HZrset = statementHZ.executeQuery();
  60.  
  61. while (HZrset.next())
  62. {
  63. LastHZVote = HZrset.getLong("LastHZVote");
  64. }
  65. statementHZ.close();
  66. HZrset.close();
  67.  
  68. PreparedStatement statementTZ = con.prepareStatement("SELECT LastTZVote FROM characters WHERE obj_Id=?");
  69. statementTZ.setInt(1, activeChar.getObjectId());
  70. ResultSet TZrset = statementTZ.executeQuery();
  71.  
  72. while (TZrset.next())
  73. {
  74. LastTZVote = TZrset.getLong("LastTZVote");
  75. }
  76. statementTZ.close();
  77. TZrset.close();
  78.  
  79. PreparedStatement statementNZ = con.prepareStatement("SELECT LastNZVote FROM characters WHERE obj_Id=?");
  80. statementNZ.setInt(1, activeChar.getObjectId());
  81. ResultSet NZrset = statementNZ.executeQuery();
  82.  
  83. while (NZrset.next())
  84. {
  85. LastNZvote = NZrset.getLong("LastNZVote");
  86. }
  87. statementNZ.close();
  88. NZrset.close();
  89. }
  90. catch (Exception e)
  91. {
  92. e.printStackTrace();
  93. System.out.println("Remind Votes: " + e);
  94. }
  95.  
  96. long HZtime = LastHZVote + voteDelay;
  97. long TZtime = LastTZVote + voteDelay;
  98. long NZtime = LastNZvote + voteDelay;
  99. long remainingTime;
  100. int hours;
  101. int minutes;
  102. int seconds;
  103.  
  104. if (HZtime >= System.currentTimeMillis())
  105. {
  106. remainingTime = (HZtime - System.currentTimeMillis()) / 1000;
  107. hours = (int) (remainingTime / 3600);
  108. minutes = (int) ((remainingTime % 3600) / 60);
  109. seconds = (int) ((remainingTime % 3600) % 60);
  110.  
  111. String msg = "Hopzone: You have to wait %hours% hours, %mins% minutes and %secs% seconds!";
  112. msg = msg.replaceAll("%hours%", Integer.toString(hours));
  113. msg = msg.replaceAll("%mins%", Integer.toString(minutes));
  114. msg = msg.replaceAll("%secs%", Integer.toString(seconds));
  115. activeChar.sendMessage(msg);
  116. }
  117. else
  118. activeChar.sendMessage("Hopzone: You can vote!");
  119.  
  120. if (TZtime >= System.currentTimeMillis())
  121. {
  122. remainingTime = (TZtime - System.currentTimeMillis()) / 1000;
  123. hours = (int) (remainingTime / 3600);
  124. minutes = (int) ((remainingTime % 3600) / 60);
  125. seconds = (int) ((remainingTime % 3600) % 60);
  126.  
  127. String msg = "Topzone: You have to wait %hours% hours, %mins% minutes and %secs% seconds!";
  128. msg = msg.replaceAll("%hours%", Integer.toString(hours));
  129. msg = msg.replaceAll("%mins%", Integer.toString(minutes));
  130. msg = msg.replaceAll("%secs%", Integer.toString(seconds));
  131. activeChar.sendMessage(msg);
  132. }
  133. else
  134. activeChar.sendMessage("Topzone: You can vote!");
  135.  
  136. if (NZtime >= System.currentTimeMillis())
  137. {
  138. remainingTime = (NZtime - System.currentTimeMillis()) / 1000;
  139. hours = (int) (remainingTime / 3600);
  140. minutes = (int) ((remainingTime % 3600) / 60);
  141. seconds = (int) ((remainingTime % 3600) % 60);
  142.  
  143. String msg = "Network: You have to wait %hours% hours, %mins% minutes and %secs% seconds!";
  144. msg = msg.replaceAll("%hours%", Integer.toString(hours));
  145. msg = msg.replaceAll("%mins%", Integer.toString(minutes));
  146. msg = msg.replaceAll("%secs%", Integer.toString(seconds));
  147. activeChar.sendMessage(msg);
  148. }
  149. else
  150. activeChar.sendMessage("Network: You can vote!");
  151. }
  152.  
  153.  
  154. @Override
  155. public String[] getVoicedCommandList()
  156. {
  157. return VOICED_COMMANDS;
  158. }
  159. }
  160. ===================================================================
  161. VoicedCommandHandler.java
  162. // coloque aqui os comandos
  163. registerHandler(new TvTEventCommand());
  164. + registerHandler(new RemindVotes());
  165. ====================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement