1212import org .bukkit .event .Event ;
1313import org .jetbrains .annotations .NotNull ;
1414import org .jetbrains .annotations .Nullable ;
15+ import org .jetbrains .annotations .Unmodifiable ;
1516import org .skriptlang .skript .lang .properties .Property ;
1617import org .skriptlang .skript .lang .properties .Property .PropertyInfo ;
1718import org .skriptlang .skript .lang .properties .PropertyHandler ;
@@ -477,22 +478,50 @@ public String toString(final @Nullable Event event, final boolean debug) {
477478 return getName ().getSingular ();
478479 }
479480
480-
481481 private final Map <Property <?>, PropertyInfo <?>> propertyInfos = new HashMap <>();
482+ private final Map <Property <?>, String > propertyDescriptions = new HashMap <>();
482483
483- public <Handler extends PropertyHandler <T >> ClassInfo <T > property (Property <? super Handler > property , @ NotNull Handler handler ) {
484+ /**
485+ * Registers this class as having the given property, using the given property handler.
486+ * @param property The property this class should have
487+ * @param description A short description of the property for documentation
488+ * @param handler The handler for this property
489+ * @return This ClassInfo object
490+ * @param <Handler> The type of the property handler
491+ * @throws IllegalStateException If this property is already registered for this class
492+ */
493+ public <Handler extends PropertyHandler <T >> ClassInfo <T > property (Property <? super Handler > property , String description , @ NotNull Handler handler ) {
484494 if (propertyInfos .containsKey (property )) {
485495 throw new IllegalStateException ("Property " + property .name () + " is already registered for the " + c .getName () + " type." );
486496 }
487497 propertyInfos .put (property , new PropertyInfo <>(property , handler ));
488498 Classes .CLASS_INFOS_BY_PROPERTY .computeIfAbsent (property , k -> new ArrayList <>()).add (this );
499+ propertyDescriptions .put (property , description );
489500 return this ;
490501 }
491502
503+ /**
504+ * Checks whether this class already has the given property registered.
505+ * @param property The property to check
506+ * @return True if this class has the property, false otherwise
507+ */
492508 public boolean hasProperty (Property <?> property ) {
493509 return propertyInfos .containsKey (property );
494510 }
495511
512+ /**
513+ * @return An unmodifiable collection of all the properties this class has.
514+ */
515+ public @ Unmodifiable Collection <Property <?>> getAllProperties () {
516+ return Collections .unmodifiableCollection (propertyInfos .keySet ());
517+ }
518+
519+ /**
520+ * Gets the property info for the given property, or null if this class does not have the property.
521+ * @param property The property to get the info for
522+ * @return The property info, or null if this class does not have the property
523+ * @param <Handler> The type of the property handler
524+ */
496525 public <Handler extends PropertyHandler <?>> @ Nullable PropertyInfo <Handler > getPropertyInfo (Property <Handler > property ) {
497526 if (!propertyInfos .containsKey (property )) {
498527 return null ;
@@ -501,5 +530,14 @@ public boolean hasProperty(Property<?> property) {
501530 return (PropertyInfo <Handler >) propertyInfos .get (property );
502531 }
503532
533+ /**
534+ * Gets the description for the given property, or null if this class does not have the property.
535+ * Meant to be used for documentation.
536+ * @param property The property to get the description for
537+ * @return The description, or null if this class does not have the property
538+ */
539+ public String getPropertyDescription (Property <?> property ) {
540+ return propertyDescriptions .get (property );
541+ }
504542
505543}
0 commit comments