From a9b1d6a61a3d706e18cf6fd5a945f03d4794cda5 Mon Sep 17 00:00:00 2001 From: iambibi_ <89582596+iambibi@users.noreply.github.com> Date: Sun, 29 Mar 2026 20:33:02 +0200 Subject: [PATCH 1/2] rewrite: Feature (next OMCRegistry?) --- .../api/cooldown/DynamicCooldownManager.java | 15 +- src/main/java/fr/openmc/core/OMCPlugin.java | 175 +++++++----------- .../commands/admin/freeze/FreezeManager.java | 13 +- .../core/commands/utils/SpawnManager.java | 11 +- .../features/adminshop/AdminShopManager.java | 11 +- .../features/analytics/AnalyticsManager.java | 17 +- .../animations/AnimationsManager.java | 11 +- .../core/features/city/CityManager.java | 36 +++- .../city/sub/mascots/MascotsManager.java | 15 +- .../contest/managers/ContestManager.java | 21 ++- .../cube/multiblocks/MultiBlockManager.java | 12 +- .../core/features/displays/TabList.java | 12 +- .../displays/bossbar/BossbarManager.java | 11 +- .../displays/holograms/HologramLoader.java | 13 +- .../scoreboards/ScoreboardManager.java | 12 +- .../core/features/dream/DreamManager.java | 27 +-- .../core/features/economy/BankManager.java | 15 +- .../core/features/economy/EconomyManager.java | 26 ++- .../features/economy/TransactionsManager.java | 17 +- .../halloween/managers/HalloweenManager.java | 14 +- .../features/friend/FriendSQLManager.java | 17 +- .../core/features/homes/HomesManager.java | 13 +- .../homes/icons/HomeIconCacheManager.java | 14 +- .../leaderboards/LeaderboardManager.java | 13 +- .../features/mailboxes/MailboxManager.java | 17 +- .../core/features/mainmenu/MainMenu.java | 14 +- .../milestones/MilestonesManager.java | 16 +- .../core/features/quests/QuestsManager.java | 14 +- .../settings/PlayerSettingsManager.java | 17 +- .../core/features/tickets/TicketManager.java | 19 +- .../fr/openmc/core/features/tpa/TPAQueue.java | 11 +- .../core/features/updates/UpdateManager.java | 11 +- .../java/fr/openmc/core/utils/MotdUtils.java | 11 +- .../core/utils/database/DatabaseManager.java | 54 ++---- .../core/utils/init/DatabaseFeature.java | 13 ++ .../fr/openmc/core/utils/init/Feature.java | 40 ++++ .../core/utils/init/LoadAfterItemsAdder.java | 7 + .../core/utils/init/NotUnitTestFeature.java | 7 + .../utils/translation/TranslationManager.java | 15 +- 39 files changed, 565 insertions(+), 242 deletions(-) create mode 100644 src/main/java/fr/openmc/core/utils/init/DatabaseFeature.java create mode 100644 src/main/java/fr/openmc/core/utils/init/Feature.java create mode 100644 src/main/java/fr/openmc/core/utils/init/LoadAfterItemsAdder.java create mode 100644 src/main/java/fr/openmc/core/utils/init/NotUnitTestFeature.java diff --git a/src/main/java/fr/openmc/api/cooldown/DynamicCooldownManager.java b/src/main/java/fr/openmc/api/cooldown/DynamicCooldownManager.java index 5497da7df..a97b49aa1 100644 --- a/src/main/java/fr/openmc/api/cooldown/DynamicCooldownManager.java +++ b/src/main/java/fr/openmc/api/cooldown/DynamicCooldownManager.java @@ -7,6 +7,8 @@ import com.j256.ormlite.table.DatabaseTable; import com.j256.ormlite.table.TableUtils; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; @@ -20,7 +22,7 @@ /** * Main class for managing cooldowns */ -public class DynamicCooldownManager { +public class DynamicCooldownManager extends Feature implements DatabaseFeature { /** * Represents a single cooldown with duration and last use time */ @@ -82,16 +84,23 @@ public long getRemaining() { } } - public static void init() { + @Override + public void init() { loadCooldowns(); } + @Override + public void save() { + DynamicCooldownManager.saveCooldowns() + } + // Map structure: UUID -> (Group -> Cooldown) private static final Map> cooldowns = new HashMap<>(); private static Dao cooldownDao; - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, Cooldown.class); cooldownDao = DaoManager.createDao(connectionSource, Cooldown.class); } diff --git a/src/main/java/fr/openmc/core/OMCPlugin.java b/src/main/java/fr/openmc/core/OMCPlugin.java index 30d956fca..b088a60e0 100644 --- a/src/main/java/fr/openmc/core/OMCPlugin.java +++ b/src/main/java/fr/openmc/core/OMCPlugin.java @@ -8,13 +8,10 @@ import fr.openmc.core.commands.admin.freeze.FreezeManager; import fr.openmc.core.commands.utils.SpawnManager; import fr.openmc.core.features.adminshop.AdminShopManager; +import fr.openmc.core.features.analytics.AnalyticsManager; import fr.openmc.core.features.animations.AnimationsManager; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.mascots.MascotsManager; -import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.notation.NotationManager; -import fr.openmc.core.features.city.sub.statistics.CityStatisticsManager; -import fr.openmc.core.features.city.sub.war.WarManager; import fr.openmc.core.features.contest.managers.ContestManager; import fr.openmc.core.features.cube.multiblocks.MultiBlockManager; import fr.openmc.core.features.displays.TabList; @@ -25,14 +22,15 @@ import fr.openmc.core.features.dream.generation.DreamDimensionManager; import fr.openmc.core.features.economy.BankManager; import fr.openmc.core.features.economy.EconomyManager; +import fr.openmc.core.features.economy.TransactionsManager; import fr.openmc.core.features.events.halloween.managers.HalloweenManager; +import fr.openmc.core.features.friend.FriendSQLManager; import fr.openmc.core.features.homes.HomesManager; import fr.openmc.core.features.homes.icons.HomeIconCacheManager; import fr.openmc.core.features.leaderboards.LeaderboardManager; import fr.openmc.core.features.mailboxes.MailboxManager; import fr.openmc.core.features.mainmenu.MainMenu; import fr.openmc.core.features.milestones.MilestonesManager; -import fr.openmc.core.features.quests.QuestProgressSaveManager; import fr.openmc.core.features.quests.QuestsManager; import fr.openmc.core.features.settings.PlayerSettingsManager; import fr.openmc.core.features.tickets.TicketManager; @@ -46,6 +44,8 @@ import fr.openmc.core.utils.ShutUpOrmLite; import fr.openmc.core.utils.database.DatabaseManager; import fr.openmc.core.utils.errors.ErrorReporter; +import fr.openmc.core.utils.init.Feature; +import fr.openmc.core.utils.init.LoadAfterItemsAdder; import fr.openmc.core.utils.translation.TranslationManager; import io.papermc.paper.datapack.Datapack; import lombok.Getter; @@ -59,6 +59,8 @@ import org.slf4j.Logger; import java.io.File; +import java.util.ArrayList; +import java.util.List; public class OMCPlugin extends JavaPlugin { @Getter @@ -68,15 +70,42 @@ public class OMCPlugin extends JavaPlugin { public static final String VANISH_META_KEY = "omcstaff.vanished"; - public static void registerEvents(Listener... listeners) { - for (Listener listener : listeners) { - instance.getServer().getPluginManager().registerEvents(listener, instance); - } - } - - public static boolean isUnitTestVersion() { - return OMCPlugin.instance.getServer().getVersion().contains("MockBukkit"); - } + // ** Registry of OMC Features + public final List REGISTRY_FEATURE = new ArrayList<>(List.of( + new TicketManager(new File(this.getDataFolder(), "data/stats")), + new SpawnManager(), + new UpdateManager(), + new EconomyManager(), + new BankManager(), + new ScoreboardManager(), + new HomesManager(), + new TPAQueue(), + new FreezeManager(), + new TransactionsManager(), + new AnalyticsManager(), + new FriendSQLManager(), + new TabList(), + new AdminShopManager(), + new BossbarManager(), + new AnimationsManager(), + new HalloweenManager(), + new MotdUtils(), + new TranslationManager(new File(this.getDataFolder(), "translations"), "fr"), + new DynamicCooldownManager(), + new MascotsManager(), + new PlayerSettingsManager(), + new MailboxManager(), + new MilestonesManager(), + new QuestsManager(), + new CityManager(), + new ContestManager(), + new DreamManager(), + new MultiBlockManager(), + new LeaderboardManager(), + new MainMenu(), + new HologramLoader(), + new HomeIconCacheManager() + )); @Override public void onLoad() { @@ -116,38 +145,14 @@ public void onEnable() { new ErrorReporter(); /* MANAGERS */ - TicketManager.loadPlayerStats(new File(this.getDataFolder(), "data/stats")); DatabaseManager.init(); CommandsManager.init(); - SpawnManager.init(); - UpdateManager.init(); ListenersManager.init(); - EconomyManager.init(); - BankManager.init(); - - if (!isUnitTestVersion()) - ScoreboardManager.init(); - - HomesManager.init(); - TPAQueue.initCommand(); - FreezeManager.init(); - QuestProgressSaveManager.init(); - if (!isUnitTestVersion()) - TabList.init(); - AdminShopManager.init(); - BossbarManager.init(); - AnimationsManager.init(); - HalloweenManager.init(); - MotdUtils.init(); - TranslationManager.init(new File(this.getDataFolder(), "translations"), "fr"); - DynamicCooldownManager.init(); - - MascotsManager.init(); - - PlayerSettingsManager.loadAllPlayerSettings(); - - MailboxManager.loadLetters(); + /* FEATURES */ + REGISTRY_FEATURE.stream() + .filter(f -> !(f instanceof LoadAfterItemsAdder)) + .forEachOrdered(Feature::startInit); } public void loadWithItemsAdder() { @@ -157,77 +162,23 @@ public void loadWithItemsAdder() { CustomLootTableRegistry.init(); // ** FEATURES ** - MilestonesManager.init(); - QuestsManager.init(); - CityManager.init(); - ContestManager.init(); - DreamManager.init(); - MultiBlockManager.init(); - if (WorldGuardHook.isHasWorldGuard()) { - ParticleUtils.spawnParticlesInRegion("spawn", Bukkit.getWorld("world"), Particle.CHERRY_LEAVES, 50, 70, 130); - ParticleUtils.spawnContestParticlesInRegion("spawn", Bukkit.getWorld("world"), 10, 70, 135); - } + REGISTRY_FEATURE.stream() + .filter(f -> f instanceof LoadAfterItemsAdder) + .forEachOrdered(Feature::startInit); + // todo: sera supprimé dans https://github.com/ServerOpenMC/PluginV2/pull/1168 DreamDimensionManager.postInit(); - if (!OMCPlugin.isUnitTestVersion()) { - LeaderboardManager.init(); - MainMenu.init(this); - HologramLoader.init(); + + if (WorldGuardHook.isHasWorldGuard()) { + ParticleUtils.spawnParticlesInRegion("spawn", Bukkit.getWorld("world"), Particle.CHERRY_LEAVES, 50, 70, 130); } - HomeIconCacheManager.initialize(); } @Override public void onDisable() { - // SAUVEGARDE - // - Dimension des Reves - DreamManager.disable(); - - // - Mailboxes - MailboxManager.saveLetters(); - - // - MultiBlocks - MultiBlockManager.save(); - - // - War - WarManager.saveWarHistories(); - - // - CityStatistics - CityStatisticsManager.saveCityStatistics(); - - // - Settings - PlayerSettingsManager.saveAllSettings(); - - // - Notation des Villes - NotationManager.saveNotations(); - - // - Maires - MayorManager.saveMayorConstant(); - MayorManager.savePlayersVote(); - MayorManager.saveMayorCandidates(); - MayorManager.saveCityMayors(); - MayorManager.saveCityLaws(); - - HomesManager.saveHomesData(); - HomeIconCacheManager.clearCache(); - - // - Milestones - MilestonesManager.saveMilestonesData(); - - // - Contest - ContestManager.saveContestData(); - ContestManager.saveContestPlayerData(); - QuestsManager.saveQuests(); - - // - Mascottes - MascotsManager.saveMascots(); - - // - Cooldowns - DynamicCooldownManager.saveCooldowns(); - - - if (!OMCPlugin.isUnitTestVersion()) { - HologramLoader.unloadAll(); + // ** SAVE ** + for (Feature feature : REGISTRY_FEATURE) { + feature.startSave(); } // - Close all inventories @@ -241,6 +192,18 @@ public void onDisable() { Bukkit.shutdown(); } + public static void registerEvents(Listener... listeners) { + for (Listener listener : listeners) { + instance.getServer().getPluginManager().registerEvents(listener, instance); + } + } + + public static boolean isUnitTestVersion() { + return OMCPlugin.instance.getServer().getVersion().contains("MockBukkit"); + } + + /* LOG MESSAGE */ + private void logLoadMessage() { Logger log = getSLF4JLogger(); diff --git a/src/main/java/fr/openmc/core/commands/admin/freeze/FreezeManager.java b/src/main/java/fr/openmc/core/commands/admin/freeze/FreezeManager.java index 559e41851..2277fdfc6 100644 --- a/src/main/java/fr/openmc/core/commands/admin/freeze/FreezeManager.java +++ b/src/main/java/fr/openmc/core/commands/admin/freeze/FreezeManager.java @@ -1,6 +1,7 @@ package fr.openmc.core.commands.admin.freeze; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.utils.init.Feature; import fr.openmc.core.utils.messages.MessageType; import fr.openmc.core.utils.messages.MessagesManager; import fr.openmc.core.utils.messages.Prefix; @@ -13,15 +14,21 @@ import java.util.HashSet; import java.util.Set; -public class FreezeManager { +public class FreezeManager extends Feature { public static final Set FROZEN_PLAYERS = new HashSet<>(); private static Player player; - public static void init() { + @Override + public void init() { Bukkit.getServer().getPluginManager().registerEvents(new FreezeListener(), OMCPlugin.getInstance()); } - + + @Override + public void save() { + // nothing to save + } + /** * Freeze or unfreeze a player * diff --git a/src/main/java/fr/openmc/core/commands/utils/SpawnManager.java b/src/main/java/fr/openmc/core/commands/utils/SpawnManager.java index 883c49797..0b4796d8b 100644 --- a/src/main/java/fr/openmc/core/commands/utils/SpawnManager.java +++ b/src/main/java/fr/openmc/core/commands/utils/SpawnManager.java @@ -1,6 +1,7 @@ package fr.openmc.core.commands.utils; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.utils.init.Feature; import lombok.Getter; import org.bukkit.Location; import org.bukkit.World; @@ -10,17 +11,23 @@ import java.io.File; import java.io.IOException; -public class SpawnManager { +public class SpawnManager extends Feature { private static File spawnFile; private static FileConfiguration spawnConfig; @Getter private static Location spawnLocation; - public static void init() { + @Override + public void init() { spawnFile = new File(OMCPlugin.getInstance().getDataFolder() + "/data", "spawn.yml"); loadSpawnConfig(); } + @Override + public void save() { + // nothing to save + } + private static void loadSpawnConfig() { if(!spawnFile.exists()) { spawnFile.getParentFile().mkdirs(); diff --git a/src/main/java/fr/openmc/core/features/adminshop/AdminShopManager.java b/src/main/java/fr/openmc/core/features/adminshop/AdminShopManager.java index 84d2f2b1f..f5fc4b754 100644 --- a/src/main/java/fr/openmc/core/features/adminshop/AdminShopManager.java +++ b/src/main/java/fr/openmc/core/features/adminshop/AdminShopManager.java @@ -7,6 +7,7 @@ import fr.openmc.core.features.adminshop.menus.*; import fr.openmc.core.features.economy.EconomyManager; import fr.openmc.core.utils.ItemUtils; +import fr.openmc.core.utils.init.Feature; import fr.openmc.core.utils.messages.MessageType; import fr.openmc.core.utils.messages.MessagesManager; import fr.openmc.core.utils.messages.Prefix; @@ -24,7 +25,7 @@ /** * Manages the admin shop system including items, categories, and player interactions. */ -public class AdminShopManager { +public class AdminShopManager extends Feature { public static final Map categories = new HashMap<>(); public static final Map> items = new HashMap<>(); // Category -> {ShopID -> ShopItem} public static final Map currentCategory = new HashMap<>(); @@ -34,11 +35,17 @@ public class AdminShopManager { /** * Initializes the AdminShopManager by loading the configuration. */ - public static void init() { + @Override + public void init() { adminShopYAML = new AdminShopYAML(); adminShopYAML.loadConfig(); } + @Override + public void save() { + // nothing to save + } + /** * Opens the confirmation menu for buying an item. * diff --git a/src/main/java/fr/openmc/core/features/analytics/AnalyticsManager.java b/src/main/java/fr/openmc/core/features/analytics/AnalyticsManager.java index b191e741f..30b4c4e75 100644 --- a/src/main/java/fr/openmc/core/features/analytics/AnalyticsManager.java +++ b/src/main/java/fr/openmc/core/features/analytics/AnalyticsManager.java @@ -7,16 +7,29 @@ import com.j256.ormlite.table.TableUtils; import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.analytics.models.Statistic; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; import org.bukkit.Bukkit; import java.sql.SQLException; import java.util.List; import java.util.UUID; -public class AnalyticsManager { +public class AnalyticsManager extends Feature implements DatabaseFeature { static Dao statsDao; - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + protected void init() { + // nothing to init + } + + @Override + protected void save() { + // nothing to save + } + + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, Statistic.class); statsDao = DaoManager.createDao(connectionSource, Statistic.class); } diff --git a/src/main/java/fr/openmc/core/features/animations/AnimationsManager.java b/src/main/java/fr/openmc/core/features/animations/AnimationsManager.java index 989acc8ef..1b0050610 100644 --- a/src/main/java/fr/openmc/core/features/animations/AnimationsManager.java +++ b/src/main/java/fr/openmc/core/features/animations/AnimationsManager.java @@ -7,6 +7,7 @@ import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.animations.listeners.EmoteListener; import fr.openmc.core.features.animations.listeners.PlayerFinishJoiningListener; +import fr.openmc.core.utils.init.Feature; import org.bukkit.util.Vector; import java.io.File; @@ -17,9 +18,10 @@ import java.nio.file.Files; import java.util.Map; -public class AnimationsManager { +public class AnimationsManager extends Feature { - public static void init() { + @Override + public void init() { OMCPlugin plugin = OMCPlugin.getInstance(); saveAllAnimation(plugin); @@ -34,6 +36,11 @@ public static void init() { } } + @Override + public void save() { + // nothing to save + } + public static JsonObject loadAnimation(OMCPlugin plugin, String ressourcePath) { File file = new File(plugin.getDataFolder(), ressourcePath); if (!file.exists()) { diff --git a/src/main/java/fr/openmc/core/features/city/CityManager.java b/src/main/java/fr/openmc/core/features/city/CityManager.java index 43c898660..7af41200e 100644 --- a/src/main/java/fr/openmc/core/features/city/CityManager.java +++ b/src/main/java/fr/openmc/core/features/city/CityManager.java @@ -28,6 +28,9 @@ import fr.openmc.core.features.city.view.CityViewManager; import fr.openmc.core.utils.ChunkPos; import fr.openmc.core.utils.cache.CacheOfflinePlayer; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; +import fr.openmc.core.utils.init.LoadAfterItemsAdder; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.entity.Player; @@ -37,13 +40,14 @@ import java.sql.SQLException; import java.util.*; -public class CityManager { +public class CityManager extends Feature implements DatabaseFeature, LoadAfterItemsAdder { private static final Map cities = new HashMap<>(); public static final Map citiesByName = new HashMap<>(); public static final Map playerCities = new HashMap<>(); private static final Map claimedChunks = new HashMap<>(); - public static void init() { + @Override + public void init() { loadCities(); CommandsManager.getHandler().register( @@ -73,13 +77,33 @@ public static void init() { CityMilestoneManager.init(); } + @Override + public void save() { + // - War + WarManager.saveWarHistories(); + + // - CityStatistics + CityStatisticsManager.saveCityStatistics(); + + // - Notation des Villes + NotationManager.saveNotations(); + + // - Maires + MayorManager.saveMayorConstant(); + MayorManager.savePlayersVote(); + MayorManager.saveMayorCandidates(); + MayorManager.saveCityMayors(); + MayorManager.saveCityLaws(); + } + private static Dao citiesDao; private static Dao membersDao; private static Dao permissionsDao; private static Dao claimsDao; private static Dao chestsDao; - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, DBCity.class); citiesDao = DaoManager.createDao(connectionSource, DBCity.class); @@ -94,6 +118,12 @@ public static void initDB(ConnectionSource connectionSource) throws SQLException TableUtils.createTableIfNotExists(connectionSource, DBCityChest.class); chestsDao = DaoManager.createDao(connectionSource, DBCityChest.class); + + WarManager.initDB(connectionSource); + NotationManager.initDB(connectionSource); + MayorManager.initDB(connectionSource); + CityRankManager.initDB(connectionSource); + CityStatisticsManager.initDB(connectionSource); } // ==================== Database Methods ==================== diff --git a/src/main/java/fr/openmc/core/features/city/sub/mascots/MascotsManager.java b/src/main/java/fr/openmc/core/features/city/sub/mascots/MascotsManager.java index 4f20f0405..52afed080 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mascots/MascotsManager.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mascots/MascotsManager.java @@ -16,6 +16,8 @@ import fr.openmc.core.features.city.sub.mascots.utils.MascotRegenerationUtils; import fr.openmc.core.features.city.sub.mascots.utils.MascotUtils; import fr.openmc.core.utils.ItemUtils; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; import fr.openmc.core.utils.messages.MessageType; import fr.openmc.core.utils.messages.MessagesManager; import fr.openmc.core.utils.messages.Prefix; @@ -40,7 +42,7 @@ import java.util.List; import java.util.UUID; -public class MascotsManager { +public class MascotsManager extends Feature implements DatabaseFeature { public static final List movingMascots = new ArrayList<>(); public static final HashMap mascotsByCityUUID = new HashMap<>(); public static final HashMap mascotsByEntityUUID = new HashMap<>(); @@ -49,7 +51,8 @@ public class MascotsManager { public static NamespacedKey mascotsKey; private static Dao mascotsDao; - public static void init() { + @Override + public void init() { // changement du spigot.yml pour permettre aux mascottes d'avoir 3000 cœurs File spigotYML = new File("spigot.yml"); YamlConfiguration spigotYMLConfig = YamlConfiguration.loadConfiguration(spigotYML); @@ -90,7 +93,13 @@ public static void init() { } } - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void save() { + MascotsManager.saveMascots(); + } + + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, Mascot.class); mascotsDao = DaoManager.createDao(connectionSource, Mascot.class); } diff --git a/src/main/java/fr/openmc/core/features/contest/managers/ContestManager.java b/src/main/java/fr/openmc/core/features/contest/managers/ContestManager.java index 3b5ae4cd8..a46597696 100644 --- a/src/main/java/fr/openmc/core/features/contest/managers/ContestManager.java +++ b/src/main/java/fr/openmc/core/features/contest/managers/ContestManager.java @@ -5,6 +5,7 @@ import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import fr.openmc.api.hooks.ItemsAdderHook; +import fr.openmc.api.hooks.WorldGuardHook; import fr.openmc.api.menulib.Menu; import fr.openmc.core.CommandsManager; import fr.openmc.core.OMCPlugin; @@ -26,6 +27,9 @@ import fr.openmc.core.utils.ParticleUtils; import fr.openmc.core.utils.cache.CacheOfflinePlayer; import fr.openmc.core.utils.database.DatabaseManager; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; +import fr.openmc.core.utils.init.LoadAfterItemsAdder; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.format.NamedTextColor; @@ -49,7 +53,7 @@ import static fr.openmc.core.features.mailboxes.utils.MailboxUtils.getHoverEvent; -public class ContestManager { +public class ContestManager extends Feature implements DatabaseFeature, LoadAfterItemsAdder { private static final DayOfWeek START_CONTEST_DAY = DayOfWeek.FRIDAY; private static final DayOfWeek START_TRADE_CONTEST_DAY = DayOfWeek.SATURDAY; @@ -80,7 +84,7 @@ public class ContestManager { * - Initialise les données globales et les joueurs * - Programme le lancement et la fin des différentes phases du contest */ - public static void init() { + public void init() { // ** LISTENERS ** if (ItemsAdderHook.isHasItemAdder()) { OMCPlugin.registerEvents( @@ -104,6 +108,16 @@ public static void init() { scheduleStartContest(); scheduleStartTradeContest(); scheduleEndContest(); + + // ** PARTICLE REGION ** + if (WorldGuardHook.isHasWorldGuard()) { + ParticleUtils.spawnContestParticlesInRegion("spawn", Bukkit.getWorld("world"), 10, 70, 135); + } + } + + public void save() { + ContestManager.saveContestData(); + ContestManager.saveContestPlayerData(); } private static Dao contestDao; @@ -113,7 +127,8 @@ public static void init() { * Initialise la base de données pour les contests et les joueurs * (création des tables si elles n’existent pas encore) */ - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, Contest.class); contestDao = DaoManager.createDao(connectionSource, Contest.class); diff --git a/src/main/java/fr/openmc/core/features/cube/multiblocks/MultiBlockManager.java b/src/main/java/fr/openmc/core/features/cube/multiblocks/MultiBlockManager.java index ca264d4e1..c7252bd39 100644 --- a/src/main/java/fr/openmc/core/features/cube/multiblocks/MultiBlockManager.java +++ b/src/main/java/fr/openmc/core/features/cube/multiblocks/MultiBlockManager.java @@ -4,6 +4,8 @@ import fr.openmc.core.features.cube.Cube; import fr.openmc.core.features.dream.DreamUtils; import fr.openmc.core.features.dream.generation.DreamDimensionManager; +import fr.openmc.core.utils.init.Feature; +import fr.openmc.core.utils.init.LoadAfterItemsAdder; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -19,14 +21,15 @@ import java.util.List; import java.util.Map; -public class MultiBlockManager { +public class MultiBlockManager extends Feature implements LoadAfterItemsAdder { private static final OMCPlugin plugin = OMCPlugin.getInstance(); @Getter public static final List multiBlocks = new ArrayList<>(); private static FileConfiguration config = null; private static File file = null; - public static void init() { + @Override + public void init() { file = new File(OMCPlugin.getInstance().getDataFolder() + "/data", "multiblocks.yml"); if (!file.exists()) { plugin.saveResource("data/multiblocks.yml", false); @@ -80,7 +83,8 @@ public static void load() { } } - public static void save() { + @Override + public void save() { if (config == null) return; List> list = new ArrayList<>(); @@ -113,7 +117,7 @@ public static void save() { } } - public static void register(MultiBlock multiBlock) { + public void register(MultiBlock multiBlock) { multiBlocks.add(multiBlock); save(); diff --git a/src/main/java/fr/openmc/core/features/displays/TabList.java b/src/main/java/fr/openmc/core/features/displays/TabList.java index f19b5ea27..9b006a7ed 100644 --- a/src/main/java/fr/openmc/core/features/displays/TabList.java +++ b/src/main/java/fr/openmc/core/features/displays/TabList.java @@ -11,6 +11,8 @@ import dev.lone.itemsadder.api.FontImages.FontImageWrapper; import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.dream.DreamUtils; +import fr.openmc.core.utils.init.Feature; +import fr.openmc.core.utils.init.NotUnitTestFeature; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -18,10 +20,11 @@ import java.util.List; import java.util.UUID; -public class TabList { +public class TabList extends Feature implements NotUnitTestFeature { private static ProtocolManager protocolManager = null; - public static void init() { + @Override + public void init() { if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) protocolManager = ProtocolLibrary.getProtocolManager(); @@ -64,6 +67,11 @@ public void onPacketSending(PacketEvent event) { }); } + @Override + public void save() { + // nothing to save + } + public static void updateHeaderFooter(Player player, String header, String footer) { try { if (protocolManager == null) return; diff --git a/src/main/java/fr/openmc/core/features/displays/bossbar/BossbarManager.java b/src/main/java/fr/openmc/core/features/displays/bossbar/BossbarManager.java index 1c1b003fd..a2887f68c 100644 --- a/src/main/java/fr/openmc/core/features/displays/bossbar/BossbarManager.java +++ b/src/main/java/fr/openmc/core/features/displays/bossbar/BossbarManager.java @@ -4,6 +4,7 @@ import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.displays.bossbar.commands.BossBarCommand; import fr.openmc.core.features.milestones.MilestoneUtils; +import fr.openmc.core.utils.init.Feature; import fr.openmc.core.utils.messages.MessageType; import fr.openmc.core.utils.messages.MessagesManager; import fr.openmc.core.utils.messages.Prefix; @@ -19,7 +20,7 @@ import java.io.File; import java.util.*; -public class BossbarManager { +public class BossbarManager extends Feature { @Getter private static final List helpMessages = new ArrayList<>(); private static final HashMap> activeBossBars = new HashMap<>(); @@ -35,7 +36,8 @@ public class BossbarManager { /** * Initializes the BossbarManager */ - public static void init() { + @Override + public void init() { configFile = new File(OMCPlugin.getInstance().getDataFolder() + "/data", "bossbars.yml"); loadConfig(); loadDefaultMessages(); @@ -50,6 +52,11 @@ public static void init() { ); } + @Override + public void save() { + // nothing to save + } + /** * Loads configuration from bossbars.yml file * Creates the file if it doesn't exist diff --git a/src/main/java/fr/openmc/core/features/displays/holograms/HologramLoader.java b/src/main/java/fr/openmc/core/features/displays/holograms/HologramLoader.java index 4a714ef39..2769a94d0 100644 --- a/src/main/java/fr/openmc/core/features/displays/holograms/HologramLoader.java +++ b/src/main/java/fr/openmc/core/features/displays/holograms/HologramLoader.java @@ -5,6 +5,9 @@ import fr.openmc.core.features.displays.holograms.commands.HologramCommand; import fr.openmc.core.features.milestones.tutorial.TutorialHologram; import fr.openmc.core.utils.entities.TextDisplay; +import fr.openmc.core.utils.init.Feature; +import fr.openmc.core.utils.init.LoadAfterItemsAdder; +import fr.openmc.core.utils.init.NotUnitTestFeature; import net.kyori.adventure.text.Component; import org.bukkit.Location; import org.bukkit.configuration.file.FileConfiguration; @@ -20,14 +23,15 @@ import java.util.List; import java.util.Objects; -public class HologramLoader { +public class HologramLoader extends Feature implements NotUnitTestFeature, LoadAfterItemsAdder { public static final HashMap displays = new HashMap<>(); private static BukkitTask taskTimer; public static final File hologramFolder = new File(OMCPlugin.getInstance().getDataFolder(), "data/holograms"); - public static void init() { + @Override + public void init() { hologramFolder.mkdirs(); CommandsManager.getHandler().register( @@ -42,6 +46,11 @@ public static void init() { HologramLoader.loadAllFromFolder(hologramFolder); } + @Override + public void save() { + HologramLoader.unloadAll(); + } + public static void updateHologramsViewers() { taskTimer = new BukkitRunnable() { @Override diff --git a/src/main/java/fr/openmc/core/features/displays/scoreboards/ScoreboardManager.java b/src/main/java/fr/openmc/core/features/displays/scoreboards/ScoreboardManager.java index d8cdc82fd..5dc5a9347 100644 --- a/src/main/java/fr/openmc/core/features/displays/scoreboards/ScoreboardManager.java +++ b/src/main/java/fr/openmc/core/features/displays/scoreboards/ScoreboardManager.java @@ -9,20 +9,23 @@ import fr.openmc.core.features.displays.scoreboards.sb.MainScoreboard; import fr.openmc.core.features.displays.scoreboards.sb.RestartScoreboard; import fr.openmc.core.features.dream.displays.DreamScoreboard; +import fr.openmc.core.utils.init.Feature; +import fr.openmc.core.utils.init.NotUnitTestFeature; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import java.util.*; -public class ScoreboardManager implements Listener { +public class ScoreboardManager extends Feature implements Listener, NotUnitTestFeature { public static final ObjectCacheRepository boardCache = new ObjectCacheRepositoryImpl(); private static final List scoreboards = new ArrayList<>(); private static GlobalTeamManager globalTeamManager; private static final Map> lastUpdate = new HashMap<>(); - public static void init() { + @Override + public void init() { OMCPlugin.registerEvents(new ScoreboardListener()); registerScoreboard( @@ -43,6 +46,11 @@ public static void init() { globalTeamManager = new GlobalTeamManager(boardCache); } + @Override + public void save() { + // nothing to save + } + public static void updateAllBoards() { long now = System.currentTimeMillis(); diff --git a/src/main/java/fr/openmc/core/features/dream/DreamManager.java b/src/main/java/fr/openmc/core/features/dream/DreamManager.java index ec28869e2..9dac3212d 100644 --- a/src/main/java/fr/openmc/core/features/dream/DreamManager.java +++ b/src/main/java/fr/openmc/core/features/dream/DreamManager.java @@ -36,13 +36,15 @@ import fr.openmc.core.features.dream.models.registry.items.DreamItem; import fr.openmc.core.features.dream.registries.*; import fr.openmc.core.utils.LocationUtils; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; +import fr.openmc.core.utils.init.LoadAfterItemsAdder; import fr.openmc.core.utils.serializer.BukkitSerializer; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -51,7 +53,7 @@ import java.util.HashMap; import java.util.UUID; -public class DreamManager { +public class DreamManager extends Feature implements DatabaseFeature, LoadAfterItemsAdder { // ** CONSTANTS ** public static final Long BASE_DREAM_TIME = 300L; @@ -63,7 +65,8 @@ public class DreamManager { private static Dao dreamPlayerDao; private static Dao savePlayerDao; - public static void init() { + @Override + public void init() { // ** LISTENERS ** OMCPlugin.registerEvents( new PlayerChangeWorldListener(), @@ -109,7 +112,16 @@ public static void init() { loadAllPlayerSaveData(); } - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void save() { + DreamManager.saveAllPlayerSaveData(); + DreamManager.saveAllDreamPlayerData(); + + SingularityManager.disable(); + } + + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, DBDreamPlayer.class); dreamPlayerDao = DaoManager.createDao(connectionSource, DBDreamPlayer.class); @@ -119,13 +131,6 @@ public static void initDB(ConnectionSource connectionSource) throws SQLException SingularityManager.initDB(connectionSource); } - public static void disable() { - DreamManager.saveAllPlayerSaveData(); - DreamManager.saveAllDreamPlayerData(); - - SingularityManager.disable(); - } - private static void loadAllPlayerSaveData() { try { playerSaveData.clear(); diff --git a/src/main/java/fr/openmc/core/features/economy/BankManager.java b/src/main/java/fr/openmc/core/features/economy/BankManager.java index 6086a0850..55396a242 100644 --- a/src/main/java/fr/openmc/core/features/economy/BankManager.java +++ b/src/main/java/fr/openmc/core/features/economy/BankManager.java @@ -18,6 +18,8 @@ import fr.openmc.core.features.economy.models.Bank; import fr.openmc.core.utils.InputUtils; import fr.openmc.core.utils.cache.CacheOfflinePlayer; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; import fr.openmc.core.utils.messages.MessageType; import fr.openmc.core.utils.messages.MessagesManager; import fr.openmc.core.utils.messages.Prefix; @@ -37,19 +39,26 @@ import java.util.Map; import java.util.UUID; -public class BankManager { +public class BankManager extends Feature implements DatabaseFeature { @Getter private static Map banks; private static Dao banksDao; - public static void init() { + @Override + public void init() { banks = loadAllBanks(); CommandsManager.getHandler().register(new BankCommands()); updateInterestTimer(); } - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void save() { + // nothing to save + } + + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, Bank.class); banksDao = DaoManager.createDao(connectionSource, Bank.class); } diff --git a/src/main/java/fr/openmc/core/features/economy/EconomyManager.java b/src/main/java/fr/openmc/core/features/economy/EconomyManager.java index 1c2ee977e..b84b34476 100644 --- a/src/main/java/fr/openmc/core/features/economy/EconomyManager.java +++ b/src/main/java/fr/openmc/core/features/economy/EconomyManager.java @@ -12,27 +12,23 @@ import fr.openmc.core.features.economy.commands.Money; import fr.openmc.core.features.economy.commands.Pay; import fr.openmc.core.features.economy.models.EconomyPlayer; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; import lombok.Getter; +import javax.annotation.Nullable; import java.math.BigDecimal; import java.sql.SQLException; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.*; -import javax.annotation.Nullable; - -public class EconomyManager { +public class EconomyManager extends Feature implements DatabaseFeature { @Getter private static Map balances; private static Dao playersDao; - public static void initDB(ConnectionSource connectionSource) throws SQLException { - TableUtils.createTableIfNotExists(connectionSource, EconomyPlayer.class); - playersDao = DaoManager.createDao(connectionSource, EconomyPlayer.class); - } - private static final DecimalFormat decimalFormat = new DecimalFormat("#.##"); private static final NavigableMap suffixes = new TreeMap<>(Map.of( 1_000L, "k", @@ -42,7 +38,8 @@ public static void initDB(ConnectionSource connectionSource) throws SQLException 1_000_000_000_000_000L, "Qa", 1_000_000_000_000_000_000L, "Qi")); - public static void init() { + @Override + public void init() { balances = loadAllBalances(); CommandsManager.getHandler().register( @@ -53,6 +50,17 @@ public static void init() { ); } + @Override + public void save() { + // nothing to save + } + + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { + TableUtils.createTableIfNotExists(connectionSource, EconomyPlayer.class); + playersDao = DaoManager.createDao(connectionSource, EconomyPlayer.class); + } + public static double getBalance(UUID playerUUID) { EconomyPlayer bank = getPlayerBank(playerUUID); return bank.getBalance(); diff --git a/src/main/java/fr/openmc/core/features/economy/TransactionsManager.java b/src/main/java/fr/openmc/core/features/economy/TransactionsManager.java index 4264ca030..2120a8979 100644 --- a/src/main/java/fr/openmc/core/features/economy/TransactionsManager.java +++ b/src/main/java/fr/openmc/core/features/economy/TransactionsManager.java @@ -7,6 +7,8 @@ import com.j256.ormlite.table.TableUtils; import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.analytics.Stats; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; import org.bukkit.Bukkit; import java.sql.SQLException; @@ -14,10 +16,21 @@ import java.util.Objects; import java.util.UUID; -public class TransactionsManager { +public class TransactionsManager extends Feature implements DatabaseFeature { private static Dao transactionsDao; - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + protected void init() { + // nothing to init + } + + @Override + protected void save() { + // nothing to save + } + + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, Transaction.class); transactionsDao = DaoManager.createDao(connectionSource, Transaction.class); } diff --git a/src/main/java/fr/openmc/core/features/events/halloween/managers/HalloweenManager.java b/src/main/java/fr/openmc/core/features/events/halloween/managers/HalloweenManager.java index bfbf96700..8248146a8 100644 --- a/src/main/java/fr/openmc/core/features/events/halloween/managers/HalloweenManager.java +++ b/src/main/java/fr/openmc/core/features/events/halloween/managers/HalloweenManager.java @@ -15,6 +15,8 @@ import fr.openmc.core.features.leaderboards.LeaderboardManager; import fr.openmc.core.features.mailboxes.MailboxManager; import fr.openmc.core.registry.items.CustomItemRegistry; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; import io.papermc.paper.datacomponent.DataComponentTypes; import io.papermc.paper.datacomponent.item.DamageResistant; import io.papermc.paper.registry.keys.tags.DamageTypeTagKeys; @@ -35,17 +37,22 @@ import java.util.*; @SuppressWarnings("UnstableApiUsage") -public class HalloweenManager { +public class HalloweenManager extends Feature implements DatabaseFeature { private static Object2ObjectMap halloweenData; private static Dao halloweenDataDao; - public static void init() { + public void init() { if (FancyNpcsHook.isHasFancyNpc()) Bukkit.getPluginManager().registerEvents(new HalloweenNPCListener(), OMCPlugin.getInstance()); halloweenData = loadAllHalloweenDatas(); } + @Override + public void save() { + // nothing to save + } + public static void depositPumpkins(UUID playerUUID, int amount) { HalloweenData data = halloweenData.get(playerUUID); data.depositPumpkins(amount); @@ -67,7 +74,8 @@ public static Object2ObjectMap getAllHalloweenData() { return halloweenData; } - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, HalloweenData.class); halloweenDataDao = DaoManager.createDao(connectionSource, HalloweenData.class); } diff --git a/src/main/java/fr/openmc/core/features/friend/FriendSQLManager.java b/src/main/java/fr/openmc/core/features/friend/FriendSQLManager.java index b33e6a1e3..80d24d898 100644 --- a/src/main/java/fr/openmc/core/features/friend/FriendSQLManager.java +++ b/src/main/java/fr/openmc/core/features/friend/FriendSQLManager.java @@ -7,6 +7,8 @@ import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; import java.sql.SQLException; import java.sql.Timestamp; @@ -16,11 +18,22 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; -public class FriendSQLManager { +public class FriendSQLManager extends Feature implements DatabaseFeature { private static Dao friendsDao; - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + protected void init() { + // nothing to init + } + + @Override + protected void save() { + // nothing to save + } + + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, Friend.class); friendsDao = DaoManager.createDao(connectionSource, Friend.class); } diff --git a/src/main/java/fr/openmc/core/features/homes/HomesManager.java b/src/main/java/fr/openmc/core/features/homes/HomesManager.java index d3fbb5bce..7166b0cde 100644 --- a/src/main/java/fr/openmc/core/features/homes/HomesManager.java +++ b/src/main/java/fr/openmc/core/features/homes/HomesManager.java @@ -10,6 +10,8 @@ import fr.openmc.core.features.homes.models.HomeLimit; import fr.openmc.core.features.homes.world.DisabledWorldHome; import fr.openmc.core.utils.database.DatabaseManager; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; import lombok.Getter; import org.bukkit.Location; @@ -19,12 +21,13 @@ import java.util.UUID; @Getter -public class HomesManager { +public class HomesManager extends Feature implements DatabaseFeature { public static final List homes = new ArrayList<>(); public static final List homeLimits = new ArrayList<>(); - public static void init() { + @Override + public void init() { DisabledWorldHome.init(); CommandsManager.getHandler().register( @@ -41,7 +44,8 @@ public static void init() { loadHomes(); } - public static void saveHomesData() { + @Override + public void save() { saveHomes(); saveHomeLimit(); } @@ -109,7 +113,8 @@ public static void updateHomeLimit(UUID playerUUID) { private static Dao homesDao; private static Dao limitsDao; - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, Home.class); homesDao = DaoManager.createDao(connectionSource, Home.class); diff --git a/src/main/java/fr/openmc/core/features/homes/icons/HomeIconCacheManager.java b/src/main/java/fr/openmc/core/features/homes/icons/HomeIconCacheManager.java index e2caeb34a..caafb013a 100644 --- a/src/main/java/fr/openmc/core/features/homes/icons/HomeIconCacheManager.java +++ b/src/main/java/fr/openmc/core/features/homes/icons/HomeIconCacheManager.java @@ -3,6 +3,8 @@ import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.homes.menu.HomeChangeIconMenu; import fr.openmc.core.features.homes.models.Home; +import fr.openmc.core.utils.init.Feature; +import fr.openmc.core.utils.init.LoadAfterItemsAdder; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -11,7 +13,7 @@ import java.util.List; import java.util.concurrent.ConcurrentHashMap; -public class HomeIconCacheManager { +public class HomeIconCacheManager extends Feature implements LoadAfterItemsAdder { private static final ConcurrentHashMap> CACHED_ITEMS = new ConcurrentHashMap<>(); private static final ConcurrentHashMap> CACHED_SEARCH_RESULTS = new ConcurrentHashMap<>(); @@ -20,6 +22,16 @@ public class HomeIconCacheManager { private static final Integer MAX_CACHE_SIZE = 50; + @Override + public void init() { + HomeIconCacheManager.initialize(); + } + + @Override + public void save() { + HomeIconCacheManager.clearCache(); + } + /** * Initializes the HomeIconCacheManager and preloads all icons into the cache. * This method should be called once at the start of the plugin. diff --git a/src/main/java/fr/openmc/core/features/leaderboards/LeaderboardManager.java b/src/main/java/fr/openmc/core/features/leaderboards/LeaderboardManager.java index fa688a272..ffdc7df0d 100644 --- a/src/main/java/fr/openmc/core/features/leaderboards/LeaderboardManager.java +++ b/src/main/java/fr/openmc/core/features/leaderboards/LeaderboardManager.java @@ -12,6 +12,9 @@ import fr.openmc.core.features.leaderboards.commands.LeaderboardCommands; import fr.openmc.core.utils.DateUtils; import fr.openmc.core.utils.entities.TextDisplay; +import fr.openmc.core.utils.init.Feature; +import fr.openmc.core.utils.init.LoadAfterItemsAdder; +import fr.openmc.core.utils.init.NotUnitTestFeature; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import lombok.Getter; import net.kyori.adventure.text.Component; @@ -38,7 +41,7 @@ import java.net.URI; import java.util.*; -public class LeaderboardManager { +public class LeaderboardManager extends Feature implements NotUnitTestFeature, LoadAfterItemsAdder { @Getter private static final Map> githubContributorsMap = new TreeMap<>(); @Getter @@ -68,12 +71,18 @@ public class LeaderboardManager { private static TextDisplay playTimeHologram; private static TextDisplay pumpkinCountHologram; - public static void init() { + @Override + public void init() { loadLeaderBoardConfig(); CommandsManager.getHandler().register(new LeaderboardCommands()); enable(); } + @Override + public void save() { + // nothing to save + } + /** * Creates the leaderboard text for GitHub contributors to be sent in chat or displayed as a hologram. * diff --git a/src/main/java/fr/openmc/core/features/mailboxes/MailboxManager.java b/src/main/java/fr/openmc/core/features/mailboxes/MailboxManager.java index 464262f76..0e9469672 100644 --- a/src/main/java/fr/openmc/core/features/mailboxes/MailboxManager.java +++ b/src/main/java/fr/openmc/core/features/mailboxes/MailboxManager.java @@ -10,6 +10,8 @@ import fr.openmc.core.features.settings.PlayerSettings; import fr.openmc.core.features.settings.PlayerSettingsManager; import fr.openmc.core.features.settings.SettingType; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; import fr.openmc.core.utils.messages.MessageType; import fr.openmc.core.utils.messages.MessagesManager; import fr.openmc.core.utils.messages.Prefix; @@ -35,12 +37,22 @@ import static fr.openmc.core.features.mailboxes.utils.MailboxUtils.getHoverEvent; import static fr.openmc.core.utils.InputUtils.pluralize; -public class MailboxManager { +public class MailboxManager extends Feature implements DatabaseFeature { private static final int MAX_STACKS_PER_LETTER = 27; private static final List letters = new ArrayList<>(); private static int nextLetterId = 1; + @Override + public void init() { + MailboxManager.loadLetters(); + } + + @Override + public void save() { + MailboxManager.saveLetters(); + } + public static boolean sendItems(Player sender, OfflinePlayer receiver, ItemStack[] items) { if (!canSend(sender, receiver)) return false; @@ -245,7 +257,8 @@ public static void cancelLetter(Player player) { private static Dao letterDao; - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, Letter.class); letterDao = DaoManager.createDao(connectionSource, Letter.class); } diff --git a/src/main/java/fr/openmc/core/features/mainmenu/MainMenu.java b/src/main/java/fr/openmc/core/features/mainmenu/MainMenu.java index 898aba1bb..767c9f873 100644 --- a/src/main/java/fr/openmc/core/features/mainmenu/MainMenu.java +++ b/src/main/java/fr/openmc/core/features/mainmenu/MainMenu.java @@ -4,14 +4,22 @@ import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.mainmenu.listeners.PacketListener; import fr.openmc.core.features.mainmenu.menus.Page1; +import fr.openmc.core.utils.init.Feature; +import fr.openmc.core.utils.init.LoadAfterItemsAdder; import org.bukkit.entity.Player; -public class MainMenu { - public static void init(OMCPlugin plugin) { - new PacketListener(plugin); +public class MainMenu extends Feature implements LoadAfterItemsAdder { + @Override + public void init() { + new PacketListener(OMCPlugin.getInstance()); } public static void openMainMenu(Player player) { PacketMenuLib.openMenu(new Page1(player), player); } + + @Override + public void save() { + //nothing to save + } } diff --git a/src/main/java/fr/openmc/core/features/milestones/MilestonesManager.java b/src/main/java/fr/openmc/core/features/milestones/MilestonesManager.java index fe9bc5672..88da4bf4c 100644 --- a/src/main/java/fr/openmc/core/features/milestones/MilestonesManager.java +++ b/src/main/java/fr/openmc/core/features/milestones/MilestonesManager.java @@ -9,18 +9,22 @@ import fr.openmc.core.features.milestones.listeners.PlayerJoin; import fr.openmc.core.features.milestones.tutorial.listeners.TutorialBossBarEvent; import fr.openmc.core.features.quests.objects.Quest; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; +import fr.openmc.core.utils.init.LoadAfterItemsAdder; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import java.sql.SQLException; import java.util.*; -public class MilestonesManager { +public class MilestonesManager extends Feature implements DatabaseFeature, LoadAfterItemsAdder { private static final Set milestones = new HashSet<>(); private static Dao millestoneDao; - public static void init() { + @Override + public void init() { Arrays.stream(MilestoneType.values()).toList().forEach(milestoneType -> registerMilestone(milestoneType.getMilestone())); loadMilestonesData(); @@ -34,12 +38,18 @@ public static void init() { ); } + @Override + public void save() { + MilestonesManager.saveMilestonesData(); + } + /** * Initialize the database for milestones. * * @param connectionSource the connection source to the database */ - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, MilestoneModel.class); millestoneDao = DaoManager.createDao(connectionSource, MilestoneModel.class); } diff --git a/src/main/java/fr/openmc/core/features/quests/QuestsManager.java b/src/main/java/fr/openmc/core/features/quests/QuestsManager.java index 3ece62f0d..4ed83b0f7 100644 --- a/src/main/java/fr/openmc/core/features/quests/QuestsManager.java +++ b/src/main/java/fr/openmc/core/features/quests/QuestsManager.java @@ -3,6 +3,8 @@ import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.quests.objects.Quest; import fr.openmc.core.features.quests.quests.*; +import fr.openmc.core.utils.init.Feature; +import fr.openmc.core.utils.init.LoadAfterItemsAdder; import org.bukkit.Bukkit; import org.bukkit.event.Listener; @@ -17,7 +19,7 @@ * It handles the registration of quests, loading default quests, * and saving quest progress for players. */ -public class QuestsManager { +public class QuestsManager extends Feature implements LoadAfterItemsAdder { static final Map quests = new HashMap<>(); /** @@ -25,11 +27,19 @@ public class QuestsManager { * This constructor initializes the instance of QuestsManager, * loads default quests, and loads all quest progress. */ - public static void init() { + @Override + public void init() { + QuestProgressSaveManager.init(); + loadDefaultQuests(); QuestProgressSaveManager.loadAllQuestProgress(); } + @Override + public void save() { + QuestsManager.saveQuests(); + } + /** * Register a quest. * If the quest is already registered, it will not be registered again. diff --git a/src/main/java/fr/openmc/core/features/settings/PlayerSettingsManager.java b/src/main/java/fr/openmc/core/features/settings/PlayerSettingsManager.java index 0b48e61c0..ca902e30f 100644 --- a/src/main/java/fr/openmc/core/features/settings/PlayerSettingsManager.java +++ b/src/main/java/fr/openmc/core/features/settings/PlayerSettingsManager.java @@ -8,6 +8,8 @@ import com.j256.ormlite.table.TableUtils; import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.settings.models.PlayerSettingEntity; +import fr.openmc.core.utils.init.DatabaseFeature; +import fr.openmc.core.utils.init.Feature; import lombok.Getter; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -23,18 +25,29 @@ import java.util.concurrent.ConcurrentHashMap; @Getter -public class PlayerSettingsManager implements Listener { +public class PlayerSettingsManager extends Feature implements Listener, DatabaseFeature { private static final Map playersSettings = new ConcurrentHashMap<>(); private static Dao playerSettingDao; + @Override + public void init() { + PlayerSettingsManager.loadAllPlayerSettings(); + } + + @Override + public void save() { + PlayerSettingsManager.saveAllSettings(); + } + /** * Initializes the database connection and creates tables if needed. * * @param connectionSource the database connection source * @throws SQLException if database initialization fails */ - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { playerSettingDao = DaoManager.createDao(connectionSource, PlayerSettingEntity.class); try { TableUtils.createTableIfNotExists(connectionSource, PlayerSettingEntity.class); diff --git a/src/main/java/fr/openmc/core/features/tickets/TicketManager.java b/src/main/java/fr/openmc/core/features/tickets/TicketManager.java index 9dc2de51a..1a4e462a2 100644 --- a/src/main/java/fr/openmc/core/features/tickets/TicketManager.java +++ b/src/main/java/fr/openmc/core/features/tickets/TicketManager.java @@ -5,6 +5,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.utils.init.Feature; import lombok.Getter; import lombok.Setter; @@ -15,7 +16,7 @@ import java.util.*; @Getter -public class TicketManager { +public class TicketManager extends Feature { public static int hoursPerTicket = 8; public static final List timePlayed = new ArrayList<>(); @@ -23,14 +24,26 @@ public class TicketManager { private static final Gson gson = new Gson(); @Setter private static File statsDirectory; + public TicketManager(File statsDirectory) { + TicketManager.setStatsDirectory(statsDirectory); + } + + @Override + public void init() { + TicketManager.loadPlayerStats(statsDirectory); + } + + @Override + public void save() { + // nothing to save + } + /** * Load player statistics from JSON files in the specified directory. * * @param statsDirectory The {@link File} directory containing player stats JSON files. */ public static void loadPlayerStats(File statsDirectory) { - TicketManager.setStatsDirectory(statsDirectory); - if (!statsDirectory.exists() || !statsDirectory.isDirectory()) { OMCPlugin.getInstance().getSLF4JLogger().info("Stats directory does not exist or is not a directory."); return; diff --git a/src/main/java/fr/openmc/core/features/tpa/TPAQueue.java b/src/main/java/fr/openmc/core/features/tpa/TPAQueue.java index 6c730739c..44a49f6df 100644 --- a/src/main/java/fr/openmc/core/features/tpa/TPAQueue.java +++ b/src/main/java/fr/openmc/core/features/tpa/TPAQueue.java @@ -5,6 +5,7 @@ import fr.openmc.core.features.tpa.commands.TPACommand; import fr.openmc.core.features.tpa.commands.TPADenyCommand; import fr.openmc.core.features.tpa.commands.TPAcceptCommand; +import fr.openmc.core.utils.init.Feature; import fr.openmc.core.utils.messages.MessageType; import fr.openmc.core.utils.messages.MessagesManager; import fr.openmc.core.utils.messages.Prefix; @@ -17,7 +18,7 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -public class TPAQueue { +public class TPAQueue extends Feature { /** * Map to store teleport requests @@ -26,7 +27,8 @@ public class TPAQueue { private static final ConcurrentHashMap> tpaRequests = new ConcurrentHashMap<>(); private static final ConcurrentHashMap tpaRequestTime = new ConcurrentHashMap<>(); - public static void initCommand() { + @Override + public void init() { CommandsManager.getHandler().register( new TPAcceptCommand(), new TPACommand(), @@ -35,6 +37,11 @@ public static void initCommand() { ); } + @Override + public void save() { + // nothing to save + } + /** * Check if the player has a pending teleport request * @param target The player to check diff --git a/src/main/java/fr/openmc/core/features/updates/UpdateManager.java b/src/main/java/fr/openmc/core/features/updates/UpdateManager.java index 7c8ec3d26..5ecaa7489 100644 --- a/src/main/java/fr/openmc/core/features/updates/UpdateManager.java +++ b/src/main/java/fr/openmc/core/features/updates/UpdateManager.java @@ -1,6 +1,7 @@ package fr.openmc.core.features.updates; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.utils.init.Feature; import lombok.Getter; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; @@ -8,11 +9,12 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -public class UpdateManager { +public class UpdateManager extends Feature { @Getter static Component message; - public static void init() { + @Override + public void init() { String version = OMCPlugin.getInstance().getPluginMeta().getVersion(); String milestoneUrl = "https://github.com/ServerOpenMC/PluginV2/releases/"; @@ -32,6 +34,11 @@ public void run() { }.runTaskTimer(OMCPlugin.getInstance(), 0, period); } + @Override + public void save() { + // nothing to save + } + public static void sendUpdateMessage(Player player) { player.sendMessage(message); } diff --git a/src/main/java/fr/openmc/core/utils/MotdUtils.java b/src/main/java/fr/openmc/core/utils/MotdUtils.java index deb38f590..c30ea49cb 100644 --- a/src/main/java/fr/openmc/core/utils/MotdUtils.java +++ b/src/main/java/fr/openmc/core/utils/MotdUtils.java @@ -1,6 +1,7 @@ package fr.openmc.core.utils; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.utils.init.Feature; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; @@ -11,11 +12,12 @@ import java.util.Map; import java.util.Random; -public class MotdUtils { +public class MotdUtils extends Feature { private static Component motd; private static YamlConfiguration motdConfig = null; - public static void init() { + @Override + public void init() { File motdFile = new File(OMCPlugin.getInstance().getDataFolder() + "/data", "motd.yml"); if (!motdFile.exists()) { @@ -42,4 +44,9 @@ public void run() { } }.runTaskTimer(OMCPlugin.getInstance(), 0L, 12000L); // 12 000 ticks = 10 minutes } + + @Override + public void save() { + // nothing to save + } } diff --git a/src/main/java/fr/openmc/core/utils/database/DatabaseManager.java b/src/main/java/fr/openmc/core/utils/database/DatabaseManager.java index 4fdacadc6..883e0e045 100644 --- a/src/main/java/fr/openmc/core/utils/database/DatabaseManager.java +++ b/src/main/java/fr/openmc/core/utils/database/DatabaseManager.java @@ -2,27 +2,8 @@ import com.j256.ormlite.jdbc.JdbcPooledConnectionSource; import com.j256.ormlite.support.ConnectionSource; -import fr.openmc.api.cooldown.DynamicCooldownManager; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.features.analytics.AnalyticsManager; -import fr.openmc.core.features.city.CityManager; -import fr.openmc.core.features.city.sub.mascots.MascotsManager; -import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.notation.NotationManager; -import fr.openmc.core.features.city.sub.rank.CityRankManager; -import fr.openmc.core.features.city.sub.statistics.CityStatisticsManager; -import fr.openmc.core.features.city.sub.war.WarManager; -import fr.openmc.core.features.contest.managers.ContestManager; -import fr.openmc.core.features.dream.DreamManager; -import fr.openmc.core.features.economy.BankManager; -import fr.openmc.core.features.economy.EconomyManager; -import fr.openmc.core.features.economy.TransactionsManager; -import fr.openmc.core.features.events.halloween.managers.HalloweenManager; -import fr.openmc.core.features.friend.FriendSQLManager; -import fr.openmc.core.features.homes.HomesManager; -import fr.openmc.core.features.mailboxes.MailboxManager; -import fr.openmc.core.features.milestones.MilestonesManager; -import fr.openmc.core.features.settings.PlayerSettingsManager; +import fr.openmc.core.utils.init.DatabaseFeature; import lombok.Getter; import org.bukkit.configuration.file.FileConfiguration; @@ -53,26 +34,19 @@ public static void init() { String password = config.getString("database.password"); connectionSource = new JdbcPooledConnectionSource(databaseUrl, username, password); - DreamManager.initDB(connectionSource); - WarManager.initDB(connectionSource); - NotationManager.initDB(connectionSource); - MayorManager.initDB(connectionSource); - MilestonesManager.initDB(connectionSource); - BankManager.initDB(connectionSource); - TransactionsManager.initDB(connectionSource); - AnalyticsManager.initDB(connectionSource); - MailboxManager.initDB(connectionSource); - ContestManager.initDB(connectionSource); - EconomyManager.initDB(connectionSource); - HomesManager.initDB(connectionSource); - FriendSQLManager.initDB(connectionSource); - DynamicCooldownManager.initDB(connectionSource); - CityManager.initDB(connectionSource); - CityRankManager.initDB(connectionSource); - MascotsManager.initDB(connectionSource); - PlayerSettingsManager.initDB(connectionSource); - CityStatisticsManager.initDB(connectionSource); - HalloweenManager.initDB(connectionSource); + OMCPlugin.getInstance().REGISTRY_FEATURE.stream() + .filter(f -> f instanceof DatabaseFeature) + .forEach(f -> { + try { + ((DatabaseFeature) f).initDB(connectionSource); + } catch (SQLException e) { + OMCPlugin.getInstance().getSLF4JLogger().error("Failed to initialize the database connection.", e); + throw new RuntimeException(e); + } catch (ConnectionPendingException e) { + OMCPlugin.getInstance().getSLF4JLogger().error("Database connection is pending. Please check your database configuration."); + throw new RuntimeException(e); + } + }); } catch (SQLException e) { OMCPlugin.getInstance().getSLF4JLogger().error("Failed to initialize the database connection.", e); throw new RuntimeException(e); diff --git a/src/main/java/fr/openmc/core/utils/init/DatabaseFeature.java b/src/main/java/fr/openmc/core/utils/init/DatabaseFeature.java new file mode 100644 index 000000000..056b1d05e --- /dev/null +++ b/src/main/java/fr/openmc/core/utils/init/DatabaseFeature.java @@ -0,0 +1,13 @@ +package fr.openmc.core.utils.init; + +import com.j256.ormlite.support.ConnectionSource; + +import java.sql.SQLException; + +/** + * Interface permettant aux features d'initialiser leur base de données lors du démarrage du plugin. + */ +public interface DatabaseFeature { + void initDB(ConnectionSource connectionSource) throws SQLException; +} + diff --git a/src/main/java/fr/openmc/core/utils/init/Feature.java b/src/main/java/fr/openmc/core/utils/init/Feature.java new file mode 100644 index 000000000..fd40897e8 --- /dev/null +++ b/src/main/java/fr/openmc/core/utils/init/Feature.java @@ -0,0 +1,40 @@ +package fr.openmc.core.utils.init; + +import com.j256.ormlite.support.ConnectionSource; +import fr.openmc.core.OMCPlugin; + +import java.sql.SQLException; + +public abstract class Feature { + protected boolean initialize = false; + + public void startInit() { + if (this instanceof NotUnitTestFeature && OMCPlugin.isUnitTestVersion()) return; + try { + init(); + initialize = true; + } catch (Exception e) { + initialize = false; + throw e; + } + } + + public final void startDB(ConnectionSource connectionSource) throws SQLException { + if (this instanceof NotUnitTestFeature && OMCPlugin.isUnitTestVersion()) return; + if (this instanceof DatabaseFeature dbF) { + dbF.initDB(connectionSource); + } + } + + public final void startSave() { + if (!initialize) return; + save(); + } + + public final boolean isInitialized() { + return initialize; + } + + protected abstract void init(); + protected abstract void save(); +} diff --git a/src/main/java/fr/openmc/core/utils/init/LoadAfterItemsAdder.java b/src/main/java/fr/openmc/core/utils/init/LoadAfterItemsAdder.java new file mode 100644 index 000000000..94891d3b0 --- /dev/null +++ b/src/main/java/fr/openmc/core/utils/init/LoadAfterItemsAdder.java @@ -0,0 +1,7 @@ +package fr.openmc.core.utils.init; + +/** + * Charge la feature apres ItemsAdder + */ +public interface LoadAfterItemsAdder { } + diff --git a/src/main/java/fr/openmc/core/utils/init/NotUnitTestFeature.java b/src/main/java/fr/openmc/core/utils/init/NotUnitTestFeature.java new file mode 100644 index 000000000..f15dc4cf5 --- /dev/null +++ b/src/main/java/fr/openmc/core/utils/init/NotUnitTestFeature.java @@ -0,0 +1,7 @@ +package fr.openmc.core.utils.init; + +/** + * Exclu la feature a ne pas etre chargé sur la version de test + */ +public interface NotUnitTestFeature { } + diff --git a/src/main/java/fr/openmc/core/utils/translation/TranslationManager.java b/src/main/java/fr/openmc/core/utils/translation/TranslationManager.java index 3bd84e8bd..091bcf3d5 100644 --- a/src/main/java/fr/openmc/core/utils/translation/TranslationManager.java +++ b/src/main/java/fr/openmc/core/utils/translation/TranslationManager.java @@ -1,6 +1,7 @@ package fr.openmc.core.utils.translation; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.utils.init.Feature; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -10,19 +11,27 @@ import java.util.Objects; -public class TranslationManager { +public class TranslationManager extends Feature { private static String defaultLanguage; private static File translationFolder; private static final Map loadedLanguages = new HashMap<>(); - - public static void init(File inTranslationFolder, String inDefaultLanguage) { + public TranslationManager(File inTranslationFolder, String inDefaultLanguage) { defaultLanguage = inDefaultLanguage; translationFolder = inTranslationFolder; + } + @Override + public void init() { loadAllLanguages(); } + + @Override + public void save() { + + } + /** * Returns a string corresponding to the specified path and the language. * From 212cddde0fb1de2a11fcecef4aef537d768ccace Mon Sep 17 00:00:00 2001 From: iambibi_ <89582596+iambibi@users.noreply.github.com> Date: Sun, 29 Mar 2026 21:06:15 +0200 Subject: [PATCH 2/2] build fix + add log --- .../api/cooldown/DynamicCooldownManager.java | 2 +- src/main/java/fr/openmc/core/OMCPlugin.java | 14 +++++++++++--- .../cube/multiblocks/MultiBlockManager.java | 8 ++++++-- .../java/fr/openmc/core/utils/init/Feature.java | 2 ++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/openmc/api/cooldown/DynamicCooldownManager.java b/src/main/java/fr/openmc/api/cooldown/DynamicCooldownManager.java index a97b49aa1..fb4ad7ac3 100644 --- a/src/main/java/fr/openmc/api/cooldown/DynamicCooldownManager.java +++ b/src/main/java/fr/openmc/api/cooldown/DynamicCooldownManager.java @@ -91,7 +91,7 @@ public void init() { @Override public void save() { - DynamicCooldownManager.saveCooldowns() + DynamicCooldownManager.saveCooldowns(); } // Map structure: UUID -> (Group -> Cooldown) diff --git a/src/main/java/fr/openmc/core/OMCPlugin.java b/src/main/java/fr/openmc/core/OMCPlugin.java index b088a60e0..81ef0dd02 100644 --- a/src/main/java/fr/openmc/core/OMCPlugin.java +++ b/src/main/java/fr/openmc/core/OMCPlugin.java @@ -1,5 +1,6 @@ package fr.openmc.core; + import com.j256.ormlite.logger.LoggerFactory; import fr.openmc.api.cooldown.DynamicCooldownManager; import fr.openmc.api.hooks.*; @@ -136,9 +137,9 @@ public void onEnable() { Datapack pack = this.getServer().getDatapackManager().getPack(getPluginMeta().getName() + "/omc"); if (pack != null) { if (pack.isEnabled()) { - getSLF4JLogger().info("\u001B[32m✔ Lancement du datapack réussi\u001B[0m"); + logSuccessMessage("Lancement du datapack réussi"); } else { - getSLF4JLogger().warn("\u001B[31m✘ Lancement du datapack échoué\u001B[0m"); + logErrorMessage("Lancement du datapack échoué"); } } } @@ -203,9 +204,16 @@ public static boolean isUnitTestVersion() { } /* LOG MESSAGE */ + public void logSuccessMessage(String message) { + this.getSLF4JLogger().info("\u001B[32m✔ {}\u001B[0m", message); + } + + public void logErrorMessage(String message) { + this.getSLF4JLogger().info("\u001B[31m✔ {}\u001B[0m", message); + } private void logLoadMessage() { - Logger log = getSLF4JLogger(); + Logger log = this.getSLF4JLogger(); String pluginVersion = getPluginMeta().getVersion(); String javaVersion = System.getProperty("java.version"); diff --git a/src/main/java/fr/openmc/core/features/cube/multiblocks/MultiBlockManager.java b/src/main/java/fr/openmc/core/features/cube/multiblocks/MultiBlockManager.java index c7252bd39..0ec2e2622 100644 --- a/src/main/java/fr/openmc/core/features/cube/multiblocks/MultiBlockManager.java +++ b/src/main/java/fr/openmc/core/features/cube/multiblocks/MultiBlockManager.java @@ -85,6 +85,10 @@ public static void load() { @Override public void save() { + saveConfig(); + } + + public static void saveConfig() { if (config == null) return; List> list = new ArrayList<>(); @@ -117,9 +121,9 @@ public void save() { } } - public void register(MultiBlock multiBlock) { + public static void register(MultiBlock multiBlock) { multiBlocks.add(multiBlock); - save(); + saveConfig(); } } diff --git a/src/main/java/fr/openmc/core/utils/init/Feature.java b/src/main/java/fr/openmc/core/utils/init/Feature.java index fd40897e8..cbf2ed1e2 100644 --- a/src/main/java/fr/openmc/core/utils/init/Feature.java +++ b/src/main/java/fr/openmc/core/utils/init/Feature.java @@ -13,8 +13,10 @@ public void startInit() { try { init(); initialize = true; + OMCPlugin.getInstance().logSuccessMessage("Feature " + this.getClass().getSimpleName() + " initialisée correctement."); } catch (Exception e) { initialize = false; + OMCPlugin.getInstance().logSuccessMessage("Feature " + this.getClass().getSimpleName() + " pas initialisée correctement."); throw e; } }