AdminLevel.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 com.l2jserver.gameserver.datatables.ExperienceTable;
  18. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.actor.L2Playable;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. public class AdminLevel implements IAdminCommandHandler
  24. {
  25. private static final String[] ADMIN_COMMANDS =
  26. {
  27. "admin_add_level",
  28. "admin_set_level"
  29. };
  30. @Override
  31. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  32. {
  33. L2Object targetChar = activeChar.getTarget();
  34. StringTokenizer st = new StringTokenizer(command, " ");
  35. String actualCommand = st.nextToken(); // Get actual command
  36. String val = "";
  37. if (st.countTokens() >= 1)
  38. {
  39. val = st.nextToken();
  40. }
  41. if (actualCommand.equalsIgnoreCase("admin_add_level"))
  42. {
  43. try
  44. {
  45. if (targetChar instanceof L2Playable)
  46. ((L2Playable) targetChar).getStat().addLevel(Byte.parseByte(val));
  47. }
  48. catch (NumberFormatException e)
  49. {
  50. activeChar.sendMessage("Wrong Number Format");
  51. }
  52. }
  53. else if (actualCommand.equalsIgnoreCase("admin_set_level"))
  54. {
  55. try
  56. {
  57. if (!(targetChar instanceof L2PcInstance))
  58. {
  59. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT); // incorrect target!
  60. return false;
  61. }
  62. L2PcInstance targetPlayer = (L2PcInstance) targetChar;
  63. byte lvl = Byte.parseByte(val);
  64. if (lvl >= 1 && lvl <= ExperienceTable.getInstance().getMaxLevel())
  65. {
  66. long pXp = targetPlayer.getExp();
  67. long tXp = ExperienceTable.getInstance().getExpForLevel(lvl);
  68. if (pXp > tXp)
  69. {
  70. targetPlayer.removeExpAndSp(pXp - tXp, 0);
  71. }
  72. else if (pXp < tXp)
  73. {
  74. targetPlayer.addExpAndSp(tXp - pXp, 0);
  75. }
  76. }
  77. else
  78. {
  79. activeChar.sendMessage("You must specify level between 1 and " + ExperienceTable.getInstance().getMaxLevel() + ".");
  80. return false;
  81. }
  82. }
  83. catch (NumberFormatException e)
  84. {
  85. activeChar.sendMessage("You must specify level between 1 and " + ExperienceTable.getInstance().getMaxLevel() + ".");
  86. return false;
  87. }
  88. }
  89. return true;
  90. }
  91. @Override
  92. public String[] getAdminCommandList()
  93. {
  94. return ADMIN_COMMANDS;
  95. }
  96. }