AdminZone.java 8.2 KB

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