State.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 com.l2jserver.gameserver.model.quest;
  16. /**
  17. * This class merely enumerates the three necessary states for all quests:<br>
  18. * <ul>
  19. * <li>CREATED: a quest state is created but the quest is not yet accepted.</li>
  20. * <li>STARTED: the player has accepted the quest. Quest is currently in progress</li>
  21. * <li>COMPLETED: the quest has been completed.</li>
  22. * </ul>
  23. * In addition, this class defines two functions for lookup and inverse lookup of the state given a name.<br>
  24. * This is useful only for saving the state values into the database with a more readable form and then being able to read the string back and remap them to their correct states.<br>
  25. * All quests have these and only these states.
  26. * @author Luis Arias; version 2 by Fulminus
  27. */
  28. public class State
  29. {
  30. public static final byte CREATED = 0;
  31. public static final byte STARTED = 1;
  32. public static final byte COMPLETED = 2;
  33. /**
  34. * Get the quest state's string representation from its byte value.
  35. * @param state the byte value of the state
  36. * @return the String representation of the quest state (default: Start)
  37. */
  38. public static String getStateName(byte state)
  39. {
  40. switch (state)
  41. {
  42. case 1:
  43. return "Started";
  44. case 2:
  45. return "Completed";
  46. default:
  47. return "Start";
  48. }
  49. }
  50. /**
  51. * Get the quest state's byte value from its string representation.
  52. * @param statename the String representation of the state
  53. * @return the byte value of the quest state (default: 0)
  54. */
  55. public static byte getStateId(String statename)
  56. {
  57. switch (statename)
  58. {
  59. case "Started":
  60. return 1;
  61. case "Completed":
  62. return 2;
  63. default:
  64. return 0;
  65. }
  66. }
  67. }