Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package net.sf.l2j.gameserver.handler.voicedcommandhandlers;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import net.sf.l2j.L2DatabaseFactory;
- import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- /**
- * @author Melron
- */
- public class RemindVotes implements IVoicedCommandHandler
- {
- private static final String[] VOICED_COMMANDS =
- {
- "votes"
- };
- @Override
- public boolean useVoicedCommand(final String command, final L2PcInstance activeChar, final String target)
- {
- if (command.startsWith("votes"))
- getVoteRealTime(activeChar);
- return true;
- }
- public static void getVoteRealTime(L2PcInstance activeChar)
- {
- if (activeChar == null)
- return;
- long LastHZVote = 0L;
- long LastTZVote = 0L;
- long LastNZvote = 0L;
- long voteDelay = 43200000L;
- try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statementHZ = con.prepareStatement("SELECT LastHZVote FROM characters WHERE obj_Id=?");
- statementHZ.setInt(1, activeChar.getObjectId());
- ResultSet HZrset = statementHZ.executeQuery();
- while (HZrset.next())
- {
- LastHZVote = HZrset.getLong("LastHZVote");
- }
- statementHZ.close();
- HZrset.close();
- PreparedStatement statementTZ = con.prepareStatement("SELECT LastTZVote FROM characters WHERE obj_Id=?");
- statementTZ.setInt(1, activeChar.getObjectId());
- ResultSet TZrset = statementTZ.executeQuery();
- while (TZrset.next())
- {
- LastTZVote = TZrset.getLong("LastTZVote");
- }
- statementTZ.close();
- TZrset.close();
- PreparedStatement statementNZ = con.prepareStatement("SELECT LastNZVote FROM characters WHERE obj_Id=?");
- statementNZ.setInt(1, activeChar.getObjectId());
- ResultSet NZrset = statementNZ.executeQuery();
- while (NZrset.next())
- {
- LastNZvote = NZrset.getLong("LastNZVote");
- }
- statementNZ.close();
- NZrset.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- System.out.println("Remind Votes: " + e);
- }
- long HZtime = LastHZVote + voteDelay;
- long TZtime = LastTZVote + voteDelay;
- long NZtime = LastNZvote + voteDelay;
- long remainingTime;
- int hours;
- int minutes;
- int seconds;
- if (HZtime >= System.currentTimeMillis())
- {
- remainingTime = (HZtime - System.currentTimeMillis()) / 1000;
- hours = (int) (remainingTime / 3600);
- minutes = (int) ((remainingTime % 3600) / 60);
- seconds = (int) ((remainingTime % 3600) % 60);
- String msg = "Hopzone: You have to wait %hours% hours, %mins% minutes and %secs% seconds!";
- msg = msg.replaceAll("%hours%", Integer.toString(hours));
- msg = msg.replaceAll("%mins%", Integer.toString(minutes));
- msg = msg.replaceAll("%secs%", Integer.toString(seconds));
- activeChar.sendMessage(msg);
- }
- else
- activeChar.sendMessage("Hopzone: You can vote!");
- if (TZtime >= System.currentTimeMillis())
- {
- remainingTime = (TZtime - System.currentTimeMillis()) / 1000;
- hours = (int) (remainingTime / 3600);
- minutes = (int) ((remainingTime % 3600) / 60);
- seconds = (int) ((remainingTime % 3600) % 60);
- String msg = "Topzone: You have to wait %hours% hours, %mins% minutes and %secs% seconds!";
- msg = msg.replaceAll("%hours%", Integer.toString(hours));
- msg = msg.replaceAll("%mins%", Integer.toString(minutes));
- msg = msg.replaceAll("%secs%", Integer.toString(seconds));
- activeChar.sendMessage(msg);
- }
- else
- activeChar.sendMessage("Topzone: You can vote!");
- if (NZtime >= System.currentTimeMillis())
- {
- remainingTime = (NZtime - System.currentTimeMillis()) / 1000;
- hours = (int) (remainingTime / 3600);
- minutes = (int) ((remainingTime % 3600) / 60);
- seconds = (int) ((remainingTime % 3600) % 60);
- String msg = "Network: You have to wait %hours% hours, %mins% minutes and %secs% seconds!";
- msg = msg.replaceAll("%hours%", Integer.toString(hours));
- msg = msg.replaceAll("%mins%", Integer.toString(minutes));
- msg = msg.replaceAll("%secs%", Integer.toString(seconds));
- activeChar.sendMessage(msg);
- }
- else
- activeChar.sendMessage("Network: You can vote!");
- }
- @Override
- public String[] getVoicedCommandList()
- {
- return VOICED_COMMANDS;
- }
- }
- ===================================================================
- VoicedCommandHandler.java
- // coloque aqui os comandos
- registerHandler(new TvTEventCommand());
- + registerHandler(new RemindVotes());
- ====================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement