AdminInstance.java 5.0 KB

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