001package net.tnemc.plugincore.core.module;
002/*
003 * The New Plugin Core
004 * Copyright (C) 2022 - 2024 Daniel "creatorfromhell" Vidmar
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU Affero General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU Affero General Public License for more details.
015 *
016 * You should have received a copy of the GNU Affero General Public License
017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018 */
019
020import net.tnemc.menu.core.MenuHandler;
021import net.tnemc.plugincore.PluginCore;
022import net.tnemc.plugincore.core.api.CallbackEntry;
023import net.tnemc.plugincore.core.api.CallbackManager;
024import net.tnemc.plugincore.core.api.callback.Callback;
025import net.tnemc.plugincore.core.io.storage.StorageManager;
026import org.jetbrains.annotations.NotNull;
027import revxrsal.commands.Lamp;
028import revxrsal.commands.LampBuilderVisitor;
029import revxrsal.commands.command.CommandActor;
030import revxrsal.commands.orphan.OrphanCommand;
031
032import java.io.File;
033import java.util.HashMap;
034import java.util.List;
035import java.util.Map;
036import java.util.function.Function;
037
038/**
039 * Module represents an add-on module for TNE.
040 *
041 * @author creatorfromhell
042 * @since 0.1.2.0
043 */
044public interface Module {
045
046  /**
047   * Called after the {@link PluginCore#enable()} method is called.
048   */
049  void enable(PluginCore core);
050
051  /**
052   * Called when the {@link PluginCore#onDisable()} method is called.
053   */
054  void disable(PluginCore core);
055
056  /**
057   * Called when the configurations are initialized and loaded.
058   *
059   * @param directory The plugin's configuration directory.
060   */
061  void initConfigurations(File directory);
062
063  /**
064   * Called when the {@link StorageManager storage manager} runs its backup method.
065   *
066   * @param manager The {@link StorageManager storage manager} instance.
067   */
068  void backup(StorageManager manager);
069
070  /**
071   * Called when the {@link StorageManager storage manager} runs its reset method.
072   *
073   * @param manager The {@link StorageManager storage manager} instance.
074   */
075  void reset(StorageManager manager);
076
077  /**
078   * Called when the {@link StorageManager storage manager} is enabled, and a connection is
079   * established.
080   *
081   * @param manager The {@link StorageManager storage manager} instance.
082   */
083  void enableSave(StorageManager manager);
084
085  /**
086   * Called when the {@link MenuHandler menu handler} is enabled.
087   *
088   * @param menuHandler The menu handler.
089   */
090  void enableMenu(MenuHandler menuHandler);
091
092  /**
093   * Called after the default TNE Commands are registered.
094   *
095   * @param handler The {@link Lamp} that the commands are registered to.
096   */
097  void registerCommands(Lamp<?> handler);
098
099  <A extends CommandActor> @NotNull LampBuilderVisitor<A> registerParameterTypes();
100
101  /**
102   * Used to register sub commands onto the exist /money command set.
103   */
104  List<OrphanCommand> registerMoneySub();
105
106  /**
107   * Used to register sub commands onto the exist /transaction command set.
108   */
109  List<OrphanCommand> registerTransactionSub();
110
111  /**
112   * Used to register sub commands onto the exist /tne command set.
113   */
114  List<OrphanCommand> registerAdminSub();
115
116  /**
117   * Called after the {@link CallbackManager} is initialized. This method will register new
118   * callbacks with the manager automatically.
119   *
120   * @return A map containing the callbacks to register where the key is the callback name and the
121   * value is the {@link CallbackEntry} function.
122   */
123  default Map<String, CallbackEntry> registerCallbacks() {
124
125    return new HashMap<>();
126  }
127
128  /**
129   * Called after the {@link CallbackManager} is initialized. This method will register the callback
130   * listeners with the manager automatically.
131   *
132   * @return A map containing the listeners to register where the key is the callback name and the
133   * value is the listener function.
134   */
135  default Map<String, Function<Callback, Boolean>> registerListeners() {
136
137    return new HashMap<>();
138  }
139}