AdminInstance.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.handler.IAdminCommandHandler;
  18. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.actor.L2Summon;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.entity.Instance;
  23. /**
  24. * @author evill33t, GodKratos
  25. *
  26. */
  27. public class AdminInstance implements IAdminCommandHandler
  28. {
  29. private static final String[] ADMIN_COMMANDS =
  30. {
  31. "admin_setinstance",
  32. "admin_ghoston",
  33. "admin_ghostoff",
  34. "admin_createinstance",
  35. "admin_destroyinstance",
  36. "admin_listinstances"
  37. };
  38. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  39. {
  40. StringTokenizer st = new StringTokenizer(command);
  41. st.nextToken();
  42. // create new instance
  43. if (command.startsWith("admin_createinstance"))
  44. {
  45. String[] parts = command.split(" ");
  46. if (parts.length < 2)
  47. {
  48. activeChar.sendMessage("Example: //createinstance <id> <templatefile> - ids => 300000 are reserved for dynamic instances");
  49. }
  50. else
  51. {
  52. try
  53. {
  54. int id = Integer.parseInt(parts[1]);
  55. if (InstanceManager.getInstance().createInstanceFromTemplate(id, parts[2]) && id < 300000)
  56. {
  57. activeChar.sendMessage("Instance created");
  58. return true;
  59. }
  60. else
  61. {
  62. activeChar.sendMessage("Failed to create instance");
  63. return true;
  64. }
  65. }
  66. catch (Exception e)
  67. {
  68. activeChar.sendMessage("Failed loading: " + parts[2]);
  69. return false;
  70. }
  71. }
  72. }
  73. else if (command.startsWith("admin_listinstances"))
  74. {
  75. for (Instance temp : InstanceManager.getInstance().getInstances().values())
  76. {
  77. activeChar.sendMessage("Id: " + temp.getId() + " Name: " + temp.getName());
  78. }
  79. }
  80. else if (command.startsWith("admin_setinstance"))
  81. {
  82. try
  83. {
  84. int val = Integer.parseInt(st.nextToken());
  85. if (InstanceManager.getInstance().getInstance(val) == null)
  86. {
  87. activeChar.sendMessage("Instance " + val + " doesnt exist.");
  88. return false;
  89. }
  90. else
  91. {
  92. L2Object target = activeChar.getTarget();
  93. if (target == null || target instanceof L2Summon) // Don't separate summons from masters
  94. {
  95. activeChar.sendMessage("Incorrect target.");
  96. return false;
  97. }
  98. target.setInstanceId(val);
  99. if (target instanceof L2PcInstance)
  100. {
  101. L2PcInstance player = (L2PcInstance) target;
  102. player.sendMessage("Admin set your instance to:" + val);
  103. player.teleToLocation(player.getX(), player.getY(), player.getZ());
  104. L2Summon pet = player.getPet();
  105. if (pet != null)
  106. {
  107. pet.setInstanceId(val);
  108. pet.teleToLocation(pet.getX(), pet.getY(), pet.getZ());
  109. player.sendMessage("Admin set " + pet.getName() + "'s instance to:" + val);
  110. }
  111. }
  112. activeChar.sendMessage("Moved " + target.getName() + " to instance " + target.getInstanceId() + ".");
  113. return true;
  114. }
  115. }
  116. catch (Exception e)
  117. {
  118. activeChar.sendMessage("Use //setinstance id");
  119. }
  120. }
  121. else if (command.startsWith("admin_destroyinstance"))
  122. {
  123. try
  124. {
  125. int val = Integer.parseInt(st.nextToken());
  126. InstanceManager.getInstance().destroyInstance(val);
  127. activeChar.sendMessage("Instance destroyed");
  128. }
  129. catch (Exception e)
  130. {
  131. activeChar.sendMessage("Use //destroyinstance id");
  132. }
  133. }
  134. // set ghost mode on aka not appearing on any knownlist
  135. // you will be invis to all players but you also dont get update packets ;)
  136. // you will see snapshots (knownlist echoes?) if you port
  137. // so kinda useless atm
  138. // TODO: enable broadcast packets for ghosts
  139. else if (command.startsWith("admin_ghoston"))
  140. {
  141. activeChar.getAppearance().setGhostMode(true);
  142. activeChar.sendMessage("Ghost mode enabled");
  143. activeChar.broadcastUserInfo();
  144. activeChar.decayMe();
  145. activeChar.spawnMe();
  146. }
  147. // ghost mode off
  148. else if (command.startsWith("admin_ghostoff"))
  149. {
  150. activeChar.getAppearance().setGhostMode(false);
  151. activeChar.sendMessage("Ghost mode disabled");
  152. activeChar.broadcastUserInfo();
  153. activeChar.decayMe();
  154. activeChar.spawnMe();
  155. }
  156. return true;
  157. }
  158. public String[] getAdminCommandList()
  159. {
  160. return ADMIN_COMMANDS;
  161. }
  162. }