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 revxrsal.commands.Lamp; 027import revxrsal.commands.command.CommandActor; 028import revxrsal.commands.orphan.OrphanCommand; 029 030import java.io.File; 031import java.util.HashMap; 032import java.util.List; 033import java.util.Map; 034import java.util.function.Function; 035 036/** 037 * Module represents an add-on module for TNE. 038 * 039 * @author creatorfromhell 040 * @since 0.1.2.0 041 */ 042public interface Module { 043 044 /** 045 * Called after the {@link PluginCore#enable()} method is called. 046 */ 047 void enable(PluginCore core); 048 049 /** 050 * Called when the {@link PluginCore#onDisable()} method is called. 051 */ 052 void disable(PluginCore core); 053 054 /** 055 * Called when the configurations are initialized and loaded. 056 * 057 * @param directory The plugin's configuration directory. 058 */ 059 void initConfigurations(File directory); 060 061 /** 062 * Called when the {@link StorageManager storage manager} runs its backup method. 063 * @param manager The {@link StorageManager storage manager} instance. 064 */ 065 void backup(StorageManager manager); 066 067 /** 068 * Called when the {@link StorageManager storage manager} runs its reset method. 069 * @param manager The {@link StorageManager storage manager} instance. 070 */ 071 void reset(StorageManager manager); 072 073 /** 074 * Called when the {@link StorageManager storage manager} is enabled, and a connection is established. 075 * @param manager The {@link StorageManager storage manager} instance. 076 */ 077 void enableSave(StorageManager manager); 078 079 /** 080 * Called when the {@link MenuHandler menu handler} is enabled. 081 * @param menuHandler The menu handler. 082 */ 083 void enableMenu(MenuHandler menuHandler); 084 085 /** 086 * Called after the default TNE Commands are registered. 087 * @param handler The {@link Lamp} that the commands are registered to. 088 */ 089 void registerCommands(Lamp.Builder<? extends CommandActor> handler); 090 091 /** 092 * Used to register sub commands onto the exist /money command set. 093 */ 094 List<OrphanCommand> registerMoneySub(); 095 096 /** 097 * Used to register sub commands onto the exist /transaction command set. 098 */ 099 List<OrphanCommand> registerTransactionSub(); 100 101 /** 102 * Used to register sub commands onto the exist /tne command set. 103 */ 104 List<OrphanCommand> registerAdminSub(); 105 106 /** 107 * Called after the {@link CallbackManager} is initialized. This method will 108 * register new callbacks with the manager automatically. 109 * 110 * @return A map containing the callbacks to register where the key is the callback name and the 111 * value is the {@link CallbackEntry} function. 112 */ 113 default Map<String, CallbackEntry> registerCallbacks() { 114 return new HashMap<>(); 115 } 116 117 /** 118 * Called after the {@link CallbackManager} is initialized. This method will 119 * register the callback listeners with the manager automatically. 120 * 121 * @return A map containing the listeners to register where the key is the callback name and the 122 * value is the listener function. 123 */ 124 default Map<String, Function<Callback, Boolean>> registerListeners() { 125 return new HashMap<>(); 126 } 127}