AdminInstanceZone.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import java.util.Map;
  21. import java.util.StringTokenizer;
  22. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  23. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  24. import com.l2jserver.gameserver.model.L2World;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  27. import com.l2jserver.gameserver.util.GMAudit;
  28. import com.l2jserver.util.StringUtil;
  29. public class AdminInstanceZone implements IAdminCommandHandler
  30. {
  31. private static final String[] ADMIN_COMMANDS =
  32. {
  33. "admin_instancezone",
  34. "admin_instancezone_clear"
  35. };
  36. @Override
  37. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  38. {
  39. String target = (activeChar.getTarget() != null) ? activeChar.getTarget().getName() : "no-target";
  40. GMAudit.auditGMAction(activeChar.getName(), command, target, "");
  41. if (command.startsWith("admin_instancezone_clear"))
  42. {
  43. try
  44. {
  45. StringTokenizer st = new StringTokenizer(command, " ");
  46. st.nextToken();
  47. final L2PcInstance player = L2World.getInstance().getPlayer(st.nextToken());
  48. final int instanceId = Integer.parseInt(st.nextToken());
  49. final String name = InstanceManager.getInstance().getInstanceIdName(instanceId);
  50. InstanceManager.getInstance().deleteInstanceTime(player.getObjectId(), instanceId);
  51. activeChar.sendMessage("Instance zone " + name + " cleared for player " + player.getName());
  52. player.sendMessage("Admin cleared instance zone " + name + " for you");
  53. return true;
  54. }
  55. catch (Exception e)
  56. {
  57. activeChar.sendMessage("Failed clearing instance time: " + e.getMessage());
  58. activeChar.sendMessage("Usage: //instancezone_clear <playername> [instanceId]");
  59. return false;
  60. }
  61. }
  62. else if (command.startsWith("admin_instancezone"))
  63. {
  64. StringTokenizer st = new StringTokenizer(command, " ");
  65. command = st.nextToken();
  66. if (st.hasMoreTokens())
  67. {
  68. L2PcInstance player = null;
  69. String playername = st.nextToken();
  70. try
  71. {
  72. player = L2World.getInstance().getPlayer(playername);
  73. }
  74. catch (Exception e)
  75. {
  76. }
  77. if (player != null)
  78. {
  79. display(player, activeChar);
  80. }
  81. else
  82. {
  83. activeChar.sendMessage("The player " + playername + " is not online");
  84. activeChar.sendMessage("Usage: //instancezone [playername]");
  85. return false;
  86. }
  87. }
  88. else if (activeChar.getTarget() != null)
  89. {
  90. if (activeChar.getTarget() instanceof L2PcInstance)
  91. {
  92. display((L2PcInstance) activeChar.getTarget(), activeChar);
  93. }
  94. }
  95. else
  96. {
  97. display(activeChar, activeChar);
  98. }
  99. }
  100. return true;
  101. }
  102. @Override
  103. public String[] getAdminCommandList()
  104. {
  105. return ADMIN_COMMANDS;
  106. }
  107. private void display(L2PcInstance player, L2PcInstance activeChar)
  108. {
  109. Map<Integer, Long> instanceTimes = InstanceManager.getInstance().getAllInstanceTimes(player.getObjectId());
  110. final StringBuilder html = StringUtil.startAppend(500 + (instanceTimes.size() * 200), "<html><center><table width=260><tr>" + "<td width=40><button value=\"Main\" action=\"bypass -h admin_admin\" width=40 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>" + "<td width=180><center>Character Instances</center></td>" + "<td width=40><button value=\"Back\" action=\"bypass -h admin_current_player\" width=40 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>" + "</tr></table><br><font color=\"LEVEL\">Instances for ", player.getName(), "</font><center><br>" + "<table>" + "<tr><td width=150>Name</td><td width=50>Time</td><td width=70>Action</td></tr>");
  111. for (int id : instanceTimes.keySet())
  112. {
  113. int hours = 0;
  114. int minutes = 0;
  115. long remainingTime = (instanceTimes.get(id) - System.currentTimeMillis()) / 1000;
  116. if (remainingTime > 0)
  117. {
  118. hours = (int) (remainingTime / 3600);
  119. minutes = (int) ((remainingTime % 3600) / 60);
  120. }
  121. StringUtil.append(html, "<tr><td>", InstanceManager.getInstance().getInstanceIdName(id), "</td><td>", String.valueOf(hours), ":", String.valueOf(minutes), "</td><td><button value=\"Clear\" action=\"bypass -h admin_instancezone_clear ", player.getName(), " ", String.valueOf(id), "\" width=60 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  122. }
  123. StringUtil.append(html, "</table></html>");
  124. final NpcHtmlMessage ms = new NpcHtmlMessage();
  125. ms.setHtml(html.toString());
  126. activeChar.sendPacket(ms);
  127. }
  128. }