State.java 2.0 KB

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