diff options
| author | Cow <cow@volloeko.de> | 2020-06-16 02:32:15 +0200 |
|---|---|---|
| committer | Cow <cow@volloeko.de> | 2020-06-16 02:32:15 +0200 |
| commit | c2c644d9b0f8a66e757b67145935b0e3c447db97 (patch) | |
| tree | 627c087f6b8c165e4fb3506ff7b559afd2318ddc /src/main/java/eu/olli/cowmoonication/search/GuiDateField.java | |
| parent | b9d6b75423ea24c4947b3a655f199c3b34aa167a (diff) | |
| download | Cowlection-c2c644d9b0f8a66e757b67145935b0e3c447db97.tar.gz Cowlection-c2c644d9b0f8a66e757b67145935b0e3c447db97.tar.bz2 Cowlection-c2c644d9b0f8a66e757b67145935b0e3c447db97.zip | |
Added `/moo search` to search through mc log files
Diffstat (limited to 'src/main/java/eu/olli/cowmoonication/search/GuiDateField.java')
| -rw-r--r-- | src/main/java/eu/olli/cowmoonication/search/GuiDateField.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main/java/eu/olli/cowmoonication/search/GuiDateField.java b/src/main/java/eu/olli/cowmoonication/search/GuiDateField.java new file mode 100644 index 0000000..136e4ac --- /dev/null +++ b/src/main/java/eu/olli/cowmoonication/search/GuiDateField.java @@ -0,0 +1,37 @@ +package eu.olli.cowmoonication.search; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiTextField; + +import java.time.LocalDate; +import java.time.format.DateTimeParseException; + +class GuiDateField extends GuiTextField { + GuiDateField(int componentId, FontRenderer fontrendererObj, int x, int y, int width, int height) { + super(componentId, fontrendererObj, x, y, width, height); + } + + LocalDate getDate() { + try { + return LocalDate.parse(this.getText()); + } catch (DateTimeParseException e) { + return LocalDate.now(); + } + } + + boolean validateDate() { + try { + LocalDate localDate = LocalDate.parse(this.getText()); + if (localDate.isAfter(LocalDate.now()) || localDate.isBefore(LocalDate.ofYearDay(2009, 1))) { + // searching for things written in the future isn't possible (yet). It is also not possible to perform a search before the existence of mc. + setTextColor(0xFFFF3333); + return false; + } + } catch (DateTimeParseException e) { + setTextColor(0xFFFF3333); + return false; + } + setTextColor(0xFFFFFF); + return true; + } +} |
