ConfigEntry.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. package me.lortseam.completeconfig.api;
  2. import me.lortseam.completeconfig.data.EnumEntry;
  3. import java.lang.annotation.ElementType;
  4. import java.lang.annotation.Retention;
  5. import java.lang.annotation.RetentionPolicy;
  6. import java.lang.annotation.Target;
  7. /**
  8. * Applied to declare that a field is an entry inside the mod's config. Only required if
  9. * the {@link ConfigContainer} is not a POJO class.
  10. *
  11. * <p>This annotation also contains various options to modify the entry.
  12. */
  13. @Target(ElementType.FIELD)
  14. @Retention(RetentionPolicy.RUNTIME)
  15. public @interface ConfigEntry {
  16. /**
  17. * Specifies the ID of this entry. If empty, the field name will be used by default.
  18. *
  19. * @return the ID
  20. */
  21. String value() default "";
  22. /**
  23. * Specifies a comment which describes the purpose of this entry. The comment will only be visible in the config
  24. * save file.
  25. *
  26. * <p>If blank, no comment will be applied to the entry.
  27. *
  28. * @return a comment
  29. */
  30. String comment() default "";
  31. /**
  32. * Specifies a custom translation key for this entry. If empty, the default key for this entry will be used.
  33. *
  34. * @return a custom translation key
  35. */
  36. String translationKey() default "";
  37. /**
  38. * Specifies one or more custom translation keys for this entry's tooltip, declared line by line. If empty, the
  39. * default single-line or multi-line keys will be used, depending on which are defined in the language file(s).
  40. *
  41. * @return an array of custom tooltip translation keys
  42. */
  43. String[] tooltipTranslationKeys() default {};
  44. /**
  45. * Specifies if the entry's field should get updated while at least one listener exists in the field's class.
  46. *
  47. * <p>In that case, by default, the entry's field will not get modified when the config is saved, but all listeners
  48. * will be called. Set this to true to always update the field when saving.
  49. *
  50. * @return true if the field should always get updated, else false
  51. */
  52. boolean forceUpdate() default false;
  53. /**
  54. * Specifies whether the game needs to be restarted after modifying the entry.
  55. *
  56. * @return whether the game needs to be restarted after modifying the entry
  57. */
  58. boolean requiresRestart() default false;
  59. /**
  60. * Applies bounds to an entry of type Integer.
  61. */
  62. @Target(ElementType.FIELD)
  63. @Retention(RetentionPolicy.RUNTIME)
  64. @interface BoundedInteger {
  65. /**
  66. * The minimum bound.
  67. *
  68. * @return the minimum bound
  69. */
  70. int min() default java.lang.Integer.MIN_VALUE;
  71. /**
  72. * The maximum bound.
  73. *
  74. * @return the maximum bound
  75. */
  76. int max() default java.lang.Integer.MAX_VALUE;
  77. /**
  78. * Specifies whether the entry should be rendered as slider.
  79. *
  80. * @return whether the entry should be rendered as slider
  81. */
  82. boolean slider() default true;
  83. }
  84. /**
  85. * Applies bounds to an entry of type Long.
  86. */
  87. @Target(ElementType.FIELD)
  88. @Retention(RetentionPolicy.RUNTIME)
  89. @interface BoundedLong {
  90. /**
  91. * The minimum bound.
  92. *
  93. * @return the minimum bound
  94. */
  95. long min() default java.lang.Long.MIN_VALUE;
  96. /**
  97. * The maximum bound.
  98. *
  99. * @return the maximum bound
  100. */
  101. long max() default java.lang.Long.MAX_VALUE;
  102. /**
  103. * Specifies whether the entry should be rendered as slider.
  104. *
  105. * @return whether the entry should be rendered as slider
  106. */
  107. boolean slider() default true;
  108. }
  109. /**
  110. * Applies bounds to an entry of type Float.
  111. */
  112. @Target(ElementType.FIELD)
  113. @Retention(RetentionPolicy.RUNTIME)
  114. @interface BoundedFloat {
  115. /**
  116. * The minimum bound.
  117. *
  118. * @return the minimum bound
  119. */
  120. float min() default -java.lang.Float.MAX_VALUE;
  121. /**
  122. * The maximum bound.
  123. *
  124. * @return the maximum bound
  125. */
  126. float max() default java.lang.Float.MAX_VALUE;
  127. }
  128. /**
  129. * Applies bounds to an entry of type Double.
  130. */
  131. @Target(ElementType.FIELD)
  132. @Retention(RetentionPolicy.RUNTIME)
  133. @interface BoundedDouble {
  134. /**
  135. * The minimum bound.
  136. *
  137. * @return the minimum bound
  138. */
  139. double min() default -java.lang.Double.MAX_VALUE;
  140. /**
  141. * The maximum bound.
  142. *
  143. * @return the maximum bound
  144. */
  145. double max() default java.lang.Double.MAX_VALUE;
  146. }
  147. /**
  148. * Applied to an entry of type Enum to change the render behaviour.
  149. *
  150. * <p>This annotation is optional.
  151. */
  152. @Target(ElementType.FIELD)
  153. @Retention(RetentionPolicy.RUNTIME)
  154. @interface Enum {
  155. /**
  156. * Specifies how the entry should be rendered.
  157. *
  158. * @return the desired {@link me.lortseam.completeconfig.data.EnumEntry.DisplayType}
  159. */
  160. EnumEntry.DisplayType displayType() default EnumEntry.DisplayType.BUTTON;
  161. }
  162. /**
  163. * Specifies that the annotated field is a color entry.
  164. *
  165. * <p>This annotation is optional for known color types, such as {@link net.minecraft.text.TextColor}, but is
  166. * required for unknown types.
  167. */
  168. @Target(ElementType.FIELD)
  169. @Retention(RetentionPolicy.RUNTIME)
  170. @interface Color {
  171. /**
  172. * Specifies whether the color has an alpha value.
  173. *
  174. * @return whether the color has an alpha value
  175. */
  176. boolean alphaMode();
  177. }
  178. }