AdminExpSp.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 java.util.logging.Logger;
  18. import com.l2jserver.Config;
  19. import com.l2jserver.gameserver.datatables.ClassListData;
  20. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  21. import com.l2jserver.gameserver.model.L2Object;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  25. /**
  26. * This class handles following admin commands:
  27. * <li> add_exp_sp_to_character <i>shows menu for add or remove</i>
  28. * <li> add_exp_sp exp sp <i>Adds exp & sp to target, displays menu if a parameter is missing</i>
  29. * <li> remove_exp_sp exp sp <i>Removes exp & sp from target, displays menu if a parameter is missing</i>
  30. * @version $Revision: 1.2.4.6 $ $Date: 2005/04/11 10:06:06 $
  31. */
  32. public class AdminExpSp implements IAdminCommandHandler
  33. {
  34. private static Logger _log = Logger.getLogger(AdminExpSp.class.getName());
  35. private static final String[] ADMIN_COMMANDS =
  36. {
  37. "admin_add_exp_sp_to_character",
  38. "admin_add_exp_sp",
  39. "admin_remove_exp_sp"
  40. };
  41. @Override
  42. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  43. {
  44. if (command.startsWith("admin_add_exp_sp"))
  45. {
  46. try
  47. {
  48. String val = command.substring(16);
  49. if (!adminAddExpSp(activeChar, val))
  50. activeChar.sendMessage("Usage: //add_exp_sp exp sp");
  51. }
  52. catch (StringIndexOutOfBoundsException e)
  53. { //Case of missing parameter
  54. activeChar.sendMessage("Usage: //add_exp_sp exp sp");
  55. }
  56. }
  57. else if (command.startsWith("admin_remove_exp_sp"))
  58. {
  59. try
  60. {
  61. String val = command.substring(19);
  62. if (!adminRemoveExpSP(activeChar, val))
  63. activeChar.sendMessage("Usage: //remove_exp_sp exp sp");
  64. }
  65. catch (StringIndexOutOfBoundsException e)
  66. { //Case of missing parameter
  67. activeChar.sendMessage("Usage: //remove_exp_sp exp sp");
  68. }
  69. }
  70. addExpSp(activeChar);
  71. return true;
  72. }
  73. @Override
  74. public String[] getAdminCommandList()
  75. {
  76. return ADMIN_COMMANDS;
  77. }
  78. private void addExpSp(L2PcInstance activeChar)
  79. {
  80. L2Object target = activeChar.getTarget();
  81. L2PcInstance player = null;
  82. if (target instanceof L2PcInstance)
  83. player = (L2PcInstance) target;
  84. else
  85. {
  86. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  87. return;
  88. }
  89. final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  90. adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/expsp.htm");
  91. adminReply.replace("%name%", player.getName());
  92. adminReply.replace("%level%", String.valueOf(player.getLevel()));
  93. adminReply.replace("%xp%", String.valueOf(player.getExp()));
  94. adminReply.replace("%sp%", String.valueOf(player.getSp()));
  95. adminReply.replace("%class%", ClassListData.getInstance().getClass(player.getClassId()).getClientCode());
  96. activeChar.sendPacket(adminReply);
  97. }
  98. private boolean adminAddExpSp(L2PcInstance activeChar, String ExpSp)
  99. {
  100. L2Object target = activeChar.getTarget();
  101. L2PcInstance player = null;
  102. if (target instanceof L2PcInstance)
  103. {
  104. player = (L2PcInstance) target;
  105. }
  106. else
  107. {
  108. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  109. return false;
  110. }
  111. StringTokenizer st = new StringTokenizer(ExpSp);
  112. if (st.countTokens() != 2)
  113. {
  114. return false;
  115. }
  116. String exp = st.nextToken();
  117. String sp = st.nextToken();
  118. long expval = 0;
  119. int spval = 0;
  120. try
  121. {
  122. expval = Long.parseLong(exp);
  123. spval = Integer.parseInt(sp);
  124. }
  125. catch (Exception e)
  126. {
  127. return false;
  128. }
  129. if (expval != 0 || spval != 0)
  130. {
  131. //Common character information
  132. player.sendMessage("Admin is adding you " + expval + " xp and " + spval + " sp.");
  133. player.addExpAndSp(expval, spval);
  134. //Admin information
  135. activeChar.sendMessage("Added " + expval + " xp and " + spval + " sp to " + player.getName() + ".");
  136. if (Config.DEBUG)
  137. _log.fine("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ") added " + expval + " xp and " + spval + " sp to " + player.getObjectId() + ".");
  138. }
  139. return true;
  140. }
  141. private boolean adminRemoveExpSP(L2PcInstance activeChar, String ExpSp)
  142. {
  143. L2Object target = activeChar.getTarget();
  144. L2PcInstance player = null;
  145. if (target instanceof L2PcInstance)
  146. {
  147. player = (L2PcInstance) target;
  148. }
  149. else
  150. {
  151. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  152. return false;
  153. }
  154. StringTokenizer st = new StringTokenizer(ExpSp);
  155. if (st.countTokens() != 2)
  156. {
  157. return false;
  158. }
  159. String exp = st.nextToken();
  160. String sp = st.nextToken();
  161. long expval = 0;
  162. int spval = 0;
  163. try
  164. {
  165. expval = Long.parseLong(exp);
  166. spval = Integer.parseInt(sp);
  167. }
  168. catch (Exception e)
  169. {
  170. return false;
  171. }
  172. if (expval != 0 || spval != 0)
  173. {
  174. //Common character information
  175. player.sendMessage("Admin is removing you " + expval + " xp and " + spval + " sp.");
  176. player.removeExpAndSp(expval, spval);
  177. //Admin information
  178. activeChar.sendMessage("Removed " + expval + " xp and " + spval + " sp from " + player.getName() + ".");
  179. if (Config.DEBUG)
  180. _log.fine("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ") removed " + expval + " xp and " + spval + " sp from " + player.getObjectId() + ".");
  181. }
  182. return true;
  183. }
  184. }