11package io .github .axolotlclient .modules .hud .gui .hud ;
22
3- import io .github .axolotlclient .config .options .BooleanOption ;
43import io .github .axolotlclient .config .options .OptionBase ;
4+ import io .github .axolotlclient .config .options .StringOption ;
55import net .minecraft .util .Identifier ;
66
77import java .text .SimpleDateFormat ;
1010
1111public class RealTimeHud extends CleanHudEntry {
1212
13- private Date date = new Date ();
14- private final SimpleDateFormat dateFormatSeconds = new SimpleDateFormat ( "kk :mm:ss " );
15- private final SimpleDateFormat dateFormat = new SimpleDateFormat ("kk :mm" );
13+ private final Date date = new Date ();
14+ private final StringOption dateFormat = new StringOption ( "format" , "HH :mm" );
15+ private SimpleDateFormat format = new SimpleDateFormat ("HH :mm" );
1616
1717 private int second = 0 ;
1818
19- protected BooleanOption showSeconds = new BooleanOption ("showSeconds" , false );
20-
2119 public static Identifier ID = new Identifier ("realtimehud" );
2220
2321 @ Override
@@ -27,7 +25,7 @@ public Identifier getId() {
2725
2826 @ Override
2927 public String getValue () {
30- return showSeconds . get ()? dateFormatSeconds . format ( date ): dateFormat .format (date );
28+ return format .format (date );
3129 }
3230
3331 @ Override
@@ -38,7 +36,7 @@ public String getPlaceholder() {
3836 @ Override
3937 public void addConfigOptions (List <OptionBase <?>> options ) {
4038 super .addConfigOptions (options );
41- options .add (showSeconds );
39+ options .add (dateFormat );
4240 }
4341
4442 @ Override
@@ -49,8 +47,16 @@ public boolean tickable() {
4947 @ Override
5048 public void tick () {
5149 if (second >=20 ){
52- date = new Date ( );
50+ date . setTime ( System . currentTimeMillis () );
5351 second =0 ;
5452 } else second ++;
53+
54+ if (!format .toPattern ().equals (dateFormat .get ()) && dateFormat .get () != null ){
55+ try {
56+ format = new SimpleDateFormat (dateFormat .get ());
57+ } catch (IllegalArgumentException e ){
58+ dateFormat .set (dateFormat .get ().substring (0 , dateFormat .get ().length ()-1 ));
59+ }
60+ }
5561 }
5662}
0 commit comments