AdminZone.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. /**
  42. *
  43. * @see com.l2jserver.gameserver.handler.IAdminCommandHandler#useAdminCommand(java.lang.String, com.l2jserver.gameserver.model.actor.instance.L2PcInstance)
  44. */
  45. @Override
  46. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  47. {
  48. if (activeChar == null)
  49. return false;
  50. StringTokenizer st = new StringTokenizer(command, " ");
  51. String actualCommand = st.nextToken(); // Get actual command
  52. //String val = "";
  53. //if (st.countTokens() >= 1) {val = st.nextToken();}
  54. if (actualCommand.equalsIgnoreCase("admin_zone_check"))
  55. {
  56. showHtml(activeChar);
  57. activeChar.sendMessage("MapRegion: x:" + MapRegionManager.getInstance().getMapRegionX(activeChar.getX()) + " y:" + MapRegionManager.getInstance().getMapRegionY(activeChar.getY()) + " ("+MapRegionManager.getInstance().getMapRegion(activeChar).getLocId()+")");
  58. getGeoRegionXY(activeChar);
  59. activeChar.sendMessage("Closest Town: " + MapRegionManager.getInstance().getClosestTownName(activeChar));
  60. Location loc;
  61. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, MapRegionManager.TeleportWhereType.Castle);
  62. activeChar.sendMessage("TeleToLocation (Castle): x:" + loc.getX() + " y:" + loc.getY() + " z:" + loc.getZ());
  63. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, MapRegionManager.TeleportWhereType.ClanHall);
  64. activeChar.sendMessage("TeleToLocation (ClanHall): x:" + loc.getX() + " y:" + loc.getY() + " z:" + loc.getZ());
  65. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, MapRegionManager.TeleportWhereType.SiegeFlag);
  66. activeChar.sendMessage("TeleToLocation (SiegeFlag): x:" + loc.getX() + " y:" + loc.getY() + " z:" + loc.getZ());
  67. loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, MapRegionManager.TeleportWhereType.Town);
  68. activeChar.sendMessage("TeleToLocation (Town): x:" + loc.getX() + " y:" + loc.getY() + " z:" + loc.getZ());
  69. }
  70. else if (actualCommand.equalsIgnoreCase("admin_zone_reload"))
  71. {
  72. ZoneManager.getInstance().reload();
  73. activeChar.sendMessage("All Zones have been reloaded");
  74. }
  75. else if (actualCommand.equalsIgnoreCase("admin_zone_visual"))
  76. {
  77. String next = st.nextToken();
  78. if (next.equalsIgnoreCase("all"))
  79. {
  80. for (L2ZoneType zone : ZoneManager.getInstance().getZones(activeChar))
  81. {
  82. zone.visualizeZone(activeChar.getZ());
  83. }
  84. showHtml(activeChar);
  85. }
  86. else
  87. {
  88. int zoneId = Integer.parseInt(next);
  89. ZoneManager.getInstance().getZoneById(zoneId).visualizeZone(activeChar.getZ());
  90. }
  91. }
  92. else if (actualCommand.equalsIgnoreCase("admin_zone_visual_clear"))
  93. {
  94. ZoneManager.getInstance().clearDebugItems();
  95. showHtml(activeChar);
  96. }
  97. return true;
  98. }
  99. private static void showHtml(L2PcInstance activeChar)
  100. {
  101. final String htmContent = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/zone.htm");
  102. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  103. adminReply.setHtml(htmContent);
  104. adminReply.replace("%PEACE%", (activeChar.isInsideZone(L2Character.ZONE_PEACE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  105. adminReply.replace("%PVP%", (activeChar.isInsideZone(L2Character.ZONE_PVP) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  106. adminReply.replace("%SIEGE%", (activeChar.isInsideZone(L2Character.ZONE_SIEGE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  107. adminReply.replace("%TOWN%", (activeChar.isInsideZone(L2Character.ZONE_TOWN) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  108. adminReply.replace("%CASTLE%", (activeChar.isInsideZone(L2Character.ZONE_CASTLE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  109. adminReply.replace("%FORT%", (activeChar.isInsideZone(L2Character.ZONE_FORT) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  110. adminReply.replace("%HQ%", (activeChar.isInsideZone(L2Character.ZONE_HQ) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  111. adminReply.replace("%CLANHALL%", (activeChar.isInsideZone(L2Character.ZONE_CLANHALL) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  112. adminReply.replace("%LAND%", (activeChar.isInsideZone(L2Character.ZONE_LANDING) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  113. adminReply.replace("%NOLAND%", (activeChar.isInsideZone(L2Character.ZONE_NOLANDING) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  114. adminReply.replace("%NOSUMMON%", (activeChar.isInsideZone(L2Character.ZONE_NOSUMMONFRIEND) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  115. adminReply.replace("%WATER%", (activeChar.isInsideZone(L2Character.ZONE_WATER) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  116. adminReply.replace("%SWAMP%", (activeChar.isInsideZone(L2Character.ZONE_SWAMP) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  117. adminReply.replace("%DANGER%", (activeChar.isInsideZone(L2Character.ZONE_DANGERAREA) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  118. adminReply.replace("%NOSTORE%", (activeChar.isInsideZone(L2Character.ZONE_NOSTORE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  119. adminReply.replace("%SCRIPT%", (activeChar.isInsideZone(L2Character.ZONE_SCRIPT) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
  120. StringBuilder zones = new StringBuilder(100);
  121. L2WorldRegion region = L2World.getInstance().getRegion(activeChar.getX(), activeChar.getY());
  122. for (L2ZoneType zone : region.getZones())
  123. {
  124. if(zone.isCharacterInZone(activeChar))
  125. {
  126. if (zone.getName() != null)
  127. {
  128. StringUtil.append(zones, zone.getName() + "<br1>");
  129. if (zone.getId() < 300000) // not display id for dynamic zones
  130. StringUtil.append(zones, "(", String.valueOf(zone.getId()), ")");
  131. }
  132. else
  133. StringUtil.append(zones, String.valueOf(zone.getId()));
  134. StringUtil.append(zones, " ");
  135. }
  136. }
  137. adminReply.replace("%ZLIST%", zones.toString());
  138. activeChar.sendPacket(adminReply);
  139. }
  140. private static void getGeoRegionXY(L2PcInstance activeChar)
  141. {
  142. int worldX = activeChar.getX();
  143. int worldY = activeChar.getY();
  144. int geoX = ((((worldX - (-327680)) >> 4) >> 11)+10);
  145. int geoY = ((((worldY - (-262144)) >> 4) >> 11)+10);
  146. activeChar.sendMessage("GeoRegion: "+geoX+"_"+geoY+"");
  147. }
  148. /**
  149. *
  150. * @see com.l2jserver.gameserver.handler.IAdminCommandHandler#getAdminCommandList()
  151. */
  152. @Override
  153. public String[] getAdminCommandList()
  154. {
  155. return ADMIN_COMMANDS;
  156. }
  157. }