AdminExpSp.java 6.2 KB

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