AdminVitality.java 3.8 KB

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