# Главный класс

Обычный главный класс любого Bukkit плагина в основном использует два метода: onEnable и onDisable. Поскольку это главный класс всего плагина эти два метода очень быстро увеличиваются, поэтому я решил написать обертку для него, где разделил эти два метода на шесть, по три для каждого.

**Вместо onEnable теперь:**

* registerConfigs - для загрузки конфигураций плагина
* registerManagers - для инициализации менеджеров систем плагина
* registerCommands - для инициализации обработчиков команд

**А вместо onDisable теперь:**

* saveConfigs - для загрузки конфигураций плагина
* saveManagers - для инициализации менеджеров систем плагина
* unregisterCommands - для инициализации обработчиков команд

Такое количество методов позволяет не добавять несчитанное колическтво методов и не делать методы по 200, 300 строк кода.

Вот так выглядит главный класс в одном из моих плагинов:

```java
@Getter
public final class Plugin extends BedrockPlugin<Plugin> {

    private static LiteCommands<CommandSender> liteCommands;

    private DataBase<Plugin> dataBase;
    private ConfigManager<Plugin> configManager;

    private QuestLoader questLoader;
    private GodItemBuilder godItemBuilder;

    private BuildingManager buildingManager;
    private BuildingPlaceManager buildingPlaceManager;
    private BuildingTemplateManager buildingTemplateManager;
    private DialogManager dialogManager;
    private EnderStorageManager enderStorageManager;
    private LimitedItemsManager limitedItemsManager;
    private QuestManager questManager;
    private ResourceTableManager resourceTableManager;
    private SpawnerManager spawnerManager;
    private InventoryManager inventoryManager;

    @Override
    protected void registerConfigs() {
        setSerializeConfig(new SerializeConfig(this));
        this.dataBase = new DataBase<>(
                this,
                new File(getDataFolder().getPath(),"data.bd"),
                getSerializeConfig()
        );
        this.configManager = ConfigManager.builder()
                .withConfigs(
                        MainConfig.class,
                        LangConfig.class
                )
                .withPluginFolder(getDataFolder())
                .build(this, getSerializeConfig());
    }

    @Override
    protected void registerManagers() {

        ColorTextUtil.setPlugin(this);

        this.questLoader = new QuestLoader(this);
        this.godItemBuilder = new GodItemBuilder(this);

        this.buildingManager = new BuildingManager(this);
        this.buildingPlaceManager = new BuildingPlaceManager(this);
        this.buildingTemplateManager = new BuildingTemplateManager(this);
        this.dialogManager = new DialogManager(this);
        this.enderStorageManager = new EnderStorageManager(this);
        this.limitedItemsManager = new LimitedItemsManager(this);
        this.questManager = new QuestManager(this);
        this.resourceTableManager = new ResourceTableManager(this);
        this.spawnerManager = new SpawnerManager(this);
        this.inventoryManager = new InventoryManager(this);
    }

    @Override
    protected void registerCommands() {
        this.liteCommands = LiteBukkitFactory.builder(this)
                .commands(
                        new BuildingCommand(this),
                        new BuildingPlaceCommand(this),
                        new EnderStorageCommand(this),
                        new KickCommand(this),
                        new LimitedItemCommand(this),
                        new NpcCommand(this),
                        new QuestCommand(this),
                        new SpawnerCommand(this),
                        new VendettaCommand(this)
                )
                .argument(Trait.class, new TraitArgument(this))
                .build();
    }

    @Override
    protected void saveConfigs() {
        this.configManager.saveConfigs();
        this.dataBase.save();
    }

    @Override
    protected void saveManagers() {
        this.buildingManager.save();
        this.buildingPlaceManager.save();
        this.enderStorageManager.save();
        this.limitedItemsManager.save();
        this.resourceTableManager.save();
        this.spawnerManager.save();
        this.questManager.saveProgresses();
    }

    @Override
    protected void unregisterCommands() {
        if (this.liteCommands != null) this.liteCommands.unregister();
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mrbedrockpys-plugins.gitbook.io/mrbedrockpys-plugins-docs/bedrocklib/glavnyi-klass.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
