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 net.sf.l2j.gameserver.handler.admincommandhandlers;
  16. import java.util.StringTokenizer;
  17. import java.util.logging.Logger;
  18. import net.sf.l2j.Config;
  19. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  20. import net.sf.l2j.gameserver.model.L2Object;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  22. import net.sf.l2j.gameserver.network.SystemMessageId;
  23. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  24. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  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. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  42. {
  43. if (command.startsWith("admin_add_exp_sp"))
  44. {
  45. try
  46. {
  47. String val = command.substring(16);
  48. if (!adminAddExpSp(activeChar, val))
  49. activeChar.sendMessage("Usage: //add_exp_sp exp sp");
  50. }
  51. catch (StringIndexOutOfBoundsException e)
  52. { //Case of missing parameter
  53. activeChar.sendMessage("Usage: //add_exp_sp exp sp");
  54. }
  55. }
  56. else if (command.startsWith("admin_remove_exp_sp"))
  57. {
  58. try
  59. {
  60. String val = command.substring(19);
  61. if (!adminRemoveExpSP(activeChar, val))
  62. activeChar.sendMessage("Usage: //remove_exp_sp exp sp");
  63. }
  64. catch (StringIndexOutOfBoundsException e)
  65. { //Case of missing parameter
  66. activeChar.sendMessage("Usage: //remove_exp_sp exp sp");
  67. }
  68. }
  69. addExpSp(activeChar);
  70. return true;
  71. }
  72. public String[] getAdminCommandList()
  73. {
  74. return ADMIN_COMMANDS;
  75. }
  76. private void addExpSp(L2PcInstance activeChar)
  77. {
  78. L2Object target = activeChar.getTarget();
  79. L2PcInstance player = null;
  80. if (target instanceof L2PcInstance)
  81. player = (L2PcInstance) target;
  82. else
  83. {
  84. activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  85. return;
  86. }
  87. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  88. adminReply.setFile("data/html/admin/expsp.htm");
  89. adminReply.replace("%name%", player.getName());
  90. adminReply.replace("%level%", String.valueOf(player.getLevel()));
  91. adminReply.replace("%xp%", String.valueOf(player.getExp()));
  92. adminReply.replace("%sp%", String.valueOf(player.getSp()));
  93. adminReply.replace("%class%", player.getTemplate().className);
  94. activeChar.sendPacket(adminReply);
  95. }
  96. private boolean adminAddExpSp(L2PcInstance activeChar, String ExpSp)
  97. {
  98. L2Object target = activeChar.getTarget();
  99. L2PcInstance player = null;
  100. if (target instanceof L2PcInstance)
  101. {
  102. player = (L2PcInstance) target;
  103. }
  104. else
  105. {
  106. activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  107. return false;
  108. }
  109. StringTokenizer st = new StringTokenizer(ExpSp);
  110. if (st.countTokens() != 2)
  111. {
  112. return false;
  113. }
  114. else
  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. }
  140. return true;
  141. }
  142. private boolean adminRemoveExpSP(L2PcInstance activeChar, String ExpSp)
  143. {
  144. L2Object target = activeChar.getTarget();
  145. L2PcInstance player = null;
  146. if (target instanceof L2PcInstance)
  147. {
  148. player = (L2PcInstance) target;
  149. }
  150. else
  151. {
  152. activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  153. return false;
  154. }
  155. StringTokenizer st = new StringTokenizer(ExpSp);
  156. if (st.countTokens() != 2)
  157. return false;
  158. else
  159. {
  160. String exp = st.nextToken();
  161. String sp = st.nextToken();
  162. long expval = 0;
  163. int spval = 0;
  164. try
  165. {
  166. expval = Long.parseLong(exp);
  167. spval = Integer.parseInt(sp);
  168. }
  169. catch (Exception e)
  170. {
  171. return false;
  172. }
  173. if (expval != 0 || spval != 0)
  174. {
  175. //Common character information
  176. player.sendMessage("Admin is removing you " + expval + " xp and " + spval + " sp.");
  177. player.removeExpAndSp(expval, spval);
  178. //Admin information
  179. activeChar.sendMessage("Removed " + expval + " xp and " + spval + " sp from " + player.getName() + ".");
  180. if (Config.DEBUG)
  181. _log.fine("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ") removed " + expval + " xp and " + spval + " sp from " + player.getObjectId() + ".");
  182. }
  183. }
  184. return true;
  185. }
  186. }