Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private boolean isNumeric(String str) {
- for(char ch : str.toCharArray()) {
- if(!Character.isDigit(ch)) {
- return false;
- }
- }
- return true;
- }
- private long parseTime(String timeString, String timeMode) throws CommandException {
- if(!isNumeric(timeString)) {
- throw new CommandException(Lang.COMMAND_ERROR_TIMEFORMAT);
- }
- if(timeMode.length() > 1) {
- throw new CommandException(Lang.COMMAND_ERROR_TIMEFORMAT);
- }
- int sec = Integer.parseInt(timeString) * 60;
- char unit = timeMode.charAt(0);
- switch (unit) {
- case 'h':
- sec *= 60;
- break;
- case 'd':
- sec *= (60 * 24);
- break;
- case 'w':
- sec *= (7 * 60 * 24);
- break;
- case 'm':
- sec *= (30 * 60 * 24);
- break;
- default:
- throw new CommandException(Lang.COMMAND_ERROR_TIMEFORMAT);
- }
- return sec * 1000L;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement