AdminInstance.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import java.util.StringTokenizer;
  21. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  22. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  23. import com.l2jserver.gameserver.model.L2Object;
  24. import com.l2jserver.gameserver.model.actor.L2Summon;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.entity.Instance;
  27. /**
  28. * @author evill33t, GodKratos
  29. */
  30. public class AdminInstance implements IAdminCommandHandler
  31. {
  32. private static final String[] ADMIN_COMMANDS =
  33. {
  34. "admin_setinstance",
  35. "admin_ghoston",
  36. "admin_ghostoff",
  37. "admin_createinstance",
  38. "admin_destroyinstance",
  39. "admin_listinstances"
  40. };
  41. @Override
  42. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  43. {
  44. StringTokenizer st = new StringTokenizer(command);
  45. st.nextToken();
  46. // create new instance
  47. if (command.startsWith("admin_createinstance"))
  48. {
  49. String[] parts = command.split(" ");
  50. if (parts.length != 3)
  51. {
  52. activeChar.sendMessage("Example: //createinstance <id> <templatefile> - ids => 300000 are reserved for dynamic instances");
  53. }
  54. else
  55. {
  56. try
  57. {
  58. final int id = Integer.parseInt(parts[1]);
  59. if ((id < 300000) && InstanceManager.getInstance().createInstanceFromTemplate(id, parts[2]))
  60. {
  61. activeChar.sendMessage("Instance created.");
  62. }
  63. else
  64. {
  65. activeChar.sendMessage("Failed to create instance.");
  66. }
  67. return true;
  68. }
  69. catch (Exception e)
  70. {
  71. activeChar.sendMessage("Failed loading: " + parts[1] + " " + parts[2]);
  72. return false;
  73. }
  74. }
  75. }
  76. else if (command.startsWith("admin_listinstances"))
  77. {
  78. for (Instance temp : InstanceManager.getInstance().getInstances().values())
  79. {
  80. activeChar.sendMessage("Id: " + temp.getId() + " Name: " + temp.getName());
  81. }
  82. }
  83. else if (command.startsWith("admin_setinstance"))
  84. {
  85. try
  86. {
  87. int val = Integer.parseInt(st.nextToken());
  88. if (InstanceManager.getInstance().getInstance(val) == null)
  89. {
  90. activeChar.sendMessage("Instance " + val + " doesnt exist.");
  91. return false;
  92. }
  93. L2Object target = activeChar.getTarget();
  94. if ((target == null) || (target instanceof L2Summon)) // Don't separate summons from masters
  95. {
  96. activeChar.sendMessage("Incorrect target.");
  97. return false;
  98. }
  99. target.setInstanceId(val);
  100. if (target instanceof L2PcInstance)
  101. {
  102. L2PcInstance player = (L2PcInstance) target;
  103. player.sendMessage("Admin set your instance to:" + val);
  104. player.teleToLocation(player.getLocation());
  105. }
  106. activeChar.sendMessage("Moved " + target.getName() + " to instance " + target.getInstanceId() + ".");
  107. return true;
  108. }
  109. catch (Exception e)
  110. {
  111. activeChar.sendMessage("Use //setinstance id");
  112. }
  113. }
  114. else if (command.startsWith("admin_destroyinstance"))
  115. {
  116. try
  117. {
  118. int val = Integer.parseInt(st.nextToken());
  119. InstanceManager.getInstance().destroyInstance(val);
  120. activeChar.sendMessage("Instance destroyed");
  121. }
  122. catch (Exception e)
  123. {
  124. activeChar.sendMessage("Use //destroyinstance id");
  125. }
  126. }
  127. // set ghost mode on aka not appearing on any knownlist
  128. // you will be invis to all players but you also dont get update packets ;)
  129. // you will see snapshots (knownlist echoes?) if you port
  130. // so kinda useless atm
  131. // TODO: enable broadcast packets for ghosts
  132. else if (command.startsWith("admin_ghoston"))
  133. {
  134. activeChar.getAppearance().setGhostMode(true);
  135. activeChar.sendMessage("Ghost mode enabled");
  136. activeChar.broadcastUserInfo();
  137. activeChar.decayMe();
  138. activeChar.spawnMe();
  139. }
  140. // ghost mode off
  141. else if (command.startsWith("admin_ghostoff"))
  142. {
  143. activeChar.getAppearance().setGhostMode(false);
  144. activeChar.sendMessage("Ghost mode disabled");
  145. activeChar.broadcastUserInfo();
  146. activeChar.decayMe();
  147. activeChar.spawnMe();
  148. }
  149. return true;
  150. }
  151. @Override
  152. public String[] getAdminCommandList()
  153. {
  154. return ADMIN_COMMANDS;
  155. }
  156. }