ConfigEntry.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package me.lortseam.completeconfig.api;
  2. import lombok.AccessLevel;
  3. import lombok.NoArgsConstructor;
  4. import me.lortseam.completeconfig.entry.EnumOptions.DisplayType;
  5. import java.lang.annotation.ElementType;
  6. import java.lang.annotation.Retention;
  7. import java.lang.annotation.RetentionPolicy;
  8. import java.lang.annotation.Target;
  9. /**
  10. * Applied to declare that a field is an entry inside the mod's config. Only required if
  11. * the {@link ConfigEntryContainer} is not a POJO class.
  12. *
  13. * This is also used to change the behaviour of the entry regarding translations, bounds and other
  14. * miscellaneous options.
  15. */
  16. @Target(ElementType.FIELD)
  17. @Retention(RetentionPolicy.RUNTIME)
  18. public @interface ConfigEntry {
  19. /**
  20. * Specifies a custom translation key for this entry. If empty, the default key will be used.
  21. * @return a custom translation key
  22. */
  23. String customTranslationKey() default "";
  24. /**
  25. * Specifies one or more custom translation keys for this entry's tooltip. If empty, the default single-line or
  26. * multi-line keys will be used, depending on which are declared in the language file(s).
  27. * @return an array of custom tooltip translation keys
  28. */
  29. String[] customTooltipKeys() default {};
  30. /**
  31. * Specifies if the entry's field should get updated while at least one listener exists in the entry's class.
  32. *
  33. * By default the entry's field will not get modified when the config is saved, but all listeners will be called
  34. * with the updated value. Set this to true to always update the field when saving.
  35. * @return true if the field should get updated, else false
  36. */
  37. boolean forceUpdate() default false;
  38. /**
  39. * Specifies whether the game needs to be restarted after modifying this entry.
  40. * @return whether the game needs to be restarted after modifying this field's entry
  41. */
  42. boolean requiresRestart() default false;
  43. @NoArgsConstructor(access = AccessLevel.PRIVATE)
  44. class Bounded {
  45. /**
  46. * Applies bounds to an entry of type Integer.
  47. */
  48. @Target(ElementType.FIELD)
  49. @Retention(RetentionPolicy.RUNTIME)
  50. public @interface Integer {
  51. /**
  52. * The minimum bound.
  53. * @return the minimum bound
  54. */
  55. int min() default java.lang.Integer.MIN_VALUE;
  56. /**
  57. * The maximum bound.
  58. * @return the maximum bound
  59. */
  60. int max() default java.lang.Integer.MAX_VALUE;
  61. /**
  62. * Specifies whether the entry should be rendered as slider.
  63. * @return whether the entry should be rendered as slider
  64. */
  65. boolean slider() default true;
  66. }
  67. /**
  68. * Applies bounds to an entry of type Long.
  69. */
  70. @Target(ElementType.FIELD)
  71. @Retention(RetentionPolicy.RUNTIME)
  72. public @interface Long {
  73. /**
  74. * The minimum bound.
  75. * @return the minimum bound
  76. */
  77. long min() default java.lang.Long.MIN_VALUE;
  78. /**
  79. * The maximum bound.
  80. * @return the maximum bound
  81. */
  82. long max() default java.lang.Long.MAX_VALUE;
  83. /**
  84. * Specifies whether the entry should be rendered as slider.
  85. * @return whether the entry should be rendered as slider
  86. */
  87. boolean slider() default true;
  88. }
  89. /**
  90. * Applies bounds to an entry of type Float.
  91. */
  92. @Target(ElementType.FIELD)
  93. @Retention(RetentionPolicy.RUNTIME)
  94. public @interface Float {
  95. /**
  96. * The minimum bound.
  97. * @return the minimum bound
  98. */
  99. float min() default -java.lang.Float.MAX_VALUE;
  100. /**
  101. * The maximum bound.
  102. * @return the maximum bound
  103. */
  104. float max() default java.lang.Float.MAX_VALUE;
  105. }
  106. /**
  107. * Applies bounds to an entry of type Double.
  108. */
  109. @Target(ElementType.FIELD)
  110. @Retention(RetentionPolicy.RUNTIME)
  111. public @interface Double {
  112. /**
  113. * The minimum bound.
  114. * @return the minimum bound
  115. */
  116. double min() default -java.lang.Double.MAX_VALUE;
  117. /**
  118. * The maximum bound.
  119. * @return the maximum bound
  120. */
  121. double max() default java.lang.Double.MAX_VALUE;
  122. }
  123. }
  124. /**
  125. * Applied to an entry of type Enum to change the render behaviour.
  126. */
  127. @Target(ElementType.FIELD)
  128. @Retention(RetentionPolicy.RUNTIME)
  129. @interface EnumOptions {
  130. /**
  131. * Specifies how the entry should be rendered.
  132. * @return the desired {@link DisplayType}
  133. */
  134. DisplayType displayType() default DisplayType.BUTTON;
  135. //TODO: Add gui suggestionMode option
  136. }
  137. /**
  138. * Can be applied to a field inside a POJO {@link ConfigEntryContainer} class to declare that the field should not
  139. * be considered as config entry.
  140. */
  141. @Target(ElementType.FIELD)
  142. @Retention(RetentionPolicy.RUNTIME)
  143. @interface Ignore {
  144. }
  145. }