Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public enum Commands
- {
- go, quit, help, charge, fire, search, take, UNKNOWN;
- /**
- * Check if the command is available for the player
- * @param player
- * @return
- */
- public boolean isAvailableTo(Player player)
- {
- switch(this)
- {
- case UNKNOWN:
- return false;
- case charge:
- case fire:
- return player.hasItem("Beamer");
- default:
- return true;
- }
- }
- /**
- * Check whether a given String is a valid command word.
- * @return true if it is, false if it isn't.
- */
- public boolean isCommand(String aString)
- {
- for(Commands com : Commands.values())
- {
- if(com.toString().equals(aString))
- return true;
- }
- // if we get here, the string was not found in the commands
- return false;
- }
- /**
- * Print all valid commands to System.out.
- * @param player the player which commands shall be shown
- */
- public void showAll(Player player)
- {
- for(Commands command: Commands.values())
- {
- if(command.isAvailableTo(player))
- System.out.print(command + " ");
- }
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment