3838 * </p>
3939 */
4040public class Profile {
41- public final int version = 3 ;
41+ public final int version = 4 ;
4242
4343 public static final Map <String , Profile > LINK_PROFILE_MAP = new HashMap <>();
4444
@@ -52,8 +52,14 @@ public class Profile {
5252 private final List <String > links ;
5353
5454 // Behavior controls
55+ public static final Control addToHistoryDefault = Control .OFF ;
5556 private Control addToHistory ;
57+ public static final Control showHudMessageDefault = Control .OFF ;
5658 private Control showHudMessage ;
59+ public static final Control resumeRepeatingDefault = Control .OFF ;
60+ private Control resumeRepeating ;
61+ public static final Control useRatelimitDefault = Control .ON ;
62+ private Control useRatelimit ;
5763 public enum Control {
5864 ON ,
5965 OFF ,
@@ -67,22 +73,39 @@ public enum Control {
6773 * Creates a default empty instance.
6874 */
6975 public Profile () {
70- this ("" , new ArrayList <>(), Control . OFF , Control . OFF , new ArrayList <>() );
76+ this ("" );
7177 }
7278
7379 public Profile (String name ) {
74- this (name , new ArrayList <>(), Control .OFF , Control .OFF , new ArrayList <>());
80+ this (
81+ name ,
82+ new ArrayList <>(),
83+ addToHistoryDefault ,
84+ showHudMessageDefault ,
85+ resumeRepeatingDefault ,
86+ useRatelimitDefault ,
87+ new ArrayList <>()
88+ );
7589 }
7690
7791 /**
7892 * Not validated, only for use by self-validating deserializer.
7993 */
80- private Profile (String name , List <String > links , Control addToHistory ,
81- Control showHudMessage , List <Macro > macros ) {
94+ private Profile (
95+ String name ,
96+ List <String > links ,
97+ Control addToHistory ,
98+ Control showHudMessage ,
99+ Control resumeRepeating ,
100+ Control useRatelimit ,
101+ List <Macro > macros
102+ ) {
82103 this .name = name ;
83104 this .links = links ;
84105 this .addToHistory = addToHistory ;
85106 this .showHudMessage = showHudMessage ;
107+ this .resumeRepeating = resumeRepeating ;
108+ this .useRatelimit = useRatelimit ;
86109 this .macros = macros ;
87110 // Add missing links to map
88111 this .links .removeIf ((link ) -> LINK_PROFILE_MAP .putIfAbsent (link , this ) != null );
@@ -96,6 +119,8 @@ private Profile(String name, List<String> links, Control addToHistory,
96119 this .links = new ArrayList <>();
97120 this .addToHistory = profile .addToHistory ;
98121 this .showHudMessage = profile .showHudMessage ;
122+ this .resumeRepeating = profile .resumeRepeating ;
123+ this .useRatelimit = profile .useRatelimit ;
99124 this .macros = profile .macros ;
100125 }
101126
@@ -157,6 +182,24 @@ public void setShowHudMessage(Control showHudMessage) {
157182 this .showHudMessage = showHudMessage ;
158183 macros .forEach ((macro ) -> setShowHudMessage (macro , macro .showHudMessage ));
159184 }
185+
186+ public Control getResumeRepeating () {
187+ return resumeRepeating ;
188+ }
189+
190+ public void setResumeRepeating (Control resumeRepeating ) {
191+ this .resumeRepeating = resumeRepeating ;
192+ macros .forEach ((macro ) -> setResumeRepeating (macro , macro .resumeRepeating ));
193+ }
194+
195+ public Control getUseRatelimit () {
196+ return useRatelimit ;
197+ }
198+
199+ public void setUseRatelimit (Control useRatelimit ) {
200+ this .useRatelimit = useRatelimit ;
201+ macros .forEach ((macro ) -> setUseRatelimit (macro , macro .useRatelimit ));
202+ }
160203
161204 // Macro management
162205
@@ -252,7 +295,7 @@ public void setLimitKey(Macro macro, Keybind keybind, InputConstants.Key key) {
252295
253296 public void setAddToHistory (Macro macro , boolean value ) {
254297 macro .addToHistory = value ;
255- macro .historyEnabled = switch (this .addToHistory ) {
298+ macro .addToHistoryStatus = switch (this .addToHistory ) {
256299 case ON -> true ;
257300 case OFF -> false ;
258301 case DEFER -> macro .addToHistory ;
@@ -261,13 +304,31 @@ public void setAddToHistory(Macro macro, boolean value) {
261304
262305 public void setShowHudMessage (Macro macro , boolean value ) {
263306 macro .showHudMessage = value ;
264- macro .hudMessageEnabled = switch (this .showHudMessage ) {
307+ macro .showHudMessageStatus = switch (this .showHudMessage ) {
265308 case ON -> true ;
266309 case OFF -> false ;
267310 case DEFER -> macro .showHudMessage ;
268311 };
269312 }
270313
314+ public void setResumeRepeating (Macro macro , boolean value ) {
315+ macro .resumeRepeating = value ;
316+ macro .resumeRepeatingStatus = switch (this .resumeRepeating ) {
317+ case ON -> true ;
318+ case OFF -> false ;
319+ case DEFER -> macro .resumeRepeating ;
320+ };
321+ }
322+
323+ public void setUseRatelimit (Macro macro , boolean value ) {
324+ macro .useRatelimit = value ;
325+ macro .useRatelimitStatus = switch (this .useRatelimit ) {
326+ case ON -> true ;
327+ case OFF -> false ;
328+ case DEFER -> macro .useRatelimit ;
329+ };
330+ }
331+
271332 // Cleanup and validation
272333
273334 void cleanup () {
@@ -281,6 +342,11 @@ void cleanup() {
281342 !macro .sendMode .equals (Macro .SendMode .TYPE )) {
282343 macro .messages .removeIf ((msg ) -> msg .string .isBlank ());
283344 }
345+ // Update transients in macros
346+ setAddToHistory (addToHistory );
347+ setShowHudMessage (showHudMessage );
348+ setResumeRepeating (resumeRepeating );
349+ setUseRatelimit (useRatelimit );
284350 return macro .messages .isEmpty ();
285351 });
286352 }
@@ -301,15 +367,29 @@ public Profile deserialize(JsonElement json, Type typeOfT, JsonDeserializationCo
301367 }
302368 Control addToHistory = version >= 2
303369 ? Control .valueOf (obj .get ("addToHistory" ).getAsString ())
304- : Control . OFF ;
370+ : addToHistoryDefault ;
305371 Control showHudMessage = version >= 2
306372 ? Control .valueOf (obj .get ("showHudMessage" ).getAsString ())
307- : Control .OFF ;
373+ : showHudMessageDefault ;
374+ Control resumeRepeating = version >= 4
375+ ? Control .valueOf (obj .get ("resumeRepeating" ).getAsString ())
376+ : resumeRepeatingDefault ;
377+ Control useRatelimit = version >= 4
378+ ? Control .valueOf (obj .get ("useRatelimit" ).getAsString ())
379+ : useRatelimitDefault ;
308380
309381 // Deserialize CommandKey objects with link to deserialized Profile
310382 List <Macro > macros = new ArrayList <>();
311383
312- Profile profile = new Profile (name , addresses , addToHistory , showHudMessage , macros );
384+ Profile profile = new Profile (
385+ name ,
386+ addresses ,
387+ addToHistory ,
388+ showHudMessage ,
389+ resumeRepeating ,
390+ useRatelimit ,
391+ macros
392+ );
313393 for (JsonElement je : obj .getAsJsonArray (version >= 2 ? "macros" : "commandKeys" )) {
314394 macros .add (ctx .deserialize (je , Macro .class ));
315395 }
0 commit comments