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.custom;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.util.logging.Logger;
- import net.sf.l2j.commons.concurrent.ThreadPool;
- import net.sf.l2j.Config;
- import net.sf.l2j.L2DatabaseFactory;
- import net.sf.l2j.gameserver.model.World;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage;
- /**
- * @author Melron
- *
- */
- public class VoteReminder
- {
- static final Logger _log = Logger.getLogger(VoteReminder.class.getName());
- protected void StartReminder()
- {
- for (L2PcInstance player : World.getInstance().getPlayers())
- if (player != null && (player.canVoteHopZone() || player.canVoteNetwork() || player.canVoteTopZone()))
- {
- boolean hopzone = false;
- boolean topzone = false;
- boolean network = false;
- if (player.canVoteHopZone())
- hopzone=true;
- if (player.canVoteNetwork())
- network=true;
- if (player.canVoteTopZone())
- topzone=true;
- if (!hopzone && !topzone && !network)
- return;
- String SitesForVote = "";
- if (hopzone && topzone && network)
- SitesForVote += "HopZone, TopZone and L2Network!";
- else if (hopzone && topzone && !network)
- SitesForVote += "HopZone and TopZone!";
- else if (hopzone && network && !topzone)
- SitesForVote += "HopZone and L2Network!";
- else if (topzone && network && !hopzone)
- SitesForVote += "TopZone and L2Network!";
- //single cases
- else if (network && !hopzone && !topzone)
- SitesForVote += "L2Network!";
- else if (hopzone && !topzone && !network)
- SitesForVote += "HopZone!";
- else
- SitesForVote += "TopZone!";
- if (!player.isVoting())
- player.sendPacket(new ExShowScreenMessage("Vote Reminder: You can vote in " + SitesForVote, 6000));
- }
- }
- protected VoteReminder()
- {
- ThreadPool.scheduleAtFixedRate(new VoteReminderC(), (60000 * Config.VOTE_REMINDER_MINUTES) , (60000 * Config.VOTE_REMINDER_MINUTES));
- }
- public static VoteReminder getInstance()
- {
- return SingletonHolder._instance;
- }
- private static class SingletonHolder
- {
- protected static final VoteReminder _instance = new VoteReminder();
- }
- protected class VoteReminderC implements Runnable
- {
- @Override
- public void run()
- {
- if(Config.ALLOW_VOTE_REMINDER)
- StartReminder();
- }
- }
- }
- ========================================================================================
- Config:
- @@ -54,6 +54,13 @@
- public static final String VOTE_MANAGER_FILE = "./config/VoteManager.properties";
- public static final String ENCHANT_SKILLS_MANAGER = "./config/EnchantSkillsManager.properties";
- public static final String PVP_COLOR_SYSTEM_FILE = "./config/PvPColorSystem.properties";
- + public static final String VOTE_REMINDER_FILE = "./config/VoteReminder.properties";
- +
- +
- + /** Vote Reminder */
- + public static boolean ALLOW_VOTE_REMINDER;
- + public static int VOTE_REMINDER_MINUTES;
- +
- @@ -798,6 +805,15 @@
- }
- + * Load Vote Reminder
- + */
- + private static final void loadVoteReminder()
- + {
- + final ExProperties voteReminder = initProperties(VOTE_REMINDER_FILE);
- + ALLOW_VOTE_REMINDER = voteReminder.getProperty("VoteReminderEnable", true);
- + VOTE_REMINDER_MINUTES = voteReminder.getProperty("MinutesDelay", 1);
- + }
- + /**
- * Loads clan and clan hall settings.
- */
- //load Vote Manager
- loadVoteManager();
- + //load Vote Reminder
- + loadVoteReminder();
- +
- =========================================================
- GameServer.java
- Olympiad.getInstance();
- Hero.getInstance();
- + if (Config.ALLOW_VOTE_REMINDER)
- + VoteReminder.getInstance();
- ============================================================
- L2PcInstance.java
- public boolean canVoteTopZone()
- {
- long LastTZVote = 0L;
- long voteDelay = 43200000L;
- try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement("SELECT LastTZVote FROM characters WHERE obj_Id=?");
- statement.setInt(1, getObjectId());
- ResultSet rset = statement.executeQuery();
- while (rset.next())
- {
- LastTZVote = rset.getLong("LastTZVote");
- }
- statement.close();
- rset.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- System.out.println("Vote Reminder: could not loadLastTZVote in characters " + e);
- return false;
- }
- return (LastTZVote + voteDelay) < System.currentTimeMillis();
- }
- public boolean canVoteHopZone()
- {
- long LastHZVote = 0L;
- long voteDelay = 43200000L;
- try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement("SELECT LastHZVote FROM characters WHERE obj_Id=?");
- statement.setInt(1, getObjectId());
- ResultSet rset = statement.executeQuery();
- while (rset.next())
- {
- LastHZVote = rset.getLong("LastHZVote");
- }
- statement.close();
- rset.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- System.out.println("Vote Reminder: could not loadLastHZVote in characters " + e);
- return false;
- }
- return (LastHZVote + voteDelay) < System.currentTimeMillis();
- }
- public boolean canVoteNetwork()
- {
- long LastNZVote = 0L;
- long voteDelay = 43200000L;
- try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement("SELECT LastNZVote FROM characters WHERE obj_Id=?");
- statement.setInt(1, getObjectId());
- ResultSet rset = statement.executeQuery();
- while (rset.next())
- {
- LastNZVote = rset.getLong("LastNZVote");
- }
- statement.close();
- rset.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- System.out.println("Vote Reminder: could not loadLastNZVote in characters " + e);
- return false;
- }
- return (LastNZVote + voteDelay) < System.currentTimeMillis();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement