AdminLevel.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.network.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. /**
  42. *
  43. * @see net.sf.l2j.gameserver.handler.IAdminCommandHandler#useAdminCommand(java.lang.String, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance)
  44. */
  45. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  46. {
  47. L2Object targetChar = activeChar.getTarget();
  48. StringTokenizer st = new StringTokenizer(command, " ");
  49. String actualCommand = st.nextToken(); // Get actual command
  50. String val = "";
  51. if (st.countTokens() >= 1)
  52. {
  53. val = st.nextToken();
  54. }
  55. if (actualCommand.equalsIgnoreCase("admin_add_level"))
  56. {
  57. try
  58. {
  59. if (targetChar instanceof L2PlayableInstance)
  60. ((L2PlayableInstance) targetChar).getStat().addLevel(Byte.parseByte(val));
  61. }
  62. catch (NumberFormatException e)
  63. {
  64. activeChar.sendMessage("Wrong Number Format");
  65. }
  66. }
  67. else if (actualCommand.equalsIgnoreCase("admin_set_level"))
  68. {
  69. try
  70. {
  71. if (!(targetChar instanceof L2PcInstance))
  72. {
  73. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT)); // incorrect target!
  74. return false;
  75. }
  76. L2PcInstance targetPlayer = (L2PcInstance) targetChar;
  77. byte lvl = Byte.parseByte(val);
  78. if (lvl >= 1 && lvl <= Experience.MAX_LEVEL)
  79. {
  80. long pXp = targetPlayer.getExp();
  81. long tXp = Experience.LEVEL[lvl];
  82. if (pXp > tXp)
  83. {
  84. targetPlayer.removeExpAndSp(pXp - tXp, 0);
  85. }
  86. else if (pXp < tXp)
  87. {
  88. targetPlayer.addExpAndSp(tXp - pXp, 0);
  89. }
  90. }
  91. else
  92. {
  93. activeChar.sendMessage("You must specify level between 1 and " + Experience.MAX_LEVEL + ".");
  94. return false;
  95. }
  96. }
  97. catch (NumberFormatException e)
  98. {
  99. activeChar.sendMessage("You must specify level between 1 and " + Experience.MAX_LEVEL + ".");
  100. return false;
  101. }
  102. }
  103. return true;
  104. }
  105. /**
  106. *
  107. * @see net.sf.l2j.gameserver.handler.IAdminCommandHandler#getAdminCommandList()
  108. */
  109. public String[] getAdminCommandList()
  110. {
  111. return ADMIN_COMMANDS;
  112. }
  113. }