Advertisement
tobaJK

Vote Reminder

Feb 19th, 2017
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.85 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. package net.sf.l2j.custom;
  16.  
  17.  
  18. import java.sql.Connection;
  19. import java.sql.PreparedStatement;
  20. import java.sql.ResultSet;
  21. import java.util.logging.Logger;
  22.  
  23. import net.sf.l2j.commons.concurrent.ThreadPool;
  24.  
  25. import net.sf.l2j.Config;
  26. import net.sf.l2j.L2DatabaseFactory;
  27. import net.sf.l2j.gameserver.model.World;
  28. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  29. import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage;
  30.  
  31. /**
  32.  * @author Melron
  33.  *
  34.  */
  35. public class VoteReminder
  36. {
  37.     static final Logger _log = Logger.getLogger(VoteReminder.class.getName());
  38.  
  39.    
  40.    protected void StartReminder()
  41.    {
  42.            
  43.        for (L2PcInstance player : World.getInstance().getPlayers())
  44.            if (player != null && (player.canVoteHopZone() || player.canVoteNetwork() || player.canVoteTopZone()))
  45.            {
  46.                
  47.                boolean hopzone = false;
  48.                boolean topzone = false;
  49.                boolean network = false;
  50.                
  51.                if (player.canVoteHopZone())
  52.                    hopzone=true;
  53.                if (player.canVoteNetwork())  
  54.                    network=true;
  55.                if (player.canVoteTopZone())
  56.                    topzone=true;
  57.                
  58.                if (!hopzone && !topzone && !network)
  59.                    return;
  60.                
  61.                String SitesForVote = "";
  62.                if (hopzone && topzone && network)
  63.                    SitesForVote += "HopZone, TopZone and L2Network!";
  64.                
  65.                else if (hopzone && topzone && !network)
  66.                    SitesForVote += "HopZone and TopZone!";
  67.                else if (hopzone && network && !topzone)
  68.                    SitesForVote += "HopZone and L2Network!";
  69.                else if (topzone && network && !hopzone)
  70.                    SitesForVote += "TopZone and L2Network!";
  71.                
  72.                //single cases
  73.                else if (network && !hopzone && !topzone)
  74.                    SitesForVote += "L2Network!";
  75.                else if (hopzone && !topzone && !network)
  76.                    SitesForVote += "HopZone!";
  77.                else
  78.                    SitesForVote += "TopZone!";
  79.                
  80.                if (!player.isVoting())
  81.                    player.sendPacket(new ExShowScreenMessage("Vote Reminder: You can vote in " + SitesForVote, 6000));
  82.            }       
  83.    }
  84.  
  85.    protected VoteReminder()
  86.    {
  87.        ThreadPool.scheduleAtFixedRate(new VoteReminderC(), (60000 * Config.VOTE_REMINDER_MINUTES) , (60000 * Config.VOTE_REMINDER_MINUTES));
  88.    }
  89.  
  90.    public static VoteReminder getInstance()
  91.    {
  92.        return SingletonHolder._instance;
  93.    }
  94.    
  95.    private static class SingletonHolder
  96.    {
  97.        protected static final VoteReminder _instance = new VoteReminder();
  98.    }
  99.    
  100.    protected class VoteReminderC implements Runnable
  101.    {
  102.        @Override
  103.        public void run()
  104.        {
  105.            if(Config.ALLOW_VOTE_REMINDER)
  106.                StartReminder();    
  107.        }
  108.    }  
  109. }
  110.  
  111.  
  112.  
  113. ========================================================================================
  114. Config:
  115.  
  116. @@ -54,6 +54,13 @@
  117.         public static final String VOTE_MANAGER_FILE = "./config/VoteManager.properties";
  118.         public static final String ENCHANT_SKILLS_MANAGER = "./config/EnchantSkillsManager.properties";
  119.         public static final String PVP_COLOR_SYSTEM_FILE = "./config/PvPColorSystem.properties";
  120. +       public static final String VOTE_REMINDER_FILE = "./config/VoteReminder.properties";
  121. +      
  122. +      
  123. +       /** Vote Reminder */
  124. +       public static boolean ALLOW_VOTE_REMINDER;
  125. +       public static int VOTE_REMINDER_MINUTES;
  126. +  
  127.    
  128.     @@ -798,6 +805,15 @@
  129. }
  130. +        * Load Vote Reminder
  131. +        */
  132. +       private static final void loadVoteReminder()
  133. +       {
  134. +           final ExProperties voteReminder = initProperties(VOTE_REMINDER_FILE);
  135. +           ALLOW_VOTE_REMINDER = voteReminder.getProperty("VoteReminderEnable", true);
  136. +           VOTE_REMINDER_MINUTES = voteReminder.getProperty("MinutesDelay", 1);
  137. +       }
  138. +       /**
  139. * Loads clan and clan hall settings.
  140. */
  141.             //load Vote Manager
  142.             loadVoteManager();
  143.  
  144. +           //load Vote Reminder
  145. +           loadVoteReminder();
  146. +          
  147.  
  148. =========================================================
  149. GameServer.java
  150.             Olympiad.getInstance();
  151.             Hero.getInstance();
  152.  
  153. +           if (Config.ALLOW_VOTE_REMINDER)
  154. +               VoteReminder.getInstance();
  155.  
  156. ============================================================
  157. L2PcInstance.java
  158.  
  159. public boolean canVoteTopZone()
  160.     {
  161.         long LastTZVote = 0L;
  162.         long voteDelay = 43200000L;
  163.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  164.         {
  165.             PreparedStatement statement = con.prepareStatement("SELECT LastTZVote FROM characters WHERE obj_Id=?");
  166.             statement.setInt(1, getObjectId());
  167.            
  168.             ResultSet rset = statement.executeQuery();
  169.            
  170.             while (rset.next())
  171.             {
  172.                 LastTZVote = rset.getLong("LastTZVote");
  173.             }
  174.             statement.close();
  175.             rset.close();
  176.            
  177.         }
  178.         catch (Exception e)
  179.         {
  180.             e.printStackTrace();
  181.             System.out.println("Vote Reminder: could not loadLastTZVote in characters " + e);
  182.             return false;
  183.         }
  184.        
  185.         return (LastTZVote + voteDelay) < System.currentTimeMillis();  
  186.     }
  187.     public boolean canVoteHopZone()
  188.     {
  189.         long LastHZVote = 0L;
  190.         long voteDelay = 43200000L;
  191.        
  192.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  193.         {
  194.             PreparedStatement statement = con.prepareStatement("SELECT LastHZVote FROM characters WHERE obj_Id=?");
  195.             statement.setInt(1, getObjectId());
  196.            
  197.             ResultSet rset = statement.executeQuery();
  198.            
  199.             while (rset.next())
  200.             {
  201.                 LastHZVote = rset.getLong("LastHZVote");
  202.             }
  203.             statement.close();
  204.             rset.close();
  205.         }
  206.         catch (Exception e)
  207.         {
  208.             e.printStackTrace();
  209.             System.out.println("Vote Reminder: could not loadLastHZVote in characters " + e);
  210.             return false;
  211.         }
  212.        
  213.         return (LastHZVote + voteDelay) < System.currentTimeMillis();
  214.     }
  215.     public boolean canVoteNetwork()
  216.     {  
  217.         long LastNZVote = 0L;
  218.         long voteDelay = 43200000L;
  219.        
  220.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  221.         {
  222.             PreparedStatement statement = con.prepareStatement("SELECT LastNZVote FROM characters WHERE obj_Id=?");
  223.             statement.setInt(1, getObjectId());
  224.             ResultSet rset = statement.executeQuery();
  225.            
  226.             while (rset.next())
  227.             {
  228.                 LastNZVote = rset.getLong("LastNZVote");
  229.             }
  230.             statement.close();
  231.             rset.close();
  232.            
  233.         }
  234.         catch (Exception e)
  235.         {
  236.             e.printStackTrace();
  237.             System.out.println("Vote Reminder: could not loadLastNZVote in characters " + e);
  238.             return false;
  239.         }
  240.        
  241.         return (LastNZVote + voteDelay) < System.currentTimeMillis();
  242.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement