AdminZone.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package handlers.admincommandhandlers;
  16. import java.util.StringTokenizer;
  17. import com.l2jserver.gameserver.cache.HtmCache;
  18. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  19. import com.l2jserver.gameserver.instancemanager.MapRegionManager;
  20. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  21. import com.l2jserver.gameserver.model.L2World;
  22. import com.l2jserver.gameserver.model.L2WorldRegion;
  23. import com.l2jserver.gameserver.model.Location;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  27. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  28. import com.l2jserver.util.StringUtil;
  29. /**
  30. * Small typo fix by Zoey76 24/02/2011
  31. */
  32. public class AdminZone implements IAdminCommandHandler
  33. {
  34. private static final String[] ADMIN_COMMANDS =
  35. {
  36. "admin_zone_check",
  37. "admin_zone_reload",
  38. "admin_zone_visual",
  39. "admin_zone_visual_clear"
  40. };
  41. @Override
  42. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  43. {
  44. if (activeChar == null)
  45. return false;
  46. StringTokenizer st = new StringTokenizer(command, " ");
  47. String actualCommand = st.nextToken(); // Get actual command
  48. //String val = "";
  49. //if (st.countTokens() >= 1) {val = st.nextToken();}
  50. if (actualCommand.equalsIgnoreCase("admin_zone_check"))
  51. {
  52. showHtml(activeChar);
  53. activeChar.sendMessage("MapRegion: x:" + MapRegionManager.getInstance().getMapRegionX(activeChar.getX()) + " y:" + MapRegionManager.getInstance().getMapRegionY(activeChar.getY()) + " ("+MapRegionManager.getInstance().getMapRegionLocId(activeChar)+")");
  54. getGeoRegionXY(activeChar);
  55. activeChar.sendMessage("Closest Town: " + MapRegionManager.getInstance().getClosestTownName(activeChar));
  56. Location loc;
  57. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, MapRegionManager.TeleportWhereType.Castle);
  58. activeChar.sendMessage("TeleToLocation (Castle): x:" + loc.getX() + " y:" + loc.getY() + " z:" + loc.getZ());
  59. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, MapRegionManager.TeleportWhereType.ClanHall);
  60. activeChar.sendMessage("TeleToLocation (ClanHall): x:" + loc.getX() + " y:" + loc.getY() + " z:" + loc.getZ());
  61. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, MapRegionManager.TeleportWhereType.SiegeFlag);
  62. activeChar.sendMessage("TeleToLocation (SiegeFlag): x:" + loc.getX() + " y:" + loc.getY() + " z:" + loc.getZ());
  63. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, MapRegionManager.TeleportWhereType.Town);
  64. activeChar.sendMessage("TeleToLocation (Town): x:" + loc.getX() + " y:" + loc.getY() + " z:" + loc.getZ());
  65. }
  66. else if (actualCommand.equalsIgnoreCase("admin_zone_reload"))
  67. {
  68. ZoneManager.getInstance().reload();
  69. activeChar.sendMessage("All Zones have been reloaded");
  70. }
  71. else if (actualCommand.equalsIgnoreCase("admin_zone_visual"))
  72. {
  73. String next = st.nextToken();
  74. if (next.equalsIgnoreCase("all"))
  75. {
  76. for (L2ZoneType zone : ZoneManager.getInstance().getZones(activeChar))
  77. {
  78. zone.visualizeZone(activeChar.getZ());
  79. }
  80. showHtml(activeChar);
  81. }
  82. else
  83. {
  84. int zoneId = Integer.parseInt(next);
  85. ZoneManager.getInstance().getZoneById(zoneId).visualizeZone(activeChar.getZ());
  86. }
  87. }
  88. else if (actualCommand.equalsIgnoreCase("admin_zone_visual_clear"))
  89. {
  90. ZoneManager.getInstance().clearDebugItems();
  91. showHtml(activeChar);
  92. }
  93. return true;
  94. }
  95. private static void showHtml(L2PcInstance activeChar)
  96. {
  97. final String htmContent = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/zone.htm");
  98. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  99. adminReply.setHtml(htmContent);
  100. adminReply.replace("%PEACE%", (activeChar.isInsideZone(L2Character.ZONE_PEACE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  101. adminReply.replace("%PVP%", (activeChar.isInsideZone(L2Character.ZONE_PVP) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  102. adminReply.replace("%SIEGE%", (activeChar.isInsideZone(L2Character.ZONE_SIEGE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  103. adminReply.replace("%TOWN%", (activeChar.isInsideZone(L2Character.ZONE_TOWN) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  104. adminReply.replace("%CASTLE%", (activeChar.isInsideZone(L2Character.ZONE_CASTLE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  105. adminReply.replace("%FORT%", (activeChar.isInsideZone(L2Character.ZONE_FORT) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  106. adminReply.replace("%HQ%", (activeChar.isInsideZone(L2Character.ZONE_HQ) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  107. adminReply.replace("%CLANHALL%", (activeChar.isInsideZone(L2Character.ZONE_CLANHALL) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  108. adminReply.replace("%LAND%", (activeChar.isInsideZone(L2Character.ZONE_LANDING) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  109. adminReply.replace("%NOLAND%", (activeChar.isInsideZone(L2Character.ZONE_NOLANDING) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  110. adminReply.replace("%NOSUMMON%", (activeChar.isInsideZone(L2Character.ZONE_NOSUMMONFRIEND) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  111. adminReply.replace("%WATER%", (activeChar.isInsideZone(L2Character.ZONE_WATER) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  112. adminReply.replace("%SWAMP%", (activeChar.isInsideZone(L2Character.ZONE_SWAMP) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  113. adminReply.replace("%DANGER%", (activeChar.isInsideZone(L2Character.ZONE_DANGERAREA) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  114. adminReply.replace("%NOSTORE%", (activeChar.isInsideZone(L2Character.ZONE_NOSTORE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  115. adminReply.replace("%SCRIPT%", (activeChar.isInsideZone(L2Character.ZONE_SCRIPT) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  116. StringBuilder zones = new StringBuilder(100);
  117. L2WorldRegion region = L2World.getInstance().getRegion(activeChar.getX(), activeChar.getY());
  118. for (L2ZoneType zone : region.getZones())
  119. {
  120. if(zone.isCharacterInZone(activeChar))
  121. {
  122. if (zone.getName() != null)
  123. {
  124. StringUtil.append(zones, zone.getName() + "<br1>");
  125. if (zone.getId() < 300000) // not display id for dynamic zones
  126. StringUtil.append(zones, "(", String.valueOf(zone.getId()), ")");
  127. }
  128. else
  129. StringUtil.append(zones, String.valueOf(zone.getId()));
  130. StringUtil.append(zones, " ");
  131. }
  132. }
  133. adminReply.replace("%ZLIST%", zones.toString());
  134. activeChar.sendPacket(adminReply);
  135. }
  136. private static void getGeoRegionXY(L2PcInstance activeChar)
  137. {
  138. int worldX = activeChar.getX();
  139. int worldY = activeChar.getY();
  140. int geoX = ((((worldX - (-327680)) >> 4) >> 11)+10);
  141. int geoY = ((((worldY - (-262144)) >> 4) >> 11)+10);
  142. activeChar.sendMessage("GeoRegion: "+geoX+"_"+geoY+"");
  143. }
  144. @Override
  145. public String[] getAdminCommandList()
  146. {
  147. return ADMIN_COMMANDS;
  148. }
  149. }