Guest User

Untitled

a guest
Aug 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1.  
  2. public enum Commands
  3. {
  4. go, quit, help, charge, fire, search, take, UNKNOWN;
  5. /**
  6. * Check if the command is available for the player
  7. * @param player
  8. * @return
  9. */
  10. public boolean isAvailableTo(Player player)
  11. {
  12. switch(this)
  13. {
  14. case UNKNOWN:
  15. return false;
  16. case charge:
  17. case fire:
  18. return player.hasItem("Beamer");
  19. default:
  20. return true;
  21. }
  22. }
  23. /**
  24. * Check whether a given String is a valid command word.
  25. * @return true if it is, false if it isn't.
  26. */
  27. public boolean isCommand(String aString)
  28. {
  29. for(Commands com : Commands.values())
  30. {
  31. if(com.toString().equals(aString))
  32. return true;
  33. }
  34. // if we get here, the string was not found in the commands
  35. return false;
  36. }
  37.  
  38. /**
  39. * Print all valid commands to System.out.
  40. * @param player the player which commands shall be shown
  41. */
  42. public void showAll(Player player)
  43. {
  44. for(Commands command: Commands.values())
  45. {
  46. if(command.isAvailableTo(player))
  47. System.out.print(command + " ");
  48. }
  49. System.out.println();
  50. }
  51. }
Add Comment
Please, Sign In to add comment