AdminZone.java 7.8 KB

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