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 com.l2jfrozen.gameserver.model.events;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.util.Calendar;
- import java.util.Date;
- import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jfrozen.gameserver.model.entity.Announcements;
- import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
- import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
- import com.l2jfrozen.util.database.L2DatabaseFactory;
- /**
- * @author Elfocrash
- *
- */
- public class PlayerOfTheHour
- {
- public static long getTimeToOclock()
- {
- Date d = new Date();
- Calendar c = Calendar.getInstance();
- c.setTime(d);
- c.add(Calendar.HOUR, 1);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- // System.out.print(c.getTime());
- long howMany = (c.getTimeInMillis()-d.getTime());
- return howMany;
- }
- public static String getNextHourToDate()
- {
- Date d = new Date();
- Calendar c = Calendar.getInstance();
- c.setTime(d);
- c.add(Calendar.HOUR, 1);
- return c.getTime().toString();
- }
- public static String getTimeToDate()
- {
- Date d = new Date();
- Calendar c = Calendar.getInstance();
- c.setTime(d);
- c.add(Calendar.HOUR, 1);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- return c.getTime().toString();
- }
- public static int getZonePvp(L2PcInstance activeChar)
- {
- int id=0;
- try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement("SELECT zone_pvp FROM characters WHERE obj_Id=?");
- statement.setInt(1, activeChar.getObjectId());
- ResultSet rset = statement.executeQuery();
- while (rset.next())
- {
- id = rset.getInt("zone_pvp");
- }
- rset.close();
- statement.close();
- }
- catch (Exception e)
- {
- }
- return id;
- }
- public static void addZonePvp(L2PcInstance activeChar)
- {
- try(Connection con = L2DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement("UPDATE characters SET zone_pvp=? WHERE obj_Id=?");
- statement.setInt(1, getZonePvp(activeChar) +1);
- statement.setInt(2, activeChar.getObjectId());
- statement.executeUpdate();
- statement.close();
- }
- catch(Exception e)
- {
- }
- }
- public static void resetZonePvp()
- {
- try(Connection con = L2DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement("UPDATE characters SET zone_pvp=0");
- statement.executeUpdate();
- statement.close();
- }
- catch(Exception e)
- {
- }
- }
- static int getTopZonePvpCount()
- {
- int id=0;
- try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement("SELECT zone_pvp FROM characters ORDER BY zone_pvp DESC LIMIT 1");
- ResultSet rset = statement.executeQuery();
- while (rset.next())
- {
- id = rset.getInt("zone_pvp");
- }
- rset.close();
- statement.close();
- }
- catch (Exception e)
- {
- }
- return id;
- }
- static String getTopZonePvpName()
- {
- String name = null;
- try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement("SELECT char_name FROM characters ORDER BY zone_pvp DESC LIMIT 1");
- ResultSet rset = statement.executeQuery();
- while (rset.next())
- {
- name = rset.getString("char_name");
- }
- rset.close();
- statement.close();
- }
- catch (Exception e)
- {
- }
- return name;
- }
- private PlayerOfTheHour()
- {
- }
- public static void getTopHtml(L2PcInstance activeChar)
- {
- NpcHtmlMessage htm = new NpcHtmlMessage(0);
- StringBuilder sb = new StringBuilder("<html><body>");
- sb.append("<center><br>Top 10 PvP:<br><br1>");
- Connection con = null;
- try
- {
- con = L2DatabaseFactory.getInstance().getConnection();
- PreparedStatement stm = con.prepareStatement("SELECT char_name,zone_pvp,accesslevel,online FROM characters ORDER BY zone_pvp DESC LIMIT 10");
- ResultSet rSet = stm.executeQuery();
- while (rSet.next())
- {
- int accessLevel = rSet.getInt("accesslevel");
- if (accessLevel > 0)
- {
- continue;
- }
- int pvpKills = rSet.getInt("zone_pvp");
- if (pvpKills == 0)
- {
- continue;
- }
- String pl = rSet.getString("char_name");
- sb.append("Player: <font color=\"LEVEL\">"+pl+"</font> PvPs: <font color=\"LEVEL\">"+pvpKills+"</font><br1>");
- }
- }
- catch (Exception e)
- {
- System.out.println("Error while selecting top 15 pvp from database.");
- }
- finally
- {
- try
- {
- if (con != null)
- con.close();
- }
- catch (Exception e)
- {}
- }
- sb.append("Next round: " + getTimeToDate() +"</body></html>");
- htm.setHtml(sb.toString());
- activeChar.sendPacket(htm);
- }
- public static void getInstance()
- {
- ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Runnable()
- {
- @Override
- public void run()
- {
- Announcements.getInstance().announceToAll("The Player of the Hour is " + getTopZonePvpName() + " with "+getTopZonePvpCount()+ " pvps");
- //TODO Your reward should go here.
- resetZonePvp();
- Announcements.getInstance().announceToAll("New Player of the Hour just started. Go to Primeval Isle and show us what you got.");
- Announcements.getInstance().announceToAll("This round will end at: " + getNextHourToDate() + ".");
- }
- }, getTimeToOclock() , 3600000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement