State.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) 2004-2014 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.model.quest;
  20. /**
  21. * This class merely enumerates the three necessary states for all quests:<br>
  22. * <ul>
  23. * <li>CREATED: a quest state is created but the quest is not yet accepted.</li>
  24. * <li>STARTED: the player has accepted the quest. Quest is currently in progress</li>
  25. * <li>COMPLETED: the quest has been completed.</li>
  26. * </ul>
  27. * In addition, this class defines two functions for lookup and inverse lookup of the state given a name.<br>
  28. * 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>
  29. * All quests have these and only these states.
  30. * @author Luis Arias; version 2 by Fulminus
  31. */
  32. public class State
  33. {
  34. public static final byte CREATED = 0;
  35. public static final byte STARTED = 1;
  36. public static final byte COMPLETED = 2;
  37. /**
  38. * Get the quest state's string representation from its byte value.
  39. * @param state the byte value of the state
  40. * @return the String representation of the quest state (default: Start)
  41. */
  42. public static String getStateName(byte state)
  43. {
  44. switch (state)
  45. {
  46. case 1:
  47. return "Started";
  48. case 2:
  49. return "Completed";
  50. default:
  51. return "Start";
  52. }
  53. }
  54. /**
  55. * Get the quest state's byte value from its string representation.
  56. * @param statename the String representation of the state
  57. * @return the byte value of the quest state (default: 0)
  58. */
  59. public static byte getStateId(String statename)
  60. {
  61. switch (statename)
  62. {
  63. case "Started":
  64. return 1;
  65. case "Completed":
  66. return 2;
  67. default:
  68. return 0;
  69. }
  70. }
  71. }