AdminVitality.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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.Config;
  18. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.actor.stat.PcStat;
  21. /**
  22. * @author Psychokiller1888
  23. */
  24. public class AdminVitality implements IAdminCommandHandler
  25. {
  26. private static final String[] ADMIN_COMMANDS =
  27. {
  28. "admin_set_vitality",
  29. "admin_set_vitality_level",
  30. "admin_full_vitality",
  31. "admin_empty_vitality",
  32. "admin_get_vitality"
  33. };
  34. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  35. {
  36. if (activeChar == null)
  37. return false;
  38. if (!Config.ENABLE_VITALITY)
  39. {
  40. activeChar.sendMessage("Vitality is not enabled on the server!");
  41. return false;
  42. }
  43. int level = 0;
  44. int vitality = 0;
  45. StringTokenizer st = new StringTokenizer(command, " ");
  46. String cmd = st.nextToken();
  47. if (activeChar.getTarget() instanceof L2PcInstance)
  48. {
  49. L2PcInstance target;
  50. target = (L2PcInstance) activeChar.getTarget();
  51. if (cmd.equals("admin_set_vitality"))
  52. {
  53. try
  54. {
  55. vitality = Integer.parseInt(st.nextToken());
  56. }
  57. catch (Exception e)
  58. {
  59. activeChar.sendMessage("Incorrect vitality");
  60. }
  61. target.setVitalityPoints(vitality, true);
  62. target.sendMessage("Admin set your Vitality points to " + vitality);
  63. }
  64. else if (cmd.equals("admin_set_vitality_level"))
  65. {
  66. try
  67. {
  68. level = Integer.parseInt(st.nextToken());
  69. }
  70. catch (Exception e)
  71. {
  72. activeChar.sendMessage("Incorrect vitality level (0-4)");
  73. }
  74. if (level >= 0 && level <= 4)
  75. {
  76. if (level == 0)
  77. vitality = PcStat.MIN_VITALITY_POINTS;
  78. else
  79. vitality = PcStat.VITALITY_LEVELS[level-1];
  80. target.setVitalityPoints(vitality, true);
  81. target.sendMessage("Admin set your Vitality level to " + level);
  82. }
  83. else
  84. activeChar.sendMessage("Incorrect vitality level (0-4)");
  85. }
  86. else if (cmd.equals("admin_full_vitality"))
  87. {
  88. target.setVitalityPoints(PcStat.MAX_VITALITY_POINTS, true);
  89. target.sendMessage("Admin completly recharged your Vitality");
  90. }
  91. else if (cmd.equals("admin_empty_vitality"))
  92. {
  93. target.setVitalityPoints(PcStat.MIN_VITALITY_POINTS, true);
  94. target.sendMessage("Admin completly emptied your Vitality");
  95. }
  96. else if (cmd.equals("admin_get_vitality"))
  97. {
  98. level = target.getVitalityLevel();
  99. vitality = target.getVitalityPoints();
  100. activeChar.sendMessage("Player vitality level: " + level);
  101. activeChar.sendMessage("Player vitality points: " + vitality);
  102. }
  103. return true;
  104. }
  105. else
  106. {
  107. activeChar.sendMessage("Target not found or not a player");
  108. return false;
  109. }
  110. }
  111. public String[] getAdminCommandList()
  112. {
  113. return ADMIN_COMMANDS;
  114. }
  115. public static void main(String[] args)
  116. {
  117. new AdminVitality();
  118. }
  119. }