AdminZone.java 8.1 KB

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