AdminZone.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (C) 2004-2013 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.StringTokenizer;
  21. import com.l2jserver.gameserver.cache.HtmCache;
  22. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  23. import com.l2jserver.gameserver.instancemanager.MapRegionManager;
  24. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  25. import com.l2jserver.gameserver.model.L2World;
  26. import com.l2jserver.gameserver.model.L2WorldRegion;
  27. import com.l2jserver.gameserver.model.Location;
  28. import com.l2jserver.gameserver.model.TeleportWhereType;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  31. import com.l2jserver.gameserver.model.zone.ZoneId;
  32. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  33. import com.l2jserver.util.StringUtil;
  34. /**
  35. * Small typo fix by Zoey76 24/02/2011
  36. */
  37. public class AdminZone implements IAdminCommandHandler
  38. {
  39. private static final String[] ADMIN_COMMANDS =
  40. {
  41. "admin_zone_check",
  42. "admin_zone_visual",
  43. "admin_zone_visual_clear"
  44. };
  45. @Override
  46. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  47. {
  48. if (activeChar == null)
  49. {
  50. return false;
  51. }
  52. StringTokenizer st = new StringTokenizer(command, " ");
  53. String actualCommand = st.nextToken(); // Get actual command
  54. // String val = "";
  55. // if (st.countTokens() >= 1) {val = st.nextToken();}
  56. if (actualCommand.equalsIgnoreCase("admin_zone_check"))
  57. {
  58. showHtml(activeChar);
  59. activeChar.sendMessage("MapRegion: x:" + MapRegionManager.getInstance().getMapRegionX(activeChar.getX()) + " y:" + MapRegionManager.getInstance().getMapRegionY(activeChar.getY()) + " (" + MapRegionManager.getInstance().getMapRegionLocId(activeChar) + ")");
  60. getGeoRegionXY(activeChar);
  61. activeChar.sendMessage("Closest Town: " + MapRegionManager.getInstance().getClosestTownName(activeChar));
  62. Location loc;
  63. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, TeleportWhereType.CASTLE);
  64. activeChar.sendMessage("TeleToLocation (Castle): x:" + loc.getX() + " y:" + loc.getY() + " z:" + loc.getZ());
  65. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, TeleportWhereType.CLANHALL);
  66. activeChar.sendMessage("TeleToLocation (ClanHall): x:" + loc.getX() + " y:" + loc.getY() + " z:" + loc.getZ());
  67. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, TeleportWhereType.SIEGEFLAG);
  68. activeChar.sendMessage("TeleToLocation (SiegeFlag): x:" + loc.getX() + " y:" + loc.getY() + " z:" + loc.getZ());
  69. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, TeleportWhereType.TOWN);
  70. activeChar.sendMessage("TeleToLocation (Town): x:" + loc.getX() + " y:" + loc.getY() + " z:" + loc.getZ());
  71. }
  72. else if (actualCommand.equalsIgnoreCase("admin_zone_visual"))
  73. {
  74. String next = st.nextToken();
  75. if (next.equalsIgnoreCase("all"))
  76. {
  77. for (L2ZoneType zone : ZoneManager.getInstance().getZones(activeChar))
  78. {
  79. zone.visualizeZone(activeChar.getZ());
  80. }
  81. showHtml(activeChar);
  82. }
  83. else
  84. {
  85. int zoneId = Integer.parseInt(next);
  86. ZoneManager.getInstance().getZoneById(zoneId).visualizeZone(activeChar.getZ());
  87. }
  88. }
  89. else if (actualCommand.equalsIgnoreCase("admin_zone_visual_clear"))
  90. {
  91. ZoneManager.getInstance().clearDebugItems();
  92. showHtml(activeChar);
  93. }
  94. return true;
  95. }
  96. private static void showHtml(L2PcInstance activeChar)
  97. {
  98. final String htmContent = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/zone.htm");
  99. final NpcHtmlMessage adminReply = new NpcHtmlMessage();
  100. adminReply.setHtml(htmContent);
  101. adminReply.replace("%PEACE%", (activeChar.isInsideZone(ZoneId.PEACE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  102. adminReply.replace("%PVP%", (activeChar.isInsideZone(ZoneId.PVP) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  103. adminReply.replace("%SIEGE%", (activeChar.isInsideZone(ZoneId.SIEGE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  104. adminReply.replace("%TOWN%", (activeChar.isInsideZone(ZoneId.TOWN) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  105. adminReply.replace("%CASTLE%", (activeChar.isInsideZone(ZoneId.CASTLE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  106. adminReply.replace("%FORT%", (activeChar.isInsideZone(ZoneId.FORT) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  107. adminReply.replace("%HQ%", (activeChar.isInsideZone(ZoneId.HQ) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  108. adminReply.replace("%CLANHALL%", (activeChar.isInsideZone(ZoneId.CLAN_HALL) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  109. adminReply.replace("%LAND%", (activeChar.isInsideZone(ZoneId.LANDING) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  110. adminReply.replace("%NOLAND%", (activeChar.isInsideZone(ZoneId.NO_LANDING) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  111. adminReply.replace("%NOSUMMON%", (activeChar.isInsideZone(ZoneId.NO_SUMMON_FRIEND) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  112. adminReply.replace("%WATER%", (activeChar.isInsideZone(ZoneId.WATER) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  113. adminReply.replace("%SWAMP%", (activeChar.isInsideZone(ZoneId.SWAMP) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  114. adminReply.replace("%DANGER%", (activeChar.isInsideZone(ZoneId.DANGER_AREA) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  115. adminReply.replace("%NOSTORE%", (activeChar.isInsideZone(ZoneId.NO_STORE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  116. adminReply.replace("%SCRIPT%", (activeChar.isInsideZone(ZoneId.SCRIPT) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  117. StringBuilder zones = new StringBuilder(100);
  118. L2WorldRegion region = L2World.getInstance().getRegion(activeChar.getX(), activeChar.getY());
  119. for (L2ZoneType zone : region.getZones())
  120. {
  121. if (zone.isCharacterInZone(activeChar))
  122. {
  123. if (zone.getName() != null)
  124. {
  125. StringUtil.append(zones, zone.getName() + "<br1>");
  126. if (zone.getId() < 300000)
  127. {
  128. StringUtil.append(zones, "(", String.valueOf(zone.getId()), ")");
  129. }
  130. }
  131. else
  132. {
  133. StringUtil.append(zones, String.valueOf(zone.getId()));
  134. }
  135. StringUtil.append(zones, " ");
  136. }
  137. }
  138. adminReply.replace("%ZLIST%", zones.toString());
  139. activeChar.sendPacket(adminReply);
  140. }
  141. private static void getGeoRegionXY(L2PcInstance activeChar)
  142. {
  143. int worldX = activeChar.getX();
  144. int worldY = activeChar.getY();
  145. int geoX = ((((worldX - (-327680)) >> 4) >> 11) + 10);
  146. int geoY = ((((worldY - (-262144)) >> 4) >> 11) + 10);
  147. activeChar.sendMessage("GeoRegion: " + geoX + "_" + geoY + "");
  148. }
  149. @Override
  150. public String[] getAdminCommandList()
  151. {
  152. return ADMIN_COMMANDS;
  153. }
  154. }