Package commands.admin

Source Code of commands.admin.AdminShutdown

package commands.admin;

import l2p.Config;
import l2p.extensions.scripts.ScriptFile;
import l2p.gameserver.GameTimeController;
import l2p.gameserver.Shutdown;
import l2p.gameserver.handler.AdminCommandHandler;
import l2p.gameserver.handler.IAdminCommandHandler;
import l2p.gameserver.model.L2ObjectsStorage;
import l2p.gameserver.model.L2Player;
import l2p.gameserver.serverpackets.NpcHtmlMessage;
import l2p.gameserver.taskmanager.MemoryWatchDog;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class AdminShutdown implements IAdminCommandHandler, ScriptFile
{
  private static enum Commands
  {
    admin_server_shutdown,
    admin_server_restart,
    admin_server_abort
  }

  public boolean useAdminCommand(Enum comm, String[] wordList, String fullString, L2Player activeChar)
  {
    Commands command = (Commands) comm;
    if(!activeChar.getPlayerAccess().CanRestart)
    {
      return false;
    }
    try
    {
      switch(command)
      {
        case admin_server_shutdown:
          serverShutdown(activeChar, Integer.parseInt(wordList[1]), false);
          break;
        case admin_server_restart:
          serverShutdown(activeChar, Integer.parseInt(wordList[1]), true);
          break;
        case admin_server_abort:
          serverAbort(activeChar);
          break;
      }
    }
    catch(Exception e)
    {
      sendHtmlForm(activeChar);
    }
    return true;
  }

  public Enum[] getAdminCommandEnum()
  {
    return Commands.values();
  }

  private void sendHtmlForm(L2Player activeChar)
  {
    NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
    int t = GameTimeController.getInstance().getGameTime();
    int h = t / 60;
    int m = t % 60;
    SimpleDateFormat format = new SimpleDateFormat("h:mm a");
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, h);
    cal.set(Calendar.MINUTE, m);
    StringBuffer replyMSG = new StringBuffer("<html><body>");
    replyMSG.append("<table width=260><tr>");
    replyMSG.append("<td width=40><button value=\"Main\" action=\"bypass -h admin_admin\" width=40 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
    replyMSG.append("<td width=180><center>Server Management Menu</center></td>");
    replyMSG.append("<td width=40><button value=\"Back\" action=\"bypass -h admin_admin\" width=40 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
    replyMSG.append("</tr></table>");
    replyMSG.append("<br><br>");
    replyMSG.append("<table>");
    replyMSG.append("<tr><td>Players Online: " + L2ObjectsStorage.getAllPlayersCount() + "</td></tr>");
    replyMSG.append("<tr><td>Used Memory: " + MemoryWatchDog.getMemUsedMb() + "</td></tr>");
    replyMSG.append("<tr><td>Server Rates: " + Config.RATE_XP + "x, " + Config.RATE_SP + "x, " + Config.RATE_DROP_ADENA + "x, " + Config.RATE_DROP_ITEMS + "x</td></tr>");
    replyMSG.append("<tr><td>Game Time: " + format.format(cal.getTime()) + "</td></tr>");
    replyMSG.append("</table><br>");
    replyMSG.append("<table width=270>");
    replyMSG.append("<tr><td>Enter in seconds the time till the server shutdowns bellow:</td></tr>");
    replyMSG.append("<br>");
    replyMSG.append("<tr><td><center>Seconds till: <edit var=\"shutdown_time\" width=60></center></td></tr>");
    replyMSG.append("</table><br>");
    replyMSG.append("<center><table><tr><td>");
    replyMSG.append("<button value=\"Shutdown\" action=\"bypass -h admin_server_shutdown $shutdown_time\" width=60 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td><td>");
    replyMSG.append("<button value=\"Restart\" action=\"bypass -h admin_server_restart $shutdown_time\" width=60 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td><td>");
    replyMSG.append("<button value=\"Abort\" action=\"bypass -h admin_server_abort\" width=60 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\">");
    replyMSG.append("</td></tr></table></center>");
    replyMSG.append("</body></html>");
    adminReply.setHtml(replyMSG.toString());
    activeChar.sendPacket(adminReply);
  }

  private void serverShutdown(L2Player activeChar, int seconds, boolean restart)
  {
    Shutdown.getInstance().startShutdown(activeChar, seconds, restart);
  }

  private void serverAbort(L2Player activeChar)
  {
    Shutdown.getInstance().abort(activeChar);
  }

  public void onLoad()
  {
    AdminCommandHandler.getInstance().registerAdminCommandHandler(this);
  }

  public void onReload()
  {
  }

  public void onShutdown()
  {
  }
}
TOP

Related Classes of commands.admin.AdminShutdown

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.