AdminLevel.java 3.2 KB

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