Class PreferencesSection

java.lang.Object
net.mcreator.preferences.PreferencesSection
Direct Known Subclasses:
BackupsSection, BedrockSection, BlocklySection, CodeStyleSection, GradleSection, HiddenSection, IDESection, ImageEditorSection, NotificationsSection, UISection

public abstract class PreferencesSection extends Object

This class defines a section inside the PreferencesDialog. It groups all PreferencesEntry together both visually and innerly (when storing preferences). For examples on how to create a new PreferencesSection and declare new PreferencesEntry inside the class, see built-in sections net.mcreator.preferences.data.

Java plugins need to initialize their section using ApplicationLoadedEvent. Example:

     
     public class MyPlugin extends JavaPlugin {

         public MySection mySection;

         public MyPlugin(Plugin plugin) {
             addListener(ApplicationLoadedEvent.class, event -> {
                 mySection = new MySection("myIdentifier");
             });
         }
     }
     
 

  • Constructor Details

    • PreferencesSection

      public PreferencesSection(String preferencesIdentifier)
  • Method Details

    • addEntry

      public final <T, S extends PreferencesEntry<T>> S addEntry(S entry)

      This method allows adding a new PreferencesEntry to this PreferencesSection. Contrary to addPluginEntry(String, PreferencesEntry), this method does not allow to specify a custom identifier, meaning the system will use the one provided by this section (preferencesIdentifier).

      For Java plugins: Use this method ONLY when making a custom PreferencesSection. Do NOT use with a built-in section (see PreferencesData). Custom PreferencesEntry will be added to the core identifier group, leading to many problems for you and users.

      Parameters:
      entry - The new PreferencesEntry to add to this section
      Returns:
      The provided PreferencesEntry to register
    • addPluginEntry

      public final <T, S extends PreferencesEntry<T>> S addPluginEntry(String pluginPreferencesIdentifier, S entry)

      This method allows adding a new PreferencesEntry to the PreferencesSection. This method is designed so Java plugins can add a custom PreferencesEntry to an already existing PreferencesSection created by MCreator (see PreferencesData). While this method will work in all types of cases, addPluginEntry(String, PreferencesEntry) can be safely used when using a custom PreferencesSection}.

      Example of a Java plugin:

       
       public class MyPlugin extends JavaPlugin {
      
       	public final BooleanEntry myEntry = new BooleanEntry("displayMCreator", true);
      
      	public MyPlugin(Plugin plugin) {
       		addListener(ApplicationLoadedEvent.class, event -> {
       			PreferencesManager.PREFERENCES.ui.addJavaEntry("myIdentifier", myEntry);
       		});
       	}
      
       }
       

      Parameters:
      pluginPreferencesIdentifier - A unique String acting like a mod's id for this system. If you use this method with one of the built-in section (see PreferencesData), this parameter can NOT be "core" as the system use it for all built-in entries.
      entry - The new PreferencesEntry to add to this section
      Returns:
      The provided PreferencesEntry to register
    • isVisible

      public boolean isVisible()
      Returns:
      True PreferencesDialog should display this PreferencesSection. Usually, this should always be true. This was implemented for HiddenSection.
    • getSectionKey

      public abstract String getSectionKey()
      Returns:
      The registry name of this specific section. It is used, among other things, for the localization's key of the PreferencesEntry inside this section.