AdminVitality.java 3.6 KB

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