AdminGeodata.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 com.l2jserver.Config;
  17. import com.l2jserver.gameserver.GeoData;
  18. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. /**
  21. * @author -Nemesiss-
  22. */
  23. public class AdminGeodata implements IAdminCommandHandler
  24. {
  25. private static final String[] ADMIN_COMMANDS =
  26. {
  27. "admin_geo_z",
  28. "admin_geo_type",
  29. "admin_geo_nswe",
  30. "admin_geo_los",
  31. "admin_geo_position",
  32. "admin_geo_bug",
  33. "admin_geo_load",
  34. "admin_geo_unload"
  35. };
  36. @Override
  37. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  38. {
  39. if (Config.GEODATA < 1)
  40. {
  41. activeChar.sendMessage("Geo Engine is Turned Off!");
  42. return true;
  43. }
  44. if (command.equals("admin_geo_z"))
  45. activeChar.sendMessage("GeoEngine: Geo_Z = " + GeoData.getInstance().getHeight(activeChar.getX(), activeChar.getY(), activeChar.getZ()) + " Loc_Z = " + activeChar.getZ());
  46. else if (command.equals("admin_geo_type"))
  47. {
  48. short type = GeoData.getInstance().getType(activeChar.getX(), activeChar.getY());
  49. activeChar.sendMessage("GeoEngine: Geo_Type = " + type);
  50. short height = GeoData.getInstance().getHeight(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  51. activeChar.sendMessage("GeoEngine: height = " + height);
  52. }
  53. else if (command.equals("admin_geo_nswe"))
  54. {
  55. String result = "";
  56. short nswe = GeoData.getInstance().getNSWE(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  57. if ((nswe & 8) == 0)
  58. result += " N";
  59. if ((nswe & 4) == 0)
  60. result += " S";
  61. if ((nswe & 2) == 0)
  62. result += " W";
  63. if ((nswe & 1) == 0)
  64. result += " E";
  65. activeChar.sendMessage("GeoEngine: Geo_NSWE -> " + nswe + "->" + result);
  66. }
  67. else if (command.equals("admin_geo_los"))
  68. {
  69. if (activeChar.getTarget() != null)
  70. {
  71. if (GeoData.getInstance().canSeeTargetDebug(activeChar, activeChar.getTarget()))
  72. activeChar.sendMessage("GeoEngine: Can See Target");
  73. else
  74. activeChar.sendMessage("GeoEngine: Can't See Target");
  75. }
  76. else
  77. activeChar.sendMessage("None Target!");
  78. }
  79. else if (command.equals("admin_geo_position"))
  80. {
  81. activeChar.sendMessage("GeoEngine: Your current position: ");
  82. activeChar.sendMessage(".... world coords: x: " + activeChar.getX() + " y: " + activeChar.getY() + " z: " + activeChar.getZ());
  83. activeChar.sendMessage(".... geo position: " + GeoData.getInstance().geoPosition(activeChar.getX(), activeChar.getY()));
  84. }
  85. else if (command.startsWith("admin_geo_load"))
  86. {
  87. String[] v = command.substring(15).split(" ");
  88. if (v.length != 2)
  89. activeChar.sendMessage("Usage: //admin_geo_load <regionX> <regionY>");
  90. else
  91. {
  92. try
  93. {
  94. byte rx = Byte.parseByte(v[0]);
  95. byte ry = Byte.parseByte(v[1]);
  96. boolean result = GeoData.loadGeodataFile(rx, ry);
  97. if (result)
  98. activeChar.sendMessage("GeoEngine: File for region [" + rx + "," + ry + "] loaded succesfuly");
  99. else
  100. activeChar.sendMessage("GeoEngine: File for region [" + rx + "," + ry + "] couldn't be loaded");
  101. }
  102. catch (Exception e)
  103. {
  104. activeChar.sendMessage("You have to write numbers of regions <regionX> <regionY>");
  105. }
  106. }
  107. }
  108. else if (command.startsWith("admin_geo_unload"))
  109. {
  110. String[] v = command.substring(17).split(" ");
  111. if (v.length != 2)
  112. activeChar.sendMessage("Usage: //admin_geo_unload <regionX> <regionY>");
  113. else
  114. {
  115. try
  116. {
  117. byte rx = Byte.parseByte(v[0]);
  118. byte ry = Byte.parseByte(v[1]);
  119. GeoData.unloadGeodata(rx, ry);
  120. activeChar.sendMessage("GeoEngine: File for region [" + rx + "," + ry + "] unloaded.");
  121. }
  122. catch (Exception e)
  123. {
  124. activeChar.sendMessage("You have to write numbers of regions <regionX> <regionY>");
  125. }
  126. }
  127. }
  128. else if (command.startsWith("admin_geo_bug"))
  129. {
  130. try
  131. {
  132. String comment = command.substring(14);
  133. GeoData.getInstance().addGeoDataBug(activeChar, comment);
  134. }
  135. catch (StringIndexOutOfBoundsException e)
  136. {
  137. activeChar.sendMessage("Usage: //admin_geo_bug you coments here");
  138. }
  139. }
  140. return true;
  141. }
  142. @Override
  143. public String[] getAdminCommandList()
  144. {
  145. return ADMIN_COMMANDS;
  146. }
  147. }