Axelut

SetLevel Acis 398

May 9th, 2023
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java b/java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
  2. index ae67764..2abbe8b 100644
  3. --- a/java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
  4. +++ b/java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
  5. @@ -18,6 +18,7 @@
  6. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminInfo;
  7. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminItem;
  8. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminKnownlist;
  9. +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminLevel;
  10. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminMaintenance;
  11. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminManage;
  12. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminManor;
  13. @@ -44,6 +45,7 @@
  14.  
  15. protected AdminCommandHandler()
  16. {
  17. + registerHandler(new AdminLevel());
  18. registerHandler(new AdminCustom());
  19. registerHandler(new AdminVip());
  20. registerHandler(new AdminAdmin());
  21. diff --git a/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminLevel.java b/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminLevel.java
  22. new file mode 100644
  23. index 0000000..add7ed7
  24. --- /dev/null
  25. +++ b/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminLevel.java
  26. @@ -0,0 +1,104 @@
  27. +/*
  28. + * This program is free software: you can redistribute it and/or modify it under
  29. + * the terms of the GNU General Public License as published by the Free Software
  30. + * Foundation, either version 3 of the License, or (at your option) any later
  31. + * version.
  32. + *
  33. + * This program is distributed in the hope that it will be useful, but WITHOUT
  34. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  35. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  36. + * details.
  37. + *
  38. + * You should have received a copy of the GNU General Public License along with
  39. + * this program. If not, see <http://www.gnu.org/licenses/>.
  40. + */
  41. +package net.sf.l2j.gameserver.handler.admincommandhandlers;
  42. +
  43. +import java.util.StringTokenizer;
  44. +
  45. +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  46. +import net.sf.l2j.gameserver.model.WorldObject;
  47. +import net.sf.l2j.gameserver.model.actor.Playable;
  48. +import net.sf.l2j.gameserver.model.actor.Player;
  49. +import net.sf.l2j.gameserver.model.base.Experience;
  50. +import net.sf.l2j.gameserver.network.SystemMessageId;
  51. +
  52. +public class AdminLevel implements IAdminCommandHandler
  53. +{
  54. + private static final String[] ADMIN_COMMANDS =
  55. + {
  56. + "admin_addlevel",
  57. + "admin_setlevel"
  58. + };
  59. +
  60. + @Override
  61. + public void useAdminCommand(String command, Player activeChar)
  62. + {
  63. + if (activeChar == null)
  64. + return;
  65. +
  66. + WorldObject targetChar = activeChar.getTarget();
  67. +
  68. + StringTokenizer st = new StringTokenizer(command, " ");
  69. + String actualCommand = st.nextToken(); // Get actual command
  70. +
  71. + String val = "";
  72. + if (st.countTokens() >= 1)
  73. + val = st.nextToken();
  74. +
  75. + if (actualCommand.equalsIgnoreCase("admin_addlevel"))
  76. + {
  77. + try
  78. + {
  79. + if (targetChar instanceof Playable)
  80. + ((Playable) targetChar).getStatus().addLevel(Byte.parseByte(val));
  81. + }
  82. + catch (NumberFormatException e)
  83. + {
  84. + activeChar.sendMessage("Wrong number format.");
  85. + return;
  86. + }
  87. + }
  88. + else if (actualCommand.equalsIgnoreCase("admin_setlevel"))
  89. + {
  90. + try
  91. + {
  92. + if (targetChar == null || !(targetChar instanceof Player))
  93. + {
  94. + activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT); // incorrect target!
  95. + return;
  96. + }
  97. + Player targetPlayer = (Player) targetChar;
  98. +
  99. + byte lvl = Byte.parseByte(val);
  100. + if (lvl >= 1 && lvl <= Experience.MAX_LEVEL)
  101. + {
  102. + long pXp = targetPlayer.getStatus().getExp();
  103. + long tXp = Experience.LEVEL[lvl];
  104. +
  105. + if (pXp > tXp)
  106. + targetPlayer.removeExpAndSp(pXp - tXp, 0);
  107. + else if (pXp < tXp)
  108. + targetPlayer.addExpAndSp(tXp - pXp, 0);
  109. + }
  110. + else
  111. + {
  112. + activeChar.sendMessage("You must specify level between 1 and " + Experience.MAX_LEVEL + ".");
  113. + return;
  114. + }
  115. + }
  116. + catch (NumberFormatException e)
  117. + {
  118. + activeChar.sendMessage("You must specify level between 1 and " + Experience.MAX_LEVEL + ".");
  119. + return;
  120. + }
  121. + }
  122. + return;
  123. + }
  124. +
  125. + @Override
  126. + public String[] getAdminCommandList()
  127. + {
  128. + return ADMIN_COMMANDS;
  129. + }
  130. +}
  131. \ No newline at end of file
  132.  
Add Comment
Please, Sign In to add comment