generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/net/vinrobot/mcemote/config/ValidationFailedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package net.vinrobot.mcemote.config; | ||
|
||
public class ValidationFailedException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public ValidationFailedException(final String message) { | ||
super(message); | ||
} | ||
|
||
public ValidationFailedException(final String message, final Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public ValidationFailedException(final Throwable cause) { | ||
super(cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/net/vinrobot/mcemote/config/impl/TwitchIdOptionImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.vinrobot.mcemote.config.impl; | ||
|
||
import net.vinrobot.mcemote.config.ValidationFailedException; | ||
|
||
public class TwitchIdOptionImpl extends OptionImpl<String> { | ||
public TwitchIdOptionImpl(final String defaultValue) { | ||
super(defaultValue); | ||
} | ||
|
||
@Override | ||
public void validate(final String value) { | ||
super.validate(value); | ||
|
||
final int length = value.length(); | ||
if (length == 0 || 8 < length) { | ||
throw new ValidationFailedException("Twitch ID must be between 1 and 8 digits"); | ||
} | ||
|
||
try { | ||
Long.parseLong(value); | ||
} catch (final NumberFormatException e) { | ||
throw new ValidationFailedException("Twitch ID must be a number"); | ||
} | ||
} | ||
} |