AdminLevel.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * $Header: AdminTest.java, 25/07/2005 17:15:21 luisantonioa Exp $
  3. *
  4. * $Author: luisantonioa $
  5. * $Date: 25/07/2005 17:15:21 $
  6. * $Revision: 1 $
  7. * $Log: AdminTest.java,v $
  8. * Revision 1 25/07/2005 17:15:21 luisantonioa
  9. * Added copyright notice
  10. *
  11. *
  12. * This program is free software: you can redistribute it and/or modify it under
  13. * the terms of the GNU General Public License as published by the Free Software
  14. * Foundation, either version 3 of the License, or (at your option) any later
  15. * version.
  16. *
  17. * This program is distributed in the hope that it will be useful, but WITHOUT
  18. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  19. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  20. * details.
  21. *
  22. * You should have received a copy of the GNU General Public License along with
  23. * this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. package net.sf.l2j.gameserver.handler.admincommandhandlers;
  26. import java.util.StringTokenizer;
  27. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  28. import net.sf.l2j.gameserver.model.L2Object;
  29. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  30. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  31. import net.sf.l2j.gameserver.model.base.Experience;
  32. import net.sf.l2j.gameserver.network.SystemMessageId;
  33. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  34. public class AdminLevel implements IAdminCommandHandler
  35. {
  36. private static final String[] ADMIN_COMMANDS =
  37. {
  38. "admin_add_level",
  39. "admin_set_level"
  40. };
  41. /* (non-Javadoc)
  42. * @see net.sf.l2j.gameserver.handler.IAdminCommandHandler#useAdminCommand(java.lang.String, net.sf.l2j.gameserver.model.L2PcInstance)
  43. */
  44. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  45. {
  46. L2Object targetChar = activeChar.getTarget();
  47. StringTokenizer st = new StringTokenizer(command, " ");
  48. String actualCommand = st.nextToken(); // Get actual command
  49. String val = "";
  50. if (st.countTokens() >= 1) { val = st.nextToken(); }
  51. if (actualCommand.equalsIgnoreCase("admin_add_level"))
  52. {
  53. try
  54. {
  55. if (targetChar instanceof L2PlayableInstance)
  56. ((L2PlayableInstance)targetChar).getStat().addLevel(Byte.parseByte(val));
  57. }
  58. catch (NumberFormatException e) { activeChar.sendMessage("Wrong Number Format"); }
  59. }
  60. else if(actualCommand.equalsIgnoreCase("admin_set_level"))
  61. {
  62. try
  63. {
  64. if (!(targetChar instanceof L2PcInstance))
  65. {
  66. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT)); // incorrect target!
  67. return false;
  68. }
  69. L2PcInstance targetPlayer = (L2PcInstance)targetChar;
  70. byte lvl = Byte.parseByte(val);
  71. if(lvl >= 1 && lvl <= Experience.MAX_LEVEL)
  72. {
  73. long pXp = targetPlayer.getExp();
  74. long tXp = Experience.LEVEL[lvl];
  75. if (pXp > tXp)
  76. {
  77. targetPlayer.removeExpAndSp(pXp - tXp, 0);
  78. } else if (pXp < tXp)
  79. {
  80. targetPlayer.addExpAndSp(tXp - pXp, 0);
  81. }
  82. }
  83. else
  84. {
  85. activeChar.sendMessage("You must specify level between 1 and "+ Experience.MAX_LEVEL+".");
  86. return false;
  87. }
  88. }
  89. catch (NumberFormatException e)
  90. {
  91. activeChar.sendMessage("You must specify level between 1 and "+ Experience.MAX_LEVEL+".");
  92. return false;
  93. }
  94. }
  95. return true;
  96. }
  97. /* (non-Javadoc)
  98. * @see net.sf.l2j.gameserver.handler.IAdminCommandHandler#getAdminCommandList()
  99. */
  100. public String[] getAdminCommandList()
  101. {
  102. return ADMIN_COMMANDS;
  103. }
  104. }