diff --git a/src/main/java/fr/openmc/api/cooldown/DynamicCooldownManager.java b/src/main/java/fr/openmc/api/cooldown/DynamicCooldownManager.java index 47aea6ea9..0b7dd82cf 100644 --- a/src/main/java/fr/openmc/api/cooldown/DynamicCooldownManager.java +++ b/src/main/java/fr/openmc/api/cooldown/DynamicCooldownManager.java @@ -7,13 +7,12 @@ import com.j256.ormlite.table.DatabaseTable; import com.j256.ormlite.table.TableUtils; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.commands.debug.DebugCooldownCommand; import fr.openmc.core.commands.utils.CooldownCommand; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; @@ -24,7 +23,7 @@ /** * Main class for managing cooldowns */ -public class DynamicCooldownManager extends Feature implements LoadAfterItemsAdder, HasDatabase, HasCommands { +public class DynamicCooldownManager extends Feature implements HasDatabase, HasCommands { /** * Represents a single cooldown with duration and last use time diff --git a/src/main/java/fr/openmc/api/entity/player/sub/OMCPlayerCity.java b/src/main/java/fr/openmc/api/entity/player/sub/OMCPlayerCity.java index 34e09e2ea..606bc664c 100644 --- a/src/main/java/fr/openmc/api/entity/player/sub/OMCPlayerCity.java +++ b/src/main/java/fr/openmc/api/entity/player/sub/OMCPlayerCity.java @@ -1,18 +1,22 @@ package fr.openmc.api.entity.player.sub; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; public class OMCPlayerCity extends OMCPlayerFeat { + private final CityManager cityManager; + public OMCPlayerCity(Player player) { super(player); + this.cityManager = OMCRegistry.FEATURES.CITY.get(); } @Nullable public City getCity() { - return CityManager.getCity(getUniqueId()); + return cityManager.getCity(getUniqueId()); } public boolean hasCity() { diff --git a/src/main/java/fr/openmc/api/menulib/Menu.java b/src/main/java/fr/openmc/api/menulib/Menu.java index fc3212194..c7dfb2499 100644 --- a/src/main/java/fr/openmc/api/menulib/Menu.java +++ b/src/main/java/fr/openmc/api/menulib/Menu.java @@ -4,7 +4,7 @@ import fr.openmc.api.menulib.events.OpenMenuEvent; import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; -import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.utils.bukkit.ItemUtils; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -274,7 +274,7 @@ public final boolean isItem(ItemStack item, String itemId) { public final Inventory getInventory() { Component title = getName(); - if (ItemsAdderHook.isEnable() && (getTexture() != null && !getTexture().isEmpty()) && getTexture() != null && !getTexture().isEmpty()) { + if (OMCRegistry.HOOKS.ITEMS_ADDER.isEnable() && (getTexture() != null && !getTexture().isEmpty()) && getTexture() != null && !getTexture().isEmpty()) { title = Component.text(getTexture()); } diff --git a/src/main/java/fr/openmc/api/menulib/MenuLib.java b/src/main/java/fr/openmc/api/menulib/MenuLib.java index 90db817fd..469d5c4c2 100644 --- a/src/main/java/fr/openmc/api/menulib/MenuLib.java +++ b/src/main/java/fr/openmc/api/menulib/MenuLib.java @@ -3,8 +3,8 @@ import fr.openmc.api.menulib.template.ConfirmMenu; import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.homes.menu.HomeDeleteConfirmMenu; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.utils.bukkit.ItemUtils; import lombok.Getter; import org.bukkit.Bukkit; diff --git a/src/main/java/fr/openmc/api/menulib/utils/ItemMenuBuilder.java b/src/main/java/fr/openmc/api/menulib/utils/ItemMenuBuilder.java index f2d1f6fce..8d1b461dc 100644 --- a/src/main/java/fr/openmc/api/menulib/utils/ItemMenuBuilder.java +++ b/src/main/java/fr/openmc/api/menulib/utils/ItemMenuBuilder.java @@ -3,7 +3,7 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.api.menulib.MenuLib; import fr.openmc.api.menulib.PaginatedMenu; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.registry.items.CustomItem; import fr.openmc.core.utils.bukkit.ItemBuilder; import fr.openmc.core.utils.text.messages.MessageType; diff --git a/src/main/java/fr/openmc/api/packetmenulib/utils/PacketUtils.java b/src/main/java/fr/openmc/api/packetmenulib/utils/PacketUtils.java index f0bbf1bcf..b18f3958e 100644 --- a/src/main/java/fr/openmc/api/packetmenulib/utils/PacketUtils.java +++ b/src/main/java/fr/openmc/api/packetmenulib/utils/PacketUtils.java @@ -4,7 +4,7 @@ import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketContainer; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; import io.papermc.paper.adventure.PaperAdventure; import net.minecraft.network.chat.Component; import net.minecraft.world.inventory.MenuType; diff --git a/src/main/java/fr/openmc/core/ListenersManager.java b/src/main/java/fr/openmc/core/ListenersManager.java index 079783e58..fde3ccc8d 100644 --- a/src/main/java/fr/openmc/core/ListenersManager.java +++ b/src/main/java/fr/openmc/core/ListenersManager.java @@ -2,8 +2,8 @@ import fr.openmc.api.input.ChatInput; import fr.openmc.api.input.location.ItemInteraction; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.itemsadder.SpawnerExtractorListener; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; import fr.openmc.core.listeners.*; import fr.openmc.core.utils.nms.entity.EntityGlowNMS; diff --git a/src/main/java/fr/openmc/core/OMCBootstrap.java b/src/main/java/fr/openmc/core/OMCBootstrap.java index ccdc6e821..95fae9e40 100644 --- a/src/main/java/fr/openmc/core/OMCBootstrap.java +++ b/src/main/java/fr/openmc/core/OMCBootstrap.java @@ -1,14 +1,12 @@ package fr.openmc.core; -import fr.openmc.core.bootstrap.integration.DatapackLoader; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.lifecycle.integration.DatapackLoader; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.utils.text.messages.TranslationManager; import io.papermc.paper.plugin.bootstrap.BootstrapContext; import io.papermc.paper.plugin.bootstrap.PluginBootstrap; import io.papermc.paper.plugin.bootstrap.PluginProviderContext; -import io.papermc.paper.registry.event.RegistryEvents; -import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/fr/openmc/core/OMCPlugin.java b/src/main/java/fr/openmc/core/OMCPlugin.java index efb97d041..2d428dae2 100644 --- a/src/main/java/fr/openmc/core/OMCPlugin.java +++ b/src/main/java/fr/openmc/core/OMCPlugin.java @@ -1,67 +1,14 @@ package fr.openmc.core; import com.j256.ormlite.logger.LoggerFactory; -import fr.openmc.api.cooldown.DynamicCooldownManager; import fr.openmc.api.menulib.MenuLib; import fr.openmc.api.packetmenulib.PacketMenuLib; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.FeatureFactory; -import fr.openmc.core.bootstrap.features.FeatureLoadingType; -import fr.openmc.core.bootstrap.hooks.Hooks; -import fr.openmc.core.bootstrap.integration.DatabaseManager; -import fr.openmc.core.bootstrap.integration.ErrorReporter; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; -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.bits.BitsManager; -import fr.openmc.core.features.chatanimations.ChatAnimationManager; -import fr.openmc.core.features.city.CityManager; -import fr.openmc.core.features.city.sub.mascots.MascotsManager; -import fr.openmc.core.features.cube.multiblocks.MultiBlockManager; -import fr.openmc.core.features.dimopener.DimensionOpenerManager; -import fr.openmc.core.features.displays.TabList; -import fr.openmc.core.features.displays.bossbar.BossbarManager; -import fr.openmc.core.features.displays.bossbar.contents.HelpConfigManager; -import fr.openmc.core.features.displays.holograms.HologramLoader; -import fr.openmc.core.features.displays.scoreboards.ScoreboardManager; -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.EventsManager; -import fr.openmc.core.features.events.contents.dailyevents.DailyEventsManager; -import fr.openmc.core.features.events.contents.halloween.managers.HalloweenManager; -import fr.openmc.core.features.events.contents.weeklyevents.WeeklyEventsManager; -import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.managers.ContestManager; -import fr.openmc.core.features.friend.FriendManager; -import fr.openmc.core.features.homes.HomesManager; -import fr.openmc.core.features.homes.icons.HomeIconCacheManager; -import fr.openmc.core.features.itemsadder.elevator.ElevatorManager; -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.privatemessage.PrivateMessageManager; -import fr.openmc.core.features.privatemessage.SocialSpyManager; -import fr.openmc.core.features.profile.ProfileManager; -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.shops.managers.ShopManager; -import fr.openmc.core.features.tickets.TicketManager; -import fr.openmc.core.features.toor.DiscordLinkManager; -import fr.openmc.core.features.tpa.TPAManager; -import fr.openmc.core.features.updates.UpdateManager; -import fr.openmc.core.hooks.*; -import fr.openmc.core.hooks.github.GitHubHook; -import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.lifecycle.integration.DatabaseManager; +import fr.openmc.core.lifecycle.integration.ErrorReporter; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; import fr.openmc.core.listeners.ItemsAddersListener; import fr.openmc.core.utils.bukkit.ParticleUtils; -import fr.openmc.core.utils.text.MotdUtils; import io.papermc.paper.datapack.Datapack; import lombok.Getter; import org.bukkit.Bukkit; @@ -70,10 +17,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import java.io.File; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; /** * Plugin principal OpenMC. @@ -87,70 +31,6 @@ public class OMCPlugin extends JavaPlugin { public static final String VANISH_META_KEY = "omcstaff.vanished"; - // ** Registry of OMC Features - // () -> : nécessaire si y'a un package d'api externe (ex com.comphenix.protocol) - public final List REGISTRY_FEATURE = new ArrayList<>(List.of( - () -> new TicketManager(new File(this.getDataFolder(), "data/stats")), - PrivateMessageManager::new, - SocialSpyManager::new, - SpawnManager::new, - UpdateManager::new, - EconomyManager::new, - BankManager::new, - BitsManager::new, - ScoreboardManager::new, - HomesManager::new, - TPAManager::new, - FreezeManager::new, - TransactionsManager::new, - AnalyticsManager::new, - FriendManager::new, - () -> new TabList(), - AdminShopManager::new, - HelpConfigManager::new, - () -> new AnimationsManager(), - () -> new HalloweenManager(), - QuestProgressSaveManager::new, - MotdUtils::new, - MascotsManager::new, - PlayerSettingsManager::new, - MailboxManager::new, - DiscordLinkManager::new, - ProfileManager::new, - QuestsManager::new, - CityManager::new, - DynamicCooldownManager::new, - ContestManager::new, - WeeklyEventsManager::new, - DailyEventsManager::new, - ChatAnimationManager::new, - EventsManager::new, - DreamManager::new, - MultiBlockManager::new, - MilestonesManager::new, - () -> new LeaderboardManager(), - () -> new MainMenu(), - () -> new HologramLoader(), - BossbarManager::new, - ShopManager::new, - HomeIconCacheManager::new, - DimensionOpenerManager::new, - () -> new ElevatorManager() - )); - - public static final List loadedFeature = new ArrayList<>(); - - // ** Registry of OMC Plugin Hooks - public final List REGISTRY_HOOKS = new ArrayList<>(List.of( - new ProtocolLibHook(), - new LuckPermsHook(), - new PapiHook(), - new WorldGuardHook(), - new ItemsAdderHook(), - new FancyNpcsHook(), - new GitHubHook() - )); - @Override public void onLoad() { LoggerFactory.setLogBackendFactory(DatabaseManager.ShutUpOrmLite::new); @@ -172,12 +52,6 @@ public void onEnable() { /* EXTERNALS */ MenuLib.init(this); - /* HOOKS */ - REGISTRY_HOOKS.forEach(Hooks::startInit); - - if (!OMCPlugin.isUnitTestVersion() && ProtocolLibHook.isEnable()) - PacketMenuLib.init(this); - OMCLogger.logLoadMessage(this); if (!OMCPlugin.isUnitTestVersion()) { Datapack pack = this.getServer().getDatapackManager().getPack(getPluginMeta().getName() + "/omc"); @@ -198,16 +72,11 @@ public void onEnable() { /* REGISTRIES */ OMCRegistry.initAll(); - /* FEATURES */ - REGISTRY_FEATURE - .forEach(f -> { - Feature feature = f.create(FeatureLoadingType.RUNTIME); - - registerFeature(feature); - }); + if (!OMCPlugin.isUnitTestVersion() && OMCRegistry.HOOKS.PROTOCOL_LIB.isEnable()) + PacketMenuLib.init(this); // * Si ItemsAdder n'est pas présent, alors on charge les dernières features maintenant - if (!ItemsAdderHook.isEnable()) { + if (!OMCRegistry.HOOKS.ITEMS_ADDER.isEnable()) { loadAfterItemsAdder(); } } @@ -219,20 +88,12 @@ public void loadAfterItemsAdder() { ItemsAddersListener.setLoaded(true); /* LOAD ITEMS ADDER CONTENTS */ - ItemsAdderHook.loadContents(); + OMCRegistry.HOOKS.ITEMS_ADDER.loadContents(); /* REGISTRIES */ OMCRegistry.postInitAll(); - /* FEATURES */ - REGISTRY_FEATURE - .forEach(f -> { - Feature feature = f.create(FeatureLoadingType.AFTER_IA); - - registerFeature(feature); - }); - - if (WorldGuardHook.isEnable()) { + if (OMCRegistry.HOOKS.WORLD_GUARD.isEnable()) { ParticleUtils.spawnParticlesInRegion("spawn", Bukkit.getWorld("world"), Particle.CHERRY_LEAVES, 50, 70, 130); } } @@ -243,13 +104,6 @@ public void loadAfterItemsAdder() { @Override public void onDisable() { // ** SAVE ** - /* HOOKS */ - REGISTRY_HOOKS.forEach(Hooks::startSave); - - for (Feature feature : loadedFeature) { - feature.startSave(); - } - /* REGISTRIES */ OMCRegistry.stopAll(); @@ -282,18 +136,6 @@ public static void registerEvents(Collection listeners) { registerEvents(listeners.toArray(new ListenerFactory[0])); } - /** - * Enregistre une feature dans le registre des features - * - * @param feature Feature à register - */ - public static void registerFeature(Feature feature) { - if (feature != null) { - feature.startInit(); - loadedFeature.add(feature); - } - } - /** * Indique si le plugin tourne dans les tests unitaires. * diff --git a/src/main/java/fr/openmc/core/OMCRegistry.java b/src/main/java/fr/openmc/core/OMCRegistry.java index 4d271ea61..6ae4e7d6f 100644 --- a/src/main/java/fr/openmc/core/OMCRegistry.java +++ b/src/main/java/fr/openmc/core/OMCRegistry.java @@ -1,14 +1,16 @@ package fr.openmc.core; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.registries.LifecycleRegistry; -import fr.openmc.core.bootstrap.registries.RegistryContext; -import fr.openmc.core.bootstrap.registries.RegistryLoadingType; import fr.openmc.core.features.events.contents.dailyevents.DailyEventsRegistry; import fr.openmc.core.features.events.contents.weeklyevents.WeeklyEventsRegistry; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.registries.LifecycleRegistry; +import fr.openmc.core.lifecycle.registries.RegistryContext; +import fr.openmc.core.lifecycle.registries.RegistryLoadingType; import fr.openmc.core.registry.ambient.CustomAmbientRegistry; import fr.openmc.core.registry.enchantments.CustomEnchantmentRegistry; +import fr.openmc.core.registry.features.FeaturesRegistry; +import fr.openmc.core.registry.hooks.HooksRegistry; import fr.openmc.core.registry.items.CustomItemRegistry; import fr.openmc.core.registry.lootboxes.CustomLootboxRegistry; import fr.openmc.core.registry.loottable.CustomLootTableRegistry; @@ -23,6 +25,9 @@ @SuppressWarnings("UnstableApiUsage") public final class OMCRegistry { // * Registre globaux + public static FeaturesRegistry FEATURES; + public static HooksRegistry HOOKS; + public static CustomItemRegistry CUSTOM_ITEMS; public static CustomMobRegistry CUSTOM_MOBS; public static CustomEnchantmentRegistry CUSTOM_ENCHANTS; @@ -36,7 +41,10 @@ public final class OMCRegistry { private static final List LOADED = new ArrayList<>(); - private static final List ALL = List.of( + private static final List ALL = new ArrayList<>(List.of( + new RegistryContext( + () -> HOOKS = new HooksRegistry(), + RegistryLoadingType.RUNTIME), new RegistryContext( () -> CUSTOM_ITEMS = new CustomItemRegistry(), RegistryLoadingType.AFTER_IA), @@ -57,8 +65,11 @@ public final class OMCRegistry { new RegistryContext(() -> WEEKLY_EVENTS = new WeeklyEventsRegistry(), RegistryLoadingType.AFTER_IA), new RegistryContext(() -> DAILY_EVENTS = new DailyEventsRegistry(), - RegistryLoadingType.AFTER_IA) - ); + RegistryLoadingType.AFTER_IA), + new RegistryContext( + () -> FEATURES = new FeaturesRegistry(), + RegistryLoadingType.RUNTIME, RegistryLoadingType.AFTER_IA) + )); private OMCRegistry() {} diff --git a/src/main/java/fr/openmc/core/bootstrap/features/FeatureFactory.java b/src/main/java/fr/openmc/core/bootstrap/features/FeatureFactory.java deleted file mode 100644 index b2038b0f9..000000000 --- a/src/main/java/fr/openmc/core/bootstrap/features/FeatureFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -package fr.openmc.core.bootstrap.features; - -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.integration.OMCLogger; - -@FunctionalInterface -public interface FeatureFactory { - Feature create() throws NoClassDefFoundError; - - default Feature create(FeatureLoadingType type) { - Feature feature = null; - try { - feature = create(); - } catch (NoClassDefFoundError e) { - String featureName = "null"; - if (feature != null) { - featureName = feature.getClass().getSimpleName(); - } - - OMCLogger.errorFormatted("Plugin has failed to start feature {} because {} does not exist.", - featureName, e.getMessage()); - } - - if ((type.equals(FeatureLoadingType.RUNTIME) && !(feature instanceof LoadAfterItemsAdder)) || - (type.equals(FeatureLoadingType.AFTER_IA) && feature instanceof LoadAfterItemsAdder) - ) { - return feature; - } - return null; - } -} diff --git a/src/main/java/fr/openmc/core/bootstrap/features/types/HasFeature.java b/src/main/java/fr/openmc/core/bootstrap/features/types/HasFeature.java deleted file mode 100644 index ab3da5354..000000000 --- a/src/main/java/fr/openmc/core/bootstrap/features/types/HasFeature.java +++ /dev/null @@ -1,13 +0,0 @@ -package fr.openmc.core.bootstrap.features.types; - -import fr.openmc.core.bootstrap.features.Feature; - -/** - * Interface permettant aux classes d'enregistrer une feature - */ -public interface HasFeature { - /** - * Feature à initialiser - */ - Feature getFeature(); -} diff --git a/src/main/java/fr/openmc/core/bootstrap/features/types/LoadAfterItemsAdder.java b/src/main/java/fr/openmc/core/bootstrap/features/types/LoadAfterItemsAdder.java deleted file mode 100644 index 42aeb603e..000000000 --- a/src/main/java/fr/openmc/core/bootstrap/features/types/LoadAfterItemsAdder.java +++ /dev/null @@ -1,6 +0,0 @@ -package fr.openmc.core.bootstrap.features.types; - -/** - * Marque une feature a initialiser apres la disponibilite d'ItemsAdder. - */ -public interface LoadAfterItemsAdder { } 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 f96005122..78a017f2b 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,9 +1,9 @@ package fr.openmc.core.commands.admin.freeze; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; import fr.openmc.core.utils.text.messages.Prefix; diff --git a/src/main/java/fr/openmc/core/commands/utils/CooldownCommand.java b/src/main/java/fr/openmc/core/commands/utils/CooldownCommand.java index 33effac02..7e8a0b5cc 100644 --- a/src/main/java/fr/openmc/core/commands/utils/CooldownCommand.java +++ b/src/main/java/fr/openmc/core/commands/utils/CooldownCommand.java @@ -1,8 +1,8 @@ package fr.openmc.core.commands.utils; import fr.openmc.api.cooldown.DynamicCooldownManager; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.utils.text.DateUtils; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -46,7 +46,7 @@ public void cooldowns(Player sender) { )) ); - City playerCity = CityManager.getCity(sender.getUniqueId()); + City playerCity = OMCRegistry.FEATURES.CITY.get().getCity(sender.getUniqueId()); if (playerCity != null) { DynamicCooldownManager.getCooldowns(playerCity.getUniqueId()).forEach( diff --git a/src/main/java/fr/openmc/core/commands/utils/Restart.java b/src/main/java/fr/openmc/core/commands/utils/Restart.java index d752466c1..1f3a83795 100644 --- a/src/main/java/fr/openmc/core/commands/utils/Restart.java +++ b/src/main/java/fr/openmc/core/commands/utils/Restart.java @@ -1,8 +1,8 @@ package fr.openmc.core.commands.utils; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; import fr.openmc.core.utils.text.messages.Prefix; @@ -43,7 +43,7 @@ public void restart(CommandSender sender) { remainingTime = 60; // protection pour le bug de duplication - for (City city : CityManager.getCities()) { + for (City city : OMCRegistry.FEATURES.CITY.get().getCities()) { UUID watcherUUID = city.getChestWatcher(); if (watcherUUID == null) continue; Player player = Bukkit.getPlayer(watcherUUID); 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 c65c872d1..ab29183e6 100644 --- a/src/main/java/fr/openmc/core/commands/utils/SpawnManager.java +++ b/src/main/java/fr/openmc/core/commands/utils/SpawnManager.java @@ -1,12 +1,12 @@ package fr.openmc.core.commands.utils; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; import fr.openmc.core.listeners.RespawnListener; +import fr.openmc.core.registry.features.Feature; import lombok.Getter; import org.bukkit.Location; import org.bukkit.World; diff --git a/src/main/java/fr/openmc/core/features/adminshop/AdminShopCommand.java b/src/main/java/fr/openmc/core/features/adminshop/AdminShopCommand.java index 1f882ecde..e2282e241 100644 --- a/src/main/java/fr/openmc/core/features/adminshop/AdminShopCommand.java +++ b/src/main/java/fr/openmc/core/features/adminshop/AdminShopCommand.java @@ -7,10 +7,16 @@ public class AdminShopCommand { + private final AdminShopManager manager; + + public AdminShopCommand(AdminShopManager manager) { + this.manager = manager; + } + @Command("adminshop") @Description("Ouvrir le menu du shop admin") @CommandPermission("omc.commands.adminshop") public void openAdminShop(Player player) { - AdminShopManager.openMainMenu(player); + manager.openMainMenu(player); } } \ No newline at end of file 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 87750f44e..f86175556 100644 --- a/src/main/java/fr/openmc/core/features/adminshop/AdminShopManager.java +++ b/src/main/java/fr/openmc/core/features/adminshop/AdminShopManager.java @@ -1,13 +1,13 @@ package fr.openmc.core.features.adminshop; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; import fr.openmc.core.features.adminshop.events.BuyEvent; import fr.openmc.core.features.adminshop.events.SellEvent; import fr.openmc.core.features.adminshop.menus.*; import fr.openmc.core.features.economy.EconomyManager; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.bukkit.ItemUtils; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -26,25 +26,25 @@ */ @Credit(developers = {"Axeno"}, graphist = {"Gexary"}) public class AdminShopManager extends Feature implements HasCommands { - public static final Map categories = new HashMap<>(); - public static final Map> items = new HashMap<>(); // Category -> {ShopID -> ShopItem} - public static final Map currentCategory = new HashMap<>(); - public static final DecimalFormat priceFormat = new DecimalFormat("#,##0.00"); - private static AdminShopYAML adminShopYAML; + public final Map categories = new HashMap<>(); + public final Map> items = new HashMap<>(); // Category -> {ShopID -> ShopItem} + public final Map currentCategory = new HashMap<>(); + public final DecimalFormat priceFormat = new DecimalFormat("#,##0.00"); + private AdminShopYAML adminShopYAML; /** * Initializes the AdminShopManager by loading the configuration. */ @Override public void init() { - adminShopYAML = new AdminShopYAML(); + adminShopYAML = new AdminShopYAML(this); adminShopYAML.loadConfig(); } @Override public Set getCommands() { return Set.of( - new AdminShopCommand() + new AdminShopCommand(this) ); } @@ -55,11 +55,11 @@ public Set getCommands() { * @param categoryId The ID of the category. * @param itemId The ID of the item. */ - public static void openBuyConfirmMenu(Player player, String categoryId, String itemId) { + public void openBuyConfirmMenu(Player player, String categoryId, String itemId) { ShopItem item = getItemSafe(player, categoryId, itemId); if (item == null) return; - new ConfirmMenu(player, item, true).open(); + new ConfirmMenu(player, this, item, true).open(); } /** @@ -69,7 +69,7 @@ public static void openBuyConfirmMenu(Player player, String categoryId, String i * @param categoryId The ID of the category. * @param itemId The ID of the item. */ - public static void openSellConfirmMenu(Player player, String categoryId, String itemId) { + public void openSellConfirmMenu(Player player, String categoryId, String itemId) { ShopItem item = getItemSafe(player, categoryId, itemId); if (item == null) return; @@ -78,7 +78,7 @@ public static void openSellConfirmMenu(Player player, String categoryId, String return; } - new ConfirmMenu(player, item, false).open(); + new ConfirmMenu(player, this, item, false).open(); } /** @@ -88,7 +88,7 @@ public static void openSellConfirmMenu(Player player, String categoryId, String * @param itemId The ID of the item. * @param amount The quantity to purchase. */ - public static void buyItem(Player player, String itemId, int amount) { + public void buyItem(Player player, String itemId, int amount) { ShopItem item = getCurrentItem(player, itemId); if (item == null) return; @@ -124,7 +124,7 @@ public static void buyItem(Player player, String itemId, int amount) { * @param itemId The ID of the item. * @param amount The quantity to sell. */ - public static void sellItem(Player player, String itemId, int amount) { + public void sellItem(Player player, String itemId, int amount) { ShopItem item = getCurrentItem(player, itemId); // Get the item from the current category if (item == null) return; @@ -159,7 +159,7 @@ public static void sellItem(Player player, String itemId, int amount) { * @param amount The quantity bought/sold. * @param isBuying True if buying, false if selling. */ - private static void adjustPrice(String categoryId, String itemId, int amount, boolean isBuying) { + private void adjustPrice(String categoryId, String itemId, int amount, boolean isBuying) { ShopItem item = items.getOrDefault(categoryId, Map.of()).get(itemId); // Get the item from the category if (item == null) return; @@ -175,10 +175,10 @@ private static void adjustPrice(String categoryId, String itemId, int amount, bo adminShopYAML.saveConfig(); // Save the updated configuration } - private static double clamp(double actual, double initial) { + private double clamp(double actual, double initial) { double min = initial * 0.8; double max = initial * 2.0; // plafond au double du prix existant - return Math.max(min, Math.min(actual, max)); + return Math.clamp(actual, min, max); } /** @@ -189,7 +189,7 @@ private static double clamp(double actual, double initial) { * @param itemId The item ID. * @return The ShopItem or null if not found. */ - private static ShopItem getItemSafe(Player player, String categoryId, String itemId) { + private ShopItem getItemSafe(Player player, String categoryId, String itemId) { ShopItem item = items.getOrDefault(categoryId, Map.of()).get(itemId); if (item == null) sendError(player, TranslationManager.translation("feature.adminshop.item_not_found")); return item; @@ -202,7 +202,7 @@ private static ShopItem getItemSafe(Player player, String categoryId, String ite * @param itemId The item ID. * @return The ShopItem or null if not available. */ - private static ShopItem getCurrentItem(Player player, String itemId) { + private ShopItem getCurrentItem(Player player, String itemId) { String categoryId = getPlayerCategory(player); if (categoryId == null) { sendError(player, TranslationManager.translation("feature.adminshop.isnt_in_category")); @@ -217,7 +217,7 @@ private static ShopItem getCurrentItem(Player player, String itemId) { * @param player The player. * @return The category ID or null. */ - private static String getPlayerCategory(Player player) { + private String getPlayerCategory(Player player) { return currentCategory.get(player.getUniqueId()); } @@ -227,7 +227,7 @@ private static String getPlayerCategory(Player player) { * @param player The player. * @param message The error message. */ - private static void sendError(Player player, Component message) { + private void sendError(Player player, Component message) { MessagesManager.sendMessage(player, message, Prefix.ADMINSHOP, MessageType.ERROR, true); } @@ -237,7 +237,7 @@ private static void sendError(Player player, Component message) { * @param player The player. * @param message The information message. */ - private static void sendInfo(Player player, Component message) { + private void sendInfo(Player player, Component message) { MessagesManager.sendMessage(player, message, Prefix.ADMINSHOP, MessageType.INFO, true); } @@ -246,8 +246,8 @@ private static void sendInfo(Player player, Component message) { * * @param player The player. */ - public static void openMainMenu(Player player) { - new AdminShopMenu(player).open(); + public void openMainMenu(Player player) { + new AdminShopMenu(player, this).open(); } /** @@ -257,8 +257,8 @@ public static void openMainMenu(Player player) { * @param categoryId The category ID. * @param originalItem The original ShopItem. */ - public static void openColorVariantsMenu(Player player, String categoryId, ShopItem originalItem) { - new ColorVariantsMenu(player, categoryId, originalItem).open(); + public void openColorVariantsMenu(Player player, String categoryId, ShopItem originalItem) { + new ColorVariantsMenu(player, this, categoryId, originalItem).open(); } /** @@ -268,8 +268,8 @@ public static void openColorVariantsMenu(Player player, String categoryId, ShopI * @param categoryId The category ID. * @param originalItem The original ShopItem. */ - public static void openLeavesVariantsMenu(Player player, String categoryId, ShopItem originalItem) { - new LeavesVariantsMenu(player, categoryId, originalItem).open(); + public void openLeavesVariantsMenu(Player player, String categoryId, ShopItem originalItem) { + new LeavesVariantsMenu(player, this, categoryId, originalItem).open(); } /** @@ -279,8 +279,8 @@ public static void openLeavesVariantsMenu(Player player, String categoryId, Shop * @param categoryId The category ID. * @param originalItem The original ShopItem. */ - public static void openLogVariantsMenu(Player player, String categoryId, ShopItem originalItem) { - new LogVariantsMenu(player, categoryId, originalItem).open(); + public void openLogVariantsMenu(Player player, String categoryId, ShopItem originalItem) { + new LogVariantsMenu(player, this, categoryId, originalItem).open(); } /** @@ -290,7 +290,7 @@ public static void openLogVariantsMenu(Player player, String categoryId, ShopIte * @param itemId The item ID. * @param item The ShopItem instance. */ - public static void registerNewItem(String categoryId, String itemId, ShopItem item) { + public void registerNewItem(String categoryId, String itemId, ShopItem item) { items.computeIfAbsent(categoryId, k -> new HashMap<>()).put(itemId, item); } @@ -299,7 +299,7 @@ public static void registerNewItem(String categoryId, String itemId, ShopItem it * * @return A collection of ShopCategory. */ - public static Collection getCategories() { + public Collection getCategories() { return categories.values(); } @@ -309,7 +309,7 @@ public static Collection getCategories() { * @param categoryId The ID of the category. * @return The ShopCategory, or null if not found. */ - public static ShopCategory getCategory(String categoryId) { + public ShopCategory getCategory(String categoryId) { return categories.get(categoryId); } @@ -319,7 +319,7 @@ public static ShopCategory getCategory(String categoryId) { * @param categoryId The ID of the category. * @return A map of item ID to ShopItem. */ - public static Map getCategoryItems(String categoryId) { + public Map getCategoryItems(String categoryId) { return items.getOrDefault(categoryId, Map.of()); } } diff --git a/src/main/java/fr/openmc/core/features/adminshop/AdminShopYAML.java b/src/main/java/fr/openmc/core/features/adminshop/AdminShopYAML.java index c56c523f0..4ac131d75 100644 --- a/src/main/java/fr/openmc/core/features/adminshop/AdminShopYAML.java +++ b/src/main/java/fr/openmc/core/features/adminshop/AdminShopYAML.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.adminshop; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.utils.bukkit.ItemUtils; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextDecoration; @@ -24,11 +24,13 @@ public class AdminShopYAML { private FileConfiguration config; private final File configFile; + private final AdminShopManager manager; /** * Constructs the AdminShopYAML manager. */ - public AdminShopYAML() { + public AdminShopYAML(AdminShopManager manager) { + this.manager = manager; this.configFile = new File(OMCPlugin.getInstance().getDataFolder() + "/data", "adminshop.yml"); } @@ -46,14 +48,14 @@ public void loadConfig() { * Loads the shop categories from the YAML configuration and adds them to the manager. */ private void loadCategories() { - AdminShopManager.categories.clear(); + manager.categories.clear(); List> categoryList = config.getMapList("category"); for (Map categoryMap : categoryList) { for (Map.Entry entry : categoryMap.entrySet()) { String key = entry.getKey().toString(); Map section = (Map) entry.getValue(); - AdminShopManager.categories.put(key, new ShopCategory( + manager.categories.put(key, new ShopCategory( key, MiniMessage.miniMessage().deserialize(section.get("name").toString()).decoration(TextDecoration.ITALIC, false), Material.valueOf(section.get("material").toString()), @@ -67,9 +69,9 @@ private void loadCategories() { * Loads all shop items from the YAML configuration and maps them by category. */ private void loadItems() { - AdminShopManager.items.clear(); + manager.items.clear(); - for (String categoryId : AdminShopManager.categories.keySet()) { + for (String categoryId : manager.categories.keySet()) { List> itemList = config.getMapList(categoryId); Map categoryItems = new HashMap<>(); @@ -96,7 +98,7 @@ private void loadItems() { } } - if (!categoryItems.isEmpty()) AdminShopManager.items.put(categoryId, categoryItems); + if (!categoryItems.isEmpty()) manager.items.put(categoryId, categoryItems); } } @@ -104,7 +106,7 @@ private void loadItems() { * Saves all shop item data back to the YAML configuration file. */ public void saveConfig() { - for (var entry : AdminShopManager.items.entrySet()) { + for (var entry : manager.items.entrySet()) { String categoryId = entry.getKey(); List> itemList = new ArrayList<>(); diff --git a/src/main/java/fr/openmc/core/features/adminshop/menus/AdminShopCategoryMenu.java b/src/main/java/fr/openmc/core/features/adminshop/menus/AdminShopCategoryMenu.java index c92737781..562fbbcdd 100644 --- a/src/main/java/fr/openmc/core/features/adminshop/menus/AdminShopCategoryMenu.java +++ b/src/main/java/fr/openmc/core/features/adminshop/menus/AdminShopCategoryMenu.java @@ -24,9 +24,11 @@ public class AdminShopCategoryMenu extends Menu { private final String categoryId; + private final AdminShopManager manager; - public AdminShopCategoryMenu(Player owner, String categoryId) { + public AdminShopCategoryMenu(Player owner, AdminShopManager manager, String categoryId) { super(owner); + this.manager = manager; this.categoryId = categoryId; } @@ -57,7 +59,7 @@ public void onClose(InventoryCloseEvent event) { public @NotNull Map getContent() { Map content = new HashMap<>(); - Map categoryItems = AdminShopManager.getCategoryItems(categoryId); + Map categoryItems = manager.getCategoryItems(categoryId); if (categoryItems != null) { for (ShopItem item : categoryItems.values()) { @@ -73,15 +75,15 @@ public void onClose(InventoryCloseEvent event) { : AdminShopUtils.extractLoreForItem(item)); }).setOnClick(event -> { if (material.name().endsWith("_LEAVES")) - AdminShopManager.openLeavesVariantsMenu(getOwner(), categoryId, item); + manager.openLeavesVariantsMenu(getOwner(), categoryId, item); else if (material.name().endsWith("_LOG")) - AdminShopManager.openLogVariantsMenu(getOwner(), categoryId, item); + manager.openLogVariantsMenu(getOwner(), categoryId, item); else if (item.isHasColorVariant()) - AdminShopManager.openColorVariantsMenu(getOwner(), categoryId, item); + manager.openColorVariantsMenu(getOwner(), categoryId, item); else if (event.isLeftClick() && item.getInitialBuyPrice() > 0) - AdminShopManager.openBuyConfirmMenu(getOwner(), categoryId, item.getId()); + manager.openBuyConfirmMenu(getOwner(), categoryId, item.getId()); else if (event.isRightClick() && item.getInitialSellPrice() > 0) - AdminShopManager.openSellConfirmMenu(getOwner(), categoryId, item.getId()); + manager.openSellConfirmMenu(getOwner(), categoryId, item.getId()); }).setItemId(item.getId())); } } diff --git a/src/main/java/fr/openmc/core/features/adminshop/menus/AdminShopMenu.java b/src/main/java/fr/openmc/core/features/adminshop/menus/AdminShopMenu.java index 8fcf02e26..eaad5eaab 100644 --- a/src/main/java/fr/openmc/core/features/adminshop/menus/AdminShopMenu.java +++ b/src/main/java/fr/openmc/core/features/adminshop/menus/AdminShopMenu.java @@ -21,8 +21,11 @@ public class AdminShopMenu extends Menu { - public AdminShopMenu(Player owner) { + private final AdminShopManager manager; + + public AdminShopMenu(Player owner, AdminShopManager manager) { super(owner); + this.manager = manager; } @Override @@ -48,13 +51,13 @@ public void onInventoryClick(InventoryClickEvent event) {} Map content = new HashMap<>(); int slot = 10; - for (ShopCategory category : AdminShopManager.getCategories().stream().sorted(Comparator.comparingInt(ShopCategory::position)).toList()) { + for (ShopCategory category : manager.getCategories().stream().sorted(Comparator.comparingInt(ShopCategory::position)).toList()) { content.put(slot, new ItemMenuBuilder(this, category.material(), meta -> meta.displayName(category.name().decoration(TextDecoration.ITALIC, false) )).setItemId(category.id()) .setOnClick(e -> { - AdminShopManager.currentCategory.put(getOwner().getUniqueId(), category.id()); - new AdminShopCategoryMenu(getOwner(), category.id()).open(); + manager.currentCategory.put(getOwner().getUniqueId(), category.id()); + new AdminShopCategoryMenu(getOwner(), manager, category.id()).open(); })); slot += 2; diff --git a/src/main/java/fr/openmc/core/features/adminshop/menus/ColorVariantsMenu.java b/src/main/java/fr/openmc/core/features/adminshop/menus/ColorVariantsMenu.java index 2bdb2f602..4dcfc502a 100644 --- a/src/main/java/fr/openmc/core/features/adminshop/menus/ColorVariantsMenu.java +++ b/src/main/java/fr/openmc/core/features/adminshop/menus/ColorVariantsMenu.java @@ -26,9 +26,11 @@ public class ColorVariantsMenu extends Menu { private final String categoryId; private final ShopItem originalItem; private static final Map> COLOR_VARIANTS = initColorVariants(); + private final AdminShopManager manager; - public ColorVariantsMenu(Player owner, String categoryId, ShopItem originalItem) { + public ColorVariantsMenu(Player owner, AdminShopManager manager, String categoryId, ShopItem originalItem) { super(owner); + this.manager = manager; this.categoryId = categoryId; this.originalItem = originalItem; } @@ -142,11 +144,11 @@ public void onInventoryClick(InventoryClickEvent event) {} if (event.isLeftClick() && originalItem.getInitialBuyPrice() > 0) { - AdminShopManager.registerNewItem(categoryId, colorVariant.getId(), colorVariant); - AdminShopManager.openBuyConfirmMenu(getOwner(), categoryId, colorVariant.getId()); + manager.registerNewItem(categoryId, colorVariant.getId(), colorVariant); + manager.openBuyConfirmMenu(getOwner(), categoryId, colorVariant.getId()); } else if (event.isRightClick() && originalItem.getInitialSellPrice() > 0) { - AdminShopManager.registerNewItem(categoryId, colorVariant.getId(), colorVariant); - AdminShopManager.openSellConfirmMenu(getOwner(), categoryId, colorVariant.getId()); + manager.registerNewItem(categoryId, colorVariant.getId(), colorVariant); + manager.openSellConfirmMenu(getOwner(), categoryId, colorVariant.getId()); } })); } diff --git a/src/main/java/fr/openmc/core/features/adminshop/menus/ConfirmMenu.java b/src/main/java/fr/openmc/core/features/adminshop/menus/ConfirmMenu.java index cfeeb562c..7f767efc3 100644 --- a/src/main/java/fr/openmc/core/features/adminshop/menus/ConfirmMenu.java +++ b/src/main/java/fr/openmc/core/features/adminshop/menus/ConfirmMenu.java @@ -29,14 +29,16 @@ import java.util.function.Consumer; public class ConfirmMenu extends Menu { + private final AdminShopManager manager; private final ShopItem shopItem; private final boolean isBuying; private int quantity; private final int maxQuantity; - public ConfirmMenu(Player owner, ShopItem shopItem, boolean isBuying) { + public ConfirmMenu(Player owner, AdminShopManager manager, ShopItem shopItem, boolean isBuying) { super(owner); + this.manager = manager; this.shopItem = shopItem; this.isBuying = isBuying; this.quantity = 1; @@ -75,9 +77,9 @@ public void onInventoryClick(InventoryClickEvent inventoryClickEvent) {} Component.text(String.valueOf(quantity), NamedTextColor.WHITE), Component.text(String.valueOf(quantityToStack), NamedTextColor.WHITE), quantityToStack > 1 ? Component.text("s", NamedTextColor.WHITE) : Component.empty(), - Component.text(AdminShopManager.priceFormat.format(pricePerUnit), NamedTextColor.GREEN), + Component.text(manager.priceFormat.format(pricePerUnit), NamedTextColor.GREEN), Component.text(EconomyManager.getEconomyIcon(), NamedTextColor.GREEN), - Component.text(AdminShopManager.priceFormat.format(totalPrice), NamedTextColor.GREEN), + Component.text(manager.priceFormat.format(totalPrice), NamedTextColor.GREEN), Component.text(EconomyManager.getEconomyIcon(), NamedTextColor.GREEN), shiftRightSellAll @@ -127,7 +129,7 @@ public void onInventoryClick(InventoryClickEvent inventoryClickEvent) {} case ClickType.SHIFT_RIGHT -> { if (!isBuying && ItemUtils.countItems(getOwner(), ItemStack.of(shopItem.getMaterial())) > 0) { getOwner().closeInventory(); - AdminShopManager.sellItem( + manager.sellItem( getOwner(), shopItem.getId(), ItemUtils.countItems(getOwner(), ItemStack.of(shopItem.getMaterial()))); @@ -146,8 +148,8 @@ public void onInventoryClick(InventoryClickEvent inventoryClickEvent) {} meta.displayName(TranslationManager.translation("messages.global.accept")); }).setOnClick(event -> { getOwner().closeInventory(); - if (isBuying) AdminShopManager.buyItem(getOwner(), shopItem.getId(), quantity); - else AdminShopManager.sellItem(getOwner(), shopItem.getId(), quantity); + if (isBuying) manager.buyItem(getOwner(), shopItem.getId(), quantity); + else manager.sellItem(getOwner(), shopItem.getId(), quantity); })); return content; diff --git a/src/main/java/fr/openmc/core/features/adminshop/menus/LeavesVariantsMenu.java b/src/main/java/fr/openmc/core/features/adminshop/menus/LeavesVariantsMenu.java index d79bdce3b..1a203c2ae 100644 --- a/src/main/java/fr/openmc/core/features/adminshop/menus/LeavesVariantsMenu.java +++ b/src/main/java/fr/openmc/core/features/adminshop/menus/LeavesVariantsMenu.java @@ -27,6 +27,7 @@ public class LeavesVariantsMenu extends Menu { private final String categoryId; private final ShopItem originalItem; + private final AdminShopManager manager; private static final List LEAVES_VARIANTS = List.of( Material.OAK_LEAVES, Material.SPRUCE_LEAVES, Material.BIRCH_LEAVES, Material.JUNGLE_LEAVES, @@ -34,8 +35,9 @@ public class LeavesVariantsMenu extends Menu { Material.PALE_OAK_LEAVES, Material.AZALEA_LEAVES, Material.FLOWERING_AZALEA_LEAVES ); - public LeavesVariantsMenu(Player owner, String categoryId, ShopItem originalItem) { + public LeavesVariantsMenu(Player owner, AdminShopManager manager, String categoryId, ShopItem originalItem) { super(owner); + this.manager = manager; this.categoryId = categoryId; this.originalItem = originalItem; } @@ -100,11 +102,11 @@ public void onInventoryClick(InventoryClickEvent event) {} if (event.isLeftClick() && originalItem.getInitialBuyPrice() > 0) { - AdminShopManager.registerNewItem(categoryId, colorVariant.getId(), colorVariant); - AdminShopManager.openBuyConfirmMenu(getOwner(), categoryId, colorVariant.getId()); + manager.registerNewItem(categoryId, colorVariant.getId(), colorVariant); + manager.openBuyConfirmMenu(getOwner(), categoryId, colorVariant.getId()); } else if (event.isRightClick() && originalItem.getInitialSellPrice() > 0) { - AdminShopManager.registerNewItem(categoryId, colorVariant.getId(), colorVariant); - AdminShopManager.openSellConfirmMenu(getOwner(), categoryId, colorVariant.getId()); + manager.registerNewItem(categoryId, colorVariant.getId(), colorVariant); + manager.openSellConfirmMenu(getOwner(), categoryId, colorVariant.getId()); } })); } diff --git a/src/main/java/fr/openmc/core/features/adminshop/menus/LogVariantsMenu.java b/src/main/java/fr/openmc/core/features/adminshop/menus/LogVariantsMenu.java index 0fbd1c85a..f569e43a3 100644 --- a/src/main/java/fr/openmc/core/features/adminshop/menus/LogVariantsMenu.java +++ b/src/main/java/fr/openmc/core/features/adminshop/menus/LogVariantsMenu.java @@ -32,9 +32,11 @@ public class LogVariantsMenu extends Menu { Material.ACACIA_LOG, Material.DARK_OAK_LOG, Material.MANGROVE_LOG, Material.CHERRY_LOG, Material.PALE_OAK_LOG ); + private final AdminShopManager manager; - public LogVariantsMenu(Player owner, String categoryId, ShopItem originalItem) { + public LogVariantsMenu(Player owner, AdminShopManager manager, String categoryId, ShopItem originalItem) { super(owner); + this.manager = manager; this.categoryId = categoryId; this.originalItem = originalItem; } @@ -99,11 +101,11 @@ public void onInventoryClick(InventoryClickEvent event) {} if (event.isLeftClick() && originalItem.getInitialBuyPrice() > 0) { - AdminShopManager.registerNewItem(categoryId, colorVariant.getId(), colorVariant); - AdminShopManager.openBuyConfirmMenu(getOwner(), categoryId, colorVariant.getId()); + manager.registerNewItem(categoryId, colorVariant.getId(), colorVariant); + manager.openBuyConfirmMenu(getOwner(), categoryId, colorVariant.getId()); } else if (event.isRightClick() && originalItem.getInitialSellPrice() > 0) { - AdminShopManager.registerNewItem(categoryId, colorVariant.getId(), colorVariant); - AdminShopManager.openSellConfirmMenu(getOwner(), categoryId, colorVariant.getId()); + manager.registerNewItem(categoryId, colorVariant.getId(), colorVariant); + manager.openSellConfirmMenu(getOwner(), categoryId, colorVariant.getId()); } })); } 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 d9928c9dd..3d8b831da 100644 --- a/src/main/java/fr/openmc/core/features/analytics/AnalyticsManager.java +++ b/src/main/java/fr/openmc/core/features/analytics/AnalyticsManager.java @@ -6,10 +6,10 @@ import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.analytics.models.Statistic; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; import org.bukkit.Bukkit; import java.sql.SQLException; 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 5d6915919..d449e44ee 100644 --- a/src/main/java/fr/openmc/core/features/animations/AnimationsManager.java +++ b/src/main/java/fr/openmc/core/features/animations/AnimationsManager.java @@ -5,18 +5,15 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.features.types.LoadIfEnable; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.animations.commands.DebugAnimationCommand; import fr.openmc.core.features.animations.listeners.EmoteListener; import fr.openmc.core.features.animations.listeners.PlayerFinishJoiningListener; -import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import org.bukkit.util.Vector; import java.io.File; @@ -29,7 +26,7 @@ import java.util.Set; @Credit(developers = {"iambibi_", "gab400"}, graphist = {"Tfloa"}) -public class AnimationsManager extends Feature implements NotLoadInUnitTest, LoadIfEnable, HasListeners, HasCommands { +public class AnimationsManager extends Feature implements HasListeners, HasCommands { @Override public void init() { diff --git a/src/main/java/fr/openmc/core/features/animations/listeners/EmoteListener.java b/src/main/java/fr/openmc/core/features/animations/listeners/EmoteListener.java index 923ea4044..81b67b108 100644 --- a/src/main/java/fr/openmc/core/features/animations/listeners/EmoteListener.java +++ b/src/main/java/fr/openmc/core/features/animations/listeners/EmoteListener.java @@ -6,9 +6,9 @@ import dev.lone.itemsadder.api.Events.PlayerEmoteEndEvent; import dev.lone.itemsadder.api.Events.PlayerEmotePlayEvent; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; import fr.openmc.core.features.animations.Animation; import fr.openmc.core.features.animations.PlayerAnimationInfo; +import fr.openmc.core.lifecycle.interfaces.NotLoadInUnitTest; import fr.openmc.core.utils.EnumUtils; import org.bukkit.Location; import org.bukkit.entity.ArmorStand; diff --git a/src/main/java/fr/openmc/core/features/animations/listeners/PlayerFinishJoiningListener.java b/src/main/java/fr/openmc/core/features/animations/listeners/PlayerFinishJoiningListener.java index 77ae6ea82..8e57247a1 100644 --- a/src/main/java/fr/openmc/core/features/animations/listeners/PlayerFinishJoiningListener.java +++ b/src/main/java/fr/openmc/core/features/animations/listeners/PlayerFinishJoiningListener.java @@ -2,11 +2,11 @@ import dev.lone.itemsadder.api.CustomPlayer; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; import fr.openmc.core.features.animations.Animation; import fr.openmc.core.features.animations.PlayerAnimationInfo; import fr.openmc.core.features.settings.PlayerSettingsManager; import fr.openmc.core.features.settings.SettingType; +import fr.openmc.core.lifecycle.interfaces.NotLoadInUnitTest; import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; diff --git a/src/main/java/fr/openmc/core/features/bits/BitsManager.java b/src/main/java/fr/openmc/core/features/bits/BitsManager.java index 14ebb9cba..43b194f32 100644 --- a/src/main/java/fr/openmc/core/features/bits/BitsManager.java +++ b/src/main/java/fr/openmc/core/features/bits/BitsManager.java @@ -6,17 +6,17 @@ import com.j256.ormlite.table.TableUtils; import dev.lone.itemsadder.api.FontImages.FontImageWrapper; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.bits.commands.BitsCommands; import fr.openmc.core.features.bits.models.BitsPlayer; -import fr.openmc.core.features.city.sub.bank.CityBankManager; import fr.openmc.core.hooks.github.GitHubHook; import fr.openmc.core.hooks.github.models.ContributorStats; import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitTask; @@ -28,6 +28,9 @@ @Credit(developers = {"iambibi_"}) public class BitsManager extends Feature implements HasDatabase, HasCommands { + private GitHubHook gitHubHook; + private ItemsAdderHook itemsAdderHook; + @Getter private static Map bitsData; @@ -40,6 +43,9 @@ public class BitsManager extends Feature implements HasDatabase, HasCommands { @Override public void init() { + this.gitHubHook = OMCRegistry.HOOKS.GITHUB; + this.itemsAdderHook = OMCRegistry.HOOKS.ITEMS_ADDER; + bitsData = loadAllBits(); updateBitsUpdateTimer(); @@ -49,7 +55,7 @@ public void init() { @Override public Set getCommands() { return Set.of( - new BitsCommands() + new BitsCommands(this, gitHubHook) ); } @@ -64,7 +70,7 @@ protected void save() { saveAllBits(); } - public static Map loadAllBits() { + private Map loadAllBits() { Map balances = new HashMap<>(); try { List dbBalances = playersBitsDao.queryForAll(); @@ -78,7 +84,7 @@ public static Map loadAllBits() { return balances; } - private static void saveAllBits() { + private void saveAllBits() { try { playersBitsDao.callBatchTasks(() -> { for (BitsPlayer player : bitsData.values()) { @@ -92,31 +98,31 @@ private static void saveAllBits() { } } - public static double getBits(UUID playerUUID) { + public double getBits(UUID playerUUID) { BitsPlayer bitsPlayer = bitsData.get(playerUUID); return bitsPlayer == null ? 0 : bitsPlayer.getBits(); } - public static void addBits(UUID playerUUID, double amount) { + public void addBits(UUID playerUUID, double amount) { BitsPlayer bitsPlayer = getBitsPlayer(playerUUID); bitsPlayer.deposit(amount); } - public static boolean withdrawBits(UUID playerUUID, double amount) { + public boolean withdrawBits(UUID playerUUID, double amount) { BitsPlayer bitsPlayer = getBitsPlayer(playerUUID); return bitsPlayer.withdraw(amount); } - public static void setBits(UUID playerUUID, double amount) { + public void setBits(UUID playerUUID, double amount) { BitsPlayer bitsPlayer = getBitsPlayer(playerUUID); bitsPlayer.setBits(amount); } - public static BitsPlayer getBitsPlayer(UUID playerUUID) { + public BitsPlayer getBitsPlayer(UUID playerUUID) { return bitsData.computeIfAbsent(playerUUID, BitsPlayer::new); } - public static String getFormattedBits(UUID playerUUID) { + public String getFormattedBits(UUID playerUUID) { String balance = String.valueOf(getBits(playerUUID)); Currency currency = Currency.getInstance(Locale.FRANCE); NumberFormat format = NumberFormat.getCurrencyInstance(Locale.FRANCE); @@ -126,19 +132,19 @@ public static String getFormattedBits(UUID playerUUID) { getBitsIcon()); } - public static String getBitsIcon() { - if (ItemsAdderHook.isEnable()) { + public String getBitsIcon() { + if (itemsAdderHook.isEnable()) { return FontImageWrapper.replaceFontImages("§f:bits:"); } else { return "✯"; } } - public static void applyContributorBitsUpdate(Long githubID) { - UUID playerLinked = GitHubHook.getPlayerLinkTo(githubID); + public void applyContributorBitsUpdate(Long githubID) { + UUID playerLinked = gitHubHook.getPlayerLinkTo(githubID); if (playerLinked == null) return; - ContributorStats stats = GitHubHook.getStats(githubID); + ContributorStats stats = gitHubHook.getStats(githubID); if (stats == null) return; int lastSavedLines = getBitsPlayer(playerLinked).getLastSavedLines(); @@ -152,17 +158,17 @@ public static void applyContributorBitsUpdate(Long githubID) { } } - public static void applyAllContributorBitsUpdate() { - Map contributors = GitHubHook.getContributors(); + public void applyAllContributorBitsUpdate() { + Map contributors = gitHubHook.getContributors(); - GitHubHook.fetchContributorStats(); + gitHubHook.fetchContributorStats(); for (Long githubID : contributors.keySet()) { applyContributorBitsUpdate(githubID); } } - public static void updateBitsUpdateTimer() { + public void updateBitsUpdateTimer() { if (OMCPlugin.isUnitTestVersion()) return; if (bitsUpdateTask != null) return; @@ -174,14 +180,14 @@ public static void updateBitsUpdateTimer() { () -> { OMCLogger.info("Applying all bits update for contributors"); applyAllContributorBitsUpdate(); - CityBankManager.applyAllCityInterests(); + OMCRegistry.FEATURES.CITY.get().CITY_BANK.applyAllCityInterests(); OMCLogger.info("All bits update for contributors applied successfully."); bitsUpdateTask = null; Bukkit.getScheduler().runTaskLater( OMCPlugin.getInstance(), - BitsManager::updateBitsUpdateTimer, + this::updateBitsUpdateTimer, 20L * 10 ); }, diff --git a/src/main/java/fr/openmc/core/features/bits/commands/BitsCommands.java b/src/main/java/fr/openmc/core/features/bits/commands/BitsCommands.java index 9a8ea4613..dd939e731 100644 --- a/src/main/java/fr/openmc/core/features/bits/commands/BitsCommands.java +++ b/src/main/java/fr/openmc/core/features/bits/commands/BitsCommands.java @@ -23,6 +23,14 @@ @CommandPermission("omc.commands.bits") public class BitsCommands { + private final BitsManager bitsManager; + private final GitHubHook gitHubHook; + + public BitsCommands(BitsManager bitsManager, GitHubHook gitHubHook) { + this.bitsManager = bitsManager; + this.gitHubHook = gitHubHook; + } + @CommandPlaceholder() public void getBits( Player sender @@ -34,19 +42,19 @@ public void getBits( @Description("Permet de définir les bits d'un joueur") @CommandPermission("omc.admin.commands.bits.set") public void setBits(CommandSender player, @SuggestWith(OnlinePlayerAutoComplete.class) OfflinePlayer target, @Range(min = 1E-10) double amount) { - BitsManager.setBits(target.getUniqueId(), amount); + bitsManager.setBits(target.getUniqueId(), amount); MessagesManager.sendMessage(player, TranslationManager.translation( "feature.economy.bits.set.success", Component.text(target.getName()).color(NamedTextColor.YELLOW), - Component.text(BitsManager.getFormattedBits(target.getUniqueId())).color(NamedTextColor.YELLOW) + Component.text(bitsManager.getFormattedBits(target.getUniqueId())).color(NamedTextColor.YELLOW) ), Prefix.OPENMC, MessageType.SUCCESS, true); if (target.isOnline()) { MessagesManager.sendMessage(target.getPlayer(), TranslationManager.translation( "feature.economy.bits.set.target", - Component.text(BitsManager.getFormattedBits(target.getUniqueId())).color(NamedTextColor.YELLOW) + Component.text(bitsManager.getFormattedBits(target.getUniqueId())).color(NamedTextColor.YELLOW) ), Prefix.OPENMC, MessageType.INFO, true); } @@ -56,11 +64,11 @@ public void setBits(CommandSender player, @SuggestWith(OnlinePlayerAutoComplete. @Description("Permet d'ajouter des bits à un joueur") @CommandPermission("omc.admin.commands.bits.add") public void addBits(CommandSender player, @SuggestWith(OnlinePlayerAutoComplete.class) OfflinePlayer target, @Range(min = 1E-10) double amount) { - BitsManager.addBits(target.getUniqueId(), amount); + bitsManager.addBits(target.getUniqueId(), amount); MessagesManager.sendMessage(player, TranslationManager.translation( "feature.economy.bits.add.success", - Component.text(BitsManager.getFormattedBits(target.getUniqueId())).color(NamedTextColor.YELLOW), + Component.text(bitsManager.getFormattedBits(target.getUniqueId())).color(NamedTextColor.YELLOW), Component.text(target.getName()).color(NamedTextColor.YELLOW) ), Prefix.OPENMC, MessageType.SUCCESS, true); @@ -68,7 +76,7 @@ public void addBits(CommandSender player, @SuggestWith(OnlinePlayerAutoComplete. MessagesManager.sendMessage(target.getPlayer(), TranslationManager.translation( "feature.economy.bits.add.target", - Component.text(BitsManager.getFormattedBits(target.getUniqueId())).color(NamedTextColor.YELLOW) + Component.text(bitsManager.getFormattedBits(target.getUniqueId())).color(NamedTextColor.YELLOW) ), Prefix.OPENMC, MessageType.INFO, true); } @@ -78,11 +86,11 @@ public void addBits(CommandSender player, @SuggestWith(OnlinePlayerAutoComplete. @Description("Permet de retirer des bits à un joueur") @CommandPermission("omc.admin.commands.bits.remove") public void removeBits(CommandSender player, @SuggestWith(OnlinePlayerAutoComplete.class) OfflinePlayer target, @Range(min = 1E-10) double amount) { - if (BitsManager.withdrawBits(target.getUniqueId(), amount)) { + if (bitsManager.withdrawBits(target.getUniqueId(), amount)) { MessagesManager.sendMessage(player, TranslationManager.translation( "feature.economy.bits.remove.success", - Component.text(BitsManager.getFormattedBits(target.getUniqueId())).color(NamedTextColor.YELLOW), + Component.text(bitsManager.getFormattedBits(target.getUniqueId())).color(NamedTextColor.YELLOW), Component.text(target.getName()).color(NamedTextColor.YELLOW) ), Prefix.OPENMC, MessageType.SUCCESS, true); @@ -103,7 +111,7 @@ public void removeBits(CommandSender player, @SuggestWith(OnlinePlayerAutoComple @Description("Permet de réinitialiser les bits d'un joueur") @CommandPermission("omc.admin.commands.bits.reset") public void resetBits(CommandSender player, @SuggestWith(OnlinePlayerAutoComplete.class) OfflinePlayer target) { - BitsManager.setBits(target.getUniqueId(), 0); + bitsManager.setBits(target.getUniqueId(), 0); MessagesManager.sendMessage(player, TranslationManager.translation( "feature.economy.bits.reset.success", @@ -125,7 +133,7 @@ public void resetBits(CommandSender player, @SuggestWith(OnlinePlayerAutoComplet @Description("Permet de forcer l'update des bits d'un joueur") @CommandPermission("omc.admin.commands.bits.forceupdate") public void forceBitsUpdate(CommandSender player, @SuggestWith(PlayerNameLinkedAutocomplete.class) Player target) { - Long githubId = GitHubHook.getContributorId(target.getUniqueId()); + Long githubId = gitHubHook.getContributorId(target.getUniqueId()); if (githubId == null) { MessagesManager.sendMessage(player, @@ -136,7 +144,7 @@ public void forceBitsUpdate(CommandSender player, @SuggestWith(PlayerNameLinkedA return; } - BitsManager.applyContributorBitsUpdate(githubId); + bitsManager.applyContributorBitsUpdate(githubId); MessagesManager.sendMessage(player, TranslationManager.translation( "feature.economy.bits.forceupdate.success", diff --git a/src/main/java/fr/openmc/core/features/bits/menu/BitsMenu.java b/src/main/java/fr/openmc/core/features/bits/menu/BitsMenu.java index d2dba6a41..6f554fc8f 100644 --- a/src/main/java/fr/openmc/core/features/bits/menu/BitsMenu.java +++ b/src/main/java/fr/openmc/core/features/bits/menu/BitsMenu.java @@ -5,6 +5,7 @@ import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.bits.BitsManager; +import fr.openmc.core.features.bits.models.BitsPlayer; import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -19,9 +20,11 @@ import java.util.Map; public class BitsMenu extends Menu { + private final BitsManager manager; public BitsMenu(Player owner) { super(owner); + this.manager = OMCRegistry.FEATURES.BITS.get(); } @Override @@ -48,15 +51,15 @@ public void onInventoryClick(InventoryClickEvent click) { public @NotNull Map getContent() { Map inventory = new HashMap<>(); - double bits = BitsManager.getBitsPlayer(getOwner().getUniqueId()) == null ? 0 : - BitsManager.getBitsPlayer(getOwner().getUniqueId()).getBits(); + BitsPlayer bitsPlayer = manager.getBitsPlayer(getOwner().getUniqueId()); + double bits = bitsPlayer == null ? 0d : bitsPlayer.getBits(); inventory.put(12, new ItemMenuBuilder(this, Material.DIAMOND, itemMeta -> { itemMeta.displayName(TranslationManager.translation("feature.bits.menu.main.bits")); itemMeta.lore(TranslationManager.translationLore( "feature.bits.menu.main.bits.lore", Component.text(bits).color(NamedTextColor.AQUA), - Component.text(BitsManager.LINE_REQ/BitsManager.BITS_PER_LINE_REQ).color(NamedTextColor.AQUA) + Component.text(BitsManager.LINE_REQ / BitsManager.BITS_PER_LINE_REQ).color(NamedTextColor.AQUA) )); })); diff --git a/src/main/java/fr/openmc/core/features/bits/menu/BitsShopMenu.java b/src/main/java/fr/openmc/core/features/bits/menu/BitsShopMenu.java index 1e13f49e0..f13d7b185 100644 --- a/src/main/java/fr/openmc/core/features/bits/menu/BitsShopMenu.java +++ b/src/main/java/fr/openmc/core/features/bits/menu/BitsShopMenu.java @@ -5,6 +5,7 @@ import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.bits.BitsManager; +import fr.openmc.core.features.bits.models.BitsPlayer; import fr.openmc.core.registry.items.CustomItem; import fr.openmc.core.utils.bukkit.ItemUtils; import fr.openmc.core.utils.text.messages.MessageType; @@ -24,8 +25,11 @@ public class BitsShopMenu extends Menu { + private final BitsManager manager; + public BitsShopMenu(Player owner) { super(owner); + this.manager = OMCRegistry.FEATURES.BITS.get(); } @Override @@ -64,8 +68,8 @@ public void onInventoryClick(InventoryClickEvent click) { private ItemMenuBuilder createBuyButton(CustomItem item, double price) { Component itemName = item.getBest().getItemMeta().displayName(); - double bits = BitsManager.getBitsPlayer(getOwner().getUniqueId()) == null ? 0d : - BitsManager.getBitsPlayer(getOwner().getUniqueId()).getBits(); + BitsPlayer bitsPlayer = manager.getBitsPlayer(getOwner().getUniqueId()); + double bits = bitsPlayer == null ? 0d : bitsPlayer.getBits(); return new ItemMenuBuilder(this, item, itemMeta -> { itemMeta.displayName(itemName); itemMeta.lore(TranslationManager.translationLore("feature.bits.menu.shop.buy.lore", @@ -77,7 +81,7 @@ private ItemMenuBuilder createBuyButton(CustomItem item, double price) { return; } - BitsManager.withdrawBits(getOwner().getUniqueId(), price); + manager.withdrawBits(getOwner().getUniqueId(), price); ItemUtils.giveItem(getOwner(), item.getBest(), 1); }); } diff --git a/src/main/java/fr/openmc/core/features/chatanimations/ChatAnimationManager.java b/src/main/java/fr/openmc/core/features/chatanimations/ChatAnimationManager.java index 8ac473e79..ee933eef5 100644 --- a/src/main/java/fr/openmc/core/features/chatanimations/ChatAnimationManager.java +++ b/src/main/java/fr/openmc/core/features/chatanimations/ChatAnimationManager.java @@ -2,15 +2,14 @@ import fr.openmc.core.OMCPlugin; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.chatanimations.contents.challenge.ChallengeListener; import fr.openmc.core.features.chatanimations.contents.challenge.types.*; import fr.openmc.core.features.chatanimations.contents.quizz.Quizz; import fr.openmc.core.features.chatanimations.contents.quizz.QuizzListener; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.registry.items.keys.KeyBlock; import fr.openmc.core.registry.loottable.LootReward; import fr.openmc.core.utils.RandomUtils; @@ -31,7 +30,7 @@ import java.util.concurrent.ThreadLocalRandom; @Credit(developers = {"iambibi_"}) -public class ChatAnimationManager extends Feature implements LoadAfterItemsAdder, HasListeners { +public class ChatAnimationManager extends Feature implements HasListeners { private static final long MIN_DELAY_TICKS = 20 * 60 * 20L; // 20 min private static final long MAX_DELAY_TICKS = 20 * 60 * 30L; // 30 min diff --git a/src/main/java/fr/openmc/core/features/city/City.java b/src/main/java/fr/openmc/core/features/city/City.java index a3e349de1..8db1fa2d0 100644 --- a/src/main/java/fr/openmc/core/features/city/City.java +++ b/src/main/java/fr/openmc/core/features/city/City.java @@ -2,6 +2,7 @@ import fr.openmc.api.cooldown.DynamicCooldownManager; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.events.*; import fr.openmc.core.features.city.models.DBCity; import fr.openmc.core.features.city.models.DBCityRank; @@ -67,10 +68,24 @@ public class City { @Getter private int level; + private final CityManager cityManager; + private final MayorManager mayorManager; + private final CityRankManager cityRankManager; + private final NotationManager notationManager; + private final CityBankManager cityBankManager; + private final WarManager warManager; + /** * Constructor used for City creation */ public City(UUID uniqueId, String name, Player owner, CityType type, Chunk chunk) { + this.cityManager = OMCRegistry.FEATURES.CITY.get(); + this.mayorManager = cityManager.MAYOR; + this.cityRankManager = cityManager.RANKS; + this.notationManager = cityManager.NOTATION; + this.cityBankManager = cityManager.CITY_BANK; + this.warManager = cityManager.WAR; + this.uniqueId = uniqueId; this.name = name; this.type = type; @@ -78,10 +93,10 @@ public City(UUID uniqueId, String name, Player owner, CityType type, Chunk chunk this.level = 1; Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> - CityManager.saveCity(this) + cityManager.saveCity(this) ); - CityManager.registerCity(this); + cityManager.registerCity(this); this.members = new HashSet<>(); this.permissions = new HashMap<>(); @@ -94,7 +109,7 @@ public City(UUID uniqueId, String name, Player owner, CityType type, Chunk chunk addPlayer(owner.getUniqueId()); addPermission(owner.getUniqueId(), CityPermission.OWNER); saveChestContent(1, null); - CityRankManager.loadCityRanks(this); + cityRankManager.loadCityRanks(this); Bukkit.getScheduler().runTask(OMCPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(new CityCreationEvent(this, owner)) @@ -105,6 +120,14 @@ public City(UUID uniqueId, String name, Player owner, CityType type, Chunk chunk * Constructor used to deserialize a City database object */ public City(UUID uniqueId, String name, double balance, String type, int power, int freeClaims, int level) { + this.cityManager = OMCRegistry.FEATURES.CITY.get(); + this.mayorManager = cityManager.MAYOR; + this.cityRankManager = cityManager.RANKS; + this.notationManager = cityManager.NOTATION; + this.cityBankManager = cityManager.CITY_BANK; + this.warManager = cityManager.WAR; + + this.uniqueId = uniqueId; this.name = name; this.balance = balance; @@ -113,7 +136,7 @@ public City(UUID uniqueId, String name, double balance, String type, int power, this.type = CityType.valueOf(type.toUpperCase()); this.level = level; - CityManager.registerCity(this); + cityManager.registerCity(this); } /** @@ -130,7 +153,7 @@ public DBCity serialize() { */ public Set getMembers() { if (this.members == null) - this.members = CityManager.getCityMembers(this); + this.members = cityManager.getCityMembers(this); return this.members; } @@ -140,7 +163,7 @@ public Set getMembers() { */ public Set getChunks() { if (this.chunks == null) - this.chunks = CityManager.getCityChunks(this); + this.chunks = cityManager.getCityChunks(this); return this.chunks; } @@ -153,7 +176,7 @@ public void rename(String newName) { this.name = newName; Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> - CityManager.saveCity(this) + cityManager.saveCity(this) ); } @@ -162,7 +185,7 @@ public void changeType() { else if (this.type == CityType.PEACE) this.type = CityType.WAR; Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> - CityManager.saveCity(this) + cityManager.saveCity(this) ); } @@ -198,13 +221,13 @@ public boolean isMember(Player player) { */ public void addPlayer(UUID player) { if (this.members == null) - this.members = CityManager.getCityMembers(this); + this.members = cityManager.getCityMembers(this); members.add(player); Bukkit.getScheduler().runTask(OMCPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(new MemberJoinEvent(CacheOfflinePlayer.getOfflinePlayer(player), this)) ); - CityManager.addPlayerToCity(this, player); + cityManager.addPlayerToCity(this, player); } /** @@ -215,7 +238,7 @@ public void addPlayer(UUID player) { */ public void removePlayer(UUID playerUUID) { if (this.members == null) - this.members = CityManager.getCityMembers(this); + this.members = cityManager.getCityMembers(this); OfflinePlayer offlinePlayer = CacheOfflinePlayer.getOfflinePlayer(playerUUID); @@ -228,7 +251,7 @@ public void removePlayer(UUID playerUUID) { Bukkit.getPluginManager() .callEvent(new MemberLeaveEvent(CacheOfflinePlayer.getOfflinePlayer(playerUUID), this)) ); - CityManager.removePlayerFromCity(this, playerUUID); + cityManager.removePlayerFromCity(this, playerUUID); } /** @@ -249,7 +272,7 @@ public void changeOwner(UUID player) { public void updateFreeClaims(int diff) { freeClaims += diff; Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> - CityManager.saveCity(this) + cityManager.saveCity(this) ); } @@ -263,7 +286,7 @@ public void updateFreeClaims(int diff) { */ public ItemStack[] getChestContent(int page) { if (this.chestContent == null) - this.chestContent = CityManager.getCityChestContent(this); + this.chestContent = cityManager.getCityChestContent(this); if (page > getChestPages()) page = getChestPages(); @@ -279,12 +302,12 @@ public ItemStack[] getChestContent(int page) { */ public void saveChestContent(int page, ItemStack[] content) { if (this.chestContent == null) - this.chestContent = CityManager.getCityChestContent(this); + this.chestContent = cityManager.getCityChestContent(this); chestContent.put(page, content); Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> - CityManager.saveChestPage(this, page, content) + cityManager.saveChestPage(this, page, content) ); } @@ -295,7 +318,7 @@ public void saveChestContent(int page, ItemStack[] content) { */ public @NotNull Integer getChestPages() { if (this.chestContent == null) - this.chestContent = CityManager.getCityChestContent(this); + this.chestContent = cityManager.getCityChestContent(this); if (this.chestContent.isEmpty()) saveChestContent(1, null); @@ -314,14 +337,14 @@ public void saveChestContent(int page, ItemStack[] content) { */ public void addChunk(int x, int z) { if (this.chunks == null) - this.chunks = CityManager.getCityChunks(this); + this.chunks = cityManager.getCityChunks(this); ChunkPos chunkPos = new ChunkPos(x, z); if (chunks.contains(chunkPos)) return; chunks.add(chunkPos); - CityManager.claimChunk(this, chunkPos); + cityManager.claimChunk(this, chunkPos); } /** @@ -333,12 +356,12 @@ public void addChunk(int x, int z) { */ public void removeChunk(int chunkX, int chunkZ) { if (this.chunks == null) - this.chunks = CityManager.getCityChunks(this); + this.chunks = cityManager.getCityChunks(this); ChunkPos chunkPos = new ChunkPos(chunkX, chunkZ); chunks.remove(chunkPos); - CityManager.unclaimChunk(this, chunkPos); + cityManager.unclaimChunk(this, chunkPos); } /** @@ -350,7 +373,7 @@ public void removeChunk(int chunkX, int chunkZ) { */ public boolean hasChunk(int x, int z) { if (this.chunks == null) - this.chunks = CityManager.getCityChunks(this); + this.chunks = cityManager.getCityChunks(this); return chunks.contains(new ChunkPos(x, z)); } @@ -369,7 +392,7 @@ public void setBalance(double value) { // Sauvegarde async Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> - CityManager.saveCity(this) + cityManager.saveCity(this) ); // Event sync @@ -396,7 +419,7 @@ public void updateBalance(double diff) { * @param input The input string to get the money value */ public void depositCityBank(Player player, String input) { - CityBankManager.depositCityBank(this, player, input); + cityBankManager.depositCityBank(this, player, input); } /** @@ -406,7 +429,7 @@ public void depositCityBank(Player player, String input) { * @param input The input string to get the money value */ public void withdrawCityBank(Player player, String input) { - CityBankManager.withdrawCityBank(this, player, input); + cityBankManager.withdrawCityBank(this, player, input); } /** @@ -416,14 +439,14 @@ public void withdrawCityBank(Player player, String input) { * @return The calculated interest as a double. */ public double calculateCityInterest() { - return CityBankManager.calculateCityInterest(this); + return cityBankManager.calculateCityInterest(this); } /** * Applies the interest to the city balance and updates it in the database. */ public void applyCityInterest() { - CityBankManager.applyCityInterest(this); + cityBankManager.applyCityInterest(this); } // ==================== Permissions Methods ==================== @@ -436,7 +459,7 @@ public void applyCityInterest() { */ public UUID getPlayerWithPermission(CityPermission permission) { if (this.permissions == null) - this.permissions = CityManager.getCityPermissions(this); + this.permissions = cityManager.getCityPermissions(this); for (UUID player : permissions.keySet()) { if (permissions.get(player).contains(permission)) { @@ -454,7 +477,7 @@ public UUID getPlayerWithPermission(CityPermission permission) { */ public Set getPermissions(UUID player) { if (this.permissions == null) - this.permissions = CityManager.getCityPermissions(this); + this.permissions = cityManager.getCityPermissions(this); return permissions.get(player); } @@ -468,7 +491,7 @@ public Set getPermissions(UUID player) { */ public boolean hasPermission(UUID uuid, CityPermission permission) { if (this.permissions == null) - this.permissions = CityManager.getCityPermissions(this); + this.permissions = cityManager.getCityPermissions(this); Set playerPerms = permissions.getOrDefault(uuid, new HashSet<>()); @@ -488,7 +511,7 @@ public boolean hasPermission(UUID uuid, CityPermission permission) { */ public void addPermission(UUID playerUUID, CityPermission permission) { if (this.permissions == null) - this.permissions = CityManager.getCityPermissions(this); + this.permissions = cityManager.getCityPermissions(this); Set playerPerms = permissions.getOrDefault(playerUUID, new HashSet<>()); @@ -499,7 +522,7 @@ public void addPermission(UUID playerUUID, CityPermission permission) { permissions.put(playerUUID, playerPerms); Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> - CityManager.addPlayerPermission(this, playerUUID, permission) + cityManager.addPlayerPermission(this, playerUUID, permission) ); Bukkit.getScheduler().runTask(OMCPlugin.getInstance(), () -> @@ -516,7 +539,7 @@ public void addPermission(UUID playerUUID, CityPermission permission) { * @param permission The permission to remove. */ public void removePermission(UUID playerUUID, CityPermission permission) { - if (this.permissions == null) this.permissions = CityManager.getCityPermissions(this); + if (this.permissions == null) this.permissions = cityManager.getCityPermissions(this); Set playerPerms = permissions.get(playerUUID); @@ -528,7 +551,7 @@ public void removePermission(UUID playerUUID, CityPermission permission) { permissions.put(playerUUID, playerPerms); Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> - CityManager.removePlayerPermission(this, playerUUID, permission)); + cityManager.removePlayerPermission(this, playerUUID, permission)); Bukkit.getScheduler().runTask(OMCPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(new CityPermissionChangeEvent(this, CacheOfflinePlayer.getOfflinePlayer(playerUUID), permission, false))); @@ -548,7 +571,7 @@ public Mascot getMascot() { * @return The mayor of the city, or null if not found. */ public Mayor getMayor() { - return MayorManager.cityMayor.get(this.getUniqueId()); + return mayorManager.cityMayor.get(this.getUniqueId()); } /** @@ -557,7 +580,7 @@ public Mayor getMayor() { * @return True if the city has a mayor, false otherwise. */ public boolean hasMayor() { - Mayor mayor = MayorManager.cityMayor.get(this.getUniqueId()); + Mayor mayor = mayorManager.cityMayor.get(this.getUniqueId()); if (mayor == null) return false; return mayor.getMayorUUID() != null; @@ -569,7 +592,7 @@ public boolean hasMayor() { * @return The election type of the city, or null if not found. */ public ElectionType getElectionType() { - Mayor mayor = MayorManager.cityMayor.get(this.getUniqueId()); + Mayor mayor = mayorManager.cityMayor.get(this.getUniqueId()); if (mayor == null) return null; return mayor.getElectionType(); @@ -581,7 +604,7 @@ public ElectionType getElectionType() { * @return The law of the city, or null if not found. */ public CityLaw getLaw() { - return MayorManager.cityLaws.get(this.getUniqueId()); + return mayorManager.cityLaws.get(this.getUniqueId()); } // ==================== War Methods ==================== @@ -592,7 +615,7 @@ public CityLaw getLaw() { * @return True if the city is in war, false otherwise. */ public boolean isInWar() { - return WarManager.isCityInWar(this.getUniqueId()); + return warManager.isCityInWar(this.getUniqueId()); } /** @@ -601,7 +624,7 @@ public boolean isInWar() { * @return The War object associated with the city or null if not in war. */ public War getWar() { - return WarManager.getWarByCity(this.getUniqueId()); + return warManager.getWarByCity(this.getUniqueId()); } /** @@ -624,7 +647,7 @@ public boolean isImmune() { public void updatePowerPoints(int diff) { powerPoints += diff; Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> - CityManager.saveCity(this) + cityManager.saveCity(this) ); } @@ -702,7 +725,7 @@ public void createRank(DBCityRank rank) { throw new IllegalStateException("Cannot add more than 18 ranks to a city."); } cityRanks.add(rank); - Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> CityRankManager.addCityRank(rank)); + Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> cityRankManager.addCityRank(rank)); } /** @@ -719,7 +742,7 @@ public void deleteRank(DBCityRank rank) { throw new IllegalArgumentException("Cannot delete the default rank (priority 0)."); } cityRanks.remove(rank); - Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> CityRankManager.removeCityRank(rank)); + Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> cityRankManager.removeCityRank(rank)); } /** @@ -731,7 +754,7 @@ public void deleteRank(DBCityRank rank) { */ public void updateRank(DBCityRank oldRank, DBCityRank newRank) { if (cityRanks.contains(oldRank)) { - Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> CityRankManager.updateCityRank(newRank)); + Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> cityRankManager.updateCityRank(newRank)); cityRanks.remove(oldRank); cityRanks.add(newRank); } else { @@ -824,10 +847,10 @@ public void changeRank(Player sender, UUID playerUUID, DBCityRank newRank) { Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> { if (currentRank != null) { - CityRankManager.updateCityRank(currentRank); + cityRankManager.updateCityRank(currentRank); } - CityRankManager.updateCityRank(newRank); + cityRankManager.updateCityRank(newRank); }); } @@ -840,19 +863,19 @@ public void changeRank(Player sender, UUID playerUUID, DBCityRank newRank) { * @return The CityNotation object representing the city's notation for the specified week, or null if not found. */ public CityNotation getNotationOfWeek(String weekStr) { - if (!NotationManager.notationPerWeek.containsKey(weekStr)) { + if (!notationManager.notationPerWeek.containsKey(weekStr)) { return null; } - return NotationManager.notationPerWeek.get(weekStr).stream() + return notationManager.notationPerWeek.get(weekStr).stream() .filter(notation -> notation.getCityUUID().equals(this.getUniqueId())) .findFirst() .orElse(null); } public List getAvailableNotation() { - if (NotationManager.cityNotations.get(this.getUniqueId()) == null) return List.of(); + if (notationManager.cityNotations.get(this.getUniqueId()) == null) return List.of(); - return NotationManager.cityNotations.get(this.getUniqueId()).stream() + return notationManager.cityNotations.get(this.getUniqueId()).stream() .filter(notation -> notation.getCityUUID().equals(this.getUniqueId())) .filter(notation -> DateUtils.isBefore(notation.getWeekStr(), DateUtils.getWeekFormat())) .toList(); @@ -867,13 +890,13 @@ public List getAvailableNotation() { * @param description A description of the notation. */ public void setNotationOfWeek(String weekStr, double architecturalNote, double coherenceNote, String description) { - NotationManager.createOrUpdateNotation(new CityNotation(this.getUniqueId(), architecturalNote, coherenceNote, description, weekStr)); + notationManager.createOrUpdateNotation(new CityNotation(this.getUniqueId(), architecturalNote, coherenceNote, description, weekStr)); } public void setLevel(int newLevel) { this.level = newLevel; Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> - CityManager.saveCity(this) + cityManager.saveCity(this) ); } } diff --git a/src/main/java/fr/openmc/core/features/city/CityChatManager.java b/src/main/java/fr/openmc/core/features/city/CityChatManager.java index e635356e7..68d2ab2c7 100644 --- a/src/main/java/fr/openmc/core/features/city/CityChatManager.java +++ b/src/main/java/fr/openmc/core/features/city/CityChatManager.java @@ -1,5 +1,6 @@ package fr.openmc.core.features.city; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.utils.cache.CacheOfflinePlayer; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -56,7 +57,7 @@ public static boolean isCityChatMember(Player player) { * @param message Le message à envoyer */ public static void sendCityChatMessage(Player sender, Component message) { - City city = CityManager.getPlayerCity(sender.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(sender.getUniqueId()); if (city == null) { MessagesManager.sendMessage(sender, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); 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 7865dc04e..ea78f08e4 100644 --- a/src/main/java/fr/openmc/core/features/city/CityManager.java +++ b/src/main/java/fr/openmc/core/features/city/CityManager.java @@ -9,13 +9,7 @@ import fr.openmc.api.chronometer.Chronometer; import fr.openmc.api.cooldown.DynamicCooldownManager; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.commands.*; import fr.openmc.core.features.city.events.CityDeleteEvent; import fr.openmc.core.features.city.listeners.CityChatListener; @@ -24,7 +18,6 @@ import fr.openmc.core.features.city.sub.mascots.MascotsManager; import fr.openmc.core.features.city.sub.mascots.models.Mascot; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.NPCManager; import fr.openmc.core.features.city.sub.milestone.CityMilestoneManager; import fr.openmc.core.features.city.sub.notation.NotationManager; import fr.openmc.core.features.city.sub.rank.CityRankCommands; @@ -32,6 +25,14 @@ import fr.openmc.core.features.city.sub.statistics.CityStatisticsManager; import fr.openmc.core.features.city.sub.war.WarManager; import fr.openmc.core.features.city.view.CityViewManager; +import fr.openmc.core.hooks.FancyNpcsHook; +import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.cache.CacheOfflinePlayer; import fr.openmc.core.utils.world.chunk.ChunkPos; import org.bukkit.Bukkit; @@ -44,37 +45,55 @@ import java.util.*; @Credit(developers = {"iambibi_", "Gyro", "gab400", "Nocolm", "Axeno", "PuppyTransGirl"}, graphist = {"Tfloa", "Gexary"}) -public class CityManager extends Feature implements HasDatabase, LoadAfterItemsAdder, HasListeners, HasCommands { +public class CityManager extends Feature + implements HasDatabase, HasListeners, HasCommands { 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<>(); + // * SUB-FEATURE + public MayorManager MAYOR; + public ProtectionsManager PROTECTIONS; + public WarManager WAR; + public CityBankManager CITY_BANK; + public CityStatisticsManager STATS; + public NotationManager NOTATION; + public CityRankManager RANKS; + public CityMilestoneManager CITY_MILESTONE; + + private ItemsAdderHook itemsAdderHook; + private FancyNpcsHook fancyNpcsHook; + @Override public void init() { + this.itemsAdderHook = OMCRegistry.HOOKS.ITEMS_ADDER; + this.fancyNpcsHook = OMCRegistry.HOOKS.FANCY_NPCS; + loadCities(); // SUB-FEATURE - MayorManager.init(); - ProtectionsManager.init(); - WarManager.init(); - CityBankManager.init(); - CityStatisticsManager.init(); - NotationManager.init(); - CityRankManager.init(); - CityMilestoneManager.init(); + // todo utiliser OMCRegistry.FEATURES.register + this.MAYOR = OMCRegistry.FEATURES.register(new MayorManager(this, fancyNpcsHook, itemsAdderHook)); + this.PROTECTIONS = OMCRegistry.FEATURES.register(new ProtectionsManager(this)); + this.WAR = OMCRegistry.FEATURES.register(new WarManager()); + this.CITY_BANK = OMCRegistry.FEATURES.register(new CityBankManager(this, MAYOR)); + this.STATS = OMCRegistry.FEATURES.register(new CityStatisticsManager()); + this.NOTATION = OMCRegistry.FEATURES.register(new NotationManager(this)); + this.RANKS = OMCRegistry.FEATURES.register(new CityRankManager(this)); + this.CITY_MILESTONE = OMCRegistry.FEATURES.register(new CityMilestoneManager()); } @Override public Set getCommands() { return Set.of( - new AdminCityCommands(), - new CityCommands(), + new AdminCityCommands(this), + new CityCommands(this), new CityChatCommand(), new CityPermsCommands(), new CityChestCommand(), - new CityRankCommands(), - new CityTopCommands(), + new CityRankCommands(this), + new CityTopCommands(this), new CityInviteCommands(), new CityClaimCommands() ); @@ -87,25 +106,6 @@ public Set getListeners() { ); } - @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; @@ -128,17 +128,11 @@ public 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 ==================== - private static void loadCities() { + private void loadCities() { try { cities.clear(); for (DBCity dbCity : citiesDao.queryForAll()) { @@ -169,7 +163,7 @@ private static void loadCities() { } } - public static void saveCity(City city) { + public void saveCity(City city) { try { citiesDao.createOrUpdate(city.serialize()); } catch (SQLException e) { @@ -183,7 +177,7 @@ public static void saveCity(City city) { * @param city The city to add the player to * @param playerUUID The playerUUID to add to the city */ - public static void addPlayerToCity(City city, UUID playerUUID) { + public void addPlayerToCity(City city, UUID playerUUID) { if (city == null || playerUUID == null) return; playerCities.put(playerUUID, city); @@ -204,7 +198,7 @@ public static void addPlayerToCity(City city, UUID playerUUID) { * @param city The city to remove the player from * @param playerUUID The playerUUID to remove from the city */ - public static void removePlayerFromCity(City city, UUID playerUUID) { + public void removePlayerFromCity(City city, UUID playerUUID) { if (city == null || playerUUID == null) return; playerCities.remove(playerUUID); @@ -219,7 +213,7 @@ public static void removePlayerFromCity(City city, UUID playerUUID) { }); } - public static HashMap> getCityPermissions(City city) { + public HashMap> getCityPermissions(City city) { HashMap> permissions = new HashMap<>(); try { @@ -240,7 +234,7 @@ public static HashMap> getCityPermissions(City city) { return permissions; } - public static void addPlayerPermission(City city, UUID playerUUID, CityPermission permission) { + public void addPlayerPermission(City city, UUID playerUUID, CityPermission permission) { try { permissionsDao.create(new DBCityPermission(city.getUniqueId(), playerUUID, permission.name())); } catch (SQLException e) { @@ -248,7 +242,7 @@ public static void addPlayerPermission(City city, UUID playerUUID, CityPermissio } } - public static void removePlayerPermission(City city, UUID playerUUID, CityPermission permission) { + public void removePlayerPermission(City city, UUID playerUUID, CityPermission permission) { try { DeleteBuilder delete = permissionsDao.deleteBuilder(); delete.where() @@ -263,7 +257,7 @@ public static void removePlayerPermission(City city, UUID playerUUID, CityPermis } } - public static HashMap getCityChestContent(City city) { + public HashMap getCityChestContent(City city) { HashMap pages = new HashMap<>(); try { @@ -279,7 +273,7 @@ public static HashMap getCityChestContent(City city) { return pages; } - public static void saveChestPage(City city, int page, ItemStack[] content) { + public void saveChestPage(City city, int page, ItemStack[] content) { try { DeleteBuilder delete = chestsDao.deleteBuilder(); delete.where().eq("city_uuid", city.getUniqueId()).and().eq("page", page); @@ -291,7 +285,7 @@ public static void saveChestPage(City city, int page, ItemStack[] content) { } } - public static void claimChunk(City city, ChunkPos chunkPos) { + public void claimChunk(City city, ChunkPos chunkPos) { claimedChunks.put(chunkPos, city); CityViewManager.updateAllViews(); @@ -304,7 +298,7 @@ public static void claimChunk(City city, ChunkPos chunkPos) { }); } - public static void unclaimChunk(City city, ChunkPos chunkPos) { + public void unclaimChunk(City city, ChunkPos chunkPos) { claimedChunks.remove(chunkPos); CityViewManager.updateAllViews(); @@ -329,7 +323,7 @@ public static void unclaimChunk(City city, ChunkPos chunkPos) { * * @return cities */ - public static Collection getCities() { + public Collection getCities() { return cities.values(); } @@ -338,7 +332,7 @@ public static Collection getCities() { * * @return A list of all city UUIDs */ - public static List getAllCityUUIDs() { + public List getAllCityUUIDs() { List uuidList = new ArrayList<>(); cities.forEach((name, city) -> uuidList.add(city.getUniqueId())); return uuidList; @@ -351,7 +345,7 @@ public static List getAllCityUUIDs() { * @param z The z coordinate of the chunk * @return true if the chunk is claimed, false otherwise */ - public static boolean isChunkClaimed(int x, int z) { + public boolean isChunkClaimed(int x, int z) { return getCityFromChunk(x, z) != null; } @@ -362,7 +356,7 @@ public static boolean isChunkClaimed(int x, int z) { * @param chunk The chunk * @return true if the chunk is claimed, false otherwise */ - public static boolean isChunkClaimed(Chunk chunk) { + public boolean isChunkClaimed(Chunk chunk) { return getCityFromChunk(chunk) != null; } @@ -373,10 +367,10 @@ public static boolean isChunkClaimed(Chunk chunk) { * @param radius The radius * @return true if the chunk is claimed, false otherwise */ - public static boolean isChunkClaimedInRadius(Chunk chunk, int radius) { + public boolean isChunkClaimedInRadius(Chunk chunk, int radius) { for (int x = -radius; x <= radius; x++) { for (int z = -radius; z <= radius; z++) { - if (CityManager.isChunkClaimed(chunk.getX() + x, chunk.getZ() + z)) { + if (this.isChunkClaimed(chunk.getX() + x, chunk.getZ() + z)) { return true; } } @@ -390,7 +384,7 @@ public static boolean isChunkClaimedInRadius(Chunk chunk, int radius) { * @param cityUUID The {@link UUID} of the city * @return The {@link City}, or null if not found */ - public static City getCity(UUID cityUUID) { + public City getCity(UUID cityUUID) { return cities.get(cityUUID); } @@ -400,7 +394,7 @@ public static City getCity(UUID cityUUID) { * @param name The name of the city * @return The city object, or null if not found */ - public static City getCityByName(String name) { + public City getCityByName(String name) { return citiesByName.get(name); } @@ -410,7 +404,7 @@ public static City getCityByName(String name) { * @param inCity The cities whose chunks are requested * @return The cities claimed chunks */ - public static Set getCityChunks(City inCity) { + public Set getCityChunks(City inCity) { Set chunks = new HashSet<>(); claimedChunks.forEach((chunk, city) -> { @@ -428,7 +422,7 @@ public static Set getCityChunks(City inCity) { * @param inCity The cities whose members are requested * @return The city members */ - public static Set getCityMembers(City inCity) { + public Set getCityMembers(City inCity) { Set members = new HashSet<>(); playerCities.forEach((player, city) -> { @@ -445,7 +439,7 @@ public static Set getCityMembers(City inCity) { * @param playerUUID The UUID of the member * @return The city object, or null if not found */ - public static City getPlayerCity(UUID playerUUID) { + public City getPlayerCity(UUID playerUUID) { return playerCities.get(playerUUID); } @@ -457,7 +451,7 @@ public static City getPlayerCity(UUID playerUUID) { * @return The city object, or null if not found */ @Nullable - public static City getCityFromChunk(int x, int z) { + public City getCityFromChunk(int x, int z) { return claimedChunks.get(new ChunkPos(x, z)); } @@ -468,7 +462,7 @@ public static City getCityFromChunk(int x, int z) { * @return The city object, or null if not found */ @Nullable - public static City getCityFromChunk(Chunk chunk) { + public City getCityFromChunk(Chunk chunk) { return claimedChunks.get(new ChunkPos(chunk.getX(), chunk.getZ())); } @@ -479,7 +473,7 @@ public static City getCityFromChunk(Chunk chunk) { * @return The city object, or null if not found */ @Nullable - public static City getCityFromChunk(ChunkPos chunkPos) { + public City getCityFromChunk(ChunkPos chunkPos) { return claimedChunks.get(chunkPos); } @@ -488,7 +482,7 @@ public static City getCityFromChunk(ChunkPos chunkPos) { * * @param city The city object */ - public static void registerCity(City city) { + public void registerCity(City city) { cities.put(city.getUniqueId(), city); citiesByName.put(city.getName(), city); } @@ -498,12 +492,12 @@ public static void registerCity(City city) { * * @param city The city */ - public static void deleteCity(City city) { + public void deleteCity(City city) { if (city == null) return; - MayorManager.cityMayor.remove(city.getUniqueId()); - MayorManager.cityElections.remove(city.getUniqueId()); - MayorManager.playerVote.remove(city.getUniqueId()); + MAYOR.cityMayor.remove(city.getUniqueId()); + MAYOR.cityElections.remove(city.getUniqueId()); + MAYOR.playerVote.remove(city.getUniqueId()); List membersCopy = new ArrayList<>(city.getMembers()); for (UUID memberId : membersCopy) { @@ -553,7 +547,7 @@ public static void deleteCity(City city) { } MascotsManager.removeMascotsFromCity(city); - NPCManager.removeNPCS(city.getUniqueId()); + MAYOR.mayorNPCManager.removeNPCS(city.getUniqueId()); Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> { try { @@ -567,7 +561,7 @@ public static void deleteCity(City city) { permissionsDelete.where().eq("city_uuid", city.getUniqueId()); permissionsDao.delete(permissionsDelete.prepare()); - CityRankManager.removeRanks(city); + RANKS.removeRanks(city); DeleteBuilder claimsDelete = claimsDao.deleteBuilder(); claimsDelete.where().eq("city_uuid", city.getUniqueId()); @@ -577,7 +571,7 @@ public static void deleteCity(City city) { chestsDelete.where().eq("city_uuid", city.getUniqueId()); chestsDao.delete(chestsDelete.prepare()); - MayorManager.removeCity(city); + MAYOR.removeCity(city); } catch (SQLException e) { throw new RuntimeException(e); } diff --git a/src/main/java/fr/openmc/core/features/city/ProtectionsManager.java b/src/main/java/fr/openmc/core/features/city/ProtectionsManager.java index 7c26618a0..eff696d50 100644 --- a/src/main/java/fr/openmc/core/features/city/ProtectionsManager.java +++ b/src/main/java/fr/openmc/core/features/city/ProtectionsManager.java @@ -1,9 +1,11 @@ package fr.openmc.core.features.city; -import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.city.listeners.protections.*; import fr.openmc.core.features.city.sub.war.War; import fr.openmc.core.features.shops.managers.ShopManager; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; import fr.openmc.core.utils.text.messages.Prefix; @@ -17,33 +19,40 @@ import java.util.*; -public class ProtectionsManager { - public static final Set canBypassPlayer = new HashSet<>(); - - private static final Map lastErrorMessageTime = new HashMap<>(); - private static final long ERROR_MESSAGE_COOLDOWN = 3000; // 3 secondes - - public static void init() { - OMCPlugin.registerEvents( - BlockProtection::new, - BowProtection::new, - DamageProtection::new, - EntityProtection::new, - ExplodeProtection::new, - FireProtection::new, - FishProtection::new, - HangingProtection::new, - InteractProtection::new, - LeashProtection::new, - MountProtection::new, - PistonProtection::new, - PotionProtection::new, - TeleportProtection::new, - TramplingProtection::new, - VehicleProtection::new - ); - } - +public class ProtectionsManager extends Feature implements HasListeners { + public final Set canBypassPlayer = new HashSet<>(); + + private final Map lastErrorMessageTime = new HashMap<>(); + private final long ERROR_MESSAGE_COOLDOWN = 3000; // 3 secondes + + private final CityManager cityManager; + + public ProtectionsManager(CityManager cityManager) { + this.cityManager = cityManager; + } + + @Override + public Set getListeners() { + return Set.of( + () -> new BlockProtection(cityManager), + () -> new BowProtection(cityManager), + () -> new DamageProtection(cityManager), + () -> new EntityProtection(cityManager), + () -> new ExplodeProtection(cityManager), + () -> new FireProtection(cityManager), + () -> new FishProtection(cityManager) , + () -> new HangingProtection(cityManager), + () -> new InteractProtection(cityManager), + () -> new LeashProtection(cityManager), + () -> new MountProtection(cityManager), + () -> new PistonProtection(cityManager), + () -> new PotionProtection(cityManager), + () -> new TeleportProtection(cityManager), + () -> new TramplingProtection(cityManager), + () -> new VehicleProtection(cityManager) + ); + } + /** * Vérifie si le joueur est dans une ville et s'il en est membre.
* Si le joueur n'en est pas membre, l'événement est annulé. @@ -51,12 +60,12 @@ public static void init() { * @param player Le joueur à vérifier * @param loc La localisation pour vérifier la ville */ - public static boolean canInteract(Player player, Location loc) { + public boolean canInteract(Player player, Location loc) { if (!player.getWorld().getName().equals("world")) return true; if (canBypassPlayer.contains(player.getUniqueId())) return true; // Le joueur peut bypass les protections - City cityAtLoc = CityManager.getCityFromChunk(loc.getChunk().getX(), loc.getChunk().getZ()); + City cityAtLoc = cityManager.getCityFromChunk(loc.getChunk().getX(), loc.getChunk().getZ()); if (cityAtLoc == null) return true; @@ -64,7 +73,7 @@ public static boolean canInteract(Player player, Location loc) { War war = cityAtLoc.getWar(); if (cityAtLoc.isInWar() && war != null && war.getPhase() == War.WarPhase.COMBAT) { - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); if (playerCity != null && war.equals(playerCity.getWar())) { return war.getAttackers().contains(player.getUniqueId()) || war.getDefenders().contains(player.getUniqueId()); @@ -74,12 +83,12 @@ public static boolean canInteract(Player player, Location loc) { return false; } - public static boolean canExplodeNaturally(Location loc) { - City city = CityManager.getCityFromChunk(loc.getChunk().getX(), loc.getChunk().getZ()); + public boolean canExplodeNaturally(Location loc) { + City city = cityManager.getCityFromChunk(loc.getChunk().getX(), loc.getChunk().getZ()); return city == null; } - public static void checkCity(Player player, Cancellable event, City city, boolean allowByPassInWar) { + public void checkCity(Player player, Cancellable event, City city, boolean allowByPassInWar) { if (!player.getWorld().getName().equals("world")) return; if (city == null) return; // Pas de ville, pas de protection @@ -94,7 +103,7 @@ public static void checkCity(Player player, Cancellable event, City city, boolea } } - public static void verify(Entity entity, Cancellable event, Location loc) { + public void verify(Entity entity, Cancellable event, Location loc) { if (!entity.getWorld().getName().equals("world")) return; if (ShopManager.getShopAt(loc) != null) { @@ -103,7 +112,7 @@ public static void verify(Entity entity, Cancellable event, Location loc) { return; } - City city = CityManager.getCityFromChunk(loc.getChunk().getX(), loc.getChunk().getZ()); // on regarde le claim ou l'action a été fait + City city = cityManager.getCityFromChunk(loc.getChunk().getX(), loc.getChunk().getZ()); // on regarde le claim ou l'action a été fait if (city == null || city.isInWar()) return; if (entity instanceof Player player) { @@ -123,7 +132,7 @@ public static void verify(Entity entity, Cancellable event, Location loc) { * * @param player Le joueur à qui envoyer le message */ - public static void cancelMessage(Player player) { + public void cancelMessage(Player player) { long now = System.currentTimeMillis(); long last = lastErrorMessageTime.getOrDefault(player.getUniqueId(), 0L); if (now - last >= ERROR_MESSAGE_COOLDOWN) { @@ -139,13 +148,13 @@ public static void cancelMessage(Player player) { } } - public static void checkPermissions(@NotNull Player player, Cancellable event, City city, CityPermission permission) { + public void checkPermissions(@NotNull Player player, Cancellable event, City city, CityPermission permission) { if (!player.getWorld().getName().equals("world")) return; - + if (canBypassPlayer.contains(player.getUniqueId())) return; // Le joueur peut bypass les protections if (city == null) return; // Pas de ville, pas de protection if (city.isInWar()) return; // En guerre, pas de protection - + if (city.isMember(player)) { if (!city.hasPermission(player.getUniqueId(), permission)) { event.setCancelled(true); diff --git a/src/main/java/fr/openmc/core/features/city/actions/CityChangeAction.java b/src/main/java/fr/openmc/core/features/city/actions/CityChangeAction.java index 104027ca0..e1df5ad59 100644 --- a/src/main/java/fr/openmc/core/features/city/actions/CityChangeAction.java +++ b/src/main/java/fr/openmc/core/features/city/actions/CityChangeAction.java @@ -2,8 +2,8 @@ import fr.openmc.api.cooldown.DynamicCooldownManager; import fr.openmc.api.menulib.template.ConfirmMenu; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityType; import fr.openmc.core.features.city.conditions.CityTypeConditions; import fr.openmc.core.features.city.sub.mascots.MascotsManager; @@ -31,7 +31,7 @@ public class CityChangeAction { private static final NamespacedKey MAX_HEALTH_KEY = NamespacedKey.fromString("openmc:mascot_max_health"); public static void beginChangeCity(Player player, CityType typeChange) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (!CityTypeConditions.canCityChangeType(city, player, typeChange)) return; @@ -73,7 +73,7 @@ public static void beginChangeCity(Player player, CityType typeChange) { } public static void finishChange(Player sender) { - City city = CityManager.getPlayerCity(sender.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(sender.getUniqueId()); if (!CityTypeConditions.canCityChangeType(city, sender, city.getType() == CityType.WAR ? CityType.PEACE : CityType.WAR)) { MessagesManager.sendMessage(sender, TranslationManager.translation("messages.global.cannot_do_this"), Prefix.CITY, MessageType.ERROR, false); diff --git a/src/main/java/fr/openmc/core/features/city/actions/CityClaimAction.java b/src/main/java/fr/openmc/core/features/city/actions/CityClaimAction.java index eacbf8b06..502e9bff3 100644 --- a/src/main/java/fr/openmc/core/features/city/actions/CityClaimAction.java +++ b/src/main/java/fr/openmc/core/features/city/actions/CityClaimAction.java @@ -1,10 +1,10 @@ package fr.openmc.core.features.city.actions; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.conditions.CityClaimCondition; import fr.openmc.core.features.economy.EconomyManager; -import fr.openmc.core.hooks.WorldGuardHook; import fr.openmc.core.utils.bukkit.ItemUtils; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -35,7 +35,8 @@ public static int calculateAywenite(int chunkCount) { } public static void startClaim(Player sender, int chunkX, int chunkZ) { - City city = CityManager.getPlayerCity(sender.getUniqueId()); + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); + City city = cityManager.getPlayerCity(sender.getUniqueId()); org.bukkit.World bWorld = sender.getWorld(); if (!bWorld.getName().equals("world")) { MessagesManager.sendMessage(sender, TranslationManager.translation("feature.city.claim.cant_claim_here"), @@ -54,14 +55,14 @@ public static void startClaim(Player sender, int chunkX, int chunkZ) { } Chunk chunk = sender.getWorld().getChunkAt(chunkX, chunkZ); - if (WorldGuardHook.doesChunkContainWGRegion(chunk)) { + if (OMCRegistry.HOOKS.WORLD_GUARD.doesChunkContainWGRegion(chunk)) { MessagesManager.sendMessage(sender, TranslationManager.translation("feature.city.claim.is_in_region"), Prefix.CITY, MessageType.ERROR, true); return; } - if (CityManager.isChunkClaimed(chunkX, chunkZ)) { - City chunkCity = CityManager.getCityFromChunk(chunkX, chunkZ); + if (cityManager.isChunkClaimed(chunkX, chunkZ)) { + City chunkCity = cityManager.getCityFromChunk(chunkX, chunkZ); if (chunkCity == null) return; String cityName = chunkCity.getName(); MessagesManager.sendMessage(sender, TranslationManager.translation("feature.city.claim.already_claim", diff --git a/src/main/java/fr/openmc/core/features/city/actions/CityCreateAction.java b/src/main/java/fr/openmc/core/features/city/actions/CityCreateAction.java index 3f5d6080e..525f54705 100644 --- a/src/main/java/fr/openmc/core/features/city/actions/CityCreateAction.java +++ b/src/main/java/fr/openmc/core/features/city/actions/CityCreateAction.java @@ -8,10 +8,8 @@ import fr.openmc.core.features.city.CityType; import fr.openmc.core.features.city.conditions.CityCreateConditions; 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.view.CityViewManager; import fr.openmc.core.features.economy.EconomyManager; -import fr.openmc.core.hooks.WorldGuardHook; import fr.openmc.core.utils.bukkit.ItemUtils; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -97,12 +95,14 @@ private static boolean isValidLocation(Player player, Location location) { public static boolean finalizeCreation(Player player, Location mascotLocation) { Chunk chunk = mascotLocation.getChunk(); - if (WorldGuardHook.doesChunkContainWGRegion(chunk)) { + if (OMCRegistry.HOOKS.WORLD_GUARD.doesChunkContainWGRegion(chunk)) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.claim.is_in_region"), Prefix.CITY, MessageType.ERROR, false); return false; } - if (CityManager.isChunkClaimedInRadius(chunk, 1)) { + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); + + if (cityManager.isChunkClaimedInRadius(chunk, 1)) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.claim.already_claim_in_adjacent"), Prefix.CITY, MessageType.ERROR, false); return false; @@ -117,7 +117,7 @@ public static boolean finalizeCreation(Player player, Location mascotLocation) { City city = new City(cityUUID, pendingCityName, player, CityType.PEACE, chunk); // Lois - MayorManager.createCityLaws(city, false, null); + cityManager.MAYOR.createCityLaws(city, false, null); // Mascotte player.getWorld().getBlockAt(mascotLocation).setType(Material.AIR); diff --git a/src/main/java/fr/openmc/core/features/city/actions/CityDeleteAction.java b/src/main/java/fr/openmc/core/features/city/actions/CityDeleteAction.java index cc8cdbb35..f7e2bfabc 100644 --- a/src/main/java/fr/openmc/core/features/city/actions/CityDeleteAction.java +++ b/src/main/java/fr/openmc/core/features/city/actions/CityDeleteAction.java @@ -2,6 +2,7 @@ import fr.openmc.api.cooldown.DynamicCooldownManager; import fr.openmc.api.menulib.template.ConfirmMenu; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.conditions.CityManageConditions; @@ -20,9 +21,10 @@ public class CityDeleteAction { public static void startDeleteCity(Player player) { + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); UUID uuid = player.getUniqueId(); - City city = CityManager.getPlayerCity(uuid); + City city = cityManager.getPlayerCity(uuid); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, true); @@ -40,7 +42,7 @@ public static void startDeleteCity(Player player) { } } - CityManager.deleteCity(city); + cityManager.deleteCity(city); MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.delete.success"), Prefix.CITY, MessageType.SUCCESS, false); DynamicCooldownManager.use(uuid, "city:big", 60000); // 1 minute diff --git a/src/main/java/fr/openmc/core/features/city/actions/CityKickAction.java b/src/main/java/fr/openmc/core/features/city/actions/CityKickAction.java index 62633901a..017a391d8 100644 --- a/src/main/java/fr/openmc/core/features/city/actions/CityKickAction.java +++ b/src/main/java/fr/openmc/core/features/city/actions/CityKickAction.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.city.actions; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.conditions.CityKickCondition; import fr.openmc.core.utils.cache.PlayerNameCache; import fr.openmc.core.utils.text.messages.MessageType; @@ -15,7 +15,7 @@ public class CityKickAction { public static void startKick(Player sender, OfflinePlayer playerKick) { - City city = CityManager.getPlayerCity(sender.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(sender.getUniqueId()); if (!CityKickCondition.canCityKickPlayer(city, sender, playerKick)) return; diff --git a/src/main/java/fr/openmc/core/features/city/actions/CityLeaveAction.java b/src/main/java/fr/openmc/core/features/city/actions/CityLeaveAction.java index cfbe85710..75e32aee3 100644 --- a/src/main/java/fr/openmc/core/features/city/actions/CityLeaveAction.java +++ b/src/main/java/fr/openmc/core/features/city/actions/CityLeaveAction.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.city.actions; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.conditions.CityLeaveCondition; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -15,7 +15,7 @@ public class CityLeaveAction { public static void startLeave(Player player) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (city == null) return; diff --git a/src/main/java/fr/openmc/core/features/city/actions/CityUnclaimAction.java b/src/main/java/fr/openmc/core/features/city/actions/CityUnclaimAction.java index 9fb981650..b52dcaa71 100644 --- a/src/main/java/fr/openmc/core/features/city/actions/CityUnclaimAction.java +++ b/src/main/java/fr/openmc/core/features/city/actions/CityUnclaimAction.java @@ -2,7 +2,6 @@ import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.economy.EconomyManager; import fr.openmc.core.utils.bukkit.ItemUtils; import fr.openmc.core.utils.text.messages.MessageType; @@ -26,7 +25,7 @@ public static int calculateAywenite(int chunkCount) { } public static void startUnclaim(Player sender, int chunkX, int chunkZ) { - City city = CityManager.getPlayerCity(sender.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(sender.getUniqueId()); World bWorld = sender.getWorld(); if (!bWorld.getName().equals("world")) { MessagesManager.sendMessage(sender, TranslationManager.translation("feature.city.claim.cant_claim_here"), Prefix.CITY, MessageType.ERROR, false); diff --git a/src/main/java/fr/openmc/core/features/city/commands/AdminCityCommands.java b/src/main/java/fr/openmc/core/features/city/commands/AdminCityCommands.java index d6b105775..c232c9020 100644 --- a/src/main/java/fr/openmc/core/features/city/commands/AdminCityCommands.java +++ b/src/main/java/fr/openmc/core/features/city/commands/AdminCityCommands.java @@ -30,20 +30,26 @@ @Command("admcity") @CommandPermission("omc.admins.commands.admincity") public class AdminCityCommands { + private final CityManager cityManager; + + public AdminCityCommands(CityManager cityManager) { + this.cityManager = cityManager; + } + @Subcommand("deleteCity") @CommandPermission("omc.admins.commands.admincity.deleteCity") void deleteCity( Player player, @Named("nom de ville") @SuggestWith(CityNameAutoComplete.class) String name ) { - City city = CityManager.getCityByName(name); + City city = cityManager.getCityByName(name); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.not_found"), Prefix.STAFF, MessageType.ERROR, false); return; } - CityManager.deleteCity(city); + cityManager.deleteCity(city); MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.admin.commands.delete.success"), Prefix.STAFF, MessageType.SUCCESS, false); } @@ -52,7 +58,7 @@ void deleteCity( @Subcommand("list") @CommandPermission("omc.admins.commands.admincity.list") void list(Player player) { - List all = new ArrayList<>(CityManager.getCities()); + List all = new ArrayList<>(cityManager.getCities()); all.sort((a, b) -> a.getName().compareToIgnoreCase(b.getName())); @@ -112,7 +118,7 @@ void info( Player player, @Named("nom de ville") @SuggestWith(CityNameAutoComplete.class) String name ) { - City city = CityManager.getCityByName(name); + City city = cityManager.getCityByName(name); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.admin.commands.info.not_found"), Prefix.STAFF, MessageType.ERROR, false); @@ -129,13 +135,13 @@ void rename( @Named("nom de ville") @SuggestWith(CityNameAutoComplete.class) String name, @Named("nouveau nom") String newName ) { - City newNameCity = CityManager.getCityByName(newName); + City newNameCity = cityManager.getCityByName(newName); if (newNameCity != null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.admin.commands.rename.name_already_used"), Prefix.STAFF, MessageType.ERROR, false); return; } - City city = CityManager.getCityByName(name); + City city = cityManager.getCityByName(name); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.not_found"), Prefix.STAFF, MessageType.ERROR, false); return; @@ -151,7 +157,7 @@ void setOwner( Player player, @Named("nom de ville") @SuggestWith(CityNameAutoComplete.class) String name, @Named("nouveau propriétaire") @SuggestWith(OnlinePlayerAutoComplete.class) Player newOwner) { - City city = CityManager.getCityByName(name); + City city = cityManager.getCityByName(name); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.not_found"), Prefix.STAFF, MessageType.ERROR, false); @@ -168,7 +174,7 @@ void setBalance( @Named("nom de ville") @SuggestWith(CityNameAutoComplete.class) String name, @Named("balance") double newBalance ) { - City city = CityManager.getCityByName(name); + City city = cityManager.getCityByName(name); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.not_found"), Prefix.STAFF, MessageType.ERROR, false); return; @@ -184,7 +190,7 @@ void getBalance( Player player, @Named("nom de ville") @SuggestWith(CityNameAutoComplete.class) String name ) { - City city = CityManager.getCityByName(name); + City city = cityManager.getCityByName(name); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.not_found"), Prefix.STAFF, MessageType.ERROR, false); return; @@ -202,14 +208,14 @@ void add( Player player, @Named("nom de ville") @SuggestWith(CityNameAutoComplete.class) String name, @Named("player") @SuggestWith(OnlinePlayerAutoComplete.class) Player newMember) { - City city = CityManager.getCityByName(name); + City city = cityManager.getCityByName(name); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.not_found"), Prefix.STAFF, MessageType.ERROR, false); return; } - if (CityManager.getPlayerCity(newMember.getUniqueId()) != null) { + if (cityManager.getPlayerCity(newMember.getUniqueId()) != null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.admin.commands.add_player.already_in_city"), Prefix.STAFF, MessageType.ERROR, false); return; } @@ -224,7 +230,7 @@ void remove( Player player, @Named("nom de ville") @SuggestWith(OnlinePlayerAutoComplete.class) Player member ) { - City city = CityManager.getPlayerCity(member.getUniqueId()); + City city = cityManager.getPlayerCity(member.getUniqueId()); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.admin.commands.remove_player.not_in_city"), Prefix.STAFF, MessageType.ERROR, false); return; @@ -245,7 +251,7 @@ void getPlayer( Player player, @Named("player") @SuggestWith(OnlinePlayerAutoComplete.class) Player member ) { - City city = CityManager.getPlayerCity(member.getUniqueId()); + City city = cityManager.getPlayerCity(member.getUniqueId()); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.admin.commands.getcity.not_in_city"), Prefix.STAFF, MessageType.ERROR, false); return; @@ -261,14 +267,15 @@ void getPlayer( @Subcommand("claim bypass") @CommandPermission("omc.admins.commands.admincity.claim.bypass") public void bypass(Player player) { + ProtectionsManager protectionsManager = cityManager.PROTECTIONS; UUID uuid = player.getUniqueId(); - boolean canBypass = ProtectionsManager.canBypassPlayer.contains(uuid); + boolean canBypass = protectionsManager.canBypassPlayer.contains(uuid); if (canBypass) { - ProtectionsManager.canBypassPlayer.remove(uuid); + protectionsManager.canBypassPlayer.remove(uuid); MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.admin.commands.claim_bypass.disabled"), Prefix.STAFF, MessageType.SUCCESS, false); } else { - ProtectionsManager.canBypassPlayer.add(uuid); + protectionsManager.canBypassPlayer.add(uuid); MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.admin.commands.claim_bypass.enabled"), Prefix.STAFF, MessageType.SUCCESS, false); } @@ -280,7 +287,7 @@ public void freeClaimAdd( Player player, @Named("nom de ville") @SuggestWith(CityNameAutoComplete.class) String name, @Named("claim") int claim) { - City city = CityManager.getCityByName(name); + City city = cityManager.getCityByName(name); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.not_found"), Prefix.STAFF, MessageType.ERROR, false); return; @@ -295,7 +302,7 @@ public void freeClaimRemove( @Named("nom de ville") @SuggestWith(CityNameAutoComplete.class) String name, @Named("claim") int claim ) { - City city = CityManager.getCityByName(name); + City city = cityManager.getCityByName(name); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.not_found"), Prefix.STAFF, MessageType.ERROR, false); return; @@ -310,7 +317,7 @@ public void freeClaimDelete( Player player, @Named("nom de ville") @SuggestWith(CityNameAutoComplete.class) String name ) { - City city = CityManager.getCityByName(name); + City city = cityManager.getCityByName(name); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.not_found"), Prefix.STAFF, MessageType.ERROR, false); return; diff --git a/src/main/java/fr/openmc/core/features/city/commands/CityChestCommand.java b/src/main/java/fr/openmc/core/features/city/commands/CityChestCommand.java index 8e2b302f1..b465bffee 100644 --- a/src/main/java/fr/openmc/core/features/city/commands/CityChestCommand.java +++ b/src/main/java/fr/openmc/core/features/city/commands/CityChestCommand.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.city.commands; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.actions.CityChestAction; import fr.openmc.core.features.city.conditions.CityChestConditions; import fr.openmc.core.features.city.menu.CityChestMenu; @@ -17,7 +17,7 @@ void chest( Player player, @Optional @Named("page") @Range(min = 0) Integer page ) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (!CityChestConditions.canCityChestOpen(city, player)) return; @@ -32,7 +32,7 @@ void chest( @Description("Améliore la coffre de la ville") @CommandPermission("omc.commands.city.chest_upgrade") void upgrade(Player player) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (!CityChestConditions.canCityChestUpgrade(city, player)) return; CityChestAction.upgradeChest(player, city); diff --git a/src/main/java/fr/openmc/core/features/city/commands/CityClaimCommands.java b/src/main/java/fr/openmc/core/features/city/commands/CityClaimCommands.java index 08bd0fc92..362dda7da 100644 --- a/src/main/java/fr/openmc/core/features/city/commands/CityClaimCommands.java +++ b/src/main/java/fr/openmc/core/features/city/commands/CityClaimCommands.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.city.commands; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.actions.CityClaimAction; import fr.openmc.core.features.city.actions.CityUnclaimAction; import fr.openmc.core.features.city.conditions.CityClaimCondition; @@ -22,7 +22,7 @@ public class CityClaimCommands { @Description("Claim un chunk pour votre ville") @CommandPlaceholder() void claim(Player sender) { - City city = CityManager.getPlayerCity(sender.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(sender.getUniqueId()); if (!CityClaimCondition.canCityClaim(city, sender)) return; @@ -35,7 +35,7 @@ void claim(Player sender) { @CommandPermission("omc.commands.city.unclaim") @Description("Unclaim un chunk pour votre ville") void unclaim(Player sender) { - City city = CityManager.getPlayerCity(sender.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(sender.getUniqueId()); if (!CityUnclaimCondition.canCityUnclaim(city, sender)) return; diff --git a/src/main/java/fr/openmc/core/features/city/commands/CityCommands.java b/src/main/java/fr/openmc/core/features/city/commands/CityCommands.java index aaff3d985..525433e78 100644 --- a/src/main/java/fr/openmc/core/features/city/commands/CityCommands.java +++ b/src/main/java/fr/openmc/core/features/city/commands/CityCommands.java @@ -2,6 +2,7 @@ import fr.openmc.api.chronometer.Chronometer; import fr.openmc.api.input.dialog.DialogInput; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.actions.*; @@ -29,10 +30,16 @@ @Command({"ville", "city"}) public class CityCommands { + private final CityManager cityManager; + + public CityCommands(CityManager cityManager) { + this.cityManager = cityManager; + } + @CommandPlaceholder() public static void mainCommand(Player player) { if (!Chronometer.containsChronometer(player.getUniqueId(), "mascot:stick")) { - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (playerCity == null) { NoCityMenu menu = new NoCityMenu(player); menu.open(); @@ -49,7 +56,7 @@ public static void mainCommand(Player player) { @CommandPermission("omc.commands.city.info") @Description("Avoir des informations sur votre ville") void info(Player player) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = cityManager.getPlayerCity(player.getUniqueId()); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); @@ -97,7 +104,7 @@ void rename( Player player, @Named("nouveau nom") String name ) { - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); if (!CityManageConditions.canCityRename(playerCity, player)) return; @@ -120,7 +127,7 @@ void transfer( Player sender, @Named("nouveau propriétaire") @SuggestWith(CityMembersAutoComplete.class) OfflinePlayer player ) { - City playerCity = CityManager.getPlayerCity(sender.getUniqueId()); + City playerCity = cityManager.getPlayerCity(sender.getUniqueId()); if (!CityManageConditions.canCityTransfer(playerCity, sender, player.getUniqueId())) return; @@ -143,7 +150,7 @@ void kick( @CommandPermission("omc.commands.city.leave") @Description("Quitter votre ville") void leave(Player player) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = cityManager.getPlayerCity(player.getUniqueId()); if (!CityLeaveCondition.canCityLeave(city, player)) return; CityLeaveAction.startLeave(player); @@ -152,7 +159,7 @@ void leave(Player player) { @Subcommand("list") @CommandPermission("omc.commands.city.list") public void list(Player player) { - if (CityManager.getCities().isEmpty()) { + if (cityManager.getCities().isEmpty()) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.commands.list.empty"), Prefix.CITY, MessageType.ERROR, false); return; } diff --git a/src/main/java/fr/openmc/core/features/city/commands/CityInviteCommands.java b/src/main/java/fr/openmc/core/features/city/commands/CityInviteCommands.java index 7fce9a589..0fc808e68 100644 --- a/src/main/java/fr/openmc/core/features/city/commands/CityInviteCommands.java +++ b/src/main/java/fr/openmc/core/features/city/commands/CityInviteCommands.java @@ -1,9 +1,9 @@ package fr.openmc.core.features.city.commands; import fr.openmc.api.entity.player.OMCPlayer; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.commands.autocomplete.OnlinePlayerAutoComplete; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.conditions.CityInviteConditions; import fr.openmc.core.utils.text.messages.Prefix; import fr.openmc.core.utils.text.messages.TranslationManager; @@ -32,7 +32,7 @@ public static void invite( OMCPlayer sender, @Named("player") @SuggestWith(OnlinePlayerAutoComplete.class) OMCPlayer target ) { - City city = CityManager.getPlayerCity(sender.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(sender.getUniqueId()); if (!CityInviteConditions.canCityInvitePlayer(city, sender, target)) return; @@ -96,7 +96,7 @@ public static void acceptInvitation( return; } - City newCity = CityManager.getPlayerCity(inviter.getUniqueId()); + City newCity = OMCRegistry.FEATURES.CITY.get().getPlayerCity(inviter.getUniqueId()); if (!CityInviteConditions.canCityInviteAccept(newCity, inviter, player)) return; diff --git a/src/main/java/fr/openmc/core/features/city/commands/CityPermsCommands.java b/src/main/java/fr/openmc/core/features/city/commands/CityPermsCommands.java index 94eade261..9a5c4cdbb 100644 --- a/src/main/java/fr/openmc/core/features/city/commands/CityPermsCommands.java +++ b/src/main/java/fr/openmc/core/features/city/commands/CityPermsCommands.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.city.commands; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.commands.autocomplete.CityMembersAutoComplete; import fr.openmc.core.features.city.commands.autocomplete.CityPermissionsAutoComplete; @@ -27,7 +27,7 @@ public static void swap(Player sender, @SuggestWith(CityMembersAutoComplete.clas if (!CityPermsConditions.canSeePerms(sender, player.getUniqueId())) return; if (!CityPermsConditions.canModifyPerms(sender, permission)) return; - City city = CityManager.getPlayerCity(sender.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(sender.getUniqueId()); if (city == null) { MessagesManager.sendMessage(sender, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); @@ -67,7 +67,7 @@ void add( if (!CityPermsConditions.canSeePerms(sender, player.getUniqueId())) return; if (!CityPermsConditions.canModifyPerms(sender, permission)) return; - City city = CityManager.getPlayerCity(sender.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(sender.getUniqueId()); if (city == null) { MessagesManager.sendMessage(sender, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); @@ -105,7 +105,7 @@ void remove( if (!CityPermsConditions.canSeePerms(sender, player.getUniqueId())) return; if (!CityPermsConditions.canModifyPerms(sender, permission)) return; - City city = CityManager.getPlayerCity(sender.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(sender.getUniqueId()); if (city == null) { MessagesManager.sendMessage(sender, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); @@ -148,7 +148,7 @@ public static void removeAll(Player sender, @SuggestWith(CityMembersAutoComplete if (!CityPermsConditions.canSeePerms(sender, player.getUniqueId())) return; if (!CityPermsConditions.canModifyPerms(sender, null)) return; - City city = CityManager.getPlayerCity(sender.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(sender.getUniqueId()); if (city == null) { MessagesManager.sendMessage(sender, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); @@ -173,7 +173,7 @@ public static void addAll(Player sender, @SuggestWith(CityMembersAutoComplete.cl if (!CityPermsConditions.canSeePerms(sender, player.getUniqueId())) return; if (!CityPermsConditions.canModifyPerms(sender, null)) return; - City city = CityManager.getPlayerCity(sender.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(sender.getUniqueId()); if (city == null) { MessagesManager.sendMessage(sender, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); return; diff --git a/src/main/java/fr/openmc/core/features/city/commands/CityTopCommands.java b/src/main/java/fr/openmc/core/features/city/commands/CityTopCommands.java index 664e83f81..98786ffeb 100644 --- a/src/main/java/fr/openmc/core/features/city/commands/CityTopCommands.java +++ b/src/main/java/fr/openmc/core/features/city/commands/CityTopCommands.java @@ -16,11 +16,17 @@ import java.util.List; public class CityTopCommands { + private final CityManager cityManager; + + public CityTopCommands(CityManager cityManager) { + this.cityManager = cityManager; + } + @Command({"city top", "citytop"}) @CommandPermission("omc.commands.city.top") @Description("Ouvre les classements inter saison des villes") - void notationTest(Player sender) { - List cities = new ArrayList<>(CityManager.getCities()); + public void notationTest(Player sender) { + List cities = new ArrayList<>(cityManager.getCities()); if (cities.isEmpty()) { MessagesManager.sendMessage(sender, TranslationManager.translation("feature.city.commands.top.empty"), Prefix.CITY, MessageType.ERROR, true); return; diff --git a/src/main/java/fr/openmc/core/features/city/commands/autocomplete/CityRanksAutoComplete.java b/src/main/java/fr/openmc/core/features/city/commands/autocomplete/CityRanksAutoComplete.java index 51942ba8e..9276136a1 100644 --- a/src/main/java/fr/openmc/core/features/city/commands/autocomplete/CityRanksAutoComplete.java +++ b/src/main/java/fr/openmc/core/features/city/commands/autocomplete/CityRanksAutoComplete.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.city.commands.autocomplete; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.models.DBCityRank; import org.jetbrains.annotations.NotNull; import revxrsal.commands.autocomplete.SuggestionProvider; @@ -14,7 +14,7 @@ public class CityRanksAutoComplete implements SuggestionProvider getSuggestions(@NotNull ExecutionContext context) { - City city = CityManager.getPlayerCity(context.actor().requirePlayer().getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(context.actor().requirePlayer().getUniqueId()); if (city == null) return List.of(); return city.getRanks().stream() diff --git a/src/main/java/fr/openmc/core/features/city/conditions/CityCreateConditions.java b/src/main/java/fr/openmc/core/features/city/conditions/CityCreateConditions.java index a4c76a676..e1fdae481 100644 --- a/src/main/java/fr/openmc/core/features/city/conditions/CityCreateConditions.java +++ b/src/main/java/fr/openmc/core/features/city/conditions/CityCreateConditions.java @@ -2,7 +2,6 @@ import fr.openmc.api.cooldown.DynamicCooldownManager; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.economy.EconomyManager; import fr.openmc.core.utils.bukkit.ItemUtils; import fr.openmc.core.utils.text.InputUtils; @@ -37,7 +36,7 @@ public static boolean canCityCreate(Player player, String cityName) { return false; } - if (CityManager.getPlayerCity(player.getUniqueId()) != null) { + if (OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()) != null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_already_in_city"), Prefix.CITY, MessageType.ERROR, false); return false; } diff --git a/src/main/java/fr/openmc/core/features/city/conditions/CityInviteConditions.java b/src/main/java/fr/openmc/core/features/city/conditions/CityInviteConditions.java index 171eb4246..cde8edf49 100644 --- a/src/main/java/fr/openmc/core/features/city/conditions/CityInviteConditions.java +++ b/src/main/java/fr/openmc/core/features/city/conditions/CityInviteConditions.java @@ -1,8 +1,8 @@ package fr.openmc.core.features.city.conditions; import fr.openmc.api.entity.player.OMCPlayer; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.commands.CityInviteCommands; import fr.openmc.core.features.city.sub.milestone.rewards.MemberLimitRewards; @@ -47,7 +47,7 @@ public static boolean canCityInvitePlayer(City city, OMCPlayer player, OMCPlayer return false; } - if (CityManager.getPlayerCity(targetUUID) != null) { + if (OMCRegistry.FEATURES.CITY.get().getPlayerCity(targetUUID) != null) { player.message().sendError( TranslationManager.translation("feature.city.conditions.invite.target_already_in_city"), Prefix.CITY ); diff --git a/src/main/java/fr/openmc/core/features/city/conditions/CityPermsConditions.java b/src/main/java/fr/openmc/core/features/city/conditions/CityPermsConditions.java index 82a30c284..c88232a00 100644 --- a/src/main/java/fr/openmc/core/features/city/conditions/CityPermsConditions.java +++ b/src/main/java/fr/openmc/core/features/city/conditions/CityPermsConditions.java @@ -1,5 +1,6 @@ package fr.openmc.core.features.city.conditions; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; @@ -14,8 +15,10 @@ public class CityPermsConditions { public static boolean canSeePerms(Player sender, UUID playerUUID) { - City city = CityManager.getPlayerCity(playerUUID); - City senderCity = CityManager.getPlayerCity(sender.getUniqueId()); + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); + + City city = cityManager.getPlayerCity(playerUUID); + City senderCity = cityManager.getPlayerCity(sender.getUniqueId()); if (senderCity == null) { MessagesManager.sendMessage(sender, TranslationManager.translation("messages.city.target_no_city"), Prefix.CITY, MessageType.ERROR, false); @@ -46,7 +49,7 @@ public static boolean canSeePerms(Player sender, UUID playerUUID) { } public static boolean canModifyPerms(Player sender, CityPermission permission) { - City city = CityManager.getPlayerCity(sender.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(sender.getUniqueId()); if (city == null) { MessagesManager.sendMessage(sender, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/BlockProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/BlockProtection.java index fcbb8c314..f68506d0d 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/BlockProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/BlockProtection.java @@ -10,27 +10,35 @@ import org.bukkit.event.block.BlockPlaceEvent; public class BlockProtection implements Listener { + private final CityManager cityManager; + private final ProtectionsManager protectionsManager; + + public BlockProtection(CityManager cityManager) { + this.cityManager = cityManager; + this.protectionsManager = cityManager.PROTECTIONS; + } + @EventHandler(ignoreCancelled = true) public void onPlaceBlock(BlockPlaceEvent event) { - City city = CityManager.getCityFromChunk(event.getBlock().getLocation().getChunk().getX(), event.getBlock().getLocation().getChunk().getZ()); + City city = cityManager.getCityFromChunk(event.getBlock().getLocation().getChunk().getX(), event.getBlock().getLocation().getChunk().getZ()); if (city == null) return; if (city.isMember(event.getPlayer())) { - ProtectionsManager.checkPermissions(event.getPlayer(), event, city, CityPermission.PLACE); + protectionsManager.checkPermissions(event.getPlayer(), event, city, CityPermission.PLACE); } else { - ProtectionsManager.checkCity(event.getPlayer(), event, city, true); + protectionsManager.checkCity(event.getPlayer(), event, city, true); } } @EventHandler(ignoreCancelled = true) void onBlockBreak(BlockBreakEvent event) { - City city = CityManager.getCityFromChunk(event.getBlock().getLocation().getChunk().getX(), event.getBlock().getLocation().getChunk().getZ()); + City city = cityManager.getCityFromChunk(event.getBlock().getLocation().getChunk().getX(), event.getBlock().getLocation().getChunk().getZ()); if (city == null) return; if (city.isMember(event.getPlayer())) { - ProtectionsManager.checkPermissions(event.getPlayer(), event, city, CityPermission.BREAK); + protectionsManager.checkPermissions(event.getPlayer(), event, city, CityPermission.BREAK); } else { - ProtectionsManager.checkCity(event.getPlayer(), event, city, false); + protectionsManager.checkCity(event.getPlayer(), event, city, false); } } } diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/BowProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/BowProtection.java index 6aeff5813..b0a94ca19 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/BowProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/BowProtection.java @@ -1,6 +1,7 @@ package fr.openmc.core.features.city.listeners.protections; import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent; +import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.ProtectionsManager; import org.bukkit.GameMode; import org.bukkit.entity.Player; @@ -9,9 +10,15 @@ import org.bukkit.event.entity.EntityShootBowEvent; public class BowProtection implements Listener { + private final ProtectionsManager protectionsManager; + + public BowProtection(CityManager cityManager) { + this.protectionsManager = cityManager.PROTECTIONS; + } + @EventHandler(ignoreCancelled = true) void onLaunchProjectile(PlayerLaunchProjectileEvent event) { - ProtectionsManager.verify(event.getPlayer(), event, event.getPlayer().getLocation()); + protectionsManager.verify(event.getPlayer(), event, event.getPlayer().getLocation()); } @EventHandler @@ -19,7 +26,7 @@ public void onEntityShootBow(EntityShootBowEvent event) { if (!(event.getEntity() instanceof Player player)) return; if (event.getConsumable() == null) return; - ProtectionsManager.verify(player, event, event.getEntity().getLocation()); + protectionsManager.verify(player, event, event.getEntity().getLocation()); if (event.isCancelled() && !player.getGameMode().equals(GameMode.CREATIVE)) { player.getInventory().addItem(event.getConsumable()); diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/DamageProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/DamageProtection.java index 423fef022..467c09938 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/DamageProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/DamageProtection.java @@ -13,6 +13,14 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; public class DamageProtection implements Listener { + private final CityManager cityManager; + private final ProtectionsManager protectionsManager; + + public DamageProtection(CityManager cityManager) { + this.cityManager = cityManager; + this.protectionsManager = cityManager.PROTECTIONS; + } + @EventHandler(ignoreCancelled = true) public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { Entity victim = event.getEntity(); @@ -27,7 +35,7 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { if (victim instanceof Player victimPlayer && attacker != null) { Location loc = victimPlayer.getLocation(); - City city = CityManager.getCityFromChunk(loc.getChunk().getX(), loc.getChunk().getZ()); + City city = cityManager.getCityFromChunk(loc.getChunk().getX(), loc.getChunk().getZ()); if (city != null && city.isMember(victimPlayer) @@ -42,13 +50,13 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { } if (victim instanceof Player victimPlayer) { - ProtectionsManager.verify(victimPlayer, event, victimPlayer.getLocation()); + protectionsManager.verify(victimPlayer, event, victimPlayer.getLocation()); } if (MascotUtils.canBeAMascot(victim)) return; if (attacker != null) { - ProtectionsManager.verify(attacker, event, victim.getLocation()); + protectionsManager.verify(attacker, event, victim.getLocation()); } } } diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/EntityProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/EntityProtection.java index f0b4b69e2..18328ae43 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/EntityProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/EntityProtection.java @@ -1,6 +1,7 @@ package fr.openmc.core.features.city.listeners.protections; import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent; +import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.ProtectionsManager; import io.papermc.paper.event.entity.EntityCollideWithEntityEvent; import org.bukkit.entity.Enderman; @@ -16,14 +17,20 @@ import org.bukkit.inventory.Merchant; public class EntityProtection implements Listener { + private final ProtectionsManager protectionsManager; + + public EntityProtection(CityManager cityManager) { + this.protectionsManager = cityManager.PROTECTIONS; + } + @EventHandler(ignoreCancelled = true) public void onArmorStandManipulate(PlayerArmorStandManipulateEvent event) { - ProtectionsManager.verify(event.getPlayer(), event, event.getRightClicked().getLocation()); + protectionsManager.verify(event.getPlayer(), event, event.getRightClicked().getLocation()); } @EventHandler(ignoreCancelled = true) void onShear(PlayerShearEntityEvent event) { - ProtectionsManager.verify(event.getPlayer(), event, event.getEntity().getLocation()); + protectionsManager.verify(event.getPlayer(), event, event.getEntity().getLocation()); } @EventHandler(ignoreCancelled = true) @@ -32,25 +39,25 @@ public void onEntityInventoryOpen(PlayerInteractEntityEvent event) { Entity entity = event.getRightClicked(); if (entity instanceof Merchant || entity instanceof InventoryHolder) { - ProtectionsManager.verify(player, event, entity.getLocation()); + protectionsManager.verify(player, event, entity.getLocation()); } } @EventHandler(ignoreCancelled = true) public void onEntityChangeBlock(EntityChangeBlockEvent event) { if (!(event.getEntity() instanceof Enderman enderman)) return; - ProtectionsManager.verify(enderman, event, enderman.getLocation()); + protectionsManager.verify(enderman, event, enderman.getLocation()); } @EventHandler(ignoreCancelled = true) public void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) { if (!(event.getHitBy() instanceof Player player)) return; - ProtectionsManager.verify(player, event, event.getEntity().getLocation()); + protectionsManager.verify(player, event, event.getEntity().getLocation()); } @EventHandler public void onPlayerCollideEntity(EntityCollideWithEntityEvent event) { if (!(event.getEntities().getFirst() instanceof Player player)) return; - ProtectionsManager.verify(player, event, event.getEntities().get(1).getLocation()); + protectionsManager.verify(player, event, event.getEntities().get(1).getLocation()); } } diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/ExplodeProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/ExplodeProtection.java index 7dad5adb4..7d47532d9 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/ExplodeProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/ExplodeProtection.java @@ -16,6 +16,14 @@ import java.util.List; public class ExplodeProtection implements Listener { + private final CityManager cityManager; + private final ProtectionsManager protectionsManager; + + public ExplodeProtection(CityManager cityManager) { + this.cityManager = cityManager; + this.protectionsManager = cityManager.PROTECTIONS; + } + private static final List NATURAL_EXPLOSIVE_ENTITIES = List.of( EntityType.CREEPER, EntityType.FIREBALL, @@ -49,7 +57,7 @@ public void onEntityExplode(EntityExplodeEvent event) { @EventHandler(ignoreCancelled = true) public void onBlockExplode(BlockExplodeEvent event) { event.blockList().removeIf(block -> { - City blockCity = CityManager.getCityFromChunk(block.getChunk().getX(), block.getChunk().getZ()); + City blockCity = cityManager.getCityFromChunk(block.getChunk().getX(), block.getChunk().getZ()); return blockCity != null; }); @@ -60,7 +68,7 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { Entity entity = event.getEntity(); if (entity.getType() == EntityType.WITHER || entity.getType() == EntityType.WITHER_SKULL) { - City city = CityManager.getCityFromChunk(event.getBlock().getChunk().getX(), event.getBlock().getChunk().getZ()); + City city = cityManager.getCityFromChunk(event.getBlock().getChunk().getX(), event.getBlock().getChunk().getZ()); if (city != null) { event.setCancelled(true); } @@ -68,10 +76,10 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { } private void handlePlayerTntExplosion(EntityExplodeEvent event, Player player) { - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); event.blockList().removeIf(block -> { - City blockCity = CityManager.getCityFromChunk(block.getChunk().getX(), block.getChunk().getZ()); + City blockCity = cityManager.getCityFromChunk(block.getChunk().getX(), block.getChunk().getZ()); if (blockCity == null) return false; return !blockCity.equals(playerCity) && !blockCity.isMember(player); @@ -79,12 +87,12 @@ private void handlePlayerTntExplosion(EntityExplodeEvent event, Player player) { } private void handleNaturalExplosion(EntityExplodeEvent event) { - if (!ProtectionsManager.canExplodeNaturally(event.getLocation())) { + if (!protectionsManager.canExplodeNaturally(event.getLocation())) { event.setCancelled(true); return; } - event.blockList().removeIf(block -> !ProtectionsManager.canExplodeNaturally(block.getLocation())); + event.blockList().removeIf(block -> !protectionsManager.canExplodeNaturally(block.getLocation())); } } diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/FireProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/FireProtection.java index b024a610e..49988b4c3 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/FireProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/FireProtection.java @@ -1,6 +1,7 @@ package fr.openmc.core.features.city.listeners.protections; +import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.ProtectionsManager; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -9,6 +10,11 @@ import org.bukkit.event.block.BlockIgniteEvent; public class FireProtection implements Listener { + private final ProtectionsManager protectionsManager; + + public FireProtection(CityManager cityManager) { + this.protectionsManager = cityManager.PROTECTIONS; + } @EventHandler(ignoreCancelled = true) public void onFireIgnite(BlockIgniteEvent event) { Location loc = event.getBlock().getLocation(); @@ -16,6 +22,6 @@ public void onFireIgnite(BlockIgniteEvent event) { if (player == null) return; - ProtectionsManager.verify(event.getPlayer(), event, loc); + protectionsManager.verify(event.getPlayer(), event, loc); } } diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/FishProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/FishProtection.java index afcbb176a..e6e9afb2f 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/FishProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/FishProtection.java @@ -1,13 +1,20 @@ package fr.openmc.core.features.city.listeners.protections; +import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.ProtectionsManager; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerFishEvent; public class FishProtection implements Listener { + private final ProtectionsManager protectionsManager; + + public FishProtection(CityManager cityManager) { + this.protectionsManager = cityManager.PROTECTIONS; + } + @EventHandler(ignoreCancelled = true) void onFish(PlayerFishEvent event) { - ProtectionsManager.verify(event.getPlayer(), event, event.getHook().getLocation()); + protectionsManager.verify(event.getPlayer(), event, event.getHook().getLocation()); } } diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/HangingProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/HangingProtection.java index a2b185cde..4ac9b8f50 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/HangingProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/HangingProtection.java @@ -1,5 +1,6 @@ package fr.openmc.core.features.city.listeners.protections; +import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.ProtectionsManager; import org.bukkit.entity.Entity; import org.bukkit.entity.Hanging; @@ -11,13 +12,19 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; public class HangingProtection implements Listener { + private final ProtectionsManager protectionsManager; + + public HangingProtection(CityManager cityManager) { + this.protectionsManager = cityManager.PROTECTIONS; + } + @EventHandler(ignoreCancelled = true) public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { Player player = event.getPlayer(); Entity entity = event.getRightClicked(); if (entity instanceof Hanging) { - ProtectionsManager.verify(player, event, entity.getLocation()); + protectionsManager.verify(player, event, entity.getLocation()); } } @@ -25,14 +32,14 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { public void onHangingBreakByEntity(HangingBreakByEntityEvent event) { Entity remover = event.getRemover(); if (remover != null) { - ProtectionsManager.verify(remover, event, event.getEntity().getLocation()); + protectionsManager.verify(remover, event, event.getEntity().getLocation()); } } @EventHandler(ignoreCancelled = true) public void onHangingBreak(HangingBreakEvent event) { if (event.getCause() == HangingBreakEvent.RemoveCause.EXPLOSION) { - if (!ProtectionsManager.canExplodeNaturally(event.getEntity().getLocation())) { + if (!protectionsManager.canExplodeNaturally(event.getEntity().getLocation())) { event.setCancelled(true); } } diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/InteractProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/InteractProtection.java index 5a61cd1cb..fa5f7af02 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/InteractProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/InteractProtection.java @@ -28,6 +28,13 @@ import java.util.Set; public class InteractProtection implements Listener { + private final CityManager cityManager; + private final ProtectionsManager protectionsManager; + + public InteractProtection(CityManager cityManager) { + this.cityManager = cityManager; + this.protectionsManager = cityManager.PROTECTIONS; + } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onInteract(PlayerInteractEvent event) { @@ -59,19 +66,19 @@ public void onInteract(PlayerInteractEvent event) { return; } - City city = CityManager.getCityFromChunk(location.getChunk().getX(), location.getChunk().getZ()); + City city = cityManager.getCityFromChunk(location.getChunk().getX(), location.getChunk().getZ()); if (city == null) return; if (city.isMember(player)) { if (clickedBlock.getType().name().endsWith("SHULKER_BOX")) return; if (clickedBlock.getType().name().endsWith("CHEST") || clickedBlock.getType().name().endsWith("BARREL")) { - ProtectionsManager.checkPermissions(player, event, city, CityPermission.OPEN_CHEST); + protectionsManager.checkPermissions(player, event, city, CityPermission.OPEN_CHEST); } else { - ProtectionsManager.checkPermissions(player, event, city, CityPermission.INTERACT); + protectionsManager.checkPermissions(player, event, city, CityPermission.INTERACT); } } else { - ProtectionsManager.checkCity(player, event, city, true); + protectionsManager.checkCity(player, event, city, true); } } @@ -79,7 +86,7 @@ public void onInteract(PlayerInteractEvent event) { if (!isMinecart) return; if (isTnt) return; - ProtectionsManager.verify(player, event, location); + protectionsManager.verify(player, event, location); } private final Set INTERACTION_REFUSED = new HashSet<>(Set.of( @@ -99,17 +106,17 @@ public void onInteractAtEntity(PlayerInteractAtEntityEvent event) { if (MascotUtils.canBeAMascot(rightClicked)) return; - ProtectionsManager.verify(event.getPlayer(), event, rightClicked.getLocation()); + protectionsManager.verify(event.getPlayer(), event, rightClicked.getLocation()); } @EventHandler public void onBucketEmpty(PlayerBucketEmptyEvent event) { - ProtectionsManager.verify(event.getPlayer(), event, event.getBlockClicked().getLocation()); + protectionsManager.verify(event.getPlayer(), event, event.getBlockClicked().getLocation()); } @EventHandler public void onBucketFill(PlayerBucketFillEvent event) { - ProtectionsManager.verify(event.getPlayer(), event, event.getBlockClicked().getLocation()); + protectionsManager.verify(event.getPlayer(), event, event.getBlockClicked().getLocation()); } private boolean isMinecart(Material type) { diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/LeashProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/LeashProtection.java index f3e87a644..4a0e5eda2 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/LeashProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/LeashProtection.java @@ -1,5 +1,6 @@ package fr.openmc.core.features.city.listeners.protections; +import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.ProtectionsManager; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -7,14 +8,20 @@ import org.bukkit.event.player.PlayerUnleashEntityEvent; public class LeashProtection implements Listener { + private final ProtectionsManager protectionsManager; + + public LeashProtection(CityManager cityManager) { + this.protectionsManager = cityManager.PROTECTIONS; + } + @EventHandler(ignoreCancelled = true) void onLeash(PlayerLeashEntityEvent event) { - ProtectionsManager.verify(event.getPlayer(), event, event.getEntity().getLocation()); + protectionsManager.verify(event.getPlayer(), event, event.getEntity().getLocation()); } @EventHandler(ignoreCancelled = true) void onUnleash(PlayerUnleashEntityEvent event) { - ProtectionsManager.verify(event.getPlayer(), event, event.getEntity().getLocation()); + protectionsManager.verify(event.getPlayer(), event, event.getEntity().getLocation()); } } diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/MountProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/MountProtection.java index 98e09f490..58cae2fa8 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/MountProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/MountProtection.java @@ -1,5 +1,6 @@ package fr.openmc.core.features.city.listeners.protections; +import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.ProtectionsManager; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -11,6 +12,12 @@ import java.util.UUID; public class MountProtection implements Listener { + private final ProtectionsManager protectionsManager; + + public MountProtection(CityManager cityManager) { + this.protectionsManager = cityManager.PROTECTIONS; + } + @EventHandler(ignoreCancelled = true) public void onEntityMount(EntityMountEvent event) { if (!(event.getEntity() instanceof Player player)) return; @@ -25,15 +32,15 @@ public void onEntityMount(EntityMountEvent event) { if (ownerUUID == null) return; if (!ownerUUID.equals(player.getUniqueId())) { - if (!ProtectionsManager.canInteract(player, mount.getLocation())) { + if (!protectionsManager.canInteract(player, mount.getLocation())) { event.setCancelled(true); - ProtectionsManager.cancelMessage(player); + protectionsManager.cancelMessage(player); } else { - ProtectionsManager.verify(player, event, mount.getLocation()); + protectionsManager.verify(player, event, mount.getLocation()); } } } else { - ProtectionsManager.verify(player, event, mount.getLocation()); + protectionsManager.verify(player, event, mount.getLocation()); } } } diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/PistonProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/PistonProtection.java index 2be00630f..78d679c1d 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/PistonProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/PistonProtection.java @@ -12,17 +12,22 @@ import java.util.Objects; public class PistonProtection implements Listener { + private final CityManager cityManager; + + public PistonProtection(CityManager cityManager) { + this.cityManager = cityManager; + } @EventHandler(ignoreCancelled = true) public void onPistonExtend(BlockPistonExtendEvent event) { Block piston = event.getBlock(); Chunk fromChunk = piston.getChunk(); - City fromCity = CityManager.getCityFromChunk(fromChunk.getX(), fromChunk.getZ()); + City fromCity = cityManager.getCityFromChunk(fromChunk.getX(), fromChunk.getZ()); for (Block moved : event.getBlocks()) { Block toBlock = moved.getRelative(event.getDirection()); Chunk toChunk = toBlock.getChunk(); - City toCity = CityManager.getCityFromChunk(toChunk.getX(), toChunk.getZ()); + City toCity = cityManager.getCityFromChunk(toChunk.getX(), toChunk.getZ()); if (isIllegalMovement(fromCity, toCity)) { event.setCancelled(true); @@ -37,12 +42,12 @@ public void onPistonRetract(BlockPistonRetractEvent event) { Block piston = event.getBlock(); Chunk fromChunk = piston.getChunk(); - City fromCity = CityManager.getCityFromChunk(fromChunk.getX(), fromChunk.getZ()); + City fromCity = cityManager.getCityFromChunk(fromChunk.getX(), fromChunk.getZ()); for (Block moved : event.getBlocks()) { Block toBlock = moved.getRelative(event.getDirection()); Chunk toChunk = toBlock.getChunk(); - City toCity = CityManager.getCityFromChunk(toChunk.getX(), toChunk.getZ()); + City toCity = cityManager.getCityFromChunk(toChunk.getX(), toChunk.getZ()); if (isIllegalMovement(fromCity, toCity)) { event.setCancelled(true); diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/PotionProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/PotionProtection.java index 3187d9a2a..0df87233a 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/PotionProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/PotionProtection.java @@ -15,6 +15,12 @@ import org.bukkit.projectiles.ProjectileSource; public class PotionProtection implements Listener { + private final CityManager cityManager; + + public PotionProtection(CityManager cityManager) { + this.cityManager = cityManager; + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPotionSplash(PotionSplashEvent event) { ThrownPotion potion = event.getPotion(); @@ -24,7 +30,7 @@ public void onPotionSplash(PotionSplashEvent event) { return; Location witchLocation = witch.getLocation(); - City city = CityManager.getCityFromChunk(witchLocation.getChunk().getX(), witchLocation.getChunk().getZ()); + City city = cityManager.getCityFromChunk(witchLocation.getChunk().getX(), witchLocation.getChunk().getZ()); if (city == null) return; diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/TeleportProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/TeleportProtection.java index dde2620dd..fb18721c8 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/TeleportProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/TeleportProtection.java @@ -1,5 +1,6 @@ package fr.openmc.core.features.city.listeners.protections; +import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.ProtectionsManager; import org.bukkit.GameMode; import org.bukkit.Material; @@ -12,6 +13,12 @@ import java.util.Set; public class TeleportProtection implements Listener { + private final ProtectionsManager protectionsManager; + + public TeleportProtection(CityManager cityManager) { + this.protectionsManager = cityManager.PROTECTIONS; + } + private final Set illegalCauses = Set.of( PlayerTeleportEvent.TeleportCause.COMMAND, PlayerTeleportEvent.TeleportCause.NETHER_PORTAL, @@ -28,8 +35,8 @@ public void onPlayerTeleport(PlayerTeleportEvent event) { Player player = event.getPlayer(); - if (!ProtectionsManager.canInteract(player, event.getTo())) { - ProtectionsManager.verify(player, event, event.getTo()); + if (!protectionsManager.canInteract(player, event.getTo())) { + protectionsManager.verify(player, event, event.getTo()); if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.ENDER_PEARL) && !player.getGameMode().equals(GameMode.CREATIVE)) { player.getInventory().addItem(new ItemStack(Material.ENDER_PEARL)); diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/TramplingProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/TramplingProtection.java index 560570250..f2ed5b593 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/TramplingProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/TramplingProtection.java @@ -1,5 +1,6 @@ package fr.openmc.core.features.city.listeners.protections; +import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.ProtectionsManager; import org.bukkit.Material; import org.bukkit.block.Block; @@ -11,11 +12,17 @@ import org.bukkit.event.player.PlayerInteractEvent; public class TramplingProtection implements Listener { + private final ProtectionsManager protectionsManager; + + public TramplingProtection(CityManager cityManager) { + this.protectionsManager = cityManager.PROTECTIONS; + } + @EventHandler(ignoreCancelled = true) public void onEntityInteract(EntityInteractEvent event) { Block block = event.getBlock(); if (block.getType() == Material.FARMLAND) { - ProtectionsManager.verify(event.getEntity(), event, block.getLocation()); + protectionsManager.verify(event.getEntity(), event, block.getLocation()); } } @@ -25,7 +32,7 @@ public void onPlayerTrampling(PlayerInteractEvent event) { if (event.getAction() == Action.PHYSICAL) { if (event.getClickedBlock() == null) return; if (event.getClickedBlock().getType() == Material.FARMLAND) { - ProtectionsManager.verify(event.getPlayer(), event, event.getClickedBlock().getLocation()); + protectionsManager.verify(event.getPlayer(), event, event.getClickedBlock().getLocation()); } } } diff --git a/src/main/java/fr/openmc/core/features/city/listeners/protections/VehicleProtection.java b/src/main/java/fr/openmc/core/features/city/listeners/protections/VehicleProtection.java index 298a06b5e..28d1278c5 100644 --- a/src/main/java/fr/openmc/core/features/city/listeners/protections/VehicleProtection.java +++ b/src/main/java/fr/openmc/core/features/city/listeners/protections/VehicleProtection.java @@ -1,5 +1,6 @@ package fr.openmc.core.features.city.listeners.protections; +import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.ProtectionsManager; import fr.openmc.core.features.city.sub.mascots.utils.MascotUtils; import org.bukkit.entity.Entity; @@ -12,6 +13,11 @@ import org.bukkit.event.vehicle.VehicleDestroyEvent; public class VehicleProtection implements Listener { + private final ProtectionsManager protectionsManager; + + public VehicleProtection(CityManager cityManager) { + this.protectionsManager = cityManager.PROTECTIONS; + } @EventHandler(ignoreCancelled = true) public void onVehicleDestroy(VehicleDestroyEvent event) { @@ -19,7 +25,7 @@ public void onVehicleDestroy(VehicleDestroyEvent event) { if (MascotUtils.canBeAMascot(event.getVehicle())) return; - ProtectionsManager.verify(player, event, event.getVehicle().getLocation()); + protectionsManager.verify(player, event, event.getVehicle().getLocation()); } @EventHandler(ignoreCancelled = true) @@ -39,7 +45,7 @@ public void onVehicleDamage(EntityDamageByEntityEvent event) { } if (player != null) { - ProtectionsManager.verify(player, event, victim.getLocation()); + protectionsManager.verify(player, event, victim.getLocation()); } } } diff --git a/src/main/java/fr/openmc/core/features/city/menu/CityChunkMenu.java b/src/main/java/fr/openmc/core/features/city/menu/CityChunkMenu.java index 381acedac..50fdb46f2 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/CityChunkMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/CityChunkMenu.java @@ -5,6 +5,7 @@ import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.ChunkDataCache; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; @@ -13,7 +14,6 @@ import fr.openmc.core.features.city.actions.CityCreateAction; import fr.openmc.core.features.city.actions.CityUnclaimAction; import fr.openmc.core.features.economy.EconomyManager; -import fr.openmc.core.hooks.WorldGuardHook; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; import fr.openmc.core.utils.text.messages.Prefix; @@ -49,15 +49,18 @@ public class CityChunkMenu extends Menu { private final int aywenite; private Map chunkInfoMap; + private final CityManager cityManager; + public CityChunkMenu(Player owner) { super(owner); this.player = owner; + this.cityManager = OMCRegistry.FEATURES.CITY.get(); this.playerChunkX = player.getLocation().getChunk().getX(); this.playerChunkZ = player.getLocation().getChunk().getZ(); this.startX = playerChunkX - 4; this.startZ = playerChunkZ - 2; - this.playerCity = CityManager.getPlayerCity(player.getUniqueId()); + this.playerCity = cityManager.getPlayerCity(player.getUniqueId()); boolean tempHasPermissionClaim = false; boolean tempHasFreeClaimAvailable = false; @@ -107,7 +110,7 @@ private void loadChunkData() { int chunkZ = startZ + row; ChunkPos pos = new ChunkPos(chunkX, chunkZ); - City city = CityManager.getCityFromChunk(chunkX, chunkZ); + City city = cityManager.getCityFromChunk(chunkX, chunkZ); if (city != null) { newChunkInfoMap.put(pos, new ChunkInfo(city, false)); } @@ -123,7 +126,7 @@ private void loadChunkData() { if (!newChunkInfoMap.containsKey(pos)) { Chunk chunk = player.getWorld().getChunkAt(chunkX, chunkZ); - boolean isProtected = WorldGuardHook.doesChunkContainWGRegion(chunk); + boolean isProtected = OMCRegistry.HOOKS.WORLD_GUARD.doesChunkContainWGRegion(chunk); if (isProtected) { newChunkInfoMap.put(pos, new ChunkInfo(null, true)); } else { @@ -334,7 +337,7 @@ private ItemMenuBuilder createUnclaimedChunkItem(Material material, int chunkX, } private void handleChunkClaimClick(Player player, int chunkX, int chunkZ, boolean hasPermissionClaim) { - City cityCheck = CityManager.getPlayerCity(player.getUniqueId()); + City cityCheck = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (cityCheck == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); @@ -370,7 +373,7 @@ private void handleChunkClaimClick(Player player, int chunkX, int chunkZ, boolea } private void handleChunkUnclaimClick(Player player, int chunkX, int chunkZ, boolean hasPermissionClaim) { - City cityCheck = CityManager.getPlayerCity(player.getUniqueId()); + City cityCheck = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (cityCheck == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); diff --git a/src/main/java/fr/openmc/core/features/city/menu/CityModifyMenu.java b/src/main/java/fr/openmc/core/features/city/menu/CityModifyMenu.java index 548f76cdb..3493f6090 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/CityModifyMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/CityModifyMenu.java @@ -7,6 +7,7 @@ import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.api.menulib.utils.MenuUtils; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; @@ -35,8 +36,11 @@ public class CityModifyMenu extends Menu { + private final CityManager cityManager; + public CityModifyMenu(Player owner) { super(owner); + this.cityManager = OMCRegistry.FEATURES.CITY.get(); } @Override @@ -64,7 +68,7 @@ public void onInventoryClick(InventoryClickEvent click) { Map inventory = new HashMap<>(); Player player = getOwner(); - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = cityManager.getPlayerCity(player.getUniqueId()); assert city != null; boolean hasPermissionRenameCity = city.hasPermission(player.getUniqueId(), CityPermission.RENAME); @@ -88,13 +92,13 @@ public void onInventoryClick(InventoryClickEvent click) { itemMeta.itemName(TranslationManager.translation("feature.city.menus.modify.rename.title")); itemMeta.lore(loreRename); }).setOnClick(inventoryClickEvent -> { - City cityCheck = CityManager.getPlayerCity(player.getUniqueId()); + City cityCheck = cityManager.getPlayerCity(player.getUniqueId()); if (!CityManageConditions.canCityRename(cityCheck, player)) return; DialogInput.send(player, TranslationManager.translation("feature.city.commands.create.enter_city_name"), MAX_LENGTH_CITY, input -> { if (input == null) return; if (InputUtils.isInputCityName(input)) { - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); playerCity.rename(input); MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.commands.rename.success", Component.text(input)), Prefix.CITY, MessageType.SUCCESS, false); @@ -121,7 +125,7 @@ public void onInventoryClick(InventoryClickEvent click) { itemMeta.itemName(TranslationManager.translation("feature.city.menus.modify.transfer.title")); itemMeta.lore(loreTransfer); }).setOnClick(inventoryClickEvent -> { - City cityCheck = CityManager.getPlayerCity(player.getUniqueId()); + City cityCheck = cityManager.getPlayerCity(player.getUniqueId()); if (!CityManageConditions.canCityTransfer(cityCheck, player)) return; diff --git a/src/main/java/fr/openmc/core/features/city/menu/CityPermsMenu.java b/src/main/java/fr/openmc/core/features/city/menu/CityPermsMenu.java index b047182aa..8d72554f8 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/CityPermsMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/CityPermsMenu.java @@ -7,7 +7,6 @@ import fr.openmc.api.menulib.utils.StaticSlots; import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.commands.CityPermsCommands; import fr.openmc.core.utils.cache.CacheOfflinePlayer; @@ -35,7 +34,7 @@ public class CityPermsMenu extends PaginatedMenu { public CityPermsMenu(Player owner, UUID memberUUID, boolean edit) { super(owner); - this.city = CityManager.getPlayerCity(owner.getUniqueId()); + this.city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(owner.getUniqueId()); this.memberUUID = memberUUID; this.edit = edit; } diff --git a/src/main/java/fr/openmc/core/features/city/menu/CityTopMenu.java b/src/main/java/fr/openmc/core/features/city/menu/CityTopMenu.java index 78e7936c7..73c5b38e5 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/CityTopMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/CityTopMenu.java @@ -3,10 +3,10 @@ import fr.openmc.api.menulib.PaginatedMenu; import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; -import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; import fr.openmc.core.features.city.sub.milestone.rewards.FeaturesRewards; import fr.openmc.core.features.city.sub.milestone.rewards.MemberLimitRewards; import fr.openmc.core.features.economy.EconomyManager; @@ -39,6 +39,8 @@ public class CityTopMenu extends PaginatedMenu { private final List cities; private SortType sortType; + private final CityManager cityManager; + /** * Constructor for CityListMenu. * @@ -56,7 +58,8 @@ public CityTopMenu(Player owner) { */ public CityTopMenu(Player owner, SortType sortType) { super(owner); - this.cities = new ArrayList<>(CityManager.getCities()); + this.cityManager = OMCRegistry.FEATURES.CITY.get(); + this.cities = new ArrayList<>(cityManager.getCities()); setSortType(sortType); } @@ -94,7 +97,7 @@ public List getItems() { Component wealthIcon = Component.text(EconomyManager.getEconomyIcon()).color(NamedTextColor.GOLD); Component powerComponent = Component.text(city.getPowerPoints()).color(NamedTextColor.RED); - if (MayorManager.phaseMayor == 2 && FeaturesRewards.hasUnlockFeature(city, FeaturesRewards.Feature.MAYOR)) { + if (cityManager.MAYOR.phaseMayor == 2 && FeaturesRewards.hasUnlockFeature(city, FeaturesRewards.Feature.MAYOR)) { Component mayorName = city.getMayor() == null ? TranslationManager.translation("messages.menus.none") : city.getMayor().getName(); diff --git a/src/main/java/fr/openmc/core/features/city/menu/CityTransferMenu.java b/src/main/java/fr/openmc/core/features/city/menu/CityTransferMenu.java index 1c85b961c..9f1ab4cb2 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/CityTransferMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/CityTransferMenu.java @@ -5,8 +5,8 @@ import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.api.menulib.utils.StaticSlots; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.actions.CityTransferAction; import fr.openmc.core.utils.bukkit.SkullUtils; @@ -50,7 +50,7 @@ public List getItems() { List items = new ArrayList<>(); Player player = getOwner(); - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); assert city != null; boolean hasPermissionOwner = city.hasPermission(player.getUniqueId(), CityPermission.OWNER); diff --git a/src/main/java/fr/openmc/core/features/city/menu/CityTypeMenu.java b/src/main/java/fr/openmc/core/features/city/menu/CityTypeMenu.java index 3dd49530c..be0442ac8 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/CityTypeMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/CityTypeMenu.java @@ -3,8 +3,8 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityType; import fr.openmc.core.features.city.actions.CityChangeAction; import fr.openmc.core.features.city.conditions.CityTypeConditions; @@ -53,7 +53,7 @@ public void onInventoryClick(InventoryClickEvent inventoryClickEvent) { Map map = new HashMap<>(); Player player = getOwner(); - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); boolean enchantPeace = city.getType() == CityType.PEACE; List peaceInfo = TranslationManager.translationLore("feature.city.menus.type.peace.lore"); diff --git a/src/main/java/fr/openmc/core/features/city/menu/InvitationsMenu.java b/src/main/java/fr/openmc/core/features/city/menu/InvitationsMenu.java index 4661c7110..79f34656c 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/InvitationsMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/InvitationsMenu.java @@ -7,8 +7,8 @@ import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.api.menulib.utils.StaticSlots; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.commands.CityInviteCommands; import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.text.Component; @@ -66,7 +66,7 @@ public List getItems() { List invitationLore = TranslationManager.translationLore("feature.city.menus.invitations.item.lore"); for (Player inviter : invitations) { - City inviterCity = CityManager.getPlayerCity(inviter.getUniqueId()); + City inviterCity = OMCRegistry.FEATURES.CITY.get().getPlayerCity(inviter.getUniqueId()); if (inviterCity == null) { invitations.remove(inviter); diff --git a/src/main/java/fr/openmc/core/features/city/menu/list/CityListDetailsMenu.java b/src/main/java/fr/openmc/core/features/city/menu/list/CityListDetailsMenu.java index 3bfcb9668..94405b02f 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/list/CityListDetailsMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/list/CityListDetailsMenu.java @@ -9,9 +9,8 @@ import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.CityType; import fr.openmc.core.features.city.sub.mayor.ElectionType; -import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; import fr.openmc.core.features.city.sub.mayor.models.Mayor; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.city.sub.milestone.rewards.FeaturesRewards; import fr.openmc.core.features.city.sub.milestone.rewards.MemberLimitRewards; @@ -78,12 +77,12 @@ public void onInventoryClick(InventoryClickEvent inventoryClickEvent) { List loreOwner = new ArrayList<>(); - if (MayorManager.phaseMayor == 2 && FeaturesRewards.hasUnlockFeature(city, FeaturesRewards.Feature.MAYOR)) { + if (OMCRegistry.FEATURES.CITY.get().MAYOR.phaseMayor == 2 && FeaturesRewards.hasUnlockFeature(city, FeaturesRewards.Feature.MAYOR)) { Mayor mayor = this.city.getMayor(); ElectionType electionType = mayor.getElectionType(); - Perks perk1 = PerkManager.getPerkById(mayor.getIdPerk1()); - Perks perk2 = PerkManager.getPerkById(mayor.getIdPerk2()); - Perks perk3 = PerkManager.getPerkById(mayor.getIdPerk3()); + Perks perk1 = PerkUtils.getPerkById(mayor.getIdPerk1()); + Perks perk2 = PerkUtils.getPerkById(mayor.getIdPerk2()); + Perks perk3 = PerkUtils.getPerkById(mayor.getIdPerk3()); loreOwner.add(Component.empty()); loreOwner.add(perk1 == null ? TranslationManager.translation("feature.city.menus.common.error") : diff --git a/src/main/java/fr/openmc/core/features/city/menu/list/CityListMenu.java b/src/main/java/fr/openmc/core/features/city/menu/list/CityListMenu.java index 427f9b7af..e5878fe3d 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/list/CityListMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/list/CityListMenu.java @@ -10,7 +10,6 @@ import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.CityType; -import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; import fr.openmc.core.features.city.sub.milestone.rewards.FeaturesRewards; import fr.openmc.core.features.city.sub.milestone.rewards.MemberLimitRewards; import fr.openmc.core.features.economy.EconomyManager; @@ -39,6 +38,8 @@ public class CityListMenu extends PaginatedMenu { private final List cities; private SortType sortType; + + private final CityManager cityManager; /** * Constructor for CityListMenu. @@ -57,7 +58,8 @@ public CityListMenu(Player owner) { */ public CityListMenu(Player owner, SortType sortType) { super(owner); - this.cities = new ArrayList<>(CityManager.getCities()); + this.cityManager = OMCRegistry.FEATURES.CITY.get(); + this.cities = new ArrayList<>(cityManager.getCities()); setSortType(sortType); } @@ -89,7 +91,7 @@ public List getItems() { Component typeComponent = city.getType().getDisplayName(); Component wealthComponent = Component.text(EconomyManager.getFormattedSimplifiedNumber(city.getBalance())).color(NamedTextColor.GOLD); Component wealthIcon = Component.text(EconomyManager.getEconomyIcon()).color(NamedTextColor.GOLD); - if (MayorManager.phaseMayor == 2 && FeaturesRewards.hasUnlockFeature(city, FeaturesRewards.Feature.MAYOR)) { + if (cityManager.MAYOR.phaseMayor == 2 && FeaturesRewards.hasUnlockFeature(city, FeaturesRewards.Feature.MAYOR)) { Component mayorCity = city.getMayor() == null ? TranslationManager.translation("messages.menus.none") : city.getMayor().getName(); diff --git a/src/main/java/fr/openmc/core/features/city/menu/main/CityMenu.java b/src/main/java/fr/openmc/core/features/city/menu/main/CityMenu.java index 511666a0a..a467e28f7 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/main/CityMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/main/CityMenu.java @@ -3,8 +3,8 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.menu.main.buttons.*; import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.text.Component; @@ -56,7 +56,7 @@ public String getTexture() { Map inventory = new HashMap<>(); Player player = getOwner(); - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); assert city != null; // ** Rank Button diff --git a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/BankButton.java b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/BankButton.java index 02987bc2f..fb8ce9126 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/BankButton.java +++ b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/BankButton.java @@ -3,8 +3,8 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.api.menulib.utils.MenuUtils; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.bank.conditions.CityBankConditions; import fr.openmc.core.features.city.sub.bank.menu.CityBankMenu; import fr.openmc.core.features.city.sub.milestone.rewards.FeaturesRewards; @@ -32,7 +32,7 @@ public static void init(Menu menu, Map contents, City itemMeta.lore(getDynamicLore(city)); itemMeta.setItemModel(NamespacedKey.minecraft("air")); }).setOnClick(inventoryClickEvent -> { - City cityCheck = CityManager.getPlayerCity(player.getUniqueId()); + City cityCheck = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (cityCheck == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); return; diff --git a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/ChestButton.java b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/ChestButton.java index 6b557deb0..d69bea014 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/ChestButton.java +++ b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/ChestButton.java @@ -3,8 +3,8 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.api.menulib.utils.MenuUtils; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.conditions.CityChestConditions; import fr.openmc.core.features.city.menu.CityChestMenu; @@ -31,7 +31,7 @@ public static void init(Menu menu, Map contents, City itemMeta.lore(getDynamicLore(city, player)); itemMeta.setItemModel(NamespacedKey.minecraft("air")); }).setOnClick(inventoryClickEvent -> { - City cityCheck = CityManager.getPlayerCity(player.getUniqueId()); + City cityCheck = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (!CityChestConditions.canCityChestOpen(cityCheck, player)) return; diff --git a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/LeaveButton.java b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/LeaveButton.java index 418422053..70d810acc 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/LeaveButton.java +++ b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/LeaveButton.java @@ -4,8 +4,8 @@ import fr.openmc.api.menulib.template.ConfirmMenu; import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.api.menulib.utils.MenuUtils; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.actions.CityLeaveAction; import fr.openmc.core.features.city.conditions.CityLeaveCondition; @@ -36,7 +36,7 @@ public static void init(Menu menu, Map contents, City }).setOnClick(inventoryClickEvent -> { if (hasPermissionOwner) return; - City cityCheck = CityManager.getPlayerCity(player.getUniqueId()); + City cityCheck = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (!CityLeaveCondition.canCityLeave(cityCheck, player)) return; new ConfirmMenu(player, diff --git a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/ManageButton.java b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/ManageButton.java index 669af4561..ae03d680c 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/ManageButton.java +++ b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/ManageButton.java @@ -2,8 +2,8 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.api.menulib.utils.ItemMenuBuilder; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.menu.CityModifyMenu; import fr.openmc.core.features.city.sub.milestone.rewards.MemberLimitRewards; @@ -36,7 +36,7 @@ public static void init(Menu menu, Map contents, City itemMeta.lore(getDynamicLore(city, player)); itemMeta.setItemModel(NamespacedKey.minecraft("air")); }).setOnClick(inventoryClickEvent -> { - City cityCheck = CityManager.getPlayerCity(player.getUniqueId()); + City cityCheck = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (cityCheck == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); return; diff --git a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/MayorButton.java b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/MayorButton.java index 3cbd22837..33ab66858 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/MayorButton.java +++ b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/MayorButton.java @@ -4,6 +4,7 @@ import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.api.menulib.utils.MenuUtils; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.sub.mayor.ElectionType; @@ -44,6 +45,7 @@ private static Supplier getItemSupplier(Menu menu, City city, P } private static List getDynamicLore(City city, Player player) { + MayorManager mayorManager = OMCRegistry.FEATURES.CITY.get().MAYOR; boolean hasPermissionOwner = city.hasPermission(player.getUniqueId(), CityPermission.OWNER); Component mayorName = (city.getMayor() != null && city.getMayor().getName() != null) ? city.getMayor().getName() @@ -53,7 +55,7 @@ private static List getDynamicLore(City city, Player player) { List lore; if (!FeaturesRewards.hasUnlockFeature(city, FeaturesRewards.Feature.MAYOR)) { - lore = switch (MayorManager.phaseMayor) { + lore = switch (mayorManager.phaseMayor) { case 2 -> TranslationManager.translationLore( "feature.city.menus.main.mayor.locked.phase2", Component.text(FeaturesRewards.getFeatureUnlockLevel(FeaturesRewards.Feature.MAYOR)).color(NamedTextColor.RED) @@ -70,7 +72,7 @@ private static List getDynamicLore(City city, Player player) { }; } else { if (city.getElectionType() == ElectionType.ELECTION) { - lore = switch (MayorManager.phaseMayor) { + lore = switch (mayorManager.phaseMayor) { case 2 -> TranslationManager.translationLore( "feature.city.menus.main.mayor.election.phase2", mayorComponent @@ -82,7 +84,7 @@ private static List getDynamicLore(City city, Player player) { default -> TranslationManager.translationLore("feature.city.menus.main.mayor.election.error"); }; } else { - switch (MayorManager.phaseMayor) { + switch (mayorManager.phaseMayor) { case 2 -> lore = TranslationManager.translationLore( "feature.city.menus.main.mayor.owner.phase2", mayorComponent, diff --git a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/MilestoneButton.java b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/MilestoneButton.java index 9e545b2e5..ac673e666 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/main/buttons/MilestoneButton.java +++ b/src/main/java/fr/openmc/core/features/city/menu/main/buttons/MilestoneButton.java @@ -3,8 +3,8 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.api.menulib.utils.MenuUtils; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.milestone.menu.CityMilestoneMenu; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -31,7 +31,7 @@ public static void init(Menu menu, Map contents, City itemMeta.lore(getDynamicLore(city)); itemMeta.setItemModel(NamespacedKey.minecraft("air")); }).setOnClick(inventoryClickEvent -> { - City cityCheck = CityManager.getPlayerCity(player.getUniqueId()); + City cityCheck = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (cityCheck == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); return; diff --git a/src/main/java/fr/openmc/core/features/city/menu/playerlist/CityPlayerGestionMenu.java b/src/main/java/fr/openmc/core/features/city/menu/playerlist/CityPlayerGestionMenu.java index bd409aa69..f7d0f0733 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/playerlist/CityPlayerGestionMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/playerlist/CityPlayerGestionMenu.java @@ -4,8 +4,8 @@ import fr.openmc.api.menulib.template.ConfirmMenu; import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.actions.CityKickAction; import fr.openmc.core.features.city.conditions.CityKickCondition; @@ -60,7 +60,7 @@ public void onInventoryClick(InventoryClickEvent click) { Map inventory = new HashMap<>(); Player player = getOwner(); - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); assert city != null; boolean hasPermissionKick = city.hasPermission(player.getUniqueId(), CityPermission.KICK); diff --git a/src/main/java/fr/openmc/core/features/city/menu/playerlist/CityPlayerListMenu.java b/src/main/java/fr/openmc/core/features/city/menu/playerlist/CityPlayerListMenu.java index aec6debf4..47ffb58cc 100644 --- a/src/main/java/fr/openmc/core/features/city/menu/playerlist/CityPlayerListMenu.java +++ b/src/main/java/fr/openmc/core/features/city/menu/playerlist/CityPlayerListMenu.java @@ -10,7 +10,6 @@ import fr.openmc.api.menulib.utils.StaticSlots; import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.actions.CityKickAction; import fr.openmc.core.features.city.commands.CityInviteCommands; @@ -69,7 +68,7 @@ public List getItems() { List items = new ArrayList<>(); Player player = getOwner(); - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); assert city != null; boolean hasPermissionKick = city.hasPermission(player.getUniqueId(), CityPermission.KICK); @@ -152,7 +151,7 @@ public Map getButtons() { Player player = getOwner(); OMCPlayer omcPlayer = OMCPlayer.of(player); - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); Map map = new HashMap<>(); map.put(45, new ItemMenuBuilder(this, Material.ARROW, true)); diff --git a/src/main/java/fr/openmc/core/features/city/sub/bank/CityBankManager.java b/src/main/java/fr/openmc/core/features/city/sub/bank/CityBankManager.java index 82560b5e0..be38c637b 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/bank/CityBankManager.java +++ b/src/main/java/fr/openmc/core/features/city/sub/bank/CityBankManager.java @@ -1,15 +1,16 @@ package fr.openmc.core.features.city.sub.bank; -import fr.openmc.core.CommandsManager; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.bank.commands.CityBankCommand; import fr.openmc.core.features.city.sub.bank.conditions.CityBankConditions; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.city.sub.milestone.rewards.InterestRewards; import fr.openmc.core.features.economy.EconomyManager; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.utils.text.InputUtils; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -22,13 +23,22 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.List; +import java.util.Set; import java.util.UUID; -public class CityBankManager { +public class CityBankManager extends Feature implements HasCommands { + private final CityManager cityManager; + private final MayorManager mayorManager; - public static void init() { - CommandsManager.getHandler().register( + public CityBankManager(CityManager cityManager, MayorManager mayorManager) { + this.cityManager = cityManager; + this.mayorManager = mayorManager; + } + + @Override + public Set getCommands() { + return Set.of( new CityBankCommand() ); } @@ -39,7 +49,7 @@ public static void init() { * @param player The player depositing into the bank * @param input The input string to get the money value */ - public static void depositCityBank(City city, Player player, String input) { + public void depositCityBank(City city, Player player, String input) { if (!CityBankConditions.canCityDeposit(city, player)) return; if (!InputUtils.isInputMoney(input)) { @@ -80,7 +90,7 @@ public static void depositCityBank(City city, Player player, String input) { * @param player The player withdrawing from the bank * @param input The input string to get the money value */ - public static void withdrawCityBank(City city, Player player, String input) { + public void withdrawCityBank(City city, Player player, String input) { if (!CityBankConditions.canCityWithdraw(city, player)) return; if (!InputUtils.isInputMoney(input)) { @@ -116,13 +126,13 @@ public static void withdrawCityBank(City city, Player player, String input) { * * @return The calculated interest as a double. */ - public static double calculateCityInterest(City city) { + public double calculateCityInterest(City city) { double interest = .01; // base interest is 1% interest += InterestRewards.getTotalInterest(city.getLevel()); - if (MayorManager.phaseMayor == 2) { - if (PerkManager.hasPerk(city.getMayor(), Perks.BUSINESS_MAN.getId())) { + if (mayorManager.phaseMayor == 2) { + if (PerkUtils.hasPerk(city.getMayor(), Perks.BUSINESS_MAN.getId())) { interest += .02; // interest is +2% when perk Business Man enabled } } @@ -133,7 +143,7 @@ public static double calculateCityInterest(City city) { /** * Applies the interest to the city balance and updates it in the database. */ - public static void applyCityInterest(City city) { + public void applyCityInterest(City city) { double interest = calculateCityInterest(city); double amount = city.getBalance() * interest; @@ -146,10 +156,10 @@ public static void applyCityInterest(City city) { * Apply all city interests * WARNING: THIS FUNCTION IS VERY EXPENSIVE DO NOT RUN FREQUENTLY IT WILL AFFECT PERFORMANCE IF THERE ARE MANY CITIES SAVED IN THE DB */ - public static void applyAllCityInterests() { - List cityUUIDs = CityManager.getAllCityUUIDs(); + public void applyAllCityInterests() { + List cityUUIDs = cityManager.getAllCityUUIDs(); for (UUID cityUUID : cityUUIDs) { - CityManager.getCity(cityUUID).applyCityInterest(); + cityManager.getCity(cityUUID).applyCityInterest(); } } } diff --git a/src/main/java/fr/openmc/core/features/city/sub/bank/commands/CityBankCommand.java b/src/main/java/fr/openmc/core/features/city/sub/bank/commands/CityBankCommand.java index d1b60d6cb..cb929d7bb 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/bank/commands/CityBankCommand.java +++ b/src/main/java/fr/openmc/core/features/city/sub/bank/commands/CityBankCommand.java @@ -11,22 +11,28 @@ import revxrsal.commands.annotation.Range; public class CityBankCommand { + private final CityManager cityManager; + + public CityBankCommand(CityManager cityManager) { + this.cityManager = cityManager; + } + @Command({"city bank", "ville bank"}) @Description("Ouvre le menu de la banque de ville") - void bank(Player player) { - if (CityManager.getPlayerCity(player.getUniqueId()) == null) + public void bank(Player player) { + if (cityManager.getPlayerCity(player.getUniqueId()) == null) return; - if (!CityBankConditions.canOpenCityBank(CityManager.getPlayerCity(player.getUniqueId()), player)) return; + if (!CityBankConditions.canOpenCityBank(cityManager.getPlayerCity(player.getUniqueId()), player)) return; new CityBankMenu(player).open(); } @Command({"city bank deposit", "ville bank deposit"}) @Description("Met de votre argent dans la banque de ville") - void deposit(Player player, + public void deposit(Player player, @Named("montant") @Range(min = 1) String input) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = cityManager.getPlayerCity(player.getUniqueId()); if (!CityBankConditions.canCityDeposit(city, player)) return; @@ -35,9 +41,9 @@ void deposit(Player player, @Command({"city bank withdraw", "ville bank withdraw"}) @Description("Prend de l'argent de la banque de ville") - void withdraw(Player player, + public void withdraw(Player player, @Named("montant") @Range(min = 1) String input) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = cityManager.getPlayerCity(player.getUniqueId()); if (!CityBankConditions.canCityWithdraw(city, player)) return; diff --git a/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankDepositMenu.java b/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankDepositMenu.java index 83009dd08..efc6a3a1f 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankDepositMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankDepositMenu.java @@ -4,8 +4,8 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.sub.bank.conditions.CityBankConditions; import fr.openmc.core.features.economy.EconomyManager; @@ -56,7 +56,7 @@ public void onInventoryClick(InventoryClickEvent click) { Map inventory = new HashMap<>(); Player player = getOwner(); - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); assert city != null; boolean hasPermissionMoneyGive = city.hasPermission(player.getUniqueId(), CityPermission.MONEY_DEPOSIT); diff --git a/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankMenu.java b/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankMenu.java index b83f93ea3..d0721b712 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankMenu.java @@ -5,8 +5,8 @@ import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.api.menulib.utils.MenuUtils; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.economy.BankManager; import fr.openmc.core.features.economy.EconomyManager; @@ -59,7 +59,7 @@ public void onInventoryClick(InventoryClickEvent click) { Map inventory = new HashMap<>(); Player player = getOwner(); - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); assert city != null; List loreBankDeposit; diff --git a/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankWithdrawMenu.java b/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankWithdrawMenu.java index eecccdf65..a0187c1b7 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankWithdrawMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/bank/menu/CityBankWithdrawMenu.java @@ -4,8 +4,8 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.sub.bank.conditions.CityBankConditions; import fr.openmc.core.features.economy.EconomyManager; @@ -56,7 +56,7 @@ public void onInventoryClick(InventoryClickEvent click) { Map inventory = new HashMap<>(); Player player = getOwner(); - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); assert city != null; boolean hasPermissionMoneyTake = city.hasPermission(player.getUniqueId(), CityPermission.MONEY_WITHDRAW); 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 270d0f781..330695c49 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 @@ -6,12 +6,7 @@ import com.j256.ormlite.table.TableUtils; import fr.openmc.api.cooldown.DynamicCooldownManager; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.mascots.commands.AdminMascotsCommands; @@ -20,7 +15,12 @@ import fr.openmc.core.features.city.sub.mascots.models.MascotsLevels; import fr.openmc.core.features.city.sub.mascots.utils.MascotRegenerationUtils; import fr.openmc.core.features.city.sub.mascots.utils.MascotUtils; -import fr.openmc.core.hooks.ProtocolLibHook; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.bukkit.ItemUtils; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -54,6 +54,12 @@ public class MascotsManager extends Feature implements HasDatabase, HasCommands, public static NamespacedKey mascotsKey; private static Dao mascotsDao; + private final CityManager cityManager; + + public MascotsManager(CityManager cityManager) { + this.cityManager = cityManager; + } + @Override public void init() { // changement du spigot.yml pour permettre aux mascottes d'avoir 3000 cœurs @@ -70,7 +76,7 @@ public void init() { loadMascots(); - if (ProtocolLibHook.isEnable()) + if (OMCRegistry.HOOKS.PROTOCOL_LIB.isEnable()) new MascotsSoundListener(); for (Mascot mascot : MascotsManager.mascotsByCityUUID.values()) { @@ -88,13 +94,13 @@ public Set getCommands() { @Override public Set getListeners() { return Set.of( - MascotsInteractionListener::new, + () -> new MascotsInteractionListener(cityManager), MascotsDamageListener::new, - MascotsDeathListener::new, + () -> new MascotsDeathListener(cityManager), MascotsSleepingListener::new, - MascotImmuneListener::new, + () -> new MascotImmuneListener(cityManager), MascotsTargetListener::new, - MascotsRenameListener::new, + () -> new MascotsRenameListener(cityManager), MascotsPotionListener::new, MascotsProtectionsListener::new ); @@ -175,7 +181,7 @@ public static void removeMascotsFromCity(City city) { } public static void upgradeMascots(UUID cityUUID) { - City city = CityManager.getCity(cityUUID); + City city = OMCRegistry.FEATURES.CITY.get().getCity(cityUUID); if (city == null) return; Mascot mascot = city.getMascot(); diff --git a/src/main/java/fr/openmc/core/features/city/sub/mascots/commands/AdminMascotsCommands.java b/src/main/java/fr/openmc/core/features/city/sub/mascots/commands/AdminMascotsCommands.java index e08e4ff05..2cf6a6172 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mascots/commands/AdminMascotsCommands.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mascots/commands/AdminMascotsCommands.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.city.sub.mascots.commands; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.commands.autocomplete.CityNameAutoComplete; import fr.openmc.core.features.city.sub.mascots.MascotsManager; import fr.openmc.core.utils.text.messages.MessageType; @@ -25,7 +25,7 @@ public void forceRemoveMascots( Player sender, @Named("cityName") @SuggestWith(CityNameAutoComplete.class) String cityName ) { - City city = CityManager.getCityByName(cityName); + City city = OMCRegistry.FEATURES.CITY.get().getCityByName(cityName); if (city == null) { MessagesManager.sendMessage(sender, TranslationManager.translation("messages.city.not_found"), Prefix.CITY, MessageType.ERROR, false); diff --git a/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotImmuneListener.java b/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotImmuneListener.java index 764dbd9e0..e8a5d1f88 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotImmuneListener.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotImmuneListener.java @@ -14,12 +14,17 @@ import org.bukkit.event.Listener; public class MascotImmuneListener implements Listener { + private final CityManager cityManager; + + public MascotImmuneListener(CityManager cityManager) { + this.cityManager = cityManager; + } @EventHandler void onStartMascotImmune(CooldownStartEvent event) { if (!event.getGroup().equals("city:immunity")) return; - City cityImmune = CityManager.getCity(event.getCooldownUUID()); + City cityImmune = cityManager.getCity(event.getCooldownUUID()); if (cityImmune == null) return; @@ -36,7 +41,7 @@ void onStartMascotImmune(CooldownStartEvent event) { void onEndMascotImmune(CooldownEndEvent event) { if (!event.getGroup().equals("city:immunity")) return; - City cityImmune = CityManager.getCity(event.getCooldownUUID()); + City cityImmune = cityManager.getCity(event.getCooldownUUID()); if (cityImmune == null) return; diff --git a/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsDamageListener.java b/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsDamageListener.java index 1ed7cc17f..2bfb4fce3 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsDamageListener.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsDamageListener.java @@ -1,5 +1,6 @@ package fr.openmc.core.features.city.sub.mascots.listeners; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityType; @@ -7,8 +8,7 @@ import fr.openmc.core.features.city.sub.mascots.models.Mascot; import fr.openmc.core.features.city.sub.mascots.utils.MascotRegenerationUtils; import fr.openmc.core.features.city.sub.mascots.utils.MascotUtils; -import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.city.sub.mayor.perks.basic.IronBloodPerk; import fr.openmc.core.features.city.sub.war.War; @@ -95,7 +95,8 @@ void onMascotTakeDamage(EntityDamageByEntityEvent e) { return; } - City city = CityManager.getPlayerCity(player.getUniqueId()); + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); + City city = cityManager.getPlayerCity(player.getUniqueId()); City cityEnemy = MascotUtils.getCityFromEntity(damageEntity.getUniqueId()); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); @@ -181,9 +182,9 @@ void onMascotTakeDamage(EntityDamageByEntityEvent e) { MascotUtils.updateDisplayName(mob, cityMob.getMascot(), e.getFinalDamage()); try { - if (MayorManager.phaseMayor != 2) return; + if (cityManager.MAYOR.phaseMayor != 2) return; - if (!PerkManager.hasPerk(cityMob.getMayor(), Perks.IRON_BLOOD.getId())) return; + if (!PerkUtils.hasPerk(cityMob.getMayor(), Perks.IRON_BLOOD.getId())) return; IronBloodPerk.spawnGolem(player, cityMob, mob); } catch (Exception ex) { diff --git a/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsDeathListener.java b/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsDeathListener.java index 7c4224c01..98fae0d52 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsDeathListener.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsDeathListener.java @@ -6,7 +6,6 @@ import fr.openmc.core.features.city.sub.mascots.models.Mascot; import fr.openmc.core.features.city.sub.mascots.utils.MascotUtils; import fr.openmc.core.features.city.sub.war.War; -import fr.openmc.core.features.city.sub.war.WarManager; import org.bukkit.Color; import org.bukkit.FireworkEffect; import org.bukkit.Location; @@ -25,6 +24,12 @@ import java.util.UUID; public class MascotsDeathListener implements Listener { + private final CityManager cityManager; + + public MascotsDeathListener(CityManager cityManager) { + this.cityManager = cityManager; + } + @EventHandler void onMascotDied(EntityDeathEvent e) { Entity entity = e.getEntity(); @@ -35,7 +40,7 @@ void onMascotDied(EntityDeathEvent e) { PersistentDataContainer data = entity.getPersistentDataContainer(); UUID cityUUID = UUID.fromString(data.get(MascotsManager.mascotsKey, PersistentDataType.STRING)); - City city = CityManager.getCity(cityUUID); + City city = cityManager.getCity(cityUUID); if (city == null) return; @@ -50,7 +55,7 @@ void onMascotDied(EntityDeathEvent e) { if (killer == null) return; - City cityEnemy = CityManager.getPlayerCity(killer.getUniqueId()); + City cityEnemy = cityManager.getPlayerCity(killer.getUniqueId()); if (cityEnemy == null) return; @@ -73,7 +78,7 @@ void onMascotDied(EntityDeathEvent e) { player.setVelocity(direction); } - WarManager.endWar(war); + cityManager.WAR.endWar(war); } else { // TODO: système de vulnerabilité d'une ville, check si la ville attaquée est vulnérable, si oui la ville attaquée est supprimée } diff --git a/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsInteractionListener.java b/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsInteractionListener.java index cc715e12a..10de89fb5 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsInteractionListener.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsInteractionListener.java @@ -24,6 +24,12 @@ import java.util.UUID; public class MascotsInteractionListener implements Listener { + private final CityManager cityManager; + + public MascotsInteractionListener(CityManager cityManager) { + this.cityManager = cityManager; + } + @SneakyThrows @EventHandler void onInteractWithMascots(PlayerInteractEntityEvent e) { @@ -39,7 +45,7 @@ void onInteractWithMascots(PlayerInteractEntityEvent e) { if (mascotsData == null) return; UUID mascotsUUID = UUID.fromString(mascotsData); - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = cityManager.getPlayerCity(player.getUniqueId()); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); diff --git a/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsProtectionsListener.java b/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsProtectionsListener.java index f4e7c551a..ab4052d6b 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsProtectionsListener.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsProtectionsListener.java @@ -1,8 +1,8 @@ package fr.openmc.core.features.city.sub.mascots.listeners; import dev.lone.itemsadder.api.Events.CustomBlockPlaceEvent; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; import fr.openmc.core.features.city.sub.mascots.utils.MascotUtils; +import fr.openmc.core.lifecycle.interfaces.NotLoadInUnitTest; import io.papermc.paper.event.entity.EntityMoveEvent; import org.bukkit.Location; import org.bukkit.block.Block; diff --git a/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsRenameListener.java b/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsRenameListener.java index dcbf21770..0842d104d 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsRenameListener.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mascots/listeners/MascotsRenameListener.java @@ -25,6 +25,11 @@ import java.util.UUID; public class MascotsRenameListener implements Listener { + private final CityManager cityManager; + + public MascotsRenameListener(CityManager cityManager) { + this.cityManager = cityManager; + } @EventHandler public void onRenameWithNameTag(PlayerInteractEntityEvent e) { @@ -47,7 +52,7 @@ public void onRenameWithNameTag(PlayerInteractEntityEvent e) { e.setCancelled(true); - City city = CityManager.getCity(UUID.fromString(cityUUID)); + City city = cityManager.getCity(UUID.fromString(cityUUID)); if (city != null) { Mascot mascot = city.getMascot(); if (mascot != null) { diff --git a/src/main/java/fr/openmc/core/features/city/sub/mascots/menu/MascotMenu.java b/src/main/java/fr/openmc/core/features/city/sub/mascots/menu/MascotMenu.java index bb6b9bed6..6721b2420 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mascots/menu/MascotMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mascots/menu/MascotMenu.java @@ -9,7 +9,6 @@ import fr.openmc.core.OMCPlugin; import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.sub.mascots.models.Mascot; import fr.openmc.core.features.city.sub.mascots.models.MascotsLevels; @@ -54,7 +53,7 @@ public class MascotMenu extends Menu { public MascotMenu(Player owner, Mascot mascot) { super(owner); this.mascot = mascot; - this.city = CityManager.getPlayerCity(owner.getUniqueId()); + this.city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(owner.getUniqueId()); } @Override @@ -141,7 +140,7 @@ public void onInventoryClick(InventoryClickEvent inventoryClickEvent) { return; } - city = CityManager.getPlayerCity(getOwner().getUniqueId()); + city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(getOwner().getUniqueId()); if (city == null) { MessagesManager.sendMessage(getOwner(), TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); getOwner().closeInventory(); diff --git a/src/main/java/fr/openmc/core/features/city/sub/mascots/menu/MascotsDeadMenu.java b/src/main/java/fr/openmc/core/features/city/sub/mascots/menu/MascotsDeadMenu.java index f6412ea2a..cc5583c4f 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mascots/menu/MascotsDeadMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mascots/menu/MascotsDeadMenu.java @@ -6,8 +6,8 @@ import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.api.menulib.utils.MenuUtils; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.utils.bukkit.ItemUtils; import fr.openmc.core.utils.text.DateUtils; import fr.openmc.core.utils.text.messages.MessageType; @@ -75,7 +75,7 @@ public void onInventoryClick(InventoryClickEvent inventoryClickEvent) { Component.text(AYWENITE_REDUCE).color(NamedTextColor.LIGHT_PURPLE) )); }).setOnClick(inventoryClickEvent -> { - City city = CityManager.getCity(cityUUID); + City city = OMCRegistry.FEATURES.CITY.get().getCity(cityUUID); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); player.closeInventory(); diff --git a/src/main/java/fr/openmc/core/features/city/sub/mascots/menu/MascotsSkinMenu.java b/src/main/java/fr/openmc/core/features/city/sub/mascots/menu/MascotsSkinMenu.java index b326c7c45..e9138225b 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mascots/menu/MascotsSkinMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mascots/menu/MascotsSkinMenu.java @@ -5,7 +5,6 @@ import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.mascots.models.Mascot; import fr.openmc.core.features.city.sub.mascots.models.MascotType; import fr.openmc.core.features.city.sub.milestone.rewards.MascotsSkinUnlockRewards; @@ -69,7 +68,7 @@ public void onInventoryClick(InventoryClickEvent inventoryClickEvent) { public @NotNull Map getContent() { Map map = new HashMap<>(); - City playerCity = CityManager.getPlayerCity(getOwner().getUniqueId()); + City playerCity = OMCRegistry.FEATURES.CITY.get().getPlayerCity(getOwner().getUniqueId()); if (playerCity == null) return map; diff --git a/src/main/java/fr/openmc/core/features/city/sub/mascots/models/Mascot.java b/src/main/java/fr/openmc/core/features/city/sub/mascots/models/Mascot.java index faed8ca86..d13fff20f 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mascots/models/Mascot.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mascots/models/Mascot.java @@ -2,8 +2,8 @@ import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import lombok.Getter; import lombok.Setter; import org.bukkit.Bukkit; @@ -92,7 +92,7 @@ public City getCity() { if (this.city != null) { return this.city; } - this.city = CityManager.getCity(this.cityUUID); + this.city = OMCRegistry.FEATURES.CITY.get().getCity(this.cityUUID); return this.city; } diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/actions/MayorCommandAction.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/actions/MayorCommandAction.java index 256d6d005..3bfecf1a7 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/actions/MayorCommandAction.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/actions/MayorCommandAction.java @@ -1,11 +1,11 @@ package fr.openmc.core.features.city.sub.mayor.actions; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.sub.mayor.ElectionType; -import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; import fr.openmc.core.features.city.sub.mayor.menu.MayorElectionMenu; import fr.openmc.core.features.city.sub.mayor.menu.MayorMandateMenu; import fr.openmc.core.features.city.sub.mayor.menu.create.MayorColorMenu; @@ -24,7 +24,8 @@ public class MayorCommandAction { public static void launchInteractionMenu(Player player) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); + City city = cityManager.getPlayerCity(player.getUniqueId()); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); @@ -40,7 +41,7 @@ public static void launchInteractionMenu(Player player) { } if (city.getElectionType() == ElectionType.ELECTION) { - if (MayorManager.phaseMayor == 1) { + if (cityManager.MAYOR.phaseMayor == 1) { MayorElectionMenu menu = new MayorElectionMenu(player); menu.open(); } else { @@ -48,10 +49,10 @@ public static void launchInteractionMenu(Player player) { menu.open(); } } else { - if (MayorManager.phaseMayor == 2) { + if (cityManager.MAYOR.phaseMayor == 2) { MayorMandateMenu menu = new MayorMandateMenu(player); menu.open(); - } else if (MayorManager.phaseMayor == 1) { + } else if (cityManager.MAYOR.phaseMayor == 1) { if (city.hasPermission(player.getUniqueId(), CityPermission.OWNER)) { if (!city.hasMayor()) { Bukkit.getScheduler().runTask(OMCPlugin.getInstance(), () -> { diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/actions/MayorSetWarpAction.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/actions/MayorSetWarpAction.java index bfbaccf5c..1374f30c9 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/actions/MayorSetWarpAction.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/actions/MayorSetWarpAction.java @@ -4,7 +4,6 @@ import fr.openmc.api.input.location.ItemInteraction; import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.sub.mayor.models.CityLaw; import fr.openmc.core.features.city.sub.mayor.models.Mayor; @@ -25,7 +24,7 @@ public class MayorSetWarpAction { public static void setWarp(Player player) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (city == null) return; diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/commands/AdminMayorCommands.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/commands/AdminMayorCommands.java index eba74e3f6..a9f63eccc 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/commands/AdminMayorCommands.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/commands/AdminMayorCommands.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.city.sub.mayor.commands; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.commands.autocomplete.CityNameAutoComplete; import fr.openmc.core.features.city.sub.mayor.ElectionType; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; @@ -25,10 +25,11 @@ public void setPhase( Player sender, @Named("phase") @Suggest({"1", "2"}) int phase ) { + MayorManager mayorManager = OMCRegistry.FEATURES.CITY.get().MAYOR; if (phase == 1) { - MayorManager.initPhase1(); + mayorManager.initPhase1(); } else if (phase == 2){ - MayorManager.initPhase2(); + mayorManager.initPhase2(); } } @@ -39,7 +40,7 @@ public void changeElection( @Named("name") @SuggestWith(CityNameAutoComplete.class) String cityName, @Named("electionType") @Suggest({"owner_choose", "election"}) String electionType ) { - City city = CityManager.getCityByName(cityName); + City city = OMCRegistry.FEATURES.CITY.get().getCityByName(cityName); if (city == null) { MessagesManager.sendMessage(sender, TranslationManager.translation("messages.city.not_found"), Prefix.STAFF, MessageType.ERROR, false); diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/commands/MayorCommands.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/commands/MayorCommands.java index 02e63075d..46960cf0d 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/commands/MayorCommands.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/commands/MayorCommands.java @@ -1,10 +1,9 @@ package fr.openmc.core.features.city.sub.mayor.commands; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.mayor.actions.MayorCommandAction; import fr.openmc.core.features.city.sub.mayor.actions.MayorSetWarpAction; -import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; import fr.openmc.core.features.city.sub.mayor.models.CityLaw; import fr.openmc.core.utils.bukkit.PlayerUtils; import fr.openmc.core.utils.text.messages.MessageType; @@ -28,7 +27,7 @@ void mayor(Player sender) { @Command({"city warp", "ville warp"}) @Description("Teleporte au warp commun de la ville") void warp(Player player) { - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (playerCity == null) return; @@ -36,7 +35,7 @@ void warp(Player player) { Location warp = law.getWarp(); if (warp == null) { - if (MayorManager.phaseMayor == 2) { + if (OMCRegistry.FEATURES.CITY.get().MAYOR.phaseMayor == 2) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.command.warp.not_set.phase2"), Prefix.CITY, MessageType.INFO, true); return; } diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/listeners/JoinListener.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/listeners/JoinListener.java index 3144e366f..714bb62ab 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/listeners/JoinListener.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/listeners/JoinListener.java @@ -11,32 +11,39 @@ import org.bukkit.event.player.PlayerJoinEvent; public class JoinListener implements Listener { + private final CityManager cityManager; + private final MayorManager mayorManager; + + public JoinListener(CityManager cityManager, MayorManager mayorManager) { + this.cityManager = cityManager; + this.mayorManager = mayorManager; + } @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); if (playerCity == null) return; if (playerCity.getLaw() == null) { - MayorManager.createCityLaws(playerCity, false, null); + mayorManager.createCityLaws(playerCity, false, null); } if (!FeaturesRewards.hasUnlockFeature(playerCity, FeaturesRewards.Feature.MAYOR)) return; - if (MayorManager.phaseMayor == 2 && MayorManager.cityMayor.get(playerCity.getUniqueId()) == null) { + if (mayorManager.phaseMayor == 2 && mayorManager.cityMayor.get(playerCity.getUniqueId()) == null) { if (playerCity.getMembers().size() >= MayorManager.MEMBER_REQUEST_ELECTION) { - MayorManager.createMayor(null, null, playerCity, null, null, null, null, ElectionType.ELECTION); + mayorManager.createMayor(null, null, playerCity, null, null, null, null, ElectionType.ELECTION); } - MayorManager.createMayor(null, null, playerCity, null, null, null, null, ElectionType.OWNER_CHOOSE); + mayorManager.createMayor(null, null, playerCity, null, null, null, null, ElectionType.OWNER_CHOOSE); - MayorManager.runSetupMayor(playerCity); - } else if (MayorManager.phaseMayor == 1 && MayorManager.cityMayor.get(playerCity.getUniqueId()) == null) { + mayorManager.runSetupMayor(playerCity); + } else if (mayorManager.phaseMayor == 1 && mayorManager.cityMayor.get(playerCity.getUniqueId()) == null) { if (playerCity.getMembers().size()>=MayorManager.MEMBER_REQUEST_ELECTION) { - MayorManager.createMayor(null,null, playerCity, null, null, null, null, ElectionType.ELECTION); + mayorManager.createMayor(null,null, playerCity, null, null, null, null, ElectionType.ELECTION); } - MayorManager.createMayor(null, null, playerCity, null, null, null, null, ElectionType.OWNER_CHOOSE); + mayorManager.createMayor(null, null, playerCity, null, null, null, null, ElectionType.OWNER_CHOOSE); } } diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/listeners/UrneListener.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/listeners/UrneListener.java index 59e03ff2f..2547b507d 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/listeners/UrneListener.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/listeners/UrneListener.java @@ -9,10 +9,11 @@ import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.sub.mayor.ElectionType; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.NPCManager; import fr.openmc.core.features.city.sub.mayor.menu.MayorVoteMenu; import fr.openmc.core.features.city.sub.milestone.rewards.FeaturesRewards; import fr.openmc.core.hooks.FancyNpcsHook; +import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.lifecycle.interfaces.LoadIfEnable; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; import fr.openmc.core.utils.text.messages.Prefix; @@ -30,17 +31,26 @@ import java.util.Objects; -public class UrneListener implements Listener { +public class UrneListener implements Listener, LoadIfEnable { + private final FancyNpcsHook fancyNpcHook; + private final CityManager cityManager; + private final MayorManager mayorManager; + + public UrneListener(FancyNpcsHook fancyNpcsHook, CityManager cityManager, MayorManager mayorManager) { + this.fancyNpcHook = fancyNpcsHook; + this.cityManager = cityManager; + this.mayorManager = mayorManager; + } @EventHandler public void onUrneInteractEvent(FurnitureInteractEvent event) { if (!Objects.equals(event.getNamespacedID(), "omc_blocks:urne")) return; Player player = event.getPlayer(); - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); Chunk chunk = event.getFurniture().getEntity().getChunk(); - City city = CityManager.getCityFromChunk(chunk.getX(), chunk.getZ()); + City city = cityManager.getCityFromChunk(chunk.getX(), chunk.getZ()); if (playerCity == null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.urne.interact.mysterious"), Prefix.MAYOR, MessageType.INFO, false); @@ -69,12 +79,12 @@ public void onUrneInteractEvent(FurnitureInteractEvent event) { return; } - if (MayorManager.phaseMayor != 1) { + if (mayorManager.phaseMayor != 1) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.urne.interact.election_already"), Prefix.MAYOR, MessageType.INFO, false); return; } - if (MayorManager.cityElections.get(playerCity.getUniqueId()) == null) { + if (mayorManager.cityElections.get(playerCity.getUniqueId()) == null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.urne.interact.no_candidate"), Prefix.MAYOR, MessageType.INFO, true); return; } @@ -95,7 +105,7 @@ public void onUrnePrePlaceEvent(FurniturePrePlaceEvent event) { return; } - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); if (playerCity == null) { event.setCancelled(true); MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.urne.place.need_city"), Prefix.MAYOR, MessageType.WARNING, false); @@ -103,7 +113,7 @@ public void onUrnePrePlaceEvent(FurniturePrePlaceEvent event) { } Chunk placedInChunk = event.getLocation().getChunk(); - City chunkCity = CityManager.getCityFromChunk(placedInChunk.getX(), placedInChunk.getZ()); + City chunkCity = cityManager.getCityFromChunk(placedInChunk.getX(), placedInChunk.getZ()); if (chunkCity == null) { event.setCancelled(true); MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.urne.place.must_be_in_city"), Prefix.MAYOR, MessageType.WARNING, false); @@ -125,7 +135,7 @@ public void onUrnePrePlaceEvent(FurniturePrePlaceEvent event) { return; } - if (NPCManager.hasNPCS(playerCity.getUniqueId())) { + if (mayorManager.mayorNPCManager.hasNPCS(playerCity.getUniqueId())) { event.setCancelled(true); MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.urne.place.already_has_npc"), Prefix.MAYOR, MessageType.ERROR, false); } @@ -134,25 +144,25 @@ public void onUrnePrePlaceEvent(FurniturePrePlaceEvent event) { @EventHandler(ignoreCancelled = true) private void onUrnePlaceSuccessEvent(FurniturePlacedEvent event) { Location urneLocation = event.getFurniture().getEntity().getLocation(); - if (!FancyNpcsHook.isEnable()) + if (!fancyNpcHook.isEnable()) return; if (!"omc_blocks:urne".equals(event.getNamespacedID())) return; Player player = event.getPlayer(); - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); Location locationMayor = LocationUtils.getSafeNearbySurface(urneLocation.clone().add(2, 0, 0), 2); Location locationOwner = LocationUtils.getSafeNearbySurface(urneLocation.clone().add(-2, 0, 0), 2); - if (CityManager.getCityFromChunk(locationMayor.getChunk()) == null) { + if (cityManager.getCityFromChunk(locationMayor.getChunk()) == null) { locationMayor = urneLocation.clone().add(0, 1, 0); } - if (CityManager.getCityFromChunk(locationOwner.getChunk()) == null) { + if (cityManager.getCityFromChunk(locationOwner.getChunk()) == null) { locationOwner = urneLocation.clone().add(0, 1, 0); } - NPCManager.createNPCS(playerCity.getUniqueId(), locationMayor, locationOwner, player.getUniqueId()); + mayorManager.mayorNPCManager.createNPCS(playerCity.getUniqueId(), locationMayor, locationOwner, player.getUniqueId()); } @EventHandler @@ -161,7 +171,7 @@ private void onUrneBreakEvent(FurnitureBreakEvent event) { Player player = event.getPlayer(); - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); if (playerCity == null) { event.setCancelled(true); return; @@ -173,8 +183,8 @@ private void onUrneBreakEvent(FurnitureBreakEvent event) { return; } - if (!FancyNpcsHook.isEnable()) return; + if (!fancyNpcHook.isEnable()) return; - NPCManager.removeNPCS(playerCity.getUniqueId()); + mayorManager.mayorNPCManager.removeNPCS(playerCity.getUniqueId()); } } diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/MayorManager.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/MayorManager.java index 2791a88ba..930dad31c 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/MayorManager.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/MayorManager.java @@ -6,9 +6,7 @@ import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import fr.openmc.api.cooldown.DynamicCooldownManager; -import fr.openmc.core.CommandsManager; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; @@ -19,12 +17,19 @@ import fr.openmc.core.features.city.sub.mayor.listeners.PhaseListener; import fr.openmc.core.features.city.sub.mayor.listeners.UrneListener; import fr.openmc.core.features.city.sub.mayor.models.*; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.city.sub.mayor.perks.basic.*; import fr.openmc.core.features.city.sub.mayor.perks.event.*; import fr.openmc.core.features.city.sub.milestone.rewards.FeaturesRewards; import fr.openmc.core.hooks.FancyNpcsHook; import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.utils.cache.CacheOfflinePlayer; import fr.openmc.core.utils.text.messages.TranslationManager; import lombok.Getter; @@ -39,10 +44,15 @@ import java.time.DayOfWeek; import java.util.*; -public class MayorManager { +public class MayorManager extends Feature implements HasListeners, HasCommands, HasDatabase { @Getter private static ConnectionSource connectionSource; + private final CityManager cityManager; + public final MayorNPCManager mayorNPCManager; + private final FancyNpcsHook fancyNpcsHook; + private final ItemsAdderHook itemsAdderHook; + public static final int MEMBER_REQUEST_ELECTION = 3; private static final List LIST_MAYOR_COLOR = List.of( @@ -63,61 +73,50 @@ public class MayorManager { public static final DayOfWeek PHASE_1_DAY = DayOfWeek.TUESDAY; public static final DayOfWeek PHASE_2_DAY = DayOfWeek.THURSDAY; - public static int phaseMayor; - public static Map cityMayor = new HashMap<>(); - public static final Map cityLaws = new HashMap<>(); - public static Map> cityElections = new HashMap<>(); - public static Map> playerVote = new HashMap<>(); + public int phaseMayor; + public Map cityMayor = new HashMap<>(); + public final Map cityLaws = new HashMap<>(); + public Map> cityElections = new HashMap<>(); + public Map> playerVote = new HashMap<>(); + + private final Random RANDOM = new Random(); - private static final Random RANDOM = new Random(); + public MayorManager(CityManager cityManager, FancyNpcsHook fancyNpcsHook, ItemsAdderHook itemsAdderHook) { + this.cityManager = cityManager; + this.fancyNpcsHook = fancyNpcsHook; + this.itemsAdderHook = itemsAdderHook; + this.mayorNPCManager = new MayorNPCManager(cityManager, fancyNpcsHook); + } - public static void init() { + @Override + public void init() { // LISTENERS new PhaseListener(OMCPlugin.getInstance()); - OMCPlugin.registerEvents( - JoinListener::new, - RagePerk::new, - MinerPerk::new, - MascotFriendlyPerk::new, - DemonFruitPerk::new, - CityHunterPerk::new, - AyweniterPerk::new, - GPSTrackerPerk::new, - SymbiosisPerk::new, - ImpotCollection::new, - AgriculturalEssorPerk::new, - MineralRushPerk::new, - MilitaryDissuasion::new, - IdyllicRain::new); - - if (ItemsAdderHook.isEnable()) { - OMCPlugin.registerEvents( - UrneListener::new); - } - if (FancyNpcsHook.isEnable()) { - OMCPlugin.registerEvents( - NPCManager::new); - } - CommandsManager.getHandler().register( - new MayorCommands(), - new AdminMayorCommands() - ); + this.loadMayorConstant(); + this.loadCityMayors(); + this.loadMayorCandidates(); + this.loadPlayersVote(); + this.loadCityLaws(); + } - loadMayorConstant(); - loadCityMayors(); - loadMayorCandidates(); - loadPlayersVote(); - loadCityLaws(); + @Override + public void save() { + this.saveMayorConstant(); + this.savePlayersVote(); + this.saveMayorCandidates(); + this.saveCityMayors(); + this.saveCityLaws(); } - private static Dao mayorsDao; - private static Dao candidatesDao; - private static Dao votesDao; - private static Dao lawsDao; - private static Dao constantsDao; + private Dao mayorsDao; + private Dao candidatesDao; + private Dao votesDao; + private Dao lawsDao; + private Dao constantsDao; - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, Mayor.class); mayorsDao = DaoManager.createDao(connectionSource, Mayor.class); @@ -136,8 +135,38 @@ public static void initDB(ConnectionSource connectionSource) throws SQLException MayorManager.connectionSource = connectionSource; } + @Override + public Set getCommands() { + return Set.of( + new MayorCommands(), + new AdminMayorCommands() + ); + } + + @Override + public Set getListeners() { + return Set.of( + () -> new JoinListener(cityManager, this), + RagePerk::new, + MinerPerk::new, + MascotFriendlyPerk::new, + DemonFruitPerk::new, + CityHunterPerk::new, + AyweniterPerk::new, + GPSTrackerPerk::new, + SymbiosisPerk::new, + ImpotCollection::new, + AgriculturalEssorPerk::new, + MineralRushPerk::new, + MilitaryDissuasion::new, + IdyllicRain::new, + () -> new UrneListener(fancyNpcsHook, cityManager, this), + () -> this.mayorNPCManager + ); + } + // Load and Save Data Methods - public static void loadMayorConstant() { + public void loadMayorConstant() { try { MayorConstant constant = constantsDao.queryForFirst(); if (constant == null) { @@ -156,7 +185,7 @@ public static void loadMayorConstant() { } } - public static void saveMayorConstant() { + public void saveMayorConstant() { try { if (phaseMayor != 1 && phaseMayor != 2) { phaseMayor = 1; @@ -168,7 +197,7 @@ public static void saveMayorConstant() { } } - public static void loadCityMayors() { + public void loadCityMayors() { try { List mayors = mayorsDao.queryForAll(); @@ -178,7 +207,7 @@ public static void loadCityMayors() { } } - public static void saveCityMayors() { + public void saveCityMayors() { cityMayor.forEach((city, mayor) -> { try { mayorsDao.createOrUpdate(mayor); @@ -188,7 +217,7 @@ public static void saveCityMayors() { }); } - public static void loadMayorCandidates() { + public void loadMayorCandidates() { try { List candidates = candidatesDao.queryForAll(); @@ -200,7 +229,7 @@ public static void loadMayorCandidates() { } } - public static void saveMayorCandidates() { + public void saveMayorCandidates() { cityElections.forEach( (city, candidates) -> candidates.forEach(candidate -> { try { @@ -211,7 +240,7 @@ public static void saveMayorCandidates() { })); } - public static void loadPlayersVote() { + public void loadPlayersVote() { try { votesDao.queryForAll().forEach( vote -> playerVote.computeIfAbsent(vote.getCity().getUniqueId(), k -> new ArrayList<>()).add(vote)); @@ -220,7 +249,7 @@ public static void loadPlayersVote() { } } - public static void savePlayersVote() { + public void savePlayersVote() { playerVote.forEach((city, votes) -> votes.forEach(vote -> { try { votesDao.createOrUpdate(vote); @@ -230,7 +259,7 @@ public static void savePlayersVote() { })); } - public static void loadCityLaws() { + public void loadCityLaws() { try { List laws = lawsDao.queryForAll(); @@ -240,7 +269,7 @@ public static void loadCityLaws() { } } - public static void saveCityLaws() { + public void saveCityLaws() { cityLaws.forEach((city, law) -> { try { lawsDao.createOrUpdate(law); @@ -250,7 +279,7 @@ public static void saveCityLaws() { }); } - public static void removeCity(City city) throws SQLException { + public void removeCity(City city) throws SQLException { DeleteBuilder mayorsDelete = mayorsDao.deleteBuilder(); mayorsDelete.where().eq("city_uuid", city.getUniqueId()); mayorsDao.delete(mayorsDelete.prepare()); @@ -273,7 +302,7 @@ public static void removeCity(City city) throws SQLException { } // setup elections - public static void initPhase1() { + public void initPhase1() { // ---OUVERTURE DES ELECTIONS--- phaseMayor = 1; @@ -304,34 +333,34 @@ public static void initPhase1() { cityMayor = new HashMap<>(); cityElections = new HashMap<>(); playerVote = new HashMap<>(); - for (City city : CityManager.getCities()) { + for (City city : cityManager.getCities()) { if (!FeaturesRewards.hasUnlockFeature(city, FeaturesRewards.Feature.MAYOR)) continue; initCityPhase1(city, copyCityMayor); } - NPCManager.updateAllNPCS(); + mayorNPCManager.updateAllNPCS(); Bukkit.broadcast(TranslationManager.translation("feature.city.mayor.broadcast.phase1")); } - public static void initPhase2() { + public void initPhase2() { OMCLogger.debug("MAYOR - INIT PHASE 2"); phaseMayor = 2; // TRAITEMENT DE CHAQUE VILLE - Complexité de O(n log(n)) - for (City city : CityManager.getCities()) { + for (City city : cityManager.getCities()) { if (!FeaturesRewards.hasUnlockFeature(city, FeaturesRewards.Feature.MAYOR)) continue; initCityPhase2(city); } - NPCManager.updateAllNPCS(); + mayorNPCManager.updateAllNPCS(); Bukkit.broadcast(TranslationManager.translation("feature.city.mayor.broadcast.phase2")); } - public static void initCityPhase1(City city, Map copyCityMayor) { + public void initCityPhase1(City city, Map copyCityMayor) { // PERKS INIT if (copyCityMayor != null) { for (UUID uuid : city.getMembers()) { @@ -344,23 +373,23 @@ public static void initCityPhase1(City city, Map copyCityMayor) { Mayor oldMayor = copyCityMayor.get(city.getUniqueId()); // Fou de Rage - if (PerkManager.hasPerk(oldMayor, Perks.FOU_DE_RAGE.getId())) { + if (PerkUtils.hasPerk(oldMayor, Perks.FOU_DE_RAGE.getId())) { player.removePotionEffect(PotionEffectType.STRENGTH); player.removePotionEffect(PotionEffectType.RESISTANCE); } // Mineur Dévoué - if (PerkManager.hasPerk(oldMayor, Perks.MINER.getId())) { + if (PerkUtils.hasPerk(oldMayor, Perks.MINER.getId())) { MinerPerk.updatePlayerEffects(player); } // Mascotte de Compagnie - if (PerkManager.hasPerk(oldMayor, Perks.MASCOTS_FRIENDLY.getId())) { + if (PerkUtils.hasPerk(oldMayor, Perks.MASCOTS_FRIENDLY.getId())) { MascotFriendlyPerk.updatePlayerEffects(player); } // Fruit du Démon - if (PerkManager.hasPerk(oldMayor, Perks.FRUIT_DEMON.getId())) { + if (PerkUtils.hasPerk(oldMayor, Perks.FRUIT_DEMON.getId())) { DemonFruitPerk.removeReachBonus(player); } } @@ -373,7 +402,7 @@ public static void initCityPhase1(City city, Map copyCityMayor) { createMayor(null, null, city, null, null, null, null, ElectionType.OWNER_CHOOSE); } - public static void initCityPhase2(City city) { + public void initCityPhase2(City city) { OMCLogger.debug("- City : {}", city.getName()); runSetupMayor(city); @@ -383,23 +412,23 @@ public static void initCityPhase2(City city) { Player player = offlinePlayer.getPlayer(); if (player == null) continue; // Mineur Dévoué - if (PerkManager.hasPerk(city.getMayor(), Perks.MINER.getId())) { + if (PerkUtils.hasPerk(city.getMayor(), Perks.MINER.getId())) { MinerPerk.updatePlayerEffects(player); } // Mascotte de Compagnie - if (PerkManager.hasPerk(city.getMayor(), Perks.MASCOTS_FRIENDLY.getId())) { + if (PerkUtils.hasPerk(city.getMayor(), Perks.MASCOTS_FRIENDLY.getId())) { MascotFriendlyPerk.updatePlayerEffects(player); } // Fruit du Démon - if (PerkManager.hasPerk(city.getMayor(), Perks.FRUIT_DEMON.getId())) { + if (PerkUtils.hasPerk(city.getMayor(), Perks.FRUIT_DEMON.getId())) { DemonFruitPerk.applyReachBonus(player); } // Fou de Rage - if (PerkManager.hasPerk(city.getMayor(), Perks.FOU_DE_RAGE.getId())) { - City locCity = CityManager.getCityFromChunk(player.getLocation().getChunk()); + if (PerkUtils.hasPerk(city.getMayor(), Perks.FOU_DE_RAGE.getId())) { + City locCity = cityManager.getCityFromChunk(player.getLocation().getChunk()); RagePerk.updateEffect(locCity, player); } } @@ -411,7 +440,7 @@ public static void initCityPhase2(City city) { * * @param city The city to update mayor */ - public static void runSetupMayor(City city) { + public void runSetupMayor(City city) { UUID ownerUUID = city.getPlayerWithPermission(CityPermission.OWNER); String ownerName = CacheOfflinePlayer.getOfflinePlayer(ownerUUID).getName(); Mayor mayor = city.getMayor(); @@ -420,7 +449,7 @@ public static void runSetupMayor(City city) { // si maire n'a pas choisis les perks if ((mayor.getIdPerk1() == 0) && (mayor.getIdPerk2() == 0) && (mayor.getIdPerk3() == 0)) { NamedTextColor color = getRandomMayorColor(); - List perks = PerkManager.getRandomPerksAll(city); + List perks = PerkUtils.getRandomPerksAll(city); if (perks.size() < 3) { OMCLogger.warn( "No unlocked mayor perks combination found for city {} (OWNER_CHOOSE)", @@ -445,12 +474,12 @@ public static void runSetupMayor(City city) { Perks perk1; if (mayor == null || (mayor.getIdPerk1() == 0)) { - perk1 = PerkManager.getRandomPerkEvent(city); + perk1 = PerkUtils.getRandomPerkEvent(city); } else { - perk1 = PerkManager.getPerkById(mayor.getIdPerk1()); + perk1 = PerkUtils.getPerkById(mayor.getIdPerk1()); } - Perks perk2 = PerkManager.getPerkById(electedMayor.getIdChoicePerk2()); - Perks perk3 = PerkManager.getPerkById(electedMayor.getIdChoicePerk3()); + Perks perk2 = PerkUtils.getPerkById(electedMayor.getIdChoicePerk2()); + Perks perk3 = PerkUtils.getPerkById(electedMayor.getIdChoicePerk3()); createMayor(electedMayor.getName(), electedMayor.getCandidateUUID(), city, perk1, perk2, perk3, electedMayor.getCandidateColor(), ElectionType.ELECTION); @@ -458,12 +487,12 @@ public static void runSetupMayor(City city) { } else { // personne s'est présenté, owner = maire NamedTextColor color = getRandomMayorColor(); - List perks = PerkManager.getRandomPerksBasic(city); + List perks = PerkUtils.getRandomPerksBasic(city); Perks perk1; if (mayor == null || (mayor.getIdPerk1() == 0)) { - perk1 = PerkManager.getRandomPerkEvent(city); + perk1 = PerkUtils.getRandomPerkEvent(city); } else { - perk1 = PerkManager.getPerkById(mayor.getIdPerk1()); + perk1 = PerkUtils.getPerkById(mayor.getIdPerk1()); } if (perk1 == null || perks.size() < 2) { @@ -506,7 +535,7 @@ public static void runSetupMayor(City city) { * @param city The city to add a candidate * @param candidate The candidate to add */ - public static void createCandidate(City city, MayorCandidate candidate) { + public void createCandidate(City city, MayorCandidate candidate) { List candidates = cityElections.computeIfAbsent(city.getUniqueId(), key -> new ArrayList<>()); candidates.add(candidate); @@ -517,7 +546,7 @@ public static void createCandidate(City city, MayorCandidate candidate) { * * @param playerUUID The playerUUID to get a candidate */ - public static MayorCandidate getCandidate(UUID playerUUID) { + public MayorCandidate getCandidate(UUID playerUUID) { for (List candidates : cityElections.values()) { for (MayorCandidate candidate : candidates) { if (candidate.getCandidateUUID().equals(playerUUID)) { @@ -534,8 +563,8 @@ public static MayorCandidate getCandidate(UUID playerUUID) { * * @param player The player to check */ - public static boolean hasCandidated(Player player) { - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + public boolean hasCandidated(Player player) { + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); if (cityElections.get(playerCity.getUniqueId()) == null) return false; @@ -550,7 +579,7 @@ public static boolean hasCandidated(Player player) { * * @param player The player to remove a vote */ - public static void removeVotePlayer(Player player) { + public void removeVotePlayer(Player player) { playerVote.forEach((city, votes) -> votes.removeIf(vote -> vote.getVoter().equals(player.getUniqueId()))); } @@ -561,7 +590,7 @@ public static void removeVotePlayer(Player player) { * @param player The player who votes * @param candidate The candidate to vote */ - public static void voteCandidate(City playerCity, Player player, MayorCandidate candidate) { + public void voteCandidate(City playerCity, Player player, MayorCandidate candidate) { candidate.setVote(candidate.getVote() + 1); List votes = playerVote.computeIfAbsent(playerCity.getUniqueId(), key -> new ArrayList<>()); @@ -573,8 +602,8 @@ public static void voteCandidate(City playerCity, Player player, MayorCandidate * * @param player The player to check */ - public static boolean hasVoted(Player player) { - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + public boolean hasVoted(Player player) { + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); if (playerVote.get(playerCity.getUniqueId()) == null) return false; @@ -589,7 +618,7 @@ public static boolean hasVoted(Player player) { * * @param player The player to get a vote */ - public static MayorCandidate getPlayerVote(Player player) { + public MayorCandidate getPlayerVote(Player player) { for (List votes : playerVote.values()) { for (MayorVote vote : votes) { if (vote.getVoter().equals(player.getUniqueId())) { @@ -606,8 +635,8 @@ public static MayorCandidate getPlayerVote(Player player) { * * @param player The player to check */ - public static boolean hasChoicePerkOwner(Player player) { - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + public boolean hasChoicePerkOwner(Player player) { + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); Mayor mayor = cityMayor.get(playerCity.getUniqueId()); if (mayor == null) @@ -622,7 +651,7 @@ public static boolean hasChoicePerkOwner(Player player) { * @param city The city to set perk * @param perk1 The perk to set */ - public static void put1Perk(City city, Perks perk1) { + public void put1Perk(City city, Perks perk1) { Mayor mayor = cityMayor.get(city.getUniqueId()); if (mayor != null) { mayor.setIdPerk1(perk1.getId()); @@ -644,7 +673,7 @@ public static void put1Perk(City city, Perks perk1) { * @param color The color of the mayor * @param type The type of the election */ - public static void createMayor(String playerName, UUID playerUUID, City city, Perks perk1, Perks perk2, Perks perk3, + public void createMayor(String playerName, UUID playerUUID, City city, Perks perk1, Perks perk2, Perks perk3, NamedTextColor color, ElectionType type) { Mayor mayor = cityMayor.get(city.getUniqueId()); int idPerk1 = perk1 != null ? perk1.getId() : 0; @@ -668,7 +697,7 @@ public static void createMayor(String playerName, UUID playerUUID, City city, Pe /** * Get random mayor color from the list. */ - public static NamedTextColor getRandomMayorColor() { + public NamedTextColor getRandomMayorColor() { return LIST_MAYOR_COLOR.get(RANDOM.nextInt(LIST_MAYOR_COLOR.size())); } @@ -679,7 +708,7 @@ public static NamedTextColor getRandomMayorColor() { * @param pvp The pvp of the city * @param locationWarp The warp location of the city */ - public static void createCityLaws(City city, boolean pvp, Location locationWarp) { + public void createCityLaws(City city, boolean pvp, Location locationWarp) { CityLaw laws = city.getLaw(); if (laws != null) { laws.setPvp(pvp); diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/NPCManager.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/MayorNPCManager.java similarity index 89% rename from src/main/java/fr/openmc/core/features/city/sub/mayor/managers/NPCManager.java rename to src/main/java/fr/openmc/core/features/city/sub/mayor/managers/MayorNPCManager.java index cdccfd85d..63af54946 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/NPCManager.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/MayorNPCManager.java @@ -18,6 +18,7 @@ import fr.openmc.core.features.city.sub.mayor.npcs.OwnerNPC; import fr.openmc.core.features.city.sub.milestone.rewards.FeaturesRewards; import fr.openmc.core.hooks.FancyNpcsHook; +import fr.openmc.core.lifecycle.interfaces.LoadIfEnable; import fr.openmc.core.utils.cache.CacheOfflinePlayer; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -40,17 +41,23 @@ import java.util.*; -public class NPCManager implements Listener { +public class MayorNPCManager implements Listener, LoadIfEnable { private static final HashMap ownerNpcMap = new HashMap<>(); private static final HashMap mayorNpcMap = new HashMap<>(); - public NPCManager() { + private final CityManager cityManager; + private final FancyNpcsHook fancyNpcsHook; + + public MayorNPCManager(CityManager cityManager, FancyNpcsHook fancyNpcsHook) { + this.fancyNpcsHook = fancyNpcsHook; + this.cityManager = cityManager; + // fetch les npcs apres 30 secondes le temps que fancy npc s'initialise. Bukkit.getScheduler().runTaskLater(OMCPlugin.getInstance(), () -> { FancyNpcsPlugin.get().getNpcManager().getAllNpcs().forEach(npc -> { if (npc.getData().getName().startsWith("owner-")) { UUID cityUUID = UUID.fromString(npc.getData().getName().replace("owner-", "")); - if (CityManager.getCity(cityUUID) != null) { + if (cityManager.getCity(cityUUID) != null) { ownerNpcMap.put(cityUUID, new OwnerNPC(npc, cityUUID, npc.getData().getLocation())); } else { FancyNpcsPlugin.get().getNpcManager().removeNpc(npc); @@ -58,7 +65,7 @@ public NPCManager() { } } else if (npc.getData().getName().startsWith("mayor-")) { UUID cityUUID = UUID.fromString(npc.getData().getName().replace("mayor-", "")); - if (CityManager.getCity(cityUUID) != null) { + if (cityManager.getCity(cityUUID) != null) { mayorNpcMap.put(cityUUID, new MayorNPC(npc, cityUUID, npc.getData().getLocation())); } else { FancyNpcsPlugin.get().getNpcManager().removeNpc(npc); @@ -69,11 +76,10 @@ public NPCManager() { }, 20L * 30); } - public static void createNPCS(UUID cityUUID, Location locationMayor, Location locationOwner, UUID creatorUUID) { - if (!FancyNpcsHook.isEnable()) return; - + public void createNPCS(UUID cityUUID, Location locationMayor, Location locationOwner, UUID creatorUUID) { + if (!fancyNpcsHook.isEnable()) return; - City city = CityManager.getCity(cityUUID); + City city = cityManager.getCity(cityUUID); if (city == null) return; NpcData dataMayor = new NpcData("mayor-" + cityUUID, creatorUUID, locationMayor); @@ -119,8 +125,8 @@ public static void createNPCS(UUID cityUUID, Location locationMayor, Location lo npcOwner.spawnForAll(); } - public static void removeNPCS(UUID cityUUID) { - if (!FancyNpcsHook.isEnable()) return; + public void removeNPCS(UUID cityUUID) { + if (!fancyNpcsHook.isEnable()) return; if (!ownerNpcMap.containsKey(cityUUID) || !mayorNpcMap.containsKey(cityUUID)) return; Npc ownerNpc = ownerNpcMap.remove(cityUUID).getNpc(); @@ -133,23 +139,23 @@ public static void removeNPCS(UUID cityUUID) { mayorNpc.removeForAll(); } - public static void updateNPCS(UUID cityUUID) { - if (!FancyNpcsHook.isEnable()) return; + public void updateNPCS(UUID cityUUID) { + if (!fancyNpcsHook.isEnable()) return; OwnerNPC ownerNPC = ownerNpcMap.get(cityUUID); MayorNPC mayorNPC = mayorNpcMap.get(cityUUID); if (ownerNPC == null || mayorNPC == null) return; - City city = CityManager.getCity(cityUUID); + City city = cityManager.getCity(cityUUID); if (city == null) return; removeNPCS(cityUUID); createNPCS(cityUUID, mayorNPC.getLocation(), ownerNPC.getLocation(), ownerNPC.getNpc().getData().getCreator()); } - public static void updateAllNPCS() { - if (!FancyNpcsHook.isEnable()) return; + public void updateAllNPCS() { + if (!fancyNpcsHook.isEnable()) return; Set cityUUIDs = new HashSet<>(ownerNpcMap.keySet()); // Copie @@ -159,7 +165,7 @@ public static void updateAllNPCS() { if (ownerNPC == null || mayorNPC == null) continue; - City city = CityManager.getCity(cityUUID); + City city = cityManager.getCity(cityUUID); if (city == null) continue; removeNPCS(cityUUID); @@ -167,8 +173,8 @@ public static void updateAllNPCS() { } } - public static void moveNPC(String type, Location location, UUID cityUUID) { - if (!FancyNpcsHook.isEnable()) return; + public void moveNPC(String type, Location location, UUID cityUUID) { + if (!fancyNpcsHook.isEnable()) return; if (type.equalsIgnoreCase("owner")) { OwnerNPC ownerNPC = ownerNpcMap.get(cityUUID); @@ -185,15 +191,15 @@ public static void moveNPC(String type, Location location, UUID cityUUID) { } } - public static boolean hasNPCS(UUID cityUUID) { - if (!FancyNpcsHook.isEnable()) return false; + public boolean hasNPCS(UUID cityUUID) { + if (!fancyNpcsHook.isEnable()) return false; return ownerNpcMap.containsKey(cityUUID) && mayorNpcMap.containsKey(cityUUID); } @EventHandler public void onInteractWithMayorNPC(NpcInteractEvent event) { - if (!FancyNpcsHook.isEnable()) return; + if (!fancyNpcsHook.isEnable()) return; Player player = event.getPlayer(); @@ -201,7 +207,7 @@ public void onInteractWithMayorNPC(NpcInteractEvent event) { if (npc.getData().getName().startsWith("mayor-")) { UUID cityUUID = UUID.fromString(npc.getData().getName().replace("mayor-", "")); - City city = CityManager.getCity(cityUUID); + City city = cityManager.getCity(cityUUID); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.error.not_in_city"), Prefix.MAYOR, MessageType.ERROR, false); removeNPCS(cityUUID); @@ -226,7 +232,7 @@ public void onInteractWithMayorNPC(NpcInteractEvent event) { return; } - if (MayorManager.phaseMayor == 1) { + if (cityManager.MAYOR.phaseMayor == 1) { if (!event.getPlayer().getUniqueId().equals(city.getPlayerWithPermission(CityPermission.OWNER))) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.npc.info.no_mayor_yet"), Prefix.MAYOR, MessageType.INFO, true); return; @@ -255,13 +261,13 @@ public void onInteractWithMayorNPC(NpcInteractEvent event) { Chunk chunk = locationClick.getChunk(); - City cityByChunk = CityManager.getCityFromChunk(chunk.getX(), chunk.getZ()); + City cityByChunk = cityManager.getCityFromChunk(chunk.getX(), chunk.getZ()); if (cityByChunk == null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.npc.move.error.outside_city"), Prefix.CITY, MessageType.ERROR, false); return false; } - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); if (playerCity == null) { return false; @@ -272,8 +278,8 @@ public void onInteractWithMayorNPC(NpcInteractEvent event) { return false; } - NPCManager.moveNPC("mayor", locationClick, city.getUniqueId()); - NPCManager.updateNPCS(city.getUniqueId()); + this.moveNPC("mayor", locationClick, city.getUniqueId()); + this.updateNPCS(city.getUniqueId()); return true; }, null @@ -295,7 +301,7 @@ public void onInteractWithMayorNPC(NpcInteractEvent event) { new MayorNpcMenu(player, city).open(); } else if (npc.getData().getName().startsWith("owner-")) { UUID cityUUID = UUID.fromString(npc.getData().getName().replace("owner-", "")); - City city = CityManager.getCity(cityUUID); + City city = cityManager.getCity(cityUUID); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.error.not_in_city"), Prefix.MAYOR, MessageType.ERROR, false); removeNPCS(cityUUID); @@ -318,7 +324,7 @@ public void onInteractWithMayorNPC(NpcInteractEvent event) { return; } - if (MayorManager.phaseMayor == 1) { + if (cityManager.MAYOR.phaseMayor == 1) { if (!event.getPlayer().getUniqueId().equals(city.getPlayerWithPermission(CityPermission.OWNER))) return; Component message = TranslationManager.translation("feature.city.mayor.npc.move.prompt") @@ -344,13 +350,13 @@ public void onInteractWithMayorNPC(NpcInteractEvent event) { Chunk chunk = locationClick.getChunk(); - City cityByChunk = CityManager.getCityFromChunk(chunk.getX(), chunk.getZ()); + City cityByChunk = cityManager.getCityFromChunk(chunk.getX(), chunk.getZ()); if (cityByChunk == null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.npc.move.error.outside_city"), Prefix.CITY, MessageType.ERROR, false); return false; } - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); if (playerCity == null) { return false; @@ -361,8 +367,8 @@ public void onInteractWithMayorNPC(NpcInteractEvent event) { return false; } - NPCManager.moveNPC("owner", locationClick, city.getUniqueId()); - NPCManager.updateNPCS(city.getUniqueId()); + this.moveNPC("owner", locationClick, city.getUniqueId()); + this.updateNPCS(city.getUniqueId()); return true; }, null diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorElectionMenu.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorElectionMenu.java index b5756bd6f..e35bec60c 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorElectionMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorElectionMenu.java @@ -10,10 +10,10 @@ import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; import fr.openmc.core.features.city.sub.mayor.menu.create.MayorCreateMenu; import fr.openmc.core.features.city.sub.mayor.menu.create.MayorModifyMenu; import fr.openmc.core.features.city.sub.mayor.menu.create.MenuType; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.utils.bukkit.SkullUtils; import fr.openmc.core.utils.text.DateUtils; @@ -121,7 +121,7 @@ public void onClose(InventoryCloseEvent event) { if (hasPermissionOwner) { List lorePerkOwner; if (MayorManager.hasChoicePerkOwner(player)) { - Perks perk1 = PerkManager.getPerkById(city.getMayor().getIdPerk1()); + Perks perk1 = PerkUtils.getPerkById(city.getMayor().getIdPerk1()); if (perk1 == null) return Map.of(); lorePerkOwner = new ArrayList<>(List.of( TranslationManager.translation("feature.city.mayor.menu.election.owner_reform.lore.chosen") diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorLawMenu.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorLawMenu.java index 127d64d55..1bb9b5cbb 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorLawMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorLawMenu.java @@ -8,12 +8,12 @@ import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.api.menulib.utils.MenuUtils; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.mayor.actions.MayorSetWarpAction; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; import fr.openmc.core.features.city.sub.mayor.models.CityLaw; import fr.openmc.core.features.city.sub.mayor.models.Mayor; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.city.sub.mayor.perks.event.IdyllicRain; import fr.openmc.core.features.city.sub.mayor.perks.event.ImpotCollection; @@ -83,7 +83,7 @@ public void onClose(InventoryCloseEvent event) { Map inventory = new HashMap<>(); Player player = getOwner(); - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); Mayor mayor = city.getMayor(); CityLaw law = city.getLaw(); @@ -273,8 +273,8 @@ public void onClose(InventoryCloseEvent event) { MenuUtils.runDynamicItem(player, this, 23, announceItemSupplier) .runTaskTimer(OMCPlugin.getInstance(), 0L, 20L); - Perks perkEvent = PerkManager.getPerkEvent(mayor); - if (PerkManager.getPerkEvent(mayor) != null) { + Perks perkEvent = PerkUtils.getPerkEvent(mayor); + if (PerkUtils.getPerkEvent(mayor) != null) { Supplier perkEventItemSupplier = () -> { ItemStack iaPerkEvent = perkEvent.getItemStack(); Component namePerkEvent = TranslationManager.translation(perkEvent.getNameKey()); @@ -311,7 +311,7 @@ public void onClose(InventoryCloseEvent event) { } // Prélévement d'impot (id : 2) - Perk Event - if (PerkManager.hasPerk(city.getMayor(), Perks.IMPOT.getId())) { + if (PerkUtils.hasPerk(city.getMayor(), Perks.IMPOT.getId())) { for (UUID uuid : city.getMembers()) { if (uuid == city.getMayor().getMayorUUID()) continue; @@ -325,8 +325,8 @@ public void onClose(InventoryCloseEvent event) { MessagesManager.sendMessage(member, TranslationManager.translation("feature.city.mayor.menu.law.perk_event.impot.trigger"), Prefix.MAYOR, MessageType.INFO, false); } - DynamicCooldownManager.use(mayor.getMayorUUID(), "mayor:law-perk-event", PerkManager.getPerkEvent(mayor).getCooldown()); - } else if (PerkManager.hasPerk(city.getMayor(), Perks.AGRICULTURAL_ESSOR.getId())) { + DynamicCooldownManager.use(mayor.getMayorUUID(), "mayor:law-perk-event", PerkUtils.getPerkEvent(mayor).getCooldown()); + } else if (PerkUtils.hasPerk(city.getMayor(), Perks.AGRICULTURAL_ESSOR.getId())) { // Essor agricole (id : 11) - Perk Event for (UUID uuid : city.getMembers()) { Player member = Bukkit.getPlayer(uuid); @@ -337,8 +337,8 @@ public void onClose(InventoryCloseEvent event) { } DynamicCooldownManager.use(city.getUniqueId(), "city:agricultural_essor", 30 * 60 * 1000L); // 30 minutes - DynamicCooldownManager.use(mayor.getMayorUUID(), "mayor:law-perk-event", PerkManager.getPerkEvent(mayor).getCooldown()); - } else if (PerkManager.hasPerk(city.getMayor(), Perks.MINERAL_RUSH.getId())) { + DynamicCooldownManager.use(mayor.getMayorUUID(), "mayor:law-perk-event", PerkUtils.getPerkEvent(mayor).getCooldown()); + } else if (PerkUtils.hasPerk(city.getMayor(), Perks.MINERAL_RUSH.getId())) { // Ruée Miniere (id : 12) - Perk Event for (UUID uuid : city.getMembers()) { Player member = Bukkit.getPlayer(uuid); @@ -349,8 +349,8 @@ public void onClose(InventoryCloseEvent event) { } DynamicCooldownManager.use(city.getUniqueId(), "city:mineral_rush", 5 * 60 * 1000L); // 5 minutes - DynamicCooldownManager.use(mayor.getMayorUUID(), "mayor:law-perk-event", PerkManager.getPerkEvent(mayor).getCooldown()); - } else if (PerkManager.hasPerk(city.getMayor(), Perks.MILITARY_DISSUASION.getId())) { + DynamicCooldownManager.use(mayor.getMayorUUID(), "mayor:law-perk-event", PerkUtils.getPerkEvent(mayor).getCooldown()); + } else if (PerkUtils.hasPerk(city.getMayor(), Perks.MILITARY_DISSUASION.getId())) { // Dissuasion Militaire (id: 13) - Perk Event for (UUID uuid : city.getMembers()) { Player member = Bukkit.getPlayer(uuid); @@ -362,7 +362,7 @@ public void onClose(InventoryCloseEvent event) { MilitaryDissuasion.startEvent(city, 10); DynamicCooldownManager.use(city.getUniqueId(), "city:military_dissuasion", 10 * 60 * 1000L); // 10 minutes - DynamicCooldownManager.use(mayor.getMayorUUID(), "mayor:law-perk-event", PerkManager.getPerkEvent(mayor).getCooldown()); + DynamicCooldownManager.use(mayor.getMayorUUID(), "mayor:law-perk-event", PerkUtils.getPerkEvent(mayor).getCooldown()); new BukkitRunnable() { @Override @@ -373,7 +373,7 @@ public void run() { } } }.runTaskTimer(OMCPlugin.getInstance(), 20L, 100L); - } else if (PerkManager.hasPerk(city.getMayor(), Perks.IDYLLIC_RAIN.getId())) { + } else if (PerkUtils.hasPerk(city.getMayor(), Perks.IDYLLIC_RAIN.getId())) { // Pluie idyllique (id : 14) - Perk Event for (UUID uuid : city.getMembers()) { Player member = Bukkit.getPlayer(uuid); @@ -386,8 +386,8 @@ public void run() { // spawn d'un total de 100 aywenite progressivement sur une minute IdyllicRain.spawnAywenite(city, 100); - DynamicCooldownManager.use(mayor.getMayorUUID(), "mayor:law-perk-event", PerkManager.getPerkEvent(mayor).getCooldown()); - } else if (PerkManager.hasPerk(city.getMayor(), Perks.CHAOS_DREAM.getId())) { + DynamicCooldownManager.use(mayor.getMayorUUID(), "mayor:law-perk-event", PerkUtils.getPerkEvent(mayor).getCooldown()); + } else if (PerkUtils.hasPerk(city.getMayor(), Perks.CHAOS_DREAM.getId())) { // Reve chaotique (id: 18) - Perk Event for (UUID uuid : city.getMembers()) { Player member = Bukkit.getPlayer(uuid); @@ -405,7 +405,7 @@ public void run() { DreamManager.tpPlayerToLastDreamLocation(player); } } - DynamicCooldownManager.use(mayor.getMayorUUID(), "mayor:law-perk-event", PerkManager.getPerkEvent(mayor).getCooldown()); + DynamicCooldownManager.use(mayor.getMayorUUID(), "mayor:law-perk-event", PerkUtils.getPerkEvent(mayor).getCooldown()); } }); }; diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorMandateMenu.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorMandateMenu.java index 741710546..5f41a14db 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorMandateMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorMandateMenu.java @@ -7,8 +7,8 @@ import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; import fr.openmc.core.features.city.sub.mayor.models.Mayor; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.utils.bukkit.SkullUtils; import fr.openmc.core.utils.cache.CacheOfflinePlayer; @@ -67,9 +67,9 @@ public void onClose(InventoryCloseEvent event) { City city = CityManager.getPlayerCity(player.getUniqueId()); Mayor mayor = city.getMayor(); - Perks perk1 = PerkManager.getPerkById(mayor.getIdPerk1()); - Perks perk2 = PerkManager.getPerkById(mayor.getIdPerk2()); - Perks perk3 = PerkManager.getPerkById(mayor.getIdPerk3()); + Perks perk1 = PerkUtils.getPerkById(mayor.getIdPerk1()); + Perks perk2 = PerkUtils.getPerkById(mayor.getIdPerk2()); + Perks perk3 = PerkUtils.getPerkById(mayor.getIdPerk3()); List loreMayor = new ArrayList<>(List.of( TranslationManager.translation( diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorVoteMenu.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorVoteMenu.java index 785018e49..58719c5e5 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorVoteMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/MayorVoteMenu.java @@ -9,8 +9,8 @@ import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; import fr.openmc.core.features.city.sub.mayor.models.MayorCandidate; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.utils.bukkit.SkullUtils; import fr.openmc.core.utils.text.messages.MessageType; @@ -70,8 +70,8 @@ public List getItems() { int totalVotes = city.getMembers().size(); for (MayorCandidate candidate : MayorManager.cityElections.get(city.getUniqueId())) { - Perks perk2 = PerkManager.getPerkById(candidate.getIdChoicePerk2()); - Perks perk3 = PerkManager.getPerkById(candidate.getIdChoicePerk3()); + Perks perk2 = PerkUtils.getPerkById(candidate.getIdChoicePerk2()); + Perks perk3 = PerkUtils.getPerkById(candidate.getIdChoicePerk3()); NamedTextColor color = candidate.getCandidateColor(); int vote = candidate.getVote(); diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/create/MayorColorMenu.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/create/MayorColorMenu.java index 1aa0a8579..0a0965ed5 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/create/MayorColorMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/create/MayorColorMenu.java @@ -5,6 +5,7 @@ import fr.openmc.api.menulib.template.ConfirmMenu; import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.mayor.ElectionType; @@ -73,8 +74,10 @@ public void onClose(InventoryCloseEvent event) { public @NotNull Map getContent() { Map inventory = new HashMap<>(); Player player = getOwner(); + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); + MayorManager mayorManager = cityManager.MAYOR; - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = cityManager.getPlayerCity(player.getUniqueId()); Map colorSlot = new HashMap<>(); { colorSlot.put(NamedTextColor.RED, 12); @@ -132,7 +135,7 @@ public void onClose(InventoryCloseEvent event) { try { if (menuType == MenuType.CANDIDATE) { MayorCandidate candidate = new MayorCandidate(city.getUniqueId(), player.getName(), player.getUniqueId(), color, perk2.getId(), perk3.getId(), 0); - MayorManager.createCandidate(city, candidate); + mayorManager.createCandidate(city, candidate); for (UUID uuid : city.getMembers()) { OfflinePlayer playerMember = CacheOfflinePlayer.getOfflinePlayer(uuid); @@ -146,7 +149,7 @@ public void onClose(InventoryCloseEvent event) { } } } else { // donc si c MenuType.OWNER - MayorManager.createMayor(player.getName(), player.getUniqueId(), city, perk1, perk2, perk3, color, city.getElectionType()); + mayorManager.createMayor(player.getName(), player.getUniqueId(), city, perk1, perk2, perk3, color, city.getElectionType()); } MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.menu.color.candidate.success"), Prefix.MAYOR, MessageType.ERROR, false); player.closeInventory(); @@ -195,7 +198,7 @@ public void onClose(InventoryCloseEvent event) { ); menu.open(); } else { - MayorCandidate mayorCandidate = MayorManager.getCandidate(player.getUniqueId()); + MayorCandidate mayorCandidate = mayorManager.getCandidate(player.getUniqueId()); NamedTextColor thisColor = mayorCandidate.getCandidateColor(); Component fromColor = TranslationManager.translation("feature.city.mayor.label.color") .decoration(TextDecoration.ITALIC, false).color(thisColor); diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/create/MayorCreateMenu.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/create/MayorCreateMenu.java index af0482c8c..872bf0614 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/create/MayorCreateMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/create/MayorCreateMenu.java @@ -232,7 +232,9 @@ public void onClose(InventoryCloseEvent event) { }).setOnClick(_ -> { if (canConfirmPerk) { if (type == MenuType.OWNER_1) { - MayorManager.put1Perk(CityManager.getPlayerCity(player.getUniqueId()), perk1); + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); + MayorManager mayorManager = cityManager.MAYOR; + mayorManager.put1Perk(cityManager.getPlayerCity(player.getUniqueId()), perk1); MessagesManager.sendMessage(player, TranslationManager.translation( "feature.city.mayor.menu.create.confirm.owner.success", TranslationManager.translation(perk1.getNameKey()) diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/create/MayorModifyMenu.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/create/MayorModifyMenu.java index aea75af2e..2d31a81ca 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/create/MayorModifyMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/create/MayorModifyMenu.java @@ -5,8 +5,8 @@ import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; import fr.openmc.core.features.city.sub.mayor.models.MayorCandidate; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.utils.text.ColorUtils; import fr.openmc.core.utils.text.messages.TranslationManager; @@ -57,8 +57,8 @@ public void onClose(InventoryCloseEvent event) { Player player = getOwner(); MayorCandidate mayorCandidate = MayorManager.getCandidate(player.getUniqueId()); - Perks perk2 = PerkManager.getPerkById(mayorCandidate.getIdChoicePerk2()); - Perks perk3 = PerkManager.getPerkById(mayorCandidate.getIdChoicePerk3()); + Perks perk2 = PerkUtils.getPerkById(mayorCandidate.getIdChoicePerk2()); + Perks perk3 = PerkUtils.getPerkById(mayorCandidate.getIdChoicePerk3()); assert perk2 != null; inventory.put(20, new ItemMenuBuilder(this, perk2.getItemStack(), itemMeta -> { diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/npc/MayorNpcMenu.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/npc/MayorNpcMenu.java index 7817372ed..f5131be37 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/npc/MayorNpcMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/npc/MayorNpcMenu.java @@ -5,12 +5,12 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; -import fr.openmc.core.features.city.sub.mayor.managers.NPCManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; import fr.openmc.core.features.city.sub.mayor.models.Mayor; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.utils.bukkit.SkullUtils; import fr.openmc.core.utils.text.messages.MessageType; @@ -73,8 +73,8 @@ public void onClose(InventoryCloseEvent event) { Mayor mayor = city.getMayor(); - Perks perk2 = PerkManager.getPerkById(mayor.getIdPerk2()); - Perks perk3 = PerkManager.getPerkById(mayor.getIdPerk3()); + Perks perk2 = PerkUtils.getPerkById(mayor.getIdPerk2()); + Perks perk3 = PerkUtils.getPerkById(mayor.getIdPerk3()); List loreMayor = new ArrayList<>(List.of( TranslationManager.translation( @@ -140,13 +140,14 @@ public void onClose(InventoryCloseEvent event) { Chunk chunk = locationClick.getChunk(); - City cityByChunk = CityManager.getCityFromChunk(chunk.getX(), chunk.getZ()); + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); + City cityByChunk = cityManager.getCityFromChunk(chunk.getX(), chunk.getZ()); if (cityByChunk == null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.npc.move.error.outside_city"), Prefix.CITY, MessageType.ERROR, false); return false; } - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); if (playerCity == null) { return false; @@ -157,8 +158,8 @@ public void onClose(InventoryCloseEvent event) { return false; } - NPCManager.moveNPC("mayor", locationClick, city.getUniqueId()); - NPCManager.updateNPCS(city.getUniqueId()); + cityManager.MAYOR.mayorNPCManager.moveNPC("mayor", locationClick, city.getUniqueId()); + cityManager.MAYOR.mayorNPCManager.updateNPCS(city.getUniqueId()); return true; }, null diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/npc/OwnerNpcMenu.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/npc/OwnerNpcMenu.java index 52bac479f..38b3e082e 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/npc/OwnerNpcMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/menu/npc/OwnerNpcMenu.java @@ -5,13 +5,13 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.api.menulib.utils.InventorySize; import fr.openmc.api.menulib.utils.ItemMenuBuilder; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.sub.mayor.ElectionType; -import fr.openmc.core.features.city.sub.mayor.managers.NPCManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; import fr.openmc.core.features.city.sub.mayor.models.Mayor; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.utils.bukkit.SkullUtils; import fr.openmc.core.utils.cache.CacheOfflinePlayer; @@ -78,7 +78,7 @@ public void onClose(InventoryCloseEvent event) { String nameOwner = CacheOfflinePlayer.getOfflinePlayer(city.getPlayerWithPermission((CityPermission.OWNER))).getName(); - Perks perk1 = PerkManager.getPerkById(mayor.getIdPerk1()); + Perks perk1 = PerkUtils.getPerkById(mayor.getIdPerk1()); if (electionType == ElectionType.ELECTION) { List loreOwner = new ArrayList<>(List.of( TranslationManager.translation( @@ -105,8 +105,8 @@ public void onClose(InventoryCloseEvent event) { itemMeta.lore(lorePerk1); }).hide(perk1 == null ? null : perk1.getToHide())); } else { - Perks perk2 = PerkManager.getPerkById(mayor.getIdPerk2()); - Perks perk3 = PerkManager.getPerkById(mayor.getIdPerk3()); + Perks perk2 = PerkUtils.getPerkById(mayor.getIdPerk2()); + Perks perk3 = PerkUtils.getPerkById(mayor.getIdPerk3()); List loreOwner = new ArrayList<>(List.of( TranslationManager.translation( @@ -186,25 +186,24 @@ public void onClose(InventoryCloseEvent event) { Chunk chunk = locationClick.getChunk(); - City cityByChunk = CityManager.getCityFromChunk(chunk.getX(), chunk.getZ()); + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); + City cityByChunk = cityManager.getCityFromChunk(chunk.getX(), chunk.getZ()); if (cityByChunk == null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.npc.move.error.outside_city"), Prefix.CITY, MessageType.ERROR, false); return false; } - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); - if (playerCity == null) { - return false; - } + if (playerCity == null) return false; if (!cityByChunk.getUniqueId().equals(playerCity.getUniqueId())) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.mayor.npc.move.error.outside_city"), Prefix.CITY, MessageType.ERROR, false); return false; } - NPCManager.moveNPC("owner", locationClick, city.getUniqueId()); - NPCManager.updateNPCS(city.getUniqueId()); + cityManager.MAYOR.mayorNPCManager.moveNPC("owner", locationClick, city.getUniqueId()); + cityManager.MAYOR.mayorNPCManager.updateNPCS(city.getUniqueId()); return true; }, null diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/models/MayorVote.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/models/MayorVote.java index 8f7180331..102477005 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/models/MayorVote.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/models/MayorVote.java @@ -2,9 +2,8 @@ import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; -import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; import lombok.Getter; import java.util.UUID; @@ -30,10 +29,10 @@ public MayorVote(UUID cityUUID, UUID voterUUID, MayorCandidate candidate) { } public City getCity() { - return CityManager.getCity(cityUUID); + return OMCRegistry.FEATURES.CITY.get().getCity(cityUUID); } public MayorCandidate getCandidate() { - return MayorManager.getCandidate(candidate); + return OMCRegistry.FEATURES.CITY.get().MAYOR.getCandidate(candidate); } } diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/PerkManager.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/PerkUtils.java similarity index 95% rename from src/main/java/fr/openmc/core/features/city/sub/mayor/managers/PerkManager.java rename to src/main/java/fr/openmc/core/features/city/sub/mayor/perks/PerkUtils.java index d54ae9397..1bc466cce 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/managers/PerkManager.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/PerkUtils.java @@ -1,9 +1,7 @@ -package fr.openmc.core.features.city.sub.mayor.managers; +package fr.openmc.core.features.city.sub.mayor.perks; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.sub.mayor.models.Mayor; -import fr.openmc.core.features.city.sub.mayor.perks.PerkType; -import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.city.sub.milestone.rewards.FeaturesRewards; import java.util.ArrayList; @@ -11,7 +9,7 @@ import java.util.List; import java.util.Random; -public class PerkManager { +public class PerkUtils { private static final Random RANDOM = new Random(); /** diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/AyweniterPerk.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/AyweniterPerk.java index 32ef6bc04..48980a6dd 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/AyweniterPerk.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/AyweniterPerk.java @@ -3,8 +3,7 @@ import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; -import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.dream.DreamUtils; import fr.openmc.core.utils.text.messages.MessageType; @@ -23,6 +22,11 @@ import java.util.Random; public class AyweniterPerk implements Listener { + private final CityManager cityManager; + + public AyweniterPerk() { + this.cityManager = OMCRegistry.FEATURES.CITY.get(); + } private static final double DROP_CHANCE = 0.01; //1% private final Random random = new Random(); @@ -34,16 +38,16 @@ public void onBlockBreak(BlockBreakEvent event) { Block block = event.getBlock(); if (DreamUtils.isDreamWorld(block.getWorld())) return; Player player = event.getPlayer(); - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); if (playerCity == null) return; - City blockCity = CityManager.getCityFromChunk(block.getChunk()); + City blockCity = cityManager.getCityFromChunk(block.getChunk()); if (blockCity != null) if (blockCity != playerCity) return; - if (MayorManager.phaseMayor == 2) { - if (!PerkManager.hasPerk(playerCity.getMayor(), Perks.AYWENITER.getId())) return; + if (cityManager.MAYOR.phaseMayor == 2) { + if (!PerkUtils.hasPerk(playerCity.getMayor(), Perks.AYWENITER.getId())) return; if (block.getType() == Material.STONE) { ItemStack ayweniteItem = OMCRegistry.CUSTOM_ITEMS.AYWENITE.getBest(); diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/CityHunterPerk.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/CityHunterPerk.java index d124f6bef..45156beb9 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/CityHunterPerk.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/CityHunterPerk.java @@ -1,9 +1,9 @@ package fr.openmc.core.features.city.sub.mayor.perks.basic; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; -import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import org.bukkit.entity.Entity; import org.bukkit.entity.Monster; @@ -13,36 +13,39 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; public class CityHunterPerk implements Listener { + private final CityManager cityManager; + + public CityHunterPerk() { + this.cityManager = OMCRegistry.FEATURES.CITY.get(); + } @EventHandler public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Player attacker)) { - return; - } + if (!(event.getDamager() instanceof Player attacker)) return; - City attackerCity = CityManager.getPlayerCity(attacker.getUniqueId()); - if (attackerCity == null) { - return; - } + City attackerCity = cityManager.getPlayerCity(attacker.getUniqueId()); + if (attackerCity == null) return; if (attackerCity.getMayor() == null) return; - if (MayorManager.phaseMayor != 2) return; + if (cityManager.MAYOR.phaseMayor != 2) return; + + if (!PerkUtils.hasPerk(attackerCity.getMayor(), Perks.CITY_HUNTER.getId())) return; - if (!PerkManager.hasPerk(attackerCity.getMayor(), Perks.CITY_HUNTER.getId())) { - return; - } Entity target = event.getEntity(); - if (!(target instanceof Player) && !(target instanceof Monster)) { - return; - } + if (!(target instanceof Player) && !(target instanceof Monster)) return; - if (CityManager.getCityFromChunk(target.getChunk().getX(), target.getChunk().getZ()) != null && CityManager.getCityFromChunk(target.getChunk().getX(), target.getChunk().getZ()) != attackerCity) { + if (cityManager.getCityFromChunk(target.getChunk().getX(), target.getChunk().getZ()) != null + && (cityManager.getCityFromChunk( + target.getChunk().getX(), + target.getChunk().getZ()) + != attackerCity) + ) return; - } + double baseDamage = event.getDamage(); double newDamage = baseDamage * 1.20; diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/DemonFruitPerk.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/DemonFruitPerk.java index 69f2a2e01..2e32d25b3 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/DemonFruitPerk.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/DemonFruitPerk.java @@ -3,7 +3,7 @@ import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.dream.DreamUtils; import org.bukkit.NamespacedKey; @@ -110,7 +110,7 @@ public void onJoin(PlayerJoinEvent event) { City playerCity = CityManager.getPlayerCity(player.getUniqueId()); if (playerCity == null) return; - if (!PerkManager.hasPerk(playerCity.getMayor(), Perks.FRUIT_DEMON.getId())) return; + if (!PerkUtils.hasPerk(playerCity.getMayor(), Perks.FRUIT_DEMON.getId())) return; if (!hasRangeAttribute(player)) applyReachBonus(player); } else { @@ -142,7 +142,7 @@ public void onDreamLeave(PlayerTeleportEvent event) { City playerCity = CityManager.getPlayerCity(player.getUniqueId()); if (playerCity == null) return; - if (!PerkManager.hasPerk(playerCity.getMayor(), Perks.FRUIT_DEMON.getId())) return; + if (!PerkUtils.hasPerk(playerCity.getMayor(), Perks.FRUIT_DEMON.getId())) return; if (!hasRangeAttribute(player)) applyReachBonus(player); } else { diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/GPSTrackerPerk.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/GPSTrackerPerk.java index bc78df629..5ea8a331a 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/GPSTrackerPerk.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/GPSTrackerPerk.java @@ -1,10 +1,10 @@ package fr.openmc.core.features.city.sub.mayor.perks.basic; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; -import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; import fr.openmc.core.features.city.sub.mayor.models.Mayor; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -25,12 +25,17 @@ import java.util.UUID; public class GPSTrackerPerk implements Listener { + private final CityManager cityManager; + + public GPSTrackerPerk() { + this.cityManager = OMCRegistry.FEATURES.CITY.get(); + } private final Map lastCityMap = new HashMap<>(); @EventHandler public void onMove(PlayerMoveEvent event) { - if (MayorManager.phaseMayor != 2) return; + if (cityManager.MAYOR.phaseMayor != 2) return; Player player = event.getPlayer(); UUID uuid = player.getUniqueId(); @@ -38,7 +43,7 @@ public void onMove(PlayerMoveEvent event) { Chunk newChunk = event.getTo().getChunk(); if (event.getFrom().getChunk().equals(newChunk)) return; - City newCity = CityManager.getCityFromChunk( + City newCity = cityManager.getCityFromChunk( newChunk.getX(), newChunk.getZ() ); @@ -72,7 +77,7 @@ public void onMove(PlayerMoveEvent event) { private boolean hasGpsTrackerPerk(City city) { Mayor mayor = city.getMayor(); - return PerkManager.hasPerk(mayor, Perks.GPS_TRACKER.getId()); + return PerkUtils.hasPerk(mayor, Perks.GPS_TRACKER.getId()); } private void applyGlowing(Player player) { diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/MascotFriendlyPerk.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/MascotFriendlyPerk.java index 4342337f7..395e56d5e 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/MascotFriendlyPerk.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/MascotFriendlyPerk.java @@ -5,7 +5,7 @@ import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.mascots.models.MascotsLevels; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.dream.DreamUtils; import org.bukkit.Bukkit; @@ -31,7 +31,7 @@ public static void updatePlayerEffects(Player player) { int level = playerCity.getMascot().getLevel(); if (phase == 2) { - if (!PerkManager.hasPerk(playerCity.getMayor(), Perks.MASCOTS_FRIENDLY.getId())) return; + if (!PerkUtils.hasPerk(playerCity.getMayor(), Perks.MASCOTS_FRIENDLY.getId())) return; for (PotionEffect potionEffect : MascotsLevels.valueOf("level" + level).getBonus()) { player.addPotionEffect(potionEffect); diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/MinerPerk.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/MinerPerk.java index a85ccc401..1f2eba05c 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/MinerPerk.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/MinerPerk.java @@ -4,7 +4,7 @@ import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.dream.DreamUtils; import org.bukkit.Bukkit; @@ -30,7 +30,7 @@ public static void updatePlayerEffects(Player player) { City playerCity = CityManager.getPlayerCity(player.getUniqueId()); if (playerCity == null) return; - if (!PerkManager.hasPerk(playerCity.getMayor(), Perks.MINER.getId())) return; + if (!PerkUtils.hasPerk(playerCity.getMayor(), Perks.MINER.getId())) return; player.addPotionEffect(new PotionEffect(PotionEffectType.HASTE, PotionEffect.INFINITE_DURATION, 0, false, false)); } else { diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/RagePerk.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/RagePerk.java index ca0849286..8d5bd8fdd 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/RagePerk.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/RagePerk.java @@ -1,9 +1,9 @@ package fr.openmc.core.features.city.sub.mayor.perks.basic; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; -import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.homes.events.HomeTpEvent; import fr.openmc.core.features.homes.models.Home; @@ -18,10 +18,15 @@ import java.util.UUID; public class RagePerk implements Listener { + private final CityManager cityManager; + + public RagePerk() { + this.cityManager = OMCRegistry.FEATURES.CITY.get(); + } @EventHandler public void onMove(PlayerMoveEvent event) { - if (MayorManager.phaseMayor != 2) return; + if (cityManager.MAYOR.phaseMayor != 2) return; Player player = event.getPlayer(); UUID uuid = player.getUniqueId(); @@ -29,12 +34,12 @@ public void onMove(PlayerMoveEvent event) { // ça sert à rien de lancer ça si on ne change pas de chunk if (event.getFrom().getChunk().equals(event.getTo().getChunk())) return; - City playerCity = CityManager.getPlayerCity(uuid); + City playerCity = cityManager.getPlayerCity(uuid); if (playerCity == null) return; - if (!PerkManager.hasPerk(playerCity.getMayor(), Perks.FOU_DE_RAGE.getId())) return; + if (!PerkUtils.hasPerk(playerCity.getMayor(), Perks.FOU_DE_RAGE.getId())) return; - City currentCity = CityManager.getCityFromChunk( + City currentCity = cityManager.getCityFromChunk( event.getTo().getChunk().getX(), event.getTo().getChunk().getZ() ); @@ -44,19 +49,19 @@ public void onMove(PlayerMoveEvent event) { @EventHandler public void onTpMove(HomeTpEvent event) { - if (MayorManager.phaseMayor != 2) return; + if (cityManager.MAYOR.phaseMayor != 2) return; Player player = event.getPlayer(); UUID uuid = player.getUniqueId(); - City playerCity = CityManager.getPlayerCity(uuid); + City playerCity = cityManager.getPlayerCity(uuid); if (playerCity == null) return; - if (!PerkManager.hasPerk(playerCity.getMayor(), Perks.FOU_DE_RAGE.getId())) return; + if (!PerkUtils.hasPerk(playerCity.getMayor(), Perks.FOU_DE_RAGE.getId())) return; Home home = event.getHome(); - City currentCity = CityManager.getCityFromChunk( + City currentCity = cityManager.getCityFromChunk( home.getLocation().getChunk().getX(), home.getLocation().getChunk().getZ() ); @@ -73,7 +78,7 @@ public void onQuit(PlayerQuitEvent event) { } public static void updateEffect(City currentCity, Player player) { - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (playerCity == null) return; player.removePotionEffect(PotionEffectType.STRENGTH); diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/SymbiosisPerk.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/SymbiosisPerk.java index bcef0d85d..b7d82b028 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/SymbiosisPerk.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/basic/SymbiosisPerk.java @@ -2,7 +2,7 @@ import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; @@ -22,7 +22,7 @@ public void onEntityDamage(EntityDamageEvent event) { City playerCity = CityManager.getPlayerCity(player.getUniqueId()); if (playerCity == null) return; - if (!PerkManager.hasPerk(playerCity.getMayor(), Perks.SYMBIOSIS.getId())) return; + if (!PerkUtils.hasPerk(playerCity.getMayor(), Perks.SYMBIOSIS.getId())) return; LivingEntity mascot = (LivingEntity) Bukkit.getEntity(playerCity.getMascot().getMascotUUID()); diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/event/AgriculturalEssorPerk.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/event/AgriculturalEssorPerk.java index 5e4868e08..d5b6a7382 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/event/AgriculturalEssorPerk.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/event/AgriculturalEssorPerk.java @@ -5,7 +5,7 @@ import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.utils.bukkit.MaterialUtils; import fr.openmc.core.utils.text.DateUtils; @@ -38,7 +38,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { if (city == null) return; - if (!PerkManager.hasPerk(city.getMayor(), Perks.AGRICULTURAL_ESSOR.getId())) return; + if (!PerkUtils.hasPerk(city.getMayor(), Perks.AGRICULTURAL_ESSOR.getId())) return; if (!DynamicCooldownManager.isReady(city.getUniqueId(), "city:agricultural_essor")) { MessagesManager.sendMessage(player, TranslationManager.translation( @@ -59,7 +59,7 @@ void onTimeEnd(Chronometer.ChronometerEndEvent e) { if (city == null) return; - if (!PerkManager.hasPerk(city.getMayor(), Perks.AGRICULTURAL_ESSOR.getId())) return; + if (!PerkUtils.hasPerk(city.getMayor(), Perks.AGRICULTURAL_ESSOR.getId())) return; for (UUID memberUUID : city.getMembers()) { Player player = Bukkit.getPlayer(memberUUID); @@ -79,7 +79,7 @@ public void onCropBreak(BlockBreakEvent event) { if (city == null) return; - if (!PerkManager.hasPerk(city.getMayor(), Perks.AGRICULTURAL_ESSOR.getId())) return; + if (!PerkUtils.hasPerk(city.getMayor(), Perks.AGRICULTURAL_ESSOR.getId())) return; if (DynamicCooldownManager.isReady(city.getUniqueId(), "city:agricultural_essor")) return; diff --git a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/event/MineralRushPerk.java b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/event/MineralRushPerk.java index fe32887c9..fc20bc715 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/event/MineralRushPerk.java +++ b/src/main/java/fr/openmc/core/features/city/sub/mayor/perks/event/MineralRushPerk.java @@ -7,7 +7,7 @@ import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.utils.bukkit.MaterialUtils; import fr.openmc.core.utils.text.DateUtils; @@ -40,7 +40,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { if (city == null) return; - if (!PerkManager.hasPerk(city.getMayor(), Perks.MINERAL_RUSH.getId())) return; + if (!PerkUtils.hasPerk(city.getMayor(), Perks.MINERAL_RUSH.getId())) return; if (!DynamicCooldownManager.isReady(city.getUniqueId(), "city:mineral_rush")) { MessagesManager.sendMessage(player, TranslationManager.translation( @@ -61,7 +61,7 @@ void onTimeEnd(Chronometer.ChronometerEndEvent e) { if (city == null) return; - if (!PerkManager.hasPerk(city.getMayor(), Perks.MINERAL_RUSH.getId())) return; + if (!PerkUtils.hasPerk(city.getMayor(), Perks.MINERAL_RUSH.getId())) return; for (UUID memberUUID : city.getMembers()) { Player player = Bukkit.getPlayer(memberUUID); @@ -83,7 +83,7 @@ public void onMineralBreak(BlockBreakEvent event) { if (city.getMayor() == null) return; - if (!PerkManager.hasPerk(city.getMayor(), Perks.MINERAL_RUSH.getId())) return; + if (!PerkUtils.hasPerk(city.getMayor(), Perks.MINERAL_RUSH.getId())) return; if (DynamicCooldownManager.isReady(city.getUniqueId(), "city:mineral_rush")) return; @@ -111,7 +111,7 @@ public void onAyweniteBreak(CustomBlockBreakEvent event) { City city = CityManager.getPlayerCity(player.getUniqueId()); if (city == null) return; - if (!PerkManager.hasPerk(city.getMayor(), Perks.MINERAL_RUSH.getId())) return; + if (!PerkUtils.hasPerk(city.getMayor(), Perks.MINERAL_RUSH.getId())) return; if (!DynamicCooldownManager.isReady(city.getUniqueId(), "city:mineral_rush")) return; String namespace = event.getNamespacedID(); diff --git a/src/main/java/fr/openmc/core/features/city/sub/milestone/CityLevels.java b/src/main/java/fr/openmc/core/features/city/sub/milestone/CityLevels.java index 2c8b9ec57..3b6919cfe 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/milestone/CityLevels.java +++ b/src/main/java/fr/openmc/core/features/city/sub/milestone/CityLevels.java @@ -4,7 +4,7 @@ import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; -import fr.openmc.core.features.city.sub.mayor.managers.NPCManager; +import fr.openmc.core.features.city.sub.mayor.managers.MayorNPCManager; import fr.openmc.core.features.city.sub.milestone.requirements.CommandRequirement; import fr.openmc.core.features.city.sub.milestone.requirements.EventTemplateRequirement; import fr.openmc.core.features.city.sub.milestone.requirements.ItemDepositRequirement; @@ -264,7 +264,7 @@ public enum CityLevels { "feature.city.levels.level_5.description", List.of( new TemplateRequirement( - city -> NPCManager.hasNPCS(city.getUniqueId()), + city -> MayorNPCManager.hasNPCS(city.getUniqueId()), city -> OMCRegistry.CUSTOM_ITEMS.URNE.getBest(), (city, level) -> TranslationManager.translation("feature.city.levels.requirements.place_urne") ), diff --git a/src/main/java/fr/openmc/core/features/city/sub/milestone/CityMilestoneManager.java b/src/main/java/fr/openmc/core/features/city/sub/milestone/CityMilestoneManager.java index 6c68eb0c8..04d7c7c3b 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/milestone/CityMilestoneManager.java +++ b/src/main/java/fr/openmc/core/features/city/sub/milestone/CityMilestoneManager.java @@ -1,20 +1,28 @@ package fr.openmc.core.features.city.sub.milestone; -import fr.openmc.core.CommandsManager; -import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.city.sub.milestone.commands.AdminCityMilestoneCommands; import fr.openmc.core.features.city.sub.milestone.commands.CityMilestoneCommands; import fr.openmc.core.features.city.sub.milestone.listeners.CooldownEndListener; import fr.openmc.core.features.city.sub.statistics.listeners.MemberJoinListener; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; -public class CityMilestoneManager { - public static void init() { - CommandsManager.getHandler().register( +import java.util.Set; + +public class CityMilestoneManager extends Feature implements HasCommands, HasListeners { + @Override + public Set getCommands() { + return Set.of( new AdminCityMilestoneCommands(), new CityMilestoneCommands() ); + } - OMCPlugin.registerEvents( + @Override + public Set getListeners() { + return Set.of( CooldownEndListener::new, CityRequirementListener::new, MemberJoinListener::new diff --git a/src/main/java/fr/openmc/core/features/city/sub/milestone/commands/AdminCityMilestoneCommands.java b/src/main/java/fr/openmc/core/features/city/sub/milestone/commands/AdminCityMilestoneCommands.java index 672f78fff..2c29b73ee 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/milestone/commands/AdminCityMilestoneCommands.java +++ b/src/main/java/fr/openmc/core/features/city/sub/milestone/commands/AdminCityMilestoneCommands.java @@ -1,8 +1,8 @@ package fr.openmc.core.features.city.sub.milestone.commands; import fr.openmc.api.cooldown.DynamicCooldownManager; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.commands.autocomplete.CityNameAutoComplete; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -21,7 +21,7 @@ void adminSkinUpgrade( Player sender, @Named("cityName") @SuggestWith(CityNameAutoComplete.class) String cityName ) { - City city = CityManager.getCityByName(cityName); + City city = OMCRegistry.FEATURES.CITY.get().getCityByName(cityName); if (city == null) { MessagesManager.sendMessage(sender, TranslationManager.translation("messages.city.not_found"), Prefix.STAFF, MessageType.ERROR, false); @@ -40,7 +40,7 @@ void setLevel( @Named("cityName") @SuggestWith(CityNameAutoComplete.class) String name, @Named("level") @Range(min = 1, max = 10) int level ) { - City city = CityManager.getCityByName(name); + City city = OMCRegistry.FEATURES.CITY.get().getCityByName(name); if (city == null) { MessagesManager.sendMessage(sender, TranslationManager.translation("messages.city.not_found"), Prefix.STAFF, MessageType.ERROR, false); diff --git a/src/main/java/fr/openmc/core/features/city/sub/notation/NotationManager.java b/src/main/java/fr/openmc/core/features/city/sub/notation/NotationManager.java index 1cbea8fec..ba346ed8c 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/notation/NotationManager.java +++ b/src/main/java/fr/openmc/core/features/city/sub/notation/NotationManager.java @@ -4,7 +4,6 @@ import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; -import fr.openmc.core.CommandsManager; import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; @@ -15,6 +14,11 @@ import fr.openmc.core.features.city.sub.notation.models.CityNotation; import fr.openmc.core.features.economy.BankManager; import fr.openmc.core.features.economy.EconomyManager; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.utils.cache.CacheOfflinePlayer; import fr.openmc.core.utils.text.DateUtils; import org.bukkit.Bukkit; @@ -36,70 +40,59 @@ * de toutes les villes. Elle interagit avec la base de données via ORMLite et planifie des * exécutions périodiques pour recalculer les scores et attribuer les récompenses.

*/ -public class NotationManager { +public class NotationManager extends Feature implements HasCommands, HasListeners, HasDatabase { + private final CityManager cityManager; /** * Jour d'application de la notation. */ private static final DayOfWeek APPLY_NOTATION_DAY = DayOfWeek.SUNDAY; - private static boolean isApplied; + private boolean isApplied; - - /** - * Map des notations par semaine (clé : chaine de la semaine, valeur : liste de CityNotation). - */ - public static final Map> notationPerWeek = new HashMap<>(); + // Map des notations par semaine (clé : chaine de la semaine, valeur : liste de CityNotation). + public final Map> notationPerWeek = new HashMap<>(); - /** - * Map des notations par ville (clé : UUID de la ville, valeur : liste de CityNotation). - */ - public static final Map> cityNotations = new HashMap<>(); + // Map des notations par ville (clé : UUID de la ville, valeur : liste de CityNotation). + public final Map> cityNotations = new HashMap<>(); - /** - * Map des temps d'activité des joueurs (clé : UUID du joueur, valeur : temps). - */ - public static final Map activityNotation = new HashMap<>(); + // Map des temps d'activité des joueurs (clé : UUID du joueur, valeur : temps). + public final Map activityNotation = new HashMap<>(); - /** - * Ensemble des 10 meilleures villes. - */ - public static final Set top10Cities = new HashSet<>(); + // Ensemble des 10 meilleures villes. + public final Set top10Cities = new HashSet<>(); - /** - * DAO pour la table des temps d'activité. - */ - private static Dao activityTimePlayedDao; - - /** - * DAO pour la table des notations de ville. - */ - private static Dao notationDao; + private Dao activityTimePlayedDao; + private Dao notationDao; + public NotationManager(CityManager cityManager) { + this.cityManager = cityManager; + } /** * Constructeur de NotationManager. * *

Charge les notations, enregistre les commandes et les listeners, et planifie la tâche nocturne.

*/ - public static void init() { + @Override + public void init() { loadNotations(); - CommandsManager.getHandler().register( - new NotationCommands(), - new AdminNotationCommands() - ); - OMCPlugin.registerEvents( - PlayerJoinListener::new - ); + scheduleMidnightTask(); loadTop10Cities(); } + @Override + public void save() { + saveNotations(); + } + /** * Initialise la base de données pour les notations. * * @param connectionSource la source de connexion de la base de données * @throws SQLException en cas d'erreur SQL */ - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, CityNotation.class); notationDao = DaoManager.createDao(connectionSource, CityNotation.class); @@ -112,15 +105,30 @@ public static void initDB(ConnectionSource connectionSource) throws SQLException )); } + @Override + public Set getCommands() { + return Set.of( + new NotationCommands(), + new AdminNotationCommands(cityManager) + ); + } + + @Override + public Set getListeners() { + return Set.of( + PlayerJoinListener::new + ); + } + /** * Charge les notations depuis la base de données et les répartit dans les maps. */ - public static void loadNotations() { + public void loadNotations() { try { List notations = notationDao.queryForAll(); for (CityNotation notation : notations) { UUID cityUUID = notation.getCityUUID(); - City city = CityManager.getCity(cityUUID); + City city = cityManager.getCity(cityUUID); if (city == null) continue; String weekStr = notation.getWeekStr(); @@ -135,7 +143,7 @@ public static void loadNotations() { /** * Sauvegarde toutes les notations dans la base de données. */ - public static void saveNotations() { + public void saveNotations() { try { notationDao.delete(notationDao.queryForAll()); } catch (SQLException e) { @@ -158,7 +166,7 @@ public static void saveNotations() { * * @param notation la notation à créer ou mettre à jour */ - public static void createOrUpdateNotation(CityNotation notation) { + public void createOrUpdateNotation(CityNotation notation) { try { notationDao.createOrUpdate(notation); @@ -185,7 +193,7 @@ public static void createOrUpdateNotation(CityNotation notation) { /** * Charge les 10 meilleures villes en fonction des notations. */ - public static void loadTop10Cities() { + public void loadTop10Cities() { top10Cities.clear(); for (String weekStr : notationPerWeek.keySet()) { getSortedNotationForWeek(weekStr).stream() @@ -201,7 +209,7 @@ public static void loadTop10Cities() { * @param weekStr la chaîne représentant la semaine * @return liste de notations triées par note architecturale et cohérence, ordre décroissant */ - public static List getSortedNotationForWeek(String weekStr) { + public List getSortedNotationForWeek(String weekStr) { List notations = notationPerWeek.getOrDefault(weekStr, Collections.emptyList()); return notations.stream() .sorted(Comparator.comparingDouble( @@ -217,7 +225,7 @@ public static List getSortedNotationForWeek(String weekStr) { * @return le score moyen d'activité des membres de la ville * @throws SQLException en cas d'erreur SQL */ - public static double getActivityScore(City city) throws SQLException { + public double getActivityScore(City city) throws SQLException { double totalScore = 0; int playerCount = 0; for (UUID playerUUID : city.getMembers()) { @@ -242,7 +250,7 @@ public static double getActivityScore(City city) throws SQLException { * @param city la ville concernée * @return le score militaire calculé */ - public static double getMilitaryScore(City city) { + public double getMilitaryScore(City city) { int powerPoints = city.getPowerPoints(); int maxNote = NotationNote.NOTE_MILITARY.getMaxNote(); int pointsToGetMaxNote = 30; @@ -263,7 +271,7 @@ public static double getMilitaryScore(City city) { * @param city la ville concernée * @return le score économique (entre 0 et 15) */ - public static double getEconomyScore(City city) { + public double getEconomyScore(City city) { double totalMoney = 0; totalMoney += city.getBalance(); @@ -287,13 +295,13 @@ public static double getEconomyScore(City city) { * @param weekStr la chaîne représentant la semaine * @throws SQLException en cas d'erreur SQL */ - public static void calculateAllCityScore(String weekStr) throws SQLException { + public void calculateAllCityScore(String weekStr) throws SQLException { List notationsCopy = new ArrayList<>( notationPerWeek.getOrDefault(weekStr, Collections.emptyList()) ); for (CityNotation notation : notationsCopy) { - City city = CityManager.getCity(notation.getCityUUID()); + City city = cityManager.getCity(notation.getCityUUID()); notation.setNoteActivity(getActivityScore(city)); notation.setNoteMilitary(getMilitaryScore(city)); double economyScore = getEconomyScore(city); @@ -308,7 +316,7 @@ public static void calculateAllCityScore(String weekStr) throws SQLException { * @param notation la notation de la ville * @return le montant de la récompense */ - public static double calculateReward(CityNotation notation) { + public double calculateReward(CityNotation notation) { double points = notation.getTotalNote(); double money = points * (45000.0 / getMaxTotalNote()); @@ -323,11 +331,11 @@ public static double calculateReward(CityNotation notation) { * * @param weekStr la chaîne représentant la semaine */ - public static void giveReward(String weekStr) { + public void giveReward(String weekStr) { List notations = notationPerWeek.getOrDefault(weekStr, Collections.emptyList()); for (CityNotation notation : notations) { - City city = CityManager.getCity(notation.getCityUUID()); + City city = cityManager.getCity(notation.getCityUUID()); if (city != null) { city.setBalance(city.getBalance() + calculateReward(notation)); } @@ -337,7 +345,7 @@ public static void giveReward(String weekStr) { /** * Planifie l'exécution de la tâche de minuit qui calcule les scores et attribue les récompenses. */ - private static void scheduleMidnightTask() { + private void scheduleMidnightTask() { long delayInTicks = DateUtils.getSecondsUntilDayOfWeekTime(APPLY_NOTATION_DAY, 0, 0, 0) * 20; Bukkit.getScheduler().runTaskLater(OMCPlugin.getInstance(), () -> { if (!isApplied) { diff --git a/src/main/java/fr/openmc/core/features/city/sub/notation/commands/AdminNotationCommands.java b/src/main/java/fr/openmc/core/features/city/sub/notation/commands/AdminNotationCommands.java index 74fff40f2..4d48117bb 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/notation/commands/AdminNotationCommands.java +++ b/src/main/java/fr/openmc/core/features/city/sub/notation/commands/AdminNotationCommands.java @@ -18,11 +18,16 @@ import java.util.List; -import static fr.openmc.core.features.city.sub.notation.NotationManager.calculateAllCityScore; -import static fr.openmc.core.features.city.sub.notation.NotationManager.giveReward; - public class AdminNotationCommands { + private final CityManager cityManager; + private final NotationManager notationManager; + + public AdminNotationCommands(CityManager cityManager) { + this.cityManager = cityManager; + this.notationManager = cityManager.NOTATION; + } + @Command({"admcity notation edit"}) @CommandPermission("omc.admins.commands.admcity.notation") public void editNotations(Player sender) { @@ -38,7 +43,7 @@ public void editNotations(Player sender) { return; } - List cities = CityManager.getCities() + List cities = cityManager.getCities() .stream() .filter(city -> FeaturesRewards.hasUnlockFeature(city, FeaturesRewards.Feature.NOTATION)) .toList(); @@ -61,19 +66,19 @@ public void editNotations(Player sender) { public void publishNotations(Player sender) { String weekStr = DateUtils.getWeekFormat(); - if (!NotationManager.notationPerWeek.containsKey(weekStr)) { + if (!notationManager.notationPerWeek.containsKey(weekStr)) { MessagesManager.sendMessage(sender, TranslationManager.translation("feature.city.notation.admin.publish.missing", Component.text(weekStr)), Prefix.STAFF, MessageType.ERROR, false); return; } try { - calculateAllCityScore(weekStr); + notationManager.calculateAllCityScore(weekStr); } catch (Exception e) { throw new RuntimeException(e); } - giveReward(weekStr); + notationManager.giveReward(weekStr); MessagesManager.sendMessage(sender, TranslationManager.translation("feature.city.notation.admin.publish.success", Component.text(weekStr)), Prefix.STAFF, MessageType.ERROR, false); diff --git a/src/main/java/fr/openmc/core/features/city/sub/rank/CityRankCommands.java b/src/main/java/fr/openmc/core/features/city/sub/rank/CityRankCommands.java index 80e0d1c14..626bd3923 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/rank/CityRankCommands.java +++ b/src/main/java/fr/openmc/core/features/city/sub/rank/CityRankCommands.java @@ -1,5 +1,6 @@ package fr.openmc.core.features.city.sub.rank; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; @@ -22,11 +23,16 @@ @Command({"city ranks", "ville grades"}) public class CityRankCommands { + private final CityManager cityManager; + + public CityRankCommands(CityManager cityManager) { + this.cityManager = cityManager; + } @CommandPlaceholder() @CommandPermission("omc.commands.city.rank") public void rank(Player player) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = cityManager.getPlayerCity(player.getUniqueId()); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); @@ -56,7 +62,7 @@ public void edit( Player player, @Named("rank") @SuggestWith(CityRanksAutoComplete.class) String rankName ) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = cityManager.getPlayerCity(player.getUniqueId()); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); return; @@ -77,7 +83,7 @@ public void edit( * @param permission The permission to swap. */ public static void swapPermission(Player player, DBCityRank rank, CityPermission permission) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); return; @@ -104,7 +110,7 @@ public static void swapPermission(Player player, DBCityRank rank, CityPermission * @param rank The rank to add the permissions to. */ public static void addAllPermissions(Player player, DBCityRank rank) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); return; @@ -131,7 +137,7 @@ public static void addAllPermissions(Player player, DBCityRank rank) { * @param rank The rank to remove the permissions from. */ public static void removeAllPermissions(Player player, DBCityRank rank) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); return; diff --git a/src/main/java/fr/openmc/core/features/city/sub/rank/CityRankManager.java b/src/main/java/fr/openmc/core/features/city/sub/rank/CityRankManager.java index b49f93370..9229fbc0f 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/rank/CityRankManager.java +++ b/src/main/java/fr/openmc/core/features/city/sub/rank/CityRankManager.java @@ -9,15 +9,23 @@ import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.models.DBCityRank; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; import java.sql.SQLException; import java.util.List; -public class CityRankManager { - - private static Dao ranksDao; +public class CityRankManager extends Feature implements HasDatabase { + + private final CityManager cityManager; + private Dao ranksDao; + + public CityRankManager(CityManager cityManager) { + this.cityManager = cityManager; + } - public static void init() { + @Override + public void init() { loadRanks(); } @@ -27,7 +35,8 @@ public static void init() { * @param connectionSource The connection source to the database. * @throws SQLException If there is an error creating the table or DAO. */ - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, DBCityRank.class); ranksDao = DaoManager.createDao(connectionSource, DBCityRank.class); } @@ -38,7 +47,7 @@ public static void initDB(ConnectionSource connectionSource) throws SQLException * @param city The city whose ranks should be removed. * @throws SQLException If there is an error during the deletion process. */ - public static void removeRanks(City city) throws SQLException { + public void removeRanks(City city) throws SQLException { DeleteBuilder ranksDelete = ranksDao.deleteBuilder(); ranksDelete.where().eq("city_uuid", city.getUniqueId()); ranksDao.delete(ranksDelete.prepare()); @@ -49,7 +58,7 @@ public static void removeRanks(City city) throws SQLException { * * @param rank The rank to add */ - public static void addCityRank(DBCityRank rank) { + public void addCityRank(DBCityRank rank) { try { ranksDao.create(rank); } catch (SQLException e) { @@ -62,7 +71,7 @@ public static void addCityRank(DBCityRank rank) { * * @param rank The rank to remove */ - public static void removeCityRank(DBCityRank rank) { + public void removeCityRank(DBCityRank rank) { try { DeleteBuilder delete = ranksDao.deleteBuilder(); delete.where().eq("city_uuid", rank.getCityUUID()).and().eq("name", rank.getName()); @@ -77,7 +86,7 @@ public static void removeCityRank(DBCityRank rank) { * * @param rank The rank to update */ - public static void updateCityRank(DBCityRank rank) { + public void updateCityRank(DBCityRank rank) { try { ranksDao.update(rank); } catch (SQLException e) { @@ -90,7 +99,7 @@ public static void updateCityRank(DBCityRank rank) { * * @param city The city to load ranks for */ - public static void loadCityRanks(City city) { + public void loadCityRanks(City city) { try { QueryBuilder query = ranksDao.queryBuilder(); query.where().eq("city_uuid", city.getUniqueId()); @@ -110,17 +119,17 @@ public static void loadCityRanks(City city) { * @param rank The rank to copy. * @return A new instance of DBCityRank with the same properties as the original. */ - public static DBCityRank copy(DBCityRank rank) { + public DBCityRank copy(DBCityRank rank) { return new DBCityRank(rank.getRankUUID(), rank.getCityUUID(), rank.getPriority(), rank.getName(), rank.getIcon(), rank.getPermissionsSet(), rank.getMembersSet()); } /** * Load all city ranks from the database and associate them with their respective cities. */ - public static void loadRanks() { + public void loadRanks() { try { for (DBCityRank rank : ranksDao.queryForAll()) { - City city = CityManager.getCity(rank.getCityUUID()); + City city = cityManager.getCity(rank.getCityUUID()); if (city != null) city.getRanks().add(rank); } diff --git a/src/main/java/fr/openmc/core/features/city/sub/rank/menus/CityRankPermsMenu.java b/src/main/java/fr/openmc/core/features/city/sub/rank/menus/CityRankPermsMenu.java index 1ece7c6d4..d6cf79d24 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/rank/menus/CityRankPermsMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/rank/menus/CityRankPermsMenu.java @@ -7,7 +7,6 @@ import fr.openmc.api.menulib.utils.StaticSlots; import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.models.DBCityRank; import fr.openmc.core.features.city.sub.rank.CityRankCommands; @@ -44,7 +43,7 @@ public CityRankPermsMenu(Player owner, DBCityRank oldRank, DBCityRank newRank, b this.oldRank = oldRank; this.newRank = newRank; this.canEdit = canEdit; - this.city = CityManager.getPlayerCity(owner.getUniqueId()); + this.city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(owner.getUniqueId()); this.page = page; } diff --git a/src/main/java/fr/openmc/core/features/city/sub/statistics/CityStatisticsManager.java b/src/main/java/fr/openmc/core/features/city/sub/statistics/CityStatisticsManager.java index df52dcfb1..f5220ed9f 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/statistics/CityStatisticsManager.java +++ b/src/main/java/fr/openmc/core/features/city/sub/statistics/CityStatisticsManager.java @@ -7,6 +7,8 @@ import com.j256.ormlite.table.TableUtils; import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.city.sub.statistics.models.CityStatistics; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; import org.bukkit.Bukkit; import java.io.Serializable; @@ -18,29 +20,36 @@ * *

Cette classe gère le chargement, la sauvegarde et la mise à jour asynchrone des statistiques associées à chaque ville.

*/ -public class CityStatisticsManager { +public class CityStatisticsManager extends Feature implements HasDatabase { /** * Map des statistiques par ville (clé : identifiant de la ville, valeur : ensemble de statistiques). */ - public static HashMap> cityStatistics = new HashMap<>(); + public HashMap> cityStatistics = new HashMap<>(); - private static Dao statisticsDao; + private Dao statisticsDao; /** * Initialise le gestionnaire des statistiques des villes en chargeant les statistiques depuis la base de données. */ - public static void init() { + @Override + public void init() { loadCityStatistics(); } + @Override + public void save() { + saveCityStatistics(); + } + /** * Initialise la base de données pour les statistiques des villes. * * @param connectionSource la source de connexion * @throws SQLException en cas d'erreur SQL */ - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, CityStatistics.class); statisticsDao = DaoManager.createDao(connectionSource, CityStatistics.class); } @@ -48,7 +57,7 @@ public static void initDB(ConnectionSource connectionSource) throws SQLException /** * Charge toutes les statistiques depuis la base de données. */ - public static void loadCityStatistics() { + public void loadCityStatistics() { try { List statistics = statisticsDao.queryForAll(); statistics.forEach(statistic -> cityStatistics.computeIfAbsent(statistic.getCityUUID(), k -> new HashSet<>()).add(statistic)); @@ -60,7 +69,7 @@ public static void loadCityStatistics() { /** * Sauvegarde toutes les statistiques dans la base de données. */ - public static void saveCityStatistics() { + public void saveCityStatistics() { cityStatistics.forEach((city, statistics) -> statistics.forEach(stat -> { try { statisticsDao.createOrUpdate(stat); @@ -76,7 +85,7 @@ public static void saveCityStatistics() { * @param cityUUID l'identifiant de la ville * @return l'ensemble des statistiques associées à la ville */ - public static Set getOrCreate(UUID cityUUID) { + public Set getOrCreate(UUID cityUUID) { return cityStatistics.computeIfAbsent(cityUUID, k -> new HashSet<>()); } @@ -87,7 +96,7 @@ public static Set getOrCreate(UUID cityUUID) { * @param scope le scope de la statistique * @return la statistique correspondante */ - public static CityStatistics getOrCreateStat(UUID cityUUID, String scope) { + public CityStatistics getOrCreateStat(UUID cityUUID, String scope) { Set stats = getOrCreate(cityUUID); for (CityStatistics stat : stats) { if (stat != null && scope.equals(stat.getScope())) { @@ -106,7 +115,7 @@ public static CityStatistics getOrCreateStat(UUID cityUUID, String scope) { * @param scope le scope de la statistique * @param value la nouvelle valeur */ - public static void setStat(UUID cityUUID, String scope, Serializable value) { + public void setStat(UUID cityUUID, String scope, Serializable value) { CityStatistics stat = getOrCreateStat(cityUUID, scope); stat.setValue(value); Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> { @@ -123,7 +132,7 @@ public static void setStat(UUID cityUUID, String scope, Serializable value) { * * @param cityUUID l'identifiant de la ville */ - public static void removeStats(UUID cityUUID) { + public void removeStats(UUID cityUUID) { if (!cityStatistics.containsKey(cityUUID)) return; cityStatistics.remove(cityUUID); Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> { @@ -144,7 +153,7 @@ public static void removeStats(UUID cityUUID) { * @param scope le scope de la statistique * @param amount le montant à ajouter */ - public static void increment(UUID cityUUID, String scope, long amount) { + public void increment(UUID cityUUID, String scope, long amount) { CityStatistics stat = getOrCreateStat(cityUUID, scope); long current = stat.asLong(); stat.setValue(current + amount); @@ -164,7 +173,7 @@ public static void increment(UUID cityUUID, String scope, long amount) { * @param scope le scope de la statistique * @return la valeur de la statistique */ - public static Object getStatValue(UUID cityUUID, String scope) { + public Object getStatValue(UUID cityUUID, String scope) { CityStatistics stat = getOrCreateStat(cityUUID, scope); return stat.getValue(); } diff --git a/src/main/java/fr/openmc/core/features/city/sub/war/War.java b/src/main/java/fr/openmc/core/features/city/sub/war/War.java index 138f62a25..849e0a859 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/war/War.java +++ b/src/main/java/fr/openmc/core/features/city/sub/war/War.java @@ -1,6 +1,7 @@ package fr.openmc.core.features.city.sub.war; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.utils.text.messages.TranslationManager; import fr.openmc.core.utils.world.LocationUtils; @@ -176,7 +177,7 @@ public int getCombatTimeRemaining() { public void end() { this.phase = WarPhase.ENDED; - WarManager.endWar(this); + OMCRegistry.FEATURES.CITY.get().WAR.endWar(this); } /** diff --git a/src/main/java/fr/openmc/core/features/city/sub/war/WarManager.java b/src/main/java/fr/openmc/core/features/city/sub/war/WarManager.java index 9c79f2939..46aae2ed6 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/war/WarManager.java +++ b/src/main/java/fr/openmc/core/features/city/sub/war/WarManager.java @@ -5,8 +5,7 @@ import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import fr.openmc.api.cooldown.DynamicCooldownManager; -import fr.openmc.core.CommandsManager; -import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.sub.mascots.models.Mascot; import fr.openmc.core.features.city.sub.war.commands.AdminWarCommand; @@ -14,6 +13,11 @@ import fr.openmc.core.features.city.sub.war.listeners.WarKillListener; import fr.openmc.core.features.city.sub.war.models.WarHistory; import fr.openmc.core.features.economy.EconomyManager; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.utils.text.messages.MessagesManager; import fr.openmc.core.utils.text.messages.TranslationManager; import fr.openmc.core.utils.world.chunk.ChunkPos; @@ -28,7 +32,7 @@ import java.util.*; import java.util.function.BiConsumer; -public class WarManager { +public class WarManager extends Feature implements HasListeners, HasCommands, HasDatabase { public static final int TIME_PREPARATION = 5; // in minutes public static final int TIME_FIGHT = 30; // in minutes @@ -36,32 +40,46 @@ public class WarManager { public static final long CITY_WINNER_IMMUNITY_FIGHT_COOLDOWN = 24 * 60 * 60 * 1000L; // 1 jour en millisecondes public static final long CITY_DRAW_IMMUNITY_FIGHT_COOLDOWN = 12 * 60 * 60 * 1000L; // 12 heures en millisecondes - public static final Map warsByAttacker = new HashMap<>(); - public static final Map warsByDefender = new HashMap<>(); + public final Map warsByAttacker = new HashMap<>(); + public final Map warsByDefender = new HashMap<>(); - private static final Map pendingDefenses = new HashMap<>(); + private final Map pendingDefenses = new HashMap<>(); - private static Dao warHistoryDeo; + private Dao warHistoryDeo; - public static final Map warHistory = new HashMap<>(); + public final Map warHistory = new HashMap<>(); - /** - * Initializes the WarManager by registering commands and listeners. - */ - public static void init() { - CommandsManager.getHandler().register( - new WarCommand(), + @Override + public Set getCommands() { + return Set.of( + new WarCommand(OMCRegistry.FEATURES.CITY.get()), new AdminWarCommand() ); + } - OMCPlugin.registerEvents( - WarKillListener::new + @Override + public Set getListeners() { + return Set.of( + () -> new WarKillListener(OMCRegistry.FEATURES.CITY.get()) ); + } + + /** + * Initializes the WarManager by registering commands and listeners. + */ + @Override + public void init() { loadWarHistories(); } - public static void initDB(ConnectionSource connectionSource) throws SQLException { + @Override + public void save() { + saveWarHistories(); + } + + @Override + public void initDB(ConnectionSource connectionSource) throws SQLException { TableUtils.createTableIfNotExists(connectionSource, WarHistory.class); warHistoryDeo = DaoManager.createDao(connectionSource, WarHistory.class); @@ -70,7 +88,7 @@ public static void initDB(ConnectionSource connectionSource) throws SQLException } } - public static void loadWarHistories() { + public void loadWarHistories() { try { List warHistories = warHistoryDeo.queryForAll(); @@ -84,7 +102,7 @@ public static void loadWarHistories() { } } - public static void saveWarHistories() { + public void saveWarHistories() { warHistory.forEach((cityUUID, warHistory) -> { try { warHistoryDeo.createOrUpdate(warHistory); @@ -95,7 +113,7 @@ public static void saveWarHistories() { ); } - public static WarHistory createOrGetWarHistory(City city) throws SQLException { + public WarHistory createOrGetWarHistory(City city) throws SQLException { WarHistory history = warHistory.get(city.getUniqueId()); if (history == null) { @@ -114,7 +132,7 @@ public static WarHistory createOrGetWarHistory(City city) throws SQLException { * @param cityUUID The UUID of the city to check. * @return true if the city is in war, false otherwise. */ - public static boolean isCityInWar(UUID cityUUID) { + public boolean isCityInWar(UUID cityUUID) { return warsByAttacker.containsKey(cityUUID) || warsByDefender.containsKey(cityUUID); } @@ -124,7 +142,7 @@ public static boolean isCityInWar(UUID cityUUID) { * @param cityUUID The UUID of the city. * @return The War object if found, null otherwise. */ - public static War getWarByCity(UUID cityUUID) { + public War getWarByCity(UUID cityUUID) { War war = warsByAttacker.get(cityUUID); if (war != null) return war; @@ -140,7 +158,7 @@ public static War getWarByCity(UUID cityUUID) { * @param attackers The list of UUIDs of the players in the attacking city. * @param defenders The list of UUIDs of the players in the defending city. */ - public static void startWar(City attacker, City defender, List attackers, List defenders) { + public void startWar(City attacker, City defender, List attackers, List defenders) { War war = new War(attacker, defender, attackers, defenders); warsByAttacker.put(attacker.getUniqueId(), war); @@ -154,7 +172,7 @@ public static void startWar(City attacker, City defender, List attackers, * * @param war The War object representing the war to be ended. */ - public static void endWar(War war) { + public void endWar(War war) { War warRemoved = warsByAttacker.remove(war.getCityAttacker().getUniqueId()); warsByDefender.remove(war.getCityDefender().getUniqueId()); @@ -289,7 +307,7 @@ public static void endWar(War war) { * @param bonusMoney Additional bonus money awarded to the winning city. * @param claimNumber The number of claims transferred to the winning city. */ - public static void broadcastWarResult(War war, City winner, City loser, WinReason reason, int powerChange, double amountStolen, double bonusMoney, int claimNumber) { + public void broadcastWarResult(War war, City winner, City loser, WinReason reason, int powerChange, double amountStolen, double bonusMoney, int claimNumber) { int killsWinner = war.getCityAttacker().equals(winner) ? war.getAttackersKill() : war.getDefendersKill(); int killsLoser = war.getCityAttacker().equals(loser) ? war.getAttackersKill() : war.getDefendersKill(); @@ -416,7 +434,7 @@ public static void broadcastWarResult(War war, City winner, City loser, WinReaso * @param claimAmount The number of chunks to transfer. * @return The number of chunks actually transferred. */ - public static int transferChunksAfterWar(City winner, City loser, int claimAmount) { + public int transferChunksAfterWar(City winner, City loser, int claimAmount) { if (claimAmount <= 0) return 0; ChunkPos mascotVec = new ChunkPos( @@ -530,7 +548,7 @@ public static int transferChunksAfterWar(City winner, City loser, int claimAmoun * @param phase The war phase to format. * @return A string representing the formatted phase. */ - public static String getFormattedPhase(War.WarPhase phase) { + public String getFormattedPhase(War.WarPhase phase) { return switch (phase) { case PREPARATION -> "Préparation"; case COMBAT -> "Combat"; @@ -543,7 +561,7 @@ public static String getFormattedPhase(War.WarPhase phase) { * * @param defense The WarPendingDefense object containing the defense details. */ - public static void addPendingDefense(WarPendingDefense defense) { + public void addPendingDefense(WarPendingDefense defense) { pendingDefenses.put(defense.getDefender().getUniqueId(), defense); } @@ -552,7 +570,7 @@ public static void addPendingDefense(WarPendingDefense defense) { * * @param city The city for which the pending defense is to be removed. */ - public static WarPendingDefense getPendingDefenseFor(City city) { + public WarPendingDefense getPendingDefenseFor(City city) { return pendingDefenses.get(city.getUniqueId()); } diff --git a/src/main/java/fr/openmc/core/features/city/sub/war/actions/WarActions.java b/src/main/java/fr/openmc/core/features/city/sub/war/actions/WarActions.java index f2a7642f9..7c8f8b662 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/war/actions/WarActions.java +++ b/src/main/java/fr/openmc/core/features/city/sub/war/actions/WarActions.java @@ -2,7 +2,7 @@ import fr.openmc.api.menulib.template.ConfirmMenu; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; @@ -12,6 +12,7 @@ import fr.openmc.core.features.city.sub.war.WarPendingDefense; import fr.openmc.core.features.city.sub.war.menu.selection.WarChooseParticipantsMenu; import fr.openmc.core.features.city.sub.war.menu.selection.WarChooseSizeMenu; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; import fr.openmc.core.utils.text.messages.Prefix; @@ -38,7 +39,9 @@ public class WarActions { */ public static void beginLaunchWar(Player player, City cityAttack) { UUID launcherUUID = player.getUniqueId(); - City launchCity = CityManager.getPlayerCity(launcherUUID); + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); + WarManager warManager = OMCRegistry.FEATURES.CITY.get().WAR; + City launchCity = cityManager.getPlayerCity(launcherUUID); if (launchCity == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); @@ -75,7 +78,7 @@ public static void beginLaunchWar(Player player, City cityAttack) { return; } - if (WarManager.getPendingDefenseFor(launchCity) != null) { + if (warManager.getPendingDefenseFor(launchCity) != null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.war.begin.already_declared"), Prefix.CITY, MessageType.ERROR, false); @@ -89,7 +92,7 @@ public static void beginLaunchWar(Player player, City cityAttack) { return; } - if (WarManager.getPendingDefenseFor(cityAttack) != null) { + if (warManager.getPendingDefenseFor(cityAttack) != null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.war.begin.target_preparing"), Prefix.CITY, MessageType.ERROR, false); @@ -278,7 +281,7 @@ public static void finishLaunchWar(Player player, City cityLaunch, City cityAtta ), Prefix.CITY, MessageType.INFO, false); WarPendingDefense pending = new WarPendingDefense(cityLaunch, cityAttack, attackers, requiredParticipants); - WarManager.addPendingDefense(pending); + OMCRegistry.FEATURES.CITY.get().WAR.addPendingDefense(pending); Bukkit.getScheduler().runTaskLater(OMCPlugin.getInstance(), () -> { if (pending.isAlreadyExecuted()) return; @@ -344,6 +347,6 @@ public static void launchWar(City cityLaunch, City cityAttack, List attack } } - WarManager.startWar(cityLaunch, cityAttack, attackers, chosenDefenders); + OMCRegistry.FEATURES.CITY.get().WAR.startWar(cityLaunch, cityAttack, attackers, chosenDefenders); } } diff --git a/src/main/java/fr/openmc/core/features/city/sub/war/commands/AdminWarCommand.java b/src/main/java/fr/openmc/core/features/city/sub/war/commands/AdminWarCommand.java index 2520c47dc..ee7ba698c 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/war/commands/AdminWarCommand.java +++ b/src/main/java/fr/openmc/core/features/city/sub/war/commands/AdminWarCommand.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.city.sub.war.commands; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.commands.autocomplete.CityNameAutoComplete; import fr.openmc.core.features.city.sub.war.War; import fr.openmc.core.utils.text.messages.MessageType; @@ -24,7 +24,7 @@ void startCombat( Player player, @Named("name") @SuggestWith(CityNameAutoComplete.class) String cityName ) { - City city = CityManager.getCityByName(cityName); + City city = OMCRegistry.FEATURES.CITY.get().getCityByName(cityName); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.not_found"), Prefix.STAFF, MessageType.ERROR, false); diff --git a/src/main/java/fr/openmc/core/features/city/sub/war/commands/WarCommand.java b/src/main/java/fr/openmc/core/features/city/sub/war/commands/WarCommand.java index 749f2a0dd..df2c8a94b 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/war/commands/WarCommand.java +++ b/src/main/java/fr/openmc/core/features/city/sub/war/commands/WarCommand.java @@ -31,9 +31,17 @@ @Command({"guerre", "war"}) @CommandPermission("omc.commands.city.war") public class WarCommand { + private final CityManager cityManager; + private final WarManager warManager; + + public WarCommand(CityManager cityManager) { + this.cityManager = cityManager; + this.warManager = cityManager.WAR; + } + @CommandPlaceholder() void mainCommand(Player player) { - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = cityManager.getPlayerCity(player.getUniqueId()); if (playerCity == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); return; @@ -72,7 +80,7 @@ void mainCommand(Player player) { return; } - if (WarManager.getPendingDefenseFor(playerCity) != null) { + if (warManager.getPendingDefenseFor(playerCity) != null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.war.command.already_declared"), Prefix.CITY, MessageType.ERROR, false); @@ -93,7 +101,7 @@ void mainCommand(Player player) { @CommandPermission("omc.commands.city.war.acceptdefense") @Description("Accepter de participer a une guerre") public void acceptDefense(Player player) { - City city = CityManager.getPlayerCity(player.getUniqueId()); + City city = cityManager.getPlayerCity(player.getUniqueId()); if (city == null) { MessagesManager.sendMessage(player, TranslationManager.translation("messages.city.player_no_in_city"), Prefix.CITY, MessageType.ERROR, false); return; @@ -107,7 +115,7 @@ public void acceptDefense(Player player) { return; } - WarPendingDefense pending = WarManager.getPendingDefenseFor(city); + WarPendingDefense pending = warManager.getPendingDefenseFor(city); if (pending == null) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.city.war.command.defense.none"), diff --git a/src/main/java/fr/openmc/core/features/city/sub/war/listeners/WarKillListener.java b/src/main/java/fr/openmc/core/features/city/sub/war/listeners/WarKillListener.java index a6fb079ec..dda234a7b 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/war/listeners/WarKillListener.java +++ b/src/main/java/fr/openmc/core/features/city/sub/war/listeners/WarKillListener.java @@ -11,6 +11,11 @@ import java.util.UUID; public class WarKillListener implements Listener { + private final CityManager cityManager; + + public WarKillListener(CityManager cityManager) { + this.cityManager = cityManager; + } @EventHandler public void onPlayerDeath(PlayerDeathEvent event) { @@ -22,8 +27,8 @@ public void onPlayerDeath(PlayerDeathEvent event) { UUID victimUUID = victim.getUniqueId(); UUID killerUUID = killer.getUniqueId(); - City victimCity = CityManager.getPlayerCity(victimUUID); - City killerCity = CityManager.getPlayerCity(killerUUID); + City victimCity = cityManager.getPlayerCity(victimUUID); + City killerCity = cityManager.getPlayerCity(killerUUID); if (victimCity == null || killerCity == null) return; diff --git a/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/MainWarMenu.java b/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/MainWarMenu.java index c2612ea85..a13123ada 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/MainWarMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/MainWarMenu.java @@ -6,14 +6,15 @@ import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.api.menulib.utils.ItemUtils; import fr.openmc.api.menulib.utils.StaticSlots; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.CityPermission; import fr.openmc.core.features.city.CityType; import fr.openmc.core.features.city.sub.mascots.models.Mascot; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; import fr.openmc.core.features.city.sub.mayor.models.Mayor; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.city.sub.war.WarManager; import fr.openmc.core.features.city.sub.war.actions.WarActions; @@ -41,9 +42,15 @@ import java.util.*; public class MainWarMenu extends PaginatedMenu { + private final CityManager cityManager; + private final WarManager warManager; + private final MayorManager mayorManager; public MainWarMenu(Player owner) { super(owner); + this.cityManager = OMCRegistry.FEATURES.CITY.get(); + this.warManager = cityManager.WAR; + this.mayorManager = cityManager.MAYOR; } @Override @@ -70,16 +77,15 @@ public int getSizeOfItems() { public List getItems() { List items = new ArrayList<>(); Player player = getOwner(); - - List warCities = CityManager.getCities().stream() + List warCities = cityManager.getCities().stream() .sorted((c1, c2) -> Integer.compare(c2.getOnlineMembers().size(), c1.getOnlineMembers().size())) .toList(); for (City city : warCities) { - if (city.getUniqueId().equals(CityManager.getPlayerCity(player.getUniqueId()).getUniqueId())) continue; + if (city.getUniqueId().equals(cityManager.getPlayerCity(player.getUniqueId()).getUniqueId())) continue; if (city.getType() != CityType.WAR) continue; if (city.isImmune()) continue; - if (WarManager.getPendingDefenseFor(city) != null) continue; + if (warManager.getPendingDefenseFor(city) != null) continue; if (city.isInWar()) continue; long onlineCount = city.getOnlineMembers().size(); @@ -113,10 +119,10 @@ public List getItems() { )); Mayor mayor = city.getMayor(); - if (MayorManager.phaseMayor == 2 && mayor != null) { - Perks perk1 = PerkManager.getPerkById(mayor.getIdPerk1()); - Perks perk2 = PerkManager.getPerkById(mayor.getIdPerk2()); - Perks perk3 = PerkManager.getPerkById(mayor.getIdPerk3()); + if (mayorManager.phaseMayor == 2 && mayor != null) { + Perks perk1 = PerkUtils.getPerkById(mayor.getIdPerk1()); + Perks perk2 = PerkUtils.getPerkById(mayor.getIdPerk2()); + Perks perk3 = PerkUtils.getPerkById(mayor.getIdPerk3()); loreCity.add(TranslationManager.translation("feature.city.war.menu.main.reforms").color(NamedTextColor.GRAY)); if (perk1 != null) loreCity.add(Component.text(" - ") diff --git a/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/WarCityDetailsMenu.java b/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/WarCityDetailsMenu.java index 44ffff6c6..612cb4dd0 100644 --- a/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/WarCityDetailsMenu.java +++ b/src/main/java/fr/openmc/core/features/city/sub/war/menu/main/WarCityDetailsMenu.java @@ -7,8 +7,8 @@ import fr.openmc.core.features.city.CityType; import fr.openmc.core.features.city.sub.mascots.models.Mascot; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; import fr.openmc.core.features.city.sub.mayor.models.Mayor; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.economy.EconomyManager; import fr.openmc.core.utils.text.messages.TranslationManager; @@ -68,9 +68,9 @@ public void onInventoryClick(InventoryClickEvent inventoryClickEvent) { Mayor mayor = city.getMayor(); if (MayorManager.phaseMayor == 2 && mayor != null) { - Perks perk1 = PerkManager.getPerkById(mayor.getIdPerk1()); - Perks perk2 = PerkManager.getPerkById(mayor.getIdPerk2()); - Perks perk3 = PerkManager.getPerkById(mayor.getIdPerk3()); + Perks perk1 = PerkUtils.getPerkById(mayor.getIdPerk1()); + Perks perk2 = PerkUtils.getPerkById(mayor.getIdPerk2()); + Perks perk3 = PerkUtils.getPerkById(mayor.getIdPerk3()); ItemStack iaPerk1 = (perk1 != null) ? perk1.getItemStack() : ItemStack.of(Material.DEAD_BRAIN_CORAL_BLOCK); Component namePerk1 = (perk1 != null) ? TranslationManager.translation(perk1.getNameKey()) : diff --git a/src/main/java/fr/openmc/core/features/city/view/CityViewManager.java b/src/main/java/fr/openmc/core/features/city/view/CityViewManager.java index eb2db322d..3845d94e3 100644 --- a/src/main/java/fr/openmc/core/features/city/view/CityViewManager.java +++ b/src/main/java/fr/openmc/core/features/city/view/CityViewManager.java @@ -1,9 +1,9 @@ package fr.openmc.core.features.city.view; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; -import fr.openmc.core.hooks.WorldGuardHook; import fr.openmc.core.utils.bukkit.ParticleUtils; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; @@ -55,7 +55,7 @@ public static void startView(@NotNull Player player) { ); } - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); ScheduledTask task = createViewTask(player, playerCity); activeViewers.put(player.getUniqueId(), new CityViewData(task, claimsToShow)); @@ -117,6 +117,7 @@ public static void updateView(@NotNull UUID playerUUID) { private static Object2ObjectMap collectClaimsInRadius(@NotNull Player player) { Object2ObjectMap claims = new Object2ObjectOpenHashMap<>(); ChunkPos playerChunk = ChunkPos.fromChunk(player.getChunk()); + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); for (int x = -VIEW_RADIUS_CHUNKS; x <= VIEW_RADIUS_CHUNKS; x++) { for (int z = -VIEW_RADIUS_CHUNKS; z <= VIEW_RADIUS_CHUNKS; z++) { @@ -124,7 +125,7 @@ private static Object2ObjectMap collectClaimsInRadius(@NotNull P int chunkZ = playerChunk.z() + z; ChunkPos claim = new ChunkPos(chunkX, chunkZ); - City city = CityManager.getCityFromChunk(claim); + City city = cityManager.getCityFromChunk(claim); if (city == null) continue; @@ -149,7 +150,7 @@ private static ScheduledTask createViewTask(@NotNull Player player, @Nullable Ci return; viewData.claims().forEach((chunkPos, city) -> { - showChunkBorders(player, chunkPos, city, city.equals(playerCity), WorldGuardHook.doesChunkContainWGRegion(chunkPos.getChunkInWorld()), player.getLocation().getBlockY() + 1); + showChunkBorders(player, chunkPos, city, city.equals(playerCity), OMCRegistry.HOOKS.WORLD_GUARD.doesChunkContainWGRegion(chunkPos.getChunkInWorld()), player.getLocation().getBlockY() + 1); }); }, 0L, VIEW_INTERVAL_SECONDS, TimeUnit.SECONDS); } diff --git a/src/main/java/fr/openmc/core/features/credits/Credits.java b/src/main/java/fr/openmc/core/features/credits/Credits.java index e34f31f69..f46df1259 100644 --- a/src/main/java/fr/openmc/core/features/credits/Credits.java +++ b/src/main/java/fr/openmc/core/features/credits/Credits.java @@ -1,12 +1,10 @@ package fr.openmc.core.features.credits; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; import fr.openmc.core.features.adminshop.AdminShopManager; import fr.openmc.core.features.animations.AnimationsManager; -import fr.openmc.core.features.chatanimations.ChatAnimationManager; import fr.openmc.core.features.bits.BitsManager; +import fr.openmc.core.features.chatanimations.ChatAnimationManager; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.mascots.MascotsManager; import fr.openmc.core.features.displays.holograms.HologramLoader; @@ -29,6 +27,8 @@ import fr.openmc.core.features.shops.managers.ShopManager; import fr.openmc.core.features.tickets.TicketManager; import fr.openmc.core.features.tpa.TPAManager; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.registry.items.CustomItem; import lombok.Getter; import org.bukkit.Material; 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 1e18f78e2..15959e7c7 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 @@ -1,19 +1,17 @@ package fr.openmc.core.features.cube.multiblocks; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.cube.Cube; import fr.openmc.core.features.cube.commands.CubeCommands; import fr.openmc.core.features.cube.listeners.CubeListener; import fr.openmc.core.features.cube.listeners.RepulseEffectListener; import fr.openmc.core.features.dream.DreamDimensionManager; import fr.openmc.core.features.dream.DreamUtils; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -26,7 +24,7 @@ import java.io.IOException; import java.util.*; -public class MultiBlockManager extends Feature implements LoadAfterItemsAdder, NotLoadInUnitTest, HasListeners, HasCommands { +public class MultiBlockManager extends Feature implements HasListeners, HasCommands { @Getter public static final List multiBlocks = new ArrayList<>(); private static FileConfiguration config = null; diff --git a/src/main/java/fr/openmc/core/features/dimopener/DimensionOpenerManager.java b/src/main/java/fr/openmc/core/features/dimopener/DimensionOpenerManager.java index e927baf7c..966e4518d 100644 --- a/src/main/java/fr/openmc/core/features/dimopener/DimensionOpenerManager.java +++ b/src/main/java/fr/openmc/core/features/dimopener/DimensionOpenerManager.java @@ -4,17 +4,16 @@ import com.google.gson.GsonBuilder; import fr.openmc.core.OMCPlugin; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.dimopener.commands.DimensionCommands; import fr.openmc.core.features.dimopener.data.DimensionData; import fr.openmc.core.features.dimopener.data.StepDimensionData; import fr.openmc.core.features.dimopener.listener.DimensionAccessListener; import fr.openmc.core.features.economy.EconomyManager; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.registry.items.CustomItem; import fr.openmc.core.utils.FilesUtils; import fr.openmc.core.utils.text.messages.MessageType; @@ -42,7 +41,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; -public class DimensionOpenerManager extends Feature implements HasListeners, HasCommands, LoadAfterItemsAdder { +public class DimensionOpenerManager extends Feature implements HasListeners, HasCommands { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); private static final String DIMENSIONS_FOLDER = "data/dimensions"; 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 3fd9c67c4..62f9d2e73 100644 --- a/src/main/java/fr/openmc/core/features/displays/TabList.java +++ b/src/main/java/fr/openmc/core/features/displays/TabList.java @@ -9,12 +9,9 @@ import com.comphenix.protocol.events.PacketEvent; import dev.lone.itemsadder.api.FontImages.FontImageWrapper; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.LoadIfEnable; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; import fr.openmc.core.features.dream.DreamUtils; -import fr.openmc.core.hooks.ProtocolLibHook; import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.utils.text.messages.TranslationManager; import io.papermc.paper.adventure.PaperAdventure; import net.kyori.adventure.text.Component; @@ -29,7 +26,7 @@ import java.util.List; import java.util.UUID; -public class TabList extends Feature implements NotLoadInUnitTest, LoadIfEnable { +public class TabList extends Feature { private static ProtocolManager protocolManager = null; @Override 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 2e233905d..cc2d00615 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 @@ -1,13 +1,12 @@ package fr.openmc.core.features.displays.bossbar; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; import fr.openmc.core.features.displays.bossbar.commands.BossBarCommand; import fr.openmc.core.features.displays.bossbar.contents.MainBossbar; import fr.openmc.core.features.dream.displays.DreamBossBar; import fr.openmc.core.features.events.contents.dailyevents.display.DailyEventBossbar; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.registry.features.Feature; import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; @@ -19,7 +18,7 @@ /** * Gère l'enregistrement, l'affichage et la mise à jour des boss bars. */ -public class BossbarManager extends Feature implements HasCommands, LoadAfterItemsAdder { +public class BossbarManager extends Feature implements HasCommands { private static final List registeredBossbar = new ArrayList<>(); private static final Map> activeBossbars = new HashMap<>(); diff --git a/src/main/java/fr/openmc/core/features/displays/bossbar/contents/HelpConfigManager.java b/src/main/java/fr/openmc/core/features/displays/bossbar/contents/HelpConfigManager.java index aea1d4833..209eea7da 100644 --- a/src/main/java/fr/openmc/core/features/displays/bossbar/contents/HelpConfigManager.java +++ b/src/main/java/fr/openmc/core/features/displays/bossbar/contents/HelpConfigManager.java @@ -1,8 +1,8 @@ package fr.openmc.core.features.displays.bossbar.contents; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.registry.features.Feature; import lombok.Getter; import org.bukkit.configuration.file.YamlConfiguration; 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 e0b63fcdb..ea13a6ed9 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 @@ -1,14 +1,12 @@ package fr.openmc.core.features.displays.holograms; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.displays.holograms.commands.HologramCommand; import fr.openmc.core.features.milestones.tutorial.TutorialHologram; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.world.entities.TextDisplay; import net.kyori.adventure.text.Component; import org.bukkit.Location; @@ -25,7 +23,7 @@ import java.util.Set; @Credit(developers = {"iambibi_", "miseur"}) -public class HologramLoader extends Feature implements NotLoadInUnitTest, LoadAfterItemsAdder, HasCommands { +public class HologramLoader extends Feature implements HasCommands { public static final HashMap displays = new HashMap<>(); private static BukkitTask taskTimer; diff --git a/src/main/java/fr/openmc/core/features/displays/scoreboards/GlobalTeamManager.java b/src/main/java/fr/openmc/core/features/displays/scoreboards/GlobalTeamManager.java index 68fa12933..d93884062 100644 --- a/src/main/java/fr/openmc/core/features/displays/scoreboards/GlobalTeamManager.java +++ b/src/main/java/fr/openmc/core/features/displays/scoreboards/GlobalTeamManager.java @@ -22,17 +22,19 @@ public class GlobalTeamManager { private LuckPerms luckPerms = null; + private LuckPermsHook hook = null; private final ObjectCacheRepository boardCache; private final Map groupToPrefixCache = new ConcurrentHashMap<>(); private record TeamState(Set members, Component prefix) {} private final Map teams = new ConcurrentHashMap<>(); private final Map playerTeam = new ConcurrentHashMap<>(); - public GlobalTeamManager(ObjectCacheRepository boardCache) { + public GlobalTeamManager(ObjectCacheRepository boardCache, LuckPermsHook hook) { this.boardCache = boardCache; - if (LuckPermsHook.isEnable()) { - this.luckPerms = LuckPermsHook.getApi(); + if (hook.isEnable()) { + this.hook = hook; + this.luckPerms = hook.getApi(); initSortedGroups(); this.luckPerms.getEventBus().subscribe( @@ -47,7 +49,7 @@ private void initSortedGroups() { List sortedGroups = new ArrayList<>(luckPerms.getGroupManager().getLoadedGroups()); sortedGroups.sort(Comparator.comparing(g -> -g.getWeight().orElse(0))); for (Group group : sortedGroups) { - groupToPrefixCache.put(group.getName(), LuckPermsHook.getFormattedPAPIPrefix(group)); + groupToPrefixCache.put(group.getName(), hook.getFormattedPAPIPrefix(group)); } } @@ -62,7 +64,7 @@ public void updatePlayerTeam(Player player) { Component prefix = groupToPrefixCache.computeIfAbsent( playerGroup.getName(), - _ -> LuckPermsHook.getFormattedPAPIPrefix(playerGroup) + _ -> hook.getFormattedPAPIPrefix(playerGroup) ); int weight = playerGroup.getWeight().orElse(0); diff --git a/src/main/java/fr/openmc/core/features/displays/scoreboards/ScoreboardListener.java b/src/main/java/fr/openmc/core/features/displays/scoreboards/ScoreboardListener.java index 59c02ddff..02100bd01 100644 --- a/src/main/java/fr/openmc/core/features/displays/scoreboards/ScoreboardListener.java +++ b/src/main/java/fr/openmc/core/features/displays/scoreboards/ScoreboardListener.java @@ -7,20 +7,24 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import static fr.openmc.core.features.displays.scoreboards.ScoreboardManager.*; - public class ScoreboardListener implements Listener { + + private final ScoreboardManager manager; + public ScoreboardListener(ScoreboardManager manager) { + this.manager = manager; + } + @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - SternalBoard board = boardCache.find(player.getUniqueId()); + SternalBoard board = manager.boardCache.find(player.getUniqueId()); - if (board == null) createNewBoard(player); - else updateBoard(player, board); + if (board == null) manager.createNewBoard(player); + else manager.updateBoard(player, board); } @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - cleanupPlayer(event.getPlayer()); + manager.cleanupPlayer(event.getPlayer()); } } \ No newline at end of file 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 b62818f6c..ef011c998 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 @@ -4,31 +4,33 @@ import fr.openmc.api.scoreboard.repository.ObjectCacheRepository; import fr.openmc.api.scoreboard.repository.impl.ObjectCacheRepositoryImpl; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.features.types.LoadIfEnable; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.displays.scoreboards.sb.CityWarScoreboard; 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.hooks.LuckPermsHook; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import java.util.*; -public class ScoreboardManager extends Feature implements Listener, NotLoadInUnitTest, LoadIfEnable, HasListeners { - public static final ObjectCacheRepository boardCache = new ObjectCacheRepositoryImpl(); - private static final List scoreboards = new ArrayList<>(); - private static GlobalTeamManager globalTeamManager; +public class ScoreboardManager extends Feature implements Listener, HasListeners { + private LuckPermsHook luckPermsHook; + public final ObjectCacheRepository boardCache = new ObjectCacheRepositoryImpl(); + private final List scoreboards = new ArrayList<>(); + private GlobalTeamManager globalTeamManager; private static final Map> lastUpdate = new HashMap<>(); @Override public void init() { + luckPermsHook = OMCRegistry.HOOKS.LUCK_PERMS; + registerScoreboard( new MainScoreboard(), new RestartScoreboard(), @@ -38,21 +40,21 @@ public void init() { Bukkit.getScheduler().runTaskTimer( OMCPlugin.getInstance(), - ScoreboardManager::updateAllBoards, + this::updateAllBoards, 0L, 20L // every second ); - if (LuckPermsHook.isEnable()) - globalTeamManager = new GlobalTeamManager(boardCache); + if (luckPermsHook.isEnable()) + globalTeamManager = new GlobalTeamManager(boardCache, luckPermsHook); } @Override public Set getListeners() { - return Set.of(ScoreboardListener::new); + return Set.of(() -> new ScoreboardListener(this)); } - public static void updateAllBoards() { + public void updateAllBoards() { long now = System.currentTimeMillis(); Bukkit.getOnlinePlayers().forEach(player -> { @@ -81,20 +83,20 @@ public static void updateAllBoards() { active.update(player, board); playerUpdates.put(active, now); - if (LuckPermsHook.isEnable() && globalTeamManager != null) { + if (luckPermsHook.isEnable() && globalTeamManager != null) { globalTeamManager.updatePlayerTeam(player); } }); } - public static SternalBoard createNewBoard(Player player) { + public SternalBoard createNewBoard(Player player) { SternalBoard board = new SternalBoard(player); updateBoard(player, board); boardCache.create(board); return board; } - public static void updateBoard(Player player, SternalBoard board) { + public void updateBoard(Player player, SternalBoard board) { for (BaseScoreboard scoreboard : scoreboards) { if (scoreboard.shouldDisplay(player)) { scoreboard.init(player, board); @@ -102,17 +104,17 @@ public static void updateBoard(Player player, SternalBoard board) { } } - if (LuckPermsHook.isEnable() && globalTeamManager != null) { + if (luckPermsHook.isEnable() && globalTeamManager != null) { globalTeamManager.updatePlayerTeam(player); } } - public static void registerScoreboard(BaseScoreboard... scoreboard) { + public void registerScoreboard(BaseScoreboard... scoreboard) { scoreboards.addAll(Arrays.asList(scoreboard)); scoreboards.sort(Comparator.comparingInt(BaseScoreboard::priority).reversed()); } - public static void cleanupPlayer(Player player) { + public void cleanupPlayer(Player player) { UUID uuid = player.getUniqueId(); lastUpdate.remove(uuid); boardCache.delete(uuid); diff --git a/src/main/java/fr/openmc/core/features/displays/scoreboards/sb/MainScoreboard.java b/src/main/java/fr/openmc/core/features/displays/scoreboards/sb/MainScoreboard.java index 67ec91649..458b29b89 100644 --- a/src/main/java/fr/openmc/core/features/displays/scoreboards/sb/MainScoreboard.java +++ b/src/main/java/fr/openmc/core/features/displays/scoreboards/sb/MainScoreboard.java @@ -4,6 +4,7 @@ import de.oliver.fancynpcs.api.Npc; import de.oliver.fancynpcs.api.NpcManager; import fr.openmc.api.scoreboard.SternalBoard; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.bits.BitsManager; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; @@ -15,9 +16,6 @@ import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.ContestPhase; import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.managers.ContestManager; import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.models.ContestData; -import fr.openmc.core.hooks.FancyNpcsHook; -import fr.openmc.core.hooks.LuckPermsHook; -import fr.openmc.core.hooks.WorldGuardHook; import fr.openmc.core.utils.text.DateUtils; import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.text.Component; @@ -76,21 +74,23 @@ public void update(Player player, SternalBoard board) { } public static List getDefaultLines(Player player) { - Component rank = LuckPermsHook.isEnable() - ? Component.text(LuckPermsHook.getFormattedPAPIPrefix(player)) - : TranslationManager.translation("feature.displays.scoreboard.rank.none.to_small").color(TextColor.color(0xFF1FCC)); + BitsManager bitsManager = OMCRegistry.FEATURES.BITS.get(); + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); + Component rank = OMCRegistry.HOOKS.LUCK_PERMS.isEnable() + ? Component.text(OMCRegistry.HOOKS.LUCK_PERMS.getFormattedPAPIPrefix(player)) + : TranslationManager.translation("feature.displays.scoreboard.rank.none.to_small").color(TextColor.color(0xFF1FCC)); - City city = CityManager.getPlayerCity(player.getUniqueId()); - City chunkCity = CityManager.getCityFromChunk(player.getChunk().getX(), player.getChunk().getZ()); - boolean isInRegion = WorldGuardHook.isRegionConflict(player.getLocation()); + City city = cityManager.getPlayerCity(player.getUniqueId()); + City chunkCity = cityManager.getCityFromChunk(player.getChunk().getX(), player.getChunk().getZ()); + boolean isInRegion = OMCRegistry.HOOKS.WORLD_GUARD.isRegionConflict(player.getLocation()); Component location = isInRegion ? TranslationManager.translation("feature.displays.scoreboard.location.protected.to_small") : TranslationManager.translation("feature.displays.scoreboard.location.wilderness.to_small"); location = (chunkCity != null) ? textToSmallComponent(chunkCity.getName()) : location; String balance = EconomyManager.getMiniBalance(player.getUniqueId()); - double bits = BitsManager.getBits(player.getUniqueId()); + double bits = bitsManager.getBits(player.getUniqueId()); List lines = new ArrayList<>(); @@ -121,7 +121,7 @@ public static List getDefaultLines(Player player) { .appendSpace() .append(textToSmallComponent(EconomyManager.getFormattedSimplifiedNumber(bits)).color(TextColor.color(0x07A0F5))) .appendSpace() - .append(text(BitsManager.getBitsIcon())) + .append(text(bitsManager.getBitsIcon())) ); } lines.add(text(" • ", NamedTextColor.DARK_GRAY) @@ -130,7 +130,7 @@ public static List getDefaultLines(Player player) { .append(location.color(TextColor.color(0xFF06DC))) ); - if (FancyNpcsHook.isEnable()) { + if (OMCRegistry.HOOKS.FANCY_NPCS.isEnable()) { NpcManager npcManager = FancyNpcsPlugin.get().getNpcManager(); Npc halloweenNPC = null; if (npcManager != null) diff --git a/src/main/java/fr/openmc/core/features/dream/DreamDimensionManager.java b/src/main/java/fr/openmc/core/features/dream/DreamDimensionManager.java index 02c8bb437..0eca5e2b1 100644 --- a/src/main/java/fr/openmc/core/features/dream/DreamDimensionManager.java +++ b/src/main/java/fr/openmc/core/features/dream/DreamDimensionManager.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.dream; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; import org.bukkit.Bukkit; import org.bukkit.GameRules; import org.bukkit.World; 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 4a51ea934..bb66c52ce 100644 --- a/src/main/java/fr/openmc/core/features/dream/DreamManager.java +++ b/src/main/java/fr/openmc/core/features/dream/DreamManager.java @@ -4,18 +4,10 @@ import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.commands.utils.SpawnManager; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.dream.commands.AdminDreamCommands; import fr.openmc.core.features.dream.commands.DreamCommands; @@ -40,6 +32,13 @@ import fr.openmc.core.features.dream.models.db.DreamPlayer; import fr.openmc.core.features.dream.models.registry.items.DreamItem; import fr.openmc.core.features.dream.registries.*; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.bukkit.serializer.BukkitSerializer; import fr.openmc.core.utils.world.LocationUtils; import org.bukkit.Bukkit; @@ -57,7 +56,7 @@ import java.util.UUID; @Credit(developers = {"iambibi_", "gab400"}, graphist = {"Tfloa"}, builders = {"Mcross_bow"}) -public class DreamManager extends Feature implements HasDatabase, LoadAfterItemsAdder, HasCommands, HasListeners { +public class DreamManager extends Feature implements HasDatabase, HasCommands, HasListeners { // ** CONSTANTS ** public static final Long BASE_DREAM_TIME = 300L; @@ -381,8 +380,8 @@ public static double calculateDreamProbability(Player player) { } } - City city = CityManager.getPlayerCity(player.getUniqueId()); - if (city != null && PerkManager.hasPerk(city.getMayor(), Perks.GREAT_SLEEPER.getId())) { + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); + if (city != null && PerkUtils.hasPerk(city.getMayor(), Perks.GREAT_SLEEPER.getId())) { base += 0.4; } return base; diff --git a/src/main/java/fr/openmc/core/features/dream/listeners/dream/PlayerObtainOrb.java b/src/main/java/fr/openmc/core/features/dream/listeners/dream/PlayerObtainOrb.java index 941ee7d37..083780b82 100644 --- a/src/main/java/fr/openmc/core/features/dream/listeners/dream/PlayerObtainOrb.java +++ b/src/main/java/fr/openmc/core/features/dream/listeners/dream/PlayerObtainOrb.java @@ -1,6 +1,5 @@ package fr.openmc.core.features.dream.listeners.dream; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.dream.DreamManager; import fr.openmc.core.features.dream.events.AltarCraftingEvent; import fr.openmc.core.features.dream.events.GlaciteTradeEvent; @@ -11,6 +10,7 @@ import fr.openmc.core.features.dream.models.registry.items.DreamItem; import fr.openmc.core.features.dream.registries.DreamBiome; import fr.openmc.core.features.dream.registries.DreamItemRegistry; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.registry.loottable.loots.CustomLoot; import fr.openmc.core.registry.loottable.loots.ItemLoot; import fr.openmc.core.utils.bukkit.ParticleUtils; diff --git a/src/main/java/fr/openmc/core/features/dream/mecanism/cloudcastle/StrayCloudSpawner.java b/src/main/java/fr/openmc/core/features/dream/mecanism/cloudcastle/StrayCloudSpawner.java index 6ac66f147..458aa8bad 100644 --- a/src/main/java/fr/openmc/core/features/dream/mecanism/cloudcastle/StrayCloudSpawner.java +++ b/src/main/java/fr/openmc/core/features/dream/mecanism/cloudcastle/StrayCloudSpawner.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.dream.mecanism.cloudcastle; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.dream.registries.DreamMobsRegistry; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.registry.mobs.CustomMob; import org.bukkit.Bukkit; import org.bukkit.Material; diff --git a/src/main/java/fr/openmc/core/features/dream/mecanism/sfx/clone/PlayerCloneNpc.java b/src/main/java/fr/openmc/core/features/dream/mecanism/sfx/clone/PlayerCloneNpc.java index 67e1872c1..3ecb18a0d 100644 --- a/src/main/java/fr/openmc/core/features/dream/mecanism/sfx/clone/PlayerCloneNpc.java +++ b/src/main/java/fr/openmc/core/features/dream/mecanism/sfx/clone/PlayerCloneNpc.java @@ -7,8 +7,8 @@ import de.oliver.fancynpcs.api.skins.SkinLoadException; import de.oliver.fancynpcs.api.utils.NpcEquipmentSlot; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.hooks.FancyNpcsHook; +import fr.openmc.core.lifecycle.integration.OMCLogger; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; diff --git a/src/main/java/fr/openmc/core/features/dream/mecanism/tradernpc/GlaciteNpcManager.java b/src/main/java/fr/openmc/core/features/dream/mecanism/tradernpc/GlaciteNpcManager.java index b91b89ef3..963f4b9c8 100644 --- a/src/main/java/fr/openmc/core/features/dream/mecanism/tradernpc/GlaciteNpcManager.java +++ b/src/main/java/fr/openmc/core/features/dream/mecanism/tradernpc/GlaciteNpcManager.java @@ -4,9 +4,9 @@ import de.oliver.fancynpcs.api.Npc; import de.oliver.fancynpcs.api.NpcData; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.dream.DreamDimensionManager; import fr.openmc.core.hooks.FancyNpcsHook; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; diff --git a/src/main/java/fr/openmc/core/features/dream/models/db/DreamPlayer.java b/src/main/java/fr/openmc/core/features/dream/models/db/DreamPlayer.java index 0c33db569..53ffdbc0c 100644 --- a/src/main/java/fr/openmc/core/features/dream/models/db/DreamPlayer.java +++ b/src/main/java/fr/openmc/core/features/dream/models/db/DreamPlayer.java @@ -3,7 +3,7 @@ import fr.openmc.core.OMCPlugin; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.dream.DreamManager; import fr.openmc.core.features.dream.events.DreamEndEvent; @@ -53,7 +53,7 @@ public DreamPlayer(Player player, ItemStack[] oldInv, Location oldLocation, Play this.dreamTime = cacheData == null ? DreamManager.BASE_DREAM_TIME : cacheData.getMaxDreamTime(); City city = CityManager.getPlayerCity(player.getUniqueId()); - if (city != null && PerkManager.hasPerk(city.getMayor(), Perks.GREAT_DREAM.getId())) { + if (city != null && PerkUtils.hasPerk(city.getMayor(), Perks.GREAT_DREAM.getId())) { this.dreamTime = (long) (this.dreamTime * 1.6); MessagesManager.sendMessage(player, TranslationManager.translation("feature.dream.message.great_dream_bonus"), Prefix.MAYOR, MessageType.INFO, false diff --git a/src/main/java/fr/openmc/core/features/dream/registries/DreamBlocksRegistry.java b/src/main/java/fr/openmc/core/features/dream/registries/DreamBlocksRegistry.java index 4ee1d5df6..f93a182ce 100644 --- a/src/main/java/fr/openmc/core/features/dream/registries/DreamBlocksRegistry.java +++ b/src/main/java/fr/openmc/core/features/dream/registries/DreamBlocksRegistry.java @@ -1,13 +1,13 @@ package fr.openmc.core.features.dream.registries; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.dream.DreamDimensionManager; import fr.openmc.core.features.dream.listeners.registry.DreamBlocksListeners; import fr.openmc.core.features.dream.mecanism.altar.AltarManager; import fr.openmc.core.features.dream.mecanism.cloudcastle.BossCloudSpawner; import fr.openmc.core.features.dream.mecanism.cloudcastle.CloudVault; import fr.openmc.core.features.dream.models.registry.DreamBlock; +import fr.openmc.core.lifecycle.integration.OMCLogger; import org.bukkit.Location; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; 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 1664ff486..d8921e89a 100644 --- a/src/main/java/fr/openmc/core/features/economy/BankManager.java +++ b/src/main/java/fr/openmc/core/features/economy/BankManager.java @@ -6,19 +6,19 @@ import com.j256.ormlite.table.TableUtils; import fr.openmc.core.CommandsManager; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.bank.CityBankManager; import fr.openmc.core.features.city.sub.mayor.managers.MayorManager; -import fr.openmc.core.features.city.sub.mayor.managers.PerkManager; +import fr.openmc.core.features.city.sub.mayor.perks.PerkUtils; import fr.openmc.core.features.city.sub.mayor.perks.Perks; import fr.openmc.core.features.city.sub.milestone.rewards.PlayerBankLimitRewards; import fr.openmc.core.features.economy.commands.BankCommands; import fr.openmc.core.features.economy.events.BankDepositEvent; import fr.openmc.core.features.economy.models.Bank; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.utils.cache.CacheOfflinePlayer; import fr.openmc.core.utils.text.DateUtils; import fr.openmc.core.utils.text.InputUtils; @@ -120,7 +120,7 @@ public static void deposit(UUID playerUUID, String input) { } double amount = InputUtils.convertToMoneyValue(input); - City city = CityManager.getPlayerCity(playerUUID); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(playerUUID); if (city == null || city.getLevel() < 2) { MessagesManager.sendMessage(offlinePlayer, @@ -213,8 +213,8 @@ public static double calculatePlayerInterest(UUID playerUUID) { double interest = .01; // base interest is 1% if (MayorManager.phaseMayor == 2) { - City city = CityManager.getPlayerCity(playerUUID); - if (city != null && PerkManager.hasPerk(city.getMayor(), Perks.BUSINESS_MAN.getId())) { + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(playerUUID); + if (city != null && PerkUtils.hasPerk(city.getMayor(), Perks.BUSINESS_MAN.getId())) { interest += .02; // interest is +2% when perk Business Man enabled } } @@ -226,7 +226,7 @@ public static void applyPlayerInterest(UUID playerUUID) { double interest = calculatePlayerInterest(playerUUID); double amount = getBankBalance(playerUUID) * interest; - City city = CityManager.getPlayerCity(playerUUID); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(playerUUID); if (city == null) return; 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 e704c1f8a..aa7b9620d 100644 --- a/src/main/java/fr/openmc/core/features/economy/EconomyManager.java +++ b/src/main/java/fr/openmc/core/features/economy/EconomyManager.java @@ -5,17 +5,17 @@ import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import dev.lone.itemsadder.api.FontImages.FontImageWrapper; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.economy.commands.Baltop; import fr.openmc.core.features.economy.commands.History; 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.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import lombok.Getter; import org.jetbrains.annotations.NotNull; 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 d934a4c06..974b46836 100644 --- a/src/main/java/fr/openmc/core/features/economy/TransactionsManager.java +++ b/src/main/java/fr/openmc/core/features/economy/TransactionsManager.java @@ -6,11 +6,11 @@ import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.analytics.Stats; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import org.bukkit.Bukkit; import java.sql.SQLException; diff --git a/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankMenu.java b/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankMenu.java index 76b734063..a0838f5b5 100644 --- a/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankMenu.java +++ b/src/main/java/fr/openmc/core/features/economy/menu/PersonalBankMenu.java @@ -5,8 +5,8 @@ import fr.openmc.api.menulib.utils.ItemMenuBuilder; import fr.openmc.api.menulib.utils.MenuUtils; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.sub.milestone.rewards.PlayerBankLimitRewards; import fr.openmc.core.features.economy.BankManager; import fr.openmc.core.features.economy.EconomyManager; @@ -69,7 +69,7 @@ public void onInventoryClick(InventoryClickEvent click) { new PersonalBankDepositMenu(player).open(); })); - City playerCity = CityManager.getPlayerCity(player.getUniqueId()); + City playerCity = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player.getUniqueId()); if (playerCity == null) { MessagesManager.sendMessage(player, diff --git a/src/main/java/fr/openmc/core/features/events/EventsManager.java b/src/main/java/fr/openmc/core/features/events/EventsManager.java index f988763c4..973ced10c 100644 --- a/src/main/java/fr/openmc/core/features/events/EventsManager.java +++ b/src/main/java/fr/openmc/core/features/events/EventsManager.java @@ -1,9 +1,6 @@ package fr.openmc.core.features.events; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; import fr.openmc.core.features.events.commands.CalendarCommand; import fr.openmc.core.features.events.commands.EventCommand; import fr.openmc.core.features.events.contents.dailyevents.DailyEventsManager; @@ -13,6 +10,8 @@ import fr.openmc.core.features.events.contents.weeklyevents.models.WeeklyEvent; import fr.openmc.core.features.events.contents.weeklyevents.models.WeeklyEventPhase; import fr.openmc.core.features.events.models.Event; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.utils.text.DateUtils; import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.text.Component; @@ -26,7 +25,7 @@ import java.util.List; import java.util.Set; -public class EventsManager extends Feature implements LoadAfterItemsAdder, HasCommands { +public class EventsManager extends Feature implements HasCommands { @Override public Set getCommands() { return Set.of( diff --git a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/DailyEventsManager.java b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/DailyEventsManager.java index e46fb3b92..495aa8c7d 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/DailyEventsManager.java +++ b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/DailyEventsManager.java @@ -6,11 +6,6 @@ import com.j256.ormlite.table.TableUtils; import fr.openmc.core.OMCPlugin; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.*; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.events.contents.dailyevents.commands.DailyEventCommand; import fr.openmc.core.features.events.contents.dailyevents.listeners.DailyEventAmbientListeners; import fr.openmc.core.features.events.contents.dailyevents.models.IncomingEventsDB; @@ -18,6 +13,14 @@ import fr.openmc.core.features.events.contents.dailyevents.models.dailyevent.DailyEvent; import fr.openmc.core.features.events.contents.dailyevents.tasks.NextEventTask; import fr.openmc.core.features.events.contents.dailyevents.tasks.ShowBeginningEventTask; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.lifecycle.interfaces.HasFeature; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.RandomUtils; import fr.openmc.core.utils.text.DateUtils; import org.bukkit.scheduler.BukkitTask; @@ -29,7 +32,7 @@ @Credit(developers = {"iambibi_"}) -public class DailyEventsManager extends Feature implements LoadAfterItemsAdder, HasDatabase, HasListeners, HasCommands { +public class DailyEventsManager extends Feature implements HasDatabase, HasListeners, HasCommands { private static final List SLOT_HOURS_EVENTS = new ArrayList<>(List.of( 9, 13, 16, 21 )); @@ -50,7 +53,7 @@ public void init() { for (DailyEvent event : OMCRegistry.DAILY_EVENTS.values()) { if (!(event instanceof HasFeature hasFeature)) continue; - OMCPlugin.registerFeature(hasFeature.getFeature()); + OMCRegistry.FEATURES.register(hasFeature.feature()); } incomingEvents = loadIncomingEvents(); diff --git a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/DailyEventsRegistry.java b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/DailyEventsRegistry.java index 347d8fec1..4b60c6c8c 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/DailyEventsRegistry.java +++ b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/DailyEventsRegistry.java @@ -1,11 +1,11 @@ package fr.openmc.core.features.events.contents.dailyevents; -import fr.openmc.core.bootstrap.registries.KeyedRegistry; -import fr.openmc.core.bootstrap.registries.Registry; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.BloodyNightEvent; import fr.openmc.core.features.events.contents.dailyevents.contents.goldenharvest.GoldenHarvestEvent; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.MiraculousFishingEvent; import fr.openmc.core.features.events.contents.dailyevents.models.dailyevent.DailyEvent; +import fr.openmc.core.lifecycle.registries.KeyedRegistry; +import fr.openmc.core.lifecycle.registries.Registry; public class DailyEventsRegistry extends Registry implements KeyedRegistry { diff --git a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/bloodynight/BloodyNightEvent.java b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/bloodynight/BloodyNightEvent.java index 977ba2f70..57dee0911 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/bloodynight/BloodyNightEvent.java +++ b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/bloodynight/BloodyNightEvent.java @@ -2,12 +2,13 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasFeature; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.menu.BloodyNightMenu; import fr.openmc.core.features.events.contents.dailyevents.models.dailyevent.*; import fr.openmc.core.features.events.models.HasMenu; +import fr.openmc.core.lifecycle.interfaces.HasFeature; import fr.openmc.core.registry.ambient.CustomAmbient; +import fr.openmc.core.registry.features.loading.FeatureEntry; +import fr.openmc.core.registry.features.loading.FeatureLoadingType; import fr.openmc.core.utils.nms.toast.CustomToastData; import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.bossbar.BossBar; @@ -116,7 +117,7 @@ public BossBar.Overlay getBossBarOverlay() { } @Override - public Feature getFeature() { - return new BloodyNightManager(); + public FeatureEntry feature() { + return FeatureEntry.of(FeatureLoadingType.RUNTIME, BloodyNightManager::new); } } diff --git a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/bloodynight/BloodyNightManager.java b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/bloodynight/BloodyNightManager.java index fcb3e8a7d..552042b22 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/bloodynight/BloodyNightManager.java +++ b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/bloodynight/BloodyNightManager.java @@ -2,9 +2,6 @@ import fr.openmc.core.OMCPlugin; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.contents.mobs.bloodytypes.AncientMonster; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.contents.mobs.bloodytypes.CorruptedMonster; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.contents.mobs.bloodytypes.CursedMonster; @@ -12,6 +9,9 @@ import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.contents.mobs.vampire.VampireBoss; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.contents.mobs.vampire.VampireSlave; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.listeners.MonsterSpawnListener; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.registry.mobs.CustomMob; import fr.openmc.core.utils.world.LocationUtils; import org.bukkit.*; diff --git a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/bloodynight/listeners/MonsterSpawnListener.java b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/bloodynight/listeners/MonsterSpawnListener.java index 0ba030d76..7b40a6b3f 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/bloodynight/listeners/MonsterSpawnListener.java +++ b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/bloodynight/listeners/MonsterSpawnListener.java @@ -3,12 +3,12 @@ import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent; import fr.openmc.core.OMCPlugin; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.events.contents.dailyevents.DailyEventsManager; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.BloodyNightEvent; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.BloodyNightManager; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.contents.mobs.vampire.VampireBoss; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.contents.mobs.vampire.VampireSlave; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.registry.mobs.CustomMob; import org.bukkit.Bukkit; import org.bukkit.entity.Entity; diff --git a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/goldenharvest/GoldenHarvestEvent.java b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/goldenharvest/GoldenHarvestEvent.java index 830bc4cc1..083013785 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/goldenharvest/GoldenHarvestEvent.java +++ b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/goldenharvest/GoldenHarvestEvent.java @@ -2,12 +2,15 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasFeature; import fr.openmc.core.features.events.contents.dailyevents.contents.goldenharvest.menu.GoldenHarvestMenu; +import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.MiraculousFishingManager; import fr.openmc.core.features.events.contents.dailyevents.models.dailyevent.*; import fr.openmc.core.features.events.models.HasMenu; +import fr.openmc.core.lifecycle.interfaces.HasFeature; import fr.openmc.core.registry.ambient.CustomAmbient; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.loading.FeatureEntry; +import fr.openmc.core.registry.features.loading.FeatureLoadingType; import fr.openmc.core.utils.nms.toast.CustomToastData; import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.bossbar.BossBar; @@ -101,8 +104,8 @@ public Component getEndBroadcast() { } @Override - public Feature getFeature() { - return new GoldenHarvestManager(); + public FeatureEntry feature() { + return FeatureEntry.of(FeatureLoadingType.RUNTIME, MiraculousFishingManager::new); } @Override diff --git a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/goldenharvest/GoldenHarvestManager.java b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/goldenharvest/GoldenHarvestManager.java index c5f909f38..150709ab7 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/goldenharvest/GoldenHarvestManager.java +++ b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/goldenharvest/GoldenHarvestManager.java @@ -2,12 +2,12 @@ import dev.lone.itemsadder.api.CustomBlock; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.events.contents.dailyevents.contents.goldenharvest.listeners.*; import fr.openmc.core.features.events.contents.dailyevents.contents.goldenharvest.obesecrops.ObeseCropsRegistry; import fr.openmc.core.hooks.itemsadder.behaviours.BehaviourUpBlock; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.registry.items.CustomItem; import fr.openmc.core.registry.items.keys.KeyBlock; import fr.openmc.core.registry.loottable.loots.ItemLoot; diff --git a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/goldenharvest/obesecrops/ObeseCropsRegistry.java b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/goldenharvest/obesecrops/ObeseCropsRegistry.java index 114eabcaa..83820cc12 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/goldenharvest/obesecrops/ObeseCropsRegistry.java +++ b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/goldenharvest/obesecrops/ObeseCropsRegistry.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.events.contents.dailyevents.contents.goldenharvest.obesecrops; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; import org.bukkit.Location; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/miraculousfishing/MiraculousFishingEvent.java b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/miraculousfishing/MiraculousFishingEvent.java index 5cf0306df..673c6704d 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/miraculousfishing/MiraculousFishingEvent.java +++ b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/miraculousfishing/MiraculousFishingEvent.java @@ -2,12 +2,13 @@ import fr.openmc.api.menulib.Menu; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasFeature; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.menu.MiraculousFishingMenu; import fr.openmc.core.features.events.contents.dailyevents.models.dailyevent.*; import fr.openmc.core.features.events.models.HasMenu; +import fr.openmc.core.lifecycle.interfaces.HasFeature; import fr.openmc.core.registry.ambient.CustomAmbient; +import fr.openmc.core.registry.features.loading.FeatureEntry; +import fr.openmc.core.registry.features.loading.FeatureLoadingType; import fr.openmc.core.utils.nms.toast.CustomToastData; import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.bossbar.BossBar; @@ -115,8 +116,8 @@ public Menu getInfoMenu(Player player) { } @Override - public Feature getFeature() { - return new MiraculousFishingManager(); + public FeatureEntry feature() { + return FeatureEntry.of(FeatureLoadingType.RUNTIME, MiraculousFishingManager::new); } @Override diff --git a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/miraculousfishing/MiraculousFishingManager.java b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/miraculousfishing/MiraculousFishingManager.java index 2e8f656b5..d92cbc3c5 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/miraculousfishing/MiraculousFishingManager.java +++ b/src/main/java/fr/openmc/core/features/events/contents/dailyevents/contents/miraculousfishing/MiraculousFishingManager.java @@ -1,13 +1,13 @@ package fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.listeners.EatKebabFermentedListener; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.listeners.PlayerFishListener; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.listeners.PlayerNotPickUpListener; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.registry.SeaCreatureLoot; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.registry.loottable.loots.CustomLoot; import fr.openmc.core.registry.loottable.loots.MoneyLoot; import fr.openmc.core.registry.loottable.loots.RepresentedItem; diff --git a/src/main/java/fr/openmc/core/features/events/contents/halloween/listeners/HalloweenNPCListener.java b/src/main/java/fr/openmc/core/features/events/contents/halloween/listeners/HalloweenNPCListener.java index fb954e064..81c0e0bf4 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/halloween/listeners/HalloweenNPCListener.java +++ b/src/main/java/fr/openmc/core/features/events/contents/halloween/listeners/HalloweenNPCListener.java @@ -1,9 +1,9 @@ package fr.openmc.core.features.events.contents.halloween.listeners; import de.oliver.fancynpcs.api.events.NpcInteractEvent; -import fr.openmc.core.bootstrap.features.types.LoadIfEnable; import fr.openmc.core.features.events.contents.halloween.menus.HalloweenPumpkinDepositMenu; import fr.openmc.core.hooks.FancyNpcsHook; +import fr.openmc.core.lifecycle.interfaces.LoadIfEnable; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; diff --git a/src/main/java/fr/openmc/core/features/events/contents/halloween/managers/HalloweenManager.java b/src/main/java/fr/openmc/core/features/events/contents/halloween/managers/HalloweenManager.java index e83ff3419..414227223 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/halloween/managers/HalloweenManager.java +++ b/src/main/java/fr/openmc/core/features/events/contents/halloween/managers/HalloweenManager.java @@ -9,18 +9,18 @@ import de.oliver.fancynpcs.api.NpcManager; import fr.openmc.core.OMCPlugin; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.economy.EconomyManager; import fr.openmc.core.features.events.contents.halloween.commands.HalloweenCommands; import fr.openmc.core.features.events.contents.halloween.listeners.HalloweenNPCListener; import fr.openmc.core.features.events.contents.halloween.models.HalloweenData; import fr.openmc.core.features.leaderboards.LeaderboardManager; import fr.openmc.core.features.mailboxes.MailboxManager; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.utils.text.messages.TranslationManager; import io.papermc.paper.datacomponent.DataComponentTypes; import io.papermc.paper.datacomponent.item.DamageResistant; diff --git a/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/WeeklyEventsManager.java b/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/WeeklyEventsManager.java index 8dccea4b8..a6f372c29 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/WeeklyEventsManager.java +++ b/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/WeeklyEventsManager.java @@ -6,14 +6,13 @@ import com.j256.ormlite.table.TableUtils; import fr.openmc.core.OMCPlugin; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.events.contents.weeklyevents.models.WeeklyEvent; import fr.openmc.core.features.events.contents.weeklyevents.models.WeeklyEventPhase; import fr.openmc.core.features.events.contents.weeklyevents.models.WeeklyEventsData; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.text.DateUtils; import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitTask; @@ -24,7 +23,7 @@ import java.util.Locale; @Credit(developers = {"iambibi_"}) -public class WeeklyEventsManager extends Feature implements LoadAfterItemsAdder, HasDatabase { +public class WeeklyEventsManager extends Feature implements HasDatabase { private static Dao dao; private static WeeklyEventsData data; diff --git a/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/WeeklyEventsRegistry.java b/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/WeeklyEventsRegistry.java index 3fd4d51e9..c2b40c29b 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/WeeklyEventsRegistry.java +++ b/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/WeeklyEventsRegistry.java @@ -1,9 +1,9 @@ package fr.openmc.core.features.events.contents.weeklyevents; -import fr.openmc.core.bootstrap.registries.KeyedRegistry; -import fr.openmc.core.bootstrap.registries.Registry; import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.Contest; import fr.openmc.core.features.events.contents.weeklyevents.models.WeeklyEvent; +import fr.openmc.core.lifecycle.registries.KeyedRegistry; +import fr.openmc.core.lifecycle.registries.Registry; import java.util.List; import java.util.Optional; diff --git a/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/managers/ContestManager.java b/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/managers/ContestManager.java index aa0cf0d28..c31a41d50 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/managers/ContestManager.java +++ b/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/managers/ContestManager.java @@ -8,12 +8,6 @@ import fr.openmc.core.CommandsManager; import fr.openmc.core.OMCPlugin; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.integration.DatabaseManager; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.economy.EconomyManager; import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.commands.ContestCommand; import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.events.ContestEndEvent; @@ -28,6 +22,11 @@ import fr.openmc.core.features.mailboxes.MailboxManager; import fr.openmc.core.hooks.WorldGuardHook; import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.lifecycle.integration.DatabaseManager; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.bukkit.ParticleUtils; import fr.openmc.core.utils.cache.CacheOfflinePlayer; import fr.openmc.core.utils.text.ColorUtils; @@ -55,7 +54,7 @@ import static fr.openmc.core.features.mailboxes.utils.MailboxUtils.getHoverEvent; @Credit(developers = {"iambibi_"}, graphist = {"Gexary", "Tfloa"}) -public class ContestManager extends Feature implements HasDatabase, LoadAfterItemsAdder { +public class ContestManager extends Feature implements HasDatabase { public static ContestData data; public static Map dataPlayer = new HashMap<>(); diff --git a/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/managers/TradeYMLManager.java b/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/managers/TradeYMLManager.java index b963884c8..ed477c590 100644 --- a/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/managers/TradeYMLManager.java +++ b/src/main/java/fr/openmc/core/features/events/contents/weeklyevents/contents/contest/managers/TradeYMLManager.java @@ -1,8 +1,8 @@ package fr.openmc.core.features.events.contents.weeklyevents.contents.contest.managers; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.models.ContestData; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.utils.YmlUtils; import lombok.Getter; import org.bukkit.configuration.file.FileConfiguration; diff --git a/src/main/java/fr/openmc/core/features/friend/FriendManager.java b/src/main/java/fr/openmc/core/features/friend/FriendManager.java index 901d596d3..3f64c5743 100644 --- a/src/main/java/fr/openmc/core/features/friend/FriendManager.java +++ b/src/main/java/fr/openmc/core/features/friend/FriendManager.java @@ -1,11 +1,11 @@ package fr.openmc.core.features.friend; import com.j256.ormlite.support.ConnectionSource; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; import fr.openmc.core.features.friend.commands.FriendCommand; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import lombok.Getter; import java.sql.SQLException; 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 1abb25afe..4efa39a80 100644 --- a/src/main/java/fr/openmc/core/features/friend/FriendSQLManager.java +++ b/src/main/java/fr/openmc/core/features/friend/FriendSQLManager.java @@ -6,7 +6,7 @@ import com.j256.ormlite.stmt.Where; import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.utils.text.DateUtils; import java.sql.SQLException; 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 e7d0dea5a..17998ea46 100644 --- a/src/main/java/fr/openmc/core/features/homes/HomesManager.java +++ b/src/main/java/fr/openmc/core/features/homes/HomesManager.java @@ -4,15 +4,15 @@ import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.integration.DatabaseManager; import fr.openmc.core.features.homes.command.*; import fr.openmc.core.features.homes.models.Home; import fr.openmc.core.features.homes.models.HomeLimit; import fr.openmc.core.features.homes.world.DisabledWorldHome; +import fr.openmc.core.lifecycle.integration.DatabaseManager; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import lombok.Getter; import java.sql.SQLException; 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 0dd4b1000..5fbc16bc8 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 @@ -1,11 +1,10 @@ package fr.openmc.core.features.homes.icons; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.homes.menu.HomeChangeIconMenu; import fr.openmc.core.features.homes.models.Home; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.registry.features.Feature; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -14,7 +13,7 @@ import java.util.List; import java.util.concurrent.ConcurrentHashMap; -public class HomeIconCacheManager extends Feature implements LoadAfterItemsAdder { +public class HomeIconCacheManager extends Feature { private static final ConcurrentHashMap> CACHED_ITEMS = new ConcurrentHashMap<>(); private static final ConcurrentHashMap> CACHED_SEARCH_RESULTS = new ConcurrentHashMap<>(); diff --git a/src/main/java/fr/openmc/core/features/homes/world/DisabledWorldHome.java b/src/main/java/fr/openmc/core/features/homes/world/DisabledWorldHome.java index f39f36d02..63dad0941 100644 --- a/src/main/java/fr/openmc/core/features/homes/world/DisabledWorldHome.java +++ b/src/main/java/fr/openmc/core/features/homes/world/DisabledWorldHome.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.homes.world; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; diff --git a/src/main/java/fr/openmc/core/features/itemsadder/SpawnerExtractorListener.java b/src/main/java/fr/openmc/core/features/itemsadder/SpawnerExtractorListener.java index eca7ced01..b7ee27146 100644 --- a/src/main/java/fr/openmc/core/features/itemsadder/SpawnerExtractorListener.java +++ b/src/main/java/fr/openmc/core/features/itemsadder/SpawnerExtractorListener.java @@ -2,7 +2,6 @@ import dev.lone.itemsadder.api.CustomStack; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.text.Component; import org.bukkit.Material; @@ -20,7 +19,7 @@ import java.util.concurrent.ThreadLocalRandom; -public class SpawnerExtractorListener implements Listener, NotLoadInUnitTest { +public class SpawnerExtractorListener implements Listener { private static final double FAILURE_CHANCE = 0.4; // 40% chance d’échec private static final NamespacedKey KEY_SPAWNER_MOB = new NamespacedKey(OMCPlugin.getInstance(), "spawner_extractor_mob_spawner"); diff --git a/src/main/java/fr/openmc/core/features/itemsadder/elevator/ElevatorManager.java b/src/main/java/fr/openmc/core/features/itemsadder/elevator/ElevatorManager.java index 6edee3a95..86825a0fe 100644 --- a/src/main/java/fr/openmc/core/features/itemsadder/elevator/ElevatorManager.java +++ b/src/main/java/fr/openmc/core/features/itemsadder/elevator/ElevatorManager.java @@ -2,10 +2,10 @@ import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomStack; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Tag; 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 54e4a796b..733db3b5b 100644 --- a/src/main/java/fr/openmc/core/features/leaderboards/LeaderboardManager.java +++ b/src/main/java/fr/openmc/core/features/leaderboards/LeaderboardManager.java @@ -1,13 +1,8 @@ package fr.openmc.core.features.leaderboards; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.economy.BankManager; import fr.openmc.core.features.economy.EconomyManager; import fr.openmc.core.features.economy.models.EconomyPlayer; @@ -16,6 +11,9 @@ import fr.openmc.core.features.leaderboards.commands.LeaderboardCommands; import fr.openmc.core.hooks.github.GitHubHook; import fr.openmc.core.hooks.github.models.ContributorStats; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.cache.PlayerNameCache; import fr.openmc.core.utils.text.DateUtils; import fr.openmc.core.utils.text.messages.TranslationManager; @@ -41,7 +39,7 @@ import java.util.*; @Credit(developers = {"miseur"}) -public class LeaderboardManager extends Feature implements NotLoadInUnitTest, LoadAfterItemsAdder, HasCommands { +public class LeaderboardManager extends Feature implements HasCommands { @Getter private static final Map> githubContributorsMap = new TreeMap<>(); @Getter @@ -448,12 +446,13 @@ private static void loadLeaderBoardConfig() { * Documentation GitHub API (REST) */ public static void updateGithubContributorsMap() { - GitHubHook.fetchContributorStats(); + GitHubHook gitHubHook = OMCRegistry.HOOKS.GITHUB; + gitHubHook.fetchContributorStats(); List> statsList = new ArrayList<>(); - for (String login : GitHubHook.getContributors().values()) { - ContributorStats stats = GitHubHook.getStats(login); + for (String login : gitHubHook.getContributors().values()) { + ContributorStats stats = gitHubHook.getStats(login); if (stats == null) continue; statsList.add(new AbstractMap.SimpleEntry<>(login, stats)); @@ -499,7 +498,7 @@ public static void updatePlayerMoneyMap() { public static void updateCityMoneyMap() { villeMoneyMap.clear(); int rank = 1; - for (City city : CityManager.getCities().stream() + for (City city : OMCRegistry.FEATURES.CITY.get().getCities().stream() .sorted((city1, city2) -> Double.compare(city2.getBalance(), city1.getBalance())) .limit(10) .toList()) { 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 267eb5eea..19d1bed61 100644 --- a/src/main/java/fr/openmc/core/features/mailboxes/MailboxManager.java +++ b/src/main/java/fr/openmc/core/features/mailboxes/MailboxManager.java @@ -4,17 +4,17 @@ import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.mailboxes.commands.MailboxCommand; import fr.openmc.core.features.mailboxes.menu.PlayerMailbox; import fr.openmc.core.features.mailboxes.menu.letter.LetterMenu; 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.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.bukkit.serializer.BukkitSerializer; import fr.openmc.core.utils.text.DateUtils; import fr.openmc.core.utils.text.messages.MessageType; 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 203e42281..1680d4038 100644 --- a/src/main/java/fr/openmc/core/features/mainmenu/MainMenu.java +++ b/src/main/java/fr/openmc/core/features/mainmenu/MainMenu.java @@ -2,22 +2,18 @@ import fr.openmc.api.packetmenulib.PacketMenuLib; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.features.types.LoadIfEnable; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; import fr.openmc.core.features.mainmenu.commands.MainMenuCommand; import fr.openmc.core.features.mainmenu.listeners.MainMenuListener; import fr.openmc.core.features.mainmenu.menus.Page1; -import fr.openmc.core.hooks.ProtocolLibHook; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import org.bukkit.entity.Player; import java.util.Set; @Credit(developers = {"miseur"}, graphist = {"Tfloa"}) -public class MainMenu extends Feature implements NotLoadInUnitTest, LoadAfterItemsAdder, LoadIfEnable, HasCommands { +public class MainMenu extends Feature implements HasCommands { @Override public void init() { new MainMenuListener(OMCPlugin.getInstance()); diff --git a/src/main/java/fr/openmc/core/features/mainmenu/menus/Page1.java b/src/main/java/fr/openmc/core/features/mainmenu/menus/Page1.java index b7c1526b4..780203352 100644 --- a/src/main/java/fr/openmc/core/features/mainmenu/menus/Page1.java +++ b/src/main/java/fr/openmc/core/features/mainmenu/menus/Page1.java @@ -10,6 +10,7 @@ import fr.openmc.api.packetmenulib.menu.InventoryType; import fr.openmc.api.packetmenulib.menu.Menu; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.adminshop.AdminShopManager; import fr.openmc.core.features.city.City; import fr.openmc.core.features.city.CityManager; @@ -69,6 +70,8 @@ public class Page1 implements Menu { private static final Set MAILBOX_SLOTS = Set.of(85, 86, 87); private static final int ADVANCEMENTS_SLOT = 88; + private final AdminShopManager adminShopManager; + public Page1(Player player) { City playerCity = CityManager.getPlayerCity(player.getUniqueId()); ItemStack cityItem = new ItemStack(Material.PAPER); @@ -226,6 +229,8 @@ public Page1(Player player) { .color(NamedTextColor.DARK_GRAY))); }); MAILBOX_SLOTS.forEach(slot -> content.put(slot, mailboxItem)); + + this.adminShopManager = OMCRegistry.FEATURES.ADMIN_SHOP.get(); } @Override @@ -275,7 +280,7 @@ public void onInventoryClick(InventoryClickEvent event) { } else if (CONTEST_SLOTS.contains(slot)) { Bukkit.getScheduler().runTask(OMCPlugin.getInstance(), () -> ContestCommand.mainCommand(player)); } else if (SHOP_SLOTS.contains(slot)) { - Bukkit.getScheduler().runTask(OMCPlugin.getInstance(), () -> AdminShopManager.openMainMenu(player)); + Bukkit.getScheduler().runTask(OMCPlugin.getInstance(), () -> adminShopManager.openMainMenu(player)); } else if (HOME_SLOTS.contains(slot)) { Bukkit.getScheduler().runTask(OMCPlugin.getInstance(), () -> TpHomeCommand.home(omcPlayer, null)); } else if (PROFILE_SLOTS.contains(slot)) { 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 acc45ed05..fddad88a5 100644 --- a/src/main/java/fr/openmc/core/features/milestones/MilestonesManager.java +++ b/src/main/java/fr/openmc/core/features/milestones/MilestonesManager.java @@ -5,14 +5,6 @@ import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.displays.bossbar.BossbarManager; import fr.openmc.core.features.milestones.bossbar.MilestoneBossBar; import fr.openmc.core.features.milestones.commands.MilestoneCommand; @@ -21,6 +13,13 @@ import fr.openmc.core.features.milestones.models.MilestoneModel; import fr.openmc.core.features.milestones.models.MilestoneType; import fr.openmc.core.features.quests.objects.Quest; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -28,7 +27,7 @@ import java.util.*; @Credit(developers = {"iambibi_", "gab400"}) -public class MilestonesManager extends Feature implements HasDatabase, LoadAfterItemsAdder, HasListeners, HasCommands { +public class MilestonesManager extends Feature implements HasDatabase, HasListeners, HasCommands { private static final Set> milestones = new HashSet<>(); private static Dao millestoneDao; diff --git a/src/main/java/fr/openmc/core/features/privatemessage/PrivateMessageManager.java b/src/main/java/fr/openmc/core/features/privatemessage/PrivateMessageManager.java index 27f5f0e19..80aab5590 100644 --- a/src/main/java/fr/openmc/core/features/privatemessage/PrivateMessageManager.java +++ b/src/main/java/fr/openmc/core/features/privatemessage/PrivateMessageManager.java @@ -1,10 +1,10 @@ package fr.openmc.core.features.privatemessage; import fr.openmc.api.entity.player.OMCPlayer; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; import fr.openmc.core.features.privatemessage.command.PrivateMessageCommand; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; import fr.openmc.core.utils.text.messages.Prefix; diff --git a/src/main/java/fr/openmc/core/features/privatemessage/SocialSpyManager.java b/src/main/java/fr/openmc/core/features/privatemessage/SocialSpyManager.java index c546f375a..8dbdec409 100644 --- a/src/main/java/fr/openmc/core/features/privatemessage/SocialSpyManager.java +++ b/src/main/java/fr/openmc/core/features/privatemessage/SocialSpyManager.java @@ -1,9 +1,9 @@ package fr.openmc.core.features.privatemessage; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; import fr.openmc.core.features.privatemessage.command.SocialSpyCommand; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; import fr.openmc.core.utils.text.messages.Prefix; diff --git a/src/main/java/fr/openmc/core/features/profile/ProfileManager.java b/src/main/java/fr/openmc/core/features/profile/ProfileManager.java index d42c9b598..573892889 100644 --- a/src/main/java/fr/openmc/core/features/profile/ProfileManager.java +++ b/src/main/java/fr/openmc/core/features/profile/ProfileManager.java @@ -1,18 +1,17 @@ package fr.openmc.core.features.profile; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.profile.command.ProfileCommand; import fr.openmc.core.features.profile.listeners.ProfileInteractionListener; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import java.util.Set; @Credit(developers = {"ar1hurgit"}) -public class ProfileManager extends Feature implements LoadAfterItemsAdder, HasCommands, HasListeners { +public class ProfileManager extends Feature implements HasCommands, HasListeners { @Override public Set getCommands() { return Set.of( diff --git a/src/main/java/fr/openmc/core/features/profile/menu/ProfileMenu.java b/src/main/java/fr/openmc/core/features/profile/menu/ProfileMenu.java index daee4ab63..1429cb2f7 100644 --- a/src/main/java/fr/openmc/core/features/profile/menu/ProfileMenu.java +++ b/src/main/java/fr/openmc/core/features/profile/menu/ProfileMenu.java @@ -6,7 +6,6 @@ import fr.openmc.core.OMCPlugin; import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.menu.list.CityListDetailsMenu; import fr.openmc.core.features.friend.FriendManager; import fr.openmc.core.features.mailboxes.menu.PlayerMailbox; @@ -94,13 +93,14 @@ public void onClose(InventoryCloseEvent event) { @SuppressWarnings("UnstableApiUsage") private void addIdentityItem(Map inventory) { + GitHubHook gitHubHook = OMCRegistry.HOOKS.GITHUB; String statusKey = target.isOnline() ? "feature.profile.status.online" : "feature.profile.status.offline"; String discordUsername = DiscordLinkManager.getLinkedDiscordUsername(target.getUniqueId()); - Long githubId = GitHubHook.getContributorId(target.getUniqueId()); - String githubUsername = githubId == null ? null : GitHubHook.getUsernameById(githubId); + Long githubId = gitHubHook.getContributorId(target.getUniqueId()); + String githubUsername = githubId == null ? null : gitHubHook.getUsernameById(githubId); List lore = new ArrayList<>(TranslationManager.translationLore( "feature.profile.item.identity.lore", @@ -128,7 +128,7 @@ private void addIdentityItem(Map inventory) { if (click.getWhoClicked().getUniqueId() == target.getUniqueId()) { Player owner = getOwner(); Bukkit.getScheduler().runTaskAsynchronously(OMCPlugin.getInstance(), () -> { - GitHubHook.refreshContributorId(target.getUniqueId()); + gitHubHook.refreshContributorId(target.getUniqueId()); Bukkit.getScheduler().runTask(OMCPlugin.getInstance(), () -> { if (owner.isOnline()) { new ProfileMenu(owner, target).open(); @@ -210,7 +210,7 @@ private void openMailbox(boolean selfProfile) { } private void addCityItem(Map inventory) { - City city = CityManager.getPlayerCity(target.getUniqueId()); + City city = OMCRegistry.FEATURES.CITY.get().getPlayerCity(target.getUniqueId()); if (city == null) { inventory.put(15, new ItemMenuBuilder( this, diff --git a/src/main/java/fr/openmc/core/features/quests/QuestProgressSaveManager.java b/src/main/java/fr/openmc/core/features/quests/QuestProgressSaveManager.java index e591f424d..d44e312d3 100644 --- a/src/main/java/fr/openmc/core/features/quests/QuestProgressSaveManager.java +++ b/src/main/java/fr/openmc/core/features/quests/QuestProgressSaveManager.java @@ -1,11 +1,11 @@ package fr.openmc.core.features.quests; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.quests.objects.Quest; import fr.openmc.core.features.quests.objects.QuestStep; import fr.openmc.core.features.quests.objects.QuestTier; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.registry.features.Feature; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.bukkit.configuration.file.YamlConfiguration; 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 28856d26e..17b12a72a 100644 --- a/src/main/java/fr/openmc/core/features/quests/QuestsManager.java +++ b/src/main/java/fr/openmc/core/features/quests/QuestsManager.java @@ -1,14 +1,13 @@ package fr.openmc.core.features.quests; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.quests.command.QuestCommand; import fr.openmc.core.features.quests.objects.Quest; import fr.openmc.core.features.quests.quests.*; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.event.Listener; @@ -22,7 +21,7 @@ * and saving quest progress for players. */ @Credit(developers = {"Axeno"}, graphist = {"Gexary"}) -public class QuestsManager extends Feature implements LoadAfterItemsAdder, HasCommands { +public class QuestsManager extends Feature implements HasCommands { static final Map quests = new HashMap<>(); /** diff --git a/src/main/java/fr/openmc/core/features/settings/PlayerSettings.java b/src/main/java/fr/openmc/core/features/settings/PlayerSettings.java index 2d6c2abb0..45a41303b 100644 --- a/src/main/java/fr/openmc/core/features/settings/PlayerSettings.java +++ b/src/main/java/fr/openmc/core/features/settings/PlayerSettings.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.settings; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.friend.FriendManager; import fr.openmc.core.features.settings.policy.CityPolicy; import fr.openmc.core.features.settings.policy.FriendPolicy; @@ -214,7 +214,7 @@ public boolean isVisibleToEveryone(SettingType visibilitySetting) { * @return true if both players are members of the same city, false otherwise */ private boolean areSameCityMembers(UUID player1UUID, UUID player2UUID) { - City player2City = CityManager.getPlayerCity(player2UUID); + City player2City = OMCRegistry.FEATURES.CITY.get().getPlayerCity(player2UUID); Player player1 = Bukkit.getPlayer(player1UUID); return player1 != null && player2City != null && player2City.isMember(player1); } 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 8e803c61c..8e6dfd21e 100644 --- a/src/main/java/fr/openmc/core/features/settings/PlayerSettingsManager.java +++ b/src/main/java/fr/openmc/core/features/settings/PlayerSettingsManager.java @@ -6,16 +6,16 @@ import com.j256.ormlite.stmt.QueryBuilder; import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.settings.command.SettingsCommand; import fr.openmc.core.features.settings.listeners.PlayerSettingsListener; import fr.openmc.core.features.settings.models.PlayerSettingEntity; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import lombok.Getter; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/openmc/core/features/shops/managers/PlayerShopManager.java b/src/main/java/fr/openmc/core/features/shops/managers/PlayerShopManager.java index 49f791488..629eac7e9 100644 --- a/src/main/java/fr/openmc/core/features/shops/managers/PlayerShopManager.java +++ b/src/main/java/fr/openmc/core/features/shops/managers/PlayerShopManager.java @@ -2,13 +2,14 @@ import fr.openmc.api.input.location.ItemInteraction; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.CityManager; import fr.openmc.core.features.city.ProtectionsManager; import fr.openmc.core.features.economy.EconomyManager; import fr.openmc.core.features.shops.events.PlaceShopEvent; import fr.openmc.core.features.shops.models.Shop; import fr.openmc.core.hooks.WorldGuardHook; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; import fr.openmc.core.utils.text.messages.Prefix; @@ -69,13 +70,15 @@ public static void startCreatingShop(Player player) { */ private static boolean createShop(Player player, Location location) { Shop shop = new Shop(player.getUniqueId(), location.setRotation(0, 0)); + CityManager cityManager = OMCRegistry.FEATURES.CITY.get(); if (WorldGuardHook.isRegionConflict(location)) return false; if (!ProtectionsManager.canBypassPlayer.contains(player.getUniqueId())) { - if ((CityManager.isChunkClaimed(location.getChunk()) - && !CityManager.getPlayerCity(player.getUniqueId()) - .equals(CityManager.getCityFromChunk(location.getChunk()))) - || (CityManager.isChunkClaimed(location.getChunk()) && CityManager.getPlayerCity(player.getUniqueId()) == null)) { + CityManager city = cityManager.getPlayerCity(player.getUniqueId()); + if ((cityManager.isChunkClaimed(location.getChunk()) + && city != null + && !city.equals(cityManager.getCityFromChunk(location.getChunk()))) + || (cityManager.isChunkClaimed(location.getChunk()) && city == null)) { MessagesManager.sendMessage(player, TranslationManager.translation("feature.shop.player.chunk_claimed"), Prefix.SHOP, MessageType.ERROR, true); return false; } diff --git a/src/main/java/fr/openmc/core/features/shops/managers/ShopDatabaseManager.java b/src/main/java/fr/openmc/core/features/shops/managers/ShopDatabaseManager.java index c6782c187..d60e7c09a 100644 --- a/src/main/java/fr/openmc/core/features/shops/managers/ShopDatabaseManager.java +++ b/src/main/java/fr/openmc/core/features/shops/managers/ShopDatabaseManager.java @@ -4,10 +4,10 @@ import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.shops.models.Shop; import fr.openmc.core.features.shops.models.ShopItem; import fr.openmc.core.features.shops.models.ShopSale; +import fr.openmc.core.lifecycle.integration.OMCLogger; import org.bukkit.Bukkit; import org.bukkit.Location; import org.jspecify.annotations.NonNull; diff --git a/src/main/java/fr/openmc/core/features/shops/managers/ShopManager.java b/src/main/java/fr/openmc/core/features/shops/managers/ShopManager.java index 08639401d..1f385d1d7 100644 --- a/src/main/java/fr/openmc/core/features/shops/managers/ShopManager.java +++ b/src/main/java/fr/openmc/core/features/shops/managers/ShopManager.java @@ -2,20 +2,19 @@ import com.j256.ormlite.support.ConnectionSource; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; import fr.openmc.core.features.shops.ShopCommand; import fr.openmc.core.features.shops.ShopFurniture; import fr.openmc.core.features.shops.ShopListener; import fr.openmc.core.features.shops.models.Shop; import fr.openmc.core.features.shops.models.ShopSale; import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.world.WorldUtils; import lombok.Getter; import org.bukkit.Bukkit; @@ -29,7 +28,7 @@ import java.util.*; @Credit(developers = {"gab400", "Nocolm", "Xernas78"}, graphist = {"Gexary"}) -public class ShopManager extends Feature implements LoadAfterItemsAdder, HasDatabase, HasListeners, HasCommands { +public class ShopManager extends Feature implements HasDatabase, HasListeners, HasCommands { @Getter private static final Map shops = new HashMap<>(); diff --git a/src/main/java/fr/openmc/core/features/tickets/TicketListener.java b/src/main/java/fr/openmc/core/features/tickets/TicketListener.java index 0b50bfc5f..9cee3916d 100644 --- a/src/main/java/fr/openmc/core/features/tickets/TicketListener.java +++ b/src/main/java/fr/openmc/core/features/tickets/TicketListener.java @@ -4,7 +4,6 @@ import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; import dev.lone.itemsadder.api.Events.FurniturePlacedEvent; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; import fr.openmc.core.events.LootboxRewardEvent; import fr.openmc.core.features.displays.holograms.Hologram; import fr.openmc.core.features.displays.holograms.HologramLoader; @@ -27,7 +26,7 @@ import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -public class TicketListener implements Listener, NotLoadInUnitTest { +public class TicketListener implements Listener { private final Map machineHolograms = new ConcurrentHashMap<>(); 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 5e2eab52b..918f0f601 100644 --- a/src/main/java/fr/openmc/core/features/tickets/TicketManager.java +++ b/src/main/java/fr/openmc/core/features/tickets/TicketManager.java @@ -4,11 +4,11 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/fr/openmc/core/features/toor/DiscordLinkManager.java b/src/main/java/fr/openmc/core/features/toor/DiscordLinkManager.java index ca445ebbc..29badefd8 100644 --- a/src/main/java/fr/openmc/core/features/toor/DiscordLinkManager.java +++ b/src/main/java/fr/openmc/core/features/toor/DiscordLinkManager.java @@ -5,15 +5,15 @@ import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.toor.commands.LinkCommand; import fr.openmc.core.features.toor.commands.UnlinkCommand; import fr.openmc.core.features.toor.event.ConnectToDiscordEvent; import fr.openmc.core.features.toor.models.DBDiscordLink; import fr.openmc.core.features.toor.utils.RequestSigner; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.utils.cache.TtlCache; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; diff --git a/src/main/java/fr/openmc/core/features/toor/InternalToorApiClient.java b/src/main/java/fr/openmc/core/features/toor/InternalToorApiClient.java index 60c675e15..38636d6bd 100644 --- a/src/main/java/fr/openmc/core/features/toor/InternalToorApiClient.java +++ b/src/main/java/fr/openmc/core/features/toor/InternalToorApiClient.java @@ -1,7 +1,7 @@ package fr.openmc.core.features.toor; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.toor.utils.RequestSigner; +import fr.openmc.core.lifecycle.integration.OMCLogger; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; diff --git a/src/main/java/fr/openmc/core/features/toor/utils/RequestSigner.java b/src/main/java/fr/openmc/core/features/toor/utils/RequestSigner.java index 66321fc19..dd64464bf 100644 --- a/src/main/java/fr/openmc/core/features/toor/utils/RequestSigner.java +++ b/src/main/java/fr/openmc/core/features/toor/utils/RequestSigner.java @@ -1,6 +1,6 @@ package fr.openmc.core.features.toor.utils; -import fr.openmc.core.bootstrap.features.DisableFeatureException; +import fr.openmc.core.registry.features.DisableFeatureException; import java.io.IOException; import java.nio.charset.StandardCharsets; diff --git a/src/main/java/fr/openmc/core/features/tpa/TPAManager.java b/src/main/java/fr/openmc/core/features/tpa/TPAManager.java index 32e1a3e17..66d082f28 100644 --- a/src/main/java/fr/openmc/core/features/tpa/TPAManager.java +++ b/src/main/java/fr/openmc/core/features/tpa/TPAManager.java @@ -1,12 +1,12 @@ package fr.openmc.core.features.tpa; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.annotations.Credit; -import fr.openmc.core.bootstrap.features.types.HasCommands; import fr.openmc.core.features.tpa.commands.TPACancelCommand; 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.lifecycle.interfaces.HasCommands; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.annotations.Credit; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; import fr.openmc.core.utils.text.messages.Prefix; 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 cdc3d4686..15c85fce8 100644 --- a/src/main/java/fr/openmc/core/features/updates/UpdateManager.java +++ b/src/main/java/fr/openmc/core/features/updates/UpdateManager.java @@ -1,10 +1,10 @@ package fr.openmc.core.features.updates; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; -import fr.openmc.core.bootstrap.features.types.HasCommands; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.registry.features.Feature; import fr.openmc.core.utils.text.messages.TranslationManager; import lombok.Getter; import net.kyori.adventure.text.Component; diff --git a/src/main/java/fr/openmc/core/hooks/FancyNpcsHook.java b/src/main/java/fr/openmc/core/hooks/FancyNpcsHook.java index d9d0542d0..be9829071 100644 --- a/src/main/java/fr/openmc/core/hooks/FancyNpcsHook.java +++ b/src/main/java/fr/openmc/core/hooks/FancyNpcsHook.java @@ -1,11 +1,11 @@ package fr.openmc.core.hooks; -import fr.openmc.core.bootstrap.hooks.Hooks; +import fr.openmc.core.registry.hooks.Hooks; public class FancyNpcsHook extends Hooks { public static long FANCY_INIT_DELAY = 20L * 30; // 30 seconds - public static boolean isEnable() { + public boolean isEnable() { return Hooks.isEnabled(FancyNpcsHook.class); } diff --git a/src/main/java/fr/openmc/core/hooks/LuckPermsHook.java b/src/main/java/fr/openmc/core/hooks/LuckPermsHook.java index 1272682da..7418ac0e0 100644 --- a/src/main/java/fr/openmc/core/hooks/LuckPermsHook.java +++ b/src/main/java/fr/openmc/core/hooks/LuckPermsHook.java @@ -1,9 +1,9 @@ package fr.openmc.core.hooks; import dev.lone.itemsadder.api.FontImages.FontImageWrapper; -import fr.openmc.core.bootstrap.hooks.ApiHook; -import fr.openmc.core.bootstrap.hooks.Hooks; import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.registry.hooks.ApiHook; +import fr.openmc.core.registry.hooks.Hooks; import lombok.Getter; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -18,9 +18,9 @@ public class LuckPermsHook extends Hooks implements ApiHook { @Getter - private static LuckPerms api; + private LuckPerms api; - public static boolean isEnable() { + public boolean isEnable() { return Hooks.isEnabled(LuckPermsHook.class); } @@ -42,7 +42,7 @@ public void init() { /** * Retourne le garde d'une personne */ - public static String getPrefix(Player player) { + public String getPrefix(Player player) { if (!isEnable()) return ""; User user = getApi().getUserManager().getUser(player.getUniqueId()); @@ -52,7 +52,20 @@ public static String getPrefix(Player player) { return Objects.requireNonNullElse(prefix, ""); } - public static String getFormattedPAPIPrefix(Player player) { + /** + * Retourne le suffix d'une personne + */ + public String getSuffix(Player player) { + if (!isEnable()) return ""; + + User user = getApi().getUserManager().getUser(player.getUniqueId()); + if (user == null) return ""; + + String prefix = user.getCachedData().getMetaData(QueryOptions.defaultContextualOptions()).getSuffix(); + return Objects.requireNonNullElse(prefix, ""); + } + + public String getFormattedPAPIPrefix(Player player) { if (!isEnable()) return ""; String prefix = getPrefix(player); @@ -65,7 +78,7 @@ public static String getFormattedPAPIPrefix(Player player) { return formattedPrefix; } - public static @NotNull Component getFormattedPAPIPrefix(Group group) { + public @NotNull Component getFormattedPAPIPrefix(Group group) { if (!isEnable()) return Component.empty(); String prefix = group.getCachedData().getMetaData(QueryOptions.defaultContextualOptions()).getPrefix(); diff --git a/src/main/java/fr/openmc/core/hooks/PapiHook.java b/src/main/java/fr/openmc/core/hooks/PapiHook.java index 4af1383fd..3bcb8ecf3 100644 --- a/src/main/java/fr/openmc/core/hooks/PapiHook.java +++ b/src/main/java/fr/openmc/core/hooks/PapiHook.java @@ -1,9 +1,9 @@ package fr.openmc.core.hooks; -import fr.openmc.core.bootstrap.hooks.Hooks; +import fr.openmc.core.registry.hooks.Hooks; public class PapiHook extends Hooks { - public static boolean isEnable() { + public boolean isEnable() { return Hooks.isEnabled(PapiHook.class); } diff --git a/src/main/java/fr/openmc/core/hooks/ProtocolLibHook.java b/src/main/java/fr/openmc/core/hooks/ProtocolLibHook.java index f70ddb6d3..1abc90ef1 100644 --- a/src/main/java/fr/openmc/core/hooks/ProtocolLibHook.java +++ b/src/main/java/fr/openmc/core/hooks/ProtocolLibHook.java @@ -1,9 +1,9 @@ package fr.openmc.core.hooks; -import fr.openmc.core.bootstrap.hooks.Hooks; +import fr.openmc.core.registry.hooks.Hooks; public class ProtocolLibHook extends Hooks { - public static boolean isEnable() { + public boolean isEnable() { return Hooks.isEnabled(ProtocolLibHook.class); } diff --git a/src/main/java/fr/openmc/core/hooks/WorldGuardHook.java b/src/main/java/fr/openmc/core/hooks/WorldGuardHook.java index eddfb0daf..cf53012db 100644 --- a/src/main/java/fr/openmc/core/hooks/WorldGuardHook.java +++ b/src/main/java/fr/openmc/core/hooks/WorldGuardHook.java @@ -8,7 +8,7 @@ import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.RegionContainer; -import fr.openmc.core.bootstrap.hooks.Hooks; +import fr.openmc.core.registry.hooks.Hooks; import org.bukkit.Chunk; import org.bukkit.Location; @@ -16,7 +16,7 @@ import java.util.Collections; public class WorldGuardHook extends Hooks { - public static boolean isEnable() { + public boolean isEnable() { return Hooks.isEnabled(WorldGuardHook.class); } @@ -25,7 +25,7 @@ protected String getPluginName() { return "WorldGuard"; } - public static boolean isRegionConflict(Location location) { + public boolean isRegionConflict(Location location) { if (!isEnable()) return false; RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); @@ -44,11 +44,11 @@ public static boolean isRegionConflict(Location location) { /** * Retourne si la positon mise est dans une région */ - public static boolean isInside(ProtectedRegion region, Location location) { + public boolean isInside(ProtectedRegion region, Location location) { return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ()); } - public static boolean doesChunkContainWGRegion(Chunk chunk) { + public boolean doesChunkContainWGRegion(Chunk chunk) { if (!isEnable()) return false; org.bukkit.World world = chunk.getWorld(); diff --git a/src/main/java/fr/openmc/core/hooks/github/GitHubHook.java b/src/main/java/fr/openmc/core/hooks/github/GitHubHook.java index d75b684a4..6407b7f35 100644 --- a/src/main/java/fr/openmc/core/hooks/github/GitHubHook.java +++ b/src/main/java/fr/openmc/core/hooks/github/GitHubHook.java @@ -4,13 +4,13 @@ import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.hooks.Hooks; -import fr.openmc.core.bootstrap.hooks.HttpsHook; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.toor.InternalToorApiClient; import fr.openmc.core.hooks.github.models.ContributorStats; import fr.openmc.core.hooks.github.models.DBGithubMinecraft; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.registry.hooks.Hooks; +import fr.openmc.core.registry.hooks.HttpsHook; import fr.openmc.core.utils.cache.TtlCache; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -31,13 +31,13 @@ public class GitHubHook extends HttpsHook implements HasDatabase { public final static String REPO_OWNER = "ServerOpenMC"; public final static String REPO_NAME = "PluginV2"; - private static Dao linkGithubMinecraft; + private Dao linkGithubMinecraft; - public static final Map lastKnownLinkMap = new ConcurrentHashMap<>(); - private static final Map contributorStatsMap = new ConcurrentHashMap<>(); + public final Map lastKnownLinkMap = new ConcurrentHashMap<>(); + private final Map contributorStatsMap = new ConcurrentHashMap<>(); - private static final TtlCache githubLinkCache = new TtlCache<>(60, TimeUnit.SECONDS); - private static final TtlCache usernameCache = new TtlCache<>(10, TimeUnit.MINUTES); + private final TtlCache githubLinkCache = new TtlCache<>(60, TimeUnit.SECONDS); + private final TtlCache usernameCache = new TtlCache<>(10, TimeUnit.MINUTES); @Override public void init() { @@ -56,11 +56,11 @@ public String getName() { return "GitHubHook"; } - public static boolean isEnable() { + public boolean isEnable() { return Hooks.isEnabled(GitHubHook.class); } - private static void loadAllPlayerLinkGithubData() { + private void loadAllPlayerLinkGithubData() { try { lastKnownLinkMap.clear(); for (DBGithubMinecraft link : linkGithubMinecraft.queryForAll()) { @@ -71,7 +71,7 @@ private static void loadAllPlayerLinkGithubData() { } } - public static Long getContributorId(UUID playerUUID) { + public Long getContributorId(UUID playerUUID) { if (githubLinkCache.contains(playerUUID)) return githubLinkCache.get(playerUUID); InternalToorApiClient.GithubStatus status = InternalToorApiClient.checkGithubStatus(playerUUID); @@ -88,7 +88,7 @@ public static Long getContributorId(UUID playerUUID) { return null; } - private static void persistFallback(UUID playerUUID, long githubId) { + private void persistFallback(UUID playerUUID, long githubId) { DBGithubMinecraft link = new DBGithubMinecraft(playerUUID, githubId); lastKnownLinkMap.put(playerUUID, link); try { @@ -98,7 +98,7 @@ private static void persistFallback(UUID playerUUID, long githubId) { } } - private static void removeFallback(UUID playerUUID) { + private void removeFallback(UUID playerUUID) { if (lastKnownLinkMap.remove(playerUUID) != null) { try { linkGithubMinecraft.deleteById(playerUUID.toString()); @@ -108,12 +108,12 @@ private static void removeFallback(UUID playerUUID) { } } - public static Long refreshContributorId(UUID playerUUID) { + public Long refreshContributorId(UUID playerUUID) { githubLinkCache.invalidate(playerUUID); return getContributorId(playerUUID); } - public static Map getContributors() { + public Map getContributors() { Map contributors = new HashMap<>(); String apiUrl = String.format("https://api.github.com/repos/%s/%s/contributors?per_page=100", REPO_OWNER, REPO_NAME); @@ -153,7 +153,7 @@ public static Map getContributors() { /** * Mets à jours les stats des contributeurs dans la map contributorStatsMap */ - public static void fetchContributorStats() { + public void fetchContributorStats() { Collection contributors = getContributors().values(); String apiUrl = String.format("https://api.github.com/repos/%s/%s/stats/contributors", REPO_OWNER, REPO_NAME); @@ -201,55 +201,55 @@ public static void fetchContributorStats() { } } - public static ContributorStats getStats(String nameGithub) { + public ContributorStats getStats(String nameGithub) { return contributorStatsMap.get(nameGithub); } - public static int getTotalLines(String nameGithub) { + public int getTotalLines(String nameGithub) { ContributorStats stats = contributorStatsMap.get(nameGithub); return stats == null ? 0 : stats.getTotalLines(); } - public static int getTotalAddedLines(String nameGithub) { + public int getTotalAddedLines(String nameGithub) { ContributorStats stats = contributorStatsMap.get(nameGithub); return stats == null ? 0 : stats.totalAddLines(); } - public static int getTotalRemovedLines(String nameGithub) { + public int getTotalRemovedLines(String nameGithub) { ContributorStats stats = contributorStatsMap.get(nameGithub); return stats == null ? 0 : stats.totalRemoveLines(); } - public static String getContributorName(long idGithub) { + public String getContributorName(long idGithub) { return getContributors().getOrDefault(idGithub, "null"); } - public static ContributorStats getStats(long idGithub) { + public ContributorStats getStats(long idGithub) { return contributorStatsMap.get(getContributorName(idGithub)); } - public static int getTotalLines(long idGithub) { + public int getTotalLines(long idGithub) { ContributorStats stats = contributorStatsMap.get(getContributorName(idGithub)); return stats == null ? 0 : stats.getTotalLines(); } - public static int getTotalAddedLines(long idGithub) { + public int getTotalAddedLines(long idGithub) { ContributorStats stats = contributorStatsMap.get(getContributorName(idGithub)); return stats == null ? 0 : stats.totalAddLines(); } - public static int getTotalRemovedLines(long idGithub) { + public int getTotalRemovedLines(long idGithub) { ContributorStats stats = contributorStatsMap.get(getContributorName(idGithub)); return stats == null ? 0 : stats.totalRemoveLines(); } - public static DBGithubMinecraft getContributorLink(UUID uuid) { + public DBGithubMinecraft getContributorLink(UUID uuid) { Long githubId = getContributorId(uuid); if (githubId == null) return null; return lastKnownLinkMap.getOrDefault(uuid, new DBGithubMinecraft(uuid, githubId)); } - public static UUID getPlayerLinkTo(long idGithub) { + public UUID getPlayerLinkTo(long idGithub) { return lastKnownLinkMap.values().stream() .filter(data -> data.getGithubID() == idGithub) .map(DBGithubMinecraft::getPlayerUUID) @@ -257,11 +257,11 @@ public static UUID getPlayerLinkTo(long idGithub) { .orElse(null); } - public static Collection getKnownLinks() { + public Collection getKnownLinks() { return lastKnownLinkMap.values(); } - public static String getUsernameById(long githubId) { + public String getUsernameById(long githubId) { return usernameCache.getOrCompute(githubId, InternalToorApiClient::getGithubUsername); } } diff --git a/src/main/java/fr/openmc/core/hooks/itemsadder/ItemsAdderHook.java b/src/main/java/fr/openmc/core/hooks/itemsadder/ItemsAdderHook.java index c252d7668..9690c0e35 100644 --- a/src/main/java/fr/openmc/core/hooks/itemsadder/ItemsAdderHook.java +++ b/src/main/java/fr/openmc/core/hooks/itemsadder/ItemsAdderHook.java @@ -2,12 +2,12 @@ import dev.lone.itemsadder.api.ItemsAdder; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.hooks.ApiHook; -import fr.openmc.core.bootstrap.hooks.Hooks; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.hooks.itemsadder.behaviours.BehaviourUpBlock; import fr.openmc.core.hooks.itemsadder.events.IAItemLoadEvent; import fr.openmc.core.hooks.itemsadder.placeholders.IAPlaceholderRegistry; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.registry.hooks.ApiHook; +import fr.openmc.core.registry.hooks.Hooks; import fr.openmc.core.utils.FilesUtils; import io.papermc.paper.plugin.bootstrap.BootstrapContext; import lombok.Getter; @@ -27,12 +27,12 @@ @SuppressWarnings("UnstableApiUsage") public class ItemsAdderHook extends Hooks implements ApiHook { @Getter - private static ItemsAdder api; + private ItemsAdder api; private static final String CONTENTS_FOLDER_NAME = "contents"; private static final String MERGE_RESOURCEPACK_PATH = "resource-pack.zip.merge_other_plugins_resourcepacks_folders"; - public static boolean isEnable() { + public boolean isEnable() { return Hooks.isEnabled(ItemsAdderHook.class); } @@ -57,7 +57,7 @@ public void init() { * Appelle {@code IAItemLoadEvent} et donne en meme temps le Yaml de l'item. * DOIT ETRE LANCE APRES QUE ITEMS ADDER SOIT COMPLETEMENT CHARGE */ - public static void loadContents() { + public void loadContents() { File pluginsDir = OMCPlugin.getInstance().getDataFolder().getParentFile(); // * root/pluigns File itemsAdderDir = new File(pluginsDir, "ItemsAdder"); // * root/pluigns/ItemsAdder File contentDir = new File(itemsAdderDir, CONTENTS_FOLDER_NAME); // * root/pluigns/ItemsAdder/contents diff --git a/src/main/java/fr/openmc/core/hooks/itemsadder/placeholders/IAPlaceholderRegistry.java b/src/main/java/fr/openmc/core/hooks/itemsadder/placeholders/IAPlaceholderRegistry.java index 169ca7bf3..19d9a72ad 100644 --- a/src/main/java/fr/openmc/core/hooks/itemsadder/placeholders/IAPlaceholderRegistry.java +++ b/src/main/java/fr/openmc/core/hooks/itemsadder/placeholders/IAPlaceholderRegistry.java @@ -1,6 +1,5 @@ package fr.openmc.core.hooks.itemsadder.placeholders; -import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.features.dream.placeholders.DreamItemMaterialPlaceholder; import fr.openmc.core.features.dream.placeholders.DreamItemNamePlaceholder; import fr.openmc.core.features.dream.placeholders.DreamItemTooltipPlaceholder; @@ -8,6 +7,8 @@ import fr.openmc.core.features.events.contents.dailyevents.contents.goldenharvest.contents.placeholder.GoldenCropsChancePlaceholder; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.contents.placeholder.DoubleHookChancePlaceholder; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.contents.placeholder.FishingSpeedPlaceholder; +import fr.openmc.core.lifecycle.integration.OMCLogger; + import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/fr/openmc/core/bootstrap/integration/DatabaseManager.java b/src/main/java/fr/openmc/core/lifecycle/integration/DatabaseManager.java similarity index 59% rename from src/main/java/fr/openmc/core/bootstrap/integration/DatabaseManager.java rename to src/main/java/fr/openmc/core/lifecycle/integration/DatabaseManager.java index e4e62c1cb..c3d2564d5 100644 --- a/src/main/java/fr/openmc/core/bootstrap/integration/DatabaseManager.java +++ b/src/main/java/fr/openmc/core/lifecycle/integration/DatabaseManager.java @@ -1,11 +1,12 @@ -package fr.openmc.core.bootstrap.integration; +package fr.openmc.core.lifecycle.integration; import com.j256.ormlite.jdbc.JdbcPooledConnectionSource; import com.j256.ormlite.logger.Level; import com.j256.ormlite.logger.LocalLogBackend; import com.j256.ormlite.support.ConnectionSource; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.hooks.Hooks; import lombok.Getter; import org.bukkit.configuration.file.FileConfiguration; @@ -32,7 +33,7 @@ public static void init() { Class.forName("com.mysql.cj.jdbc.Driver"); } } catch (ClassNotFoundException e) { - OMCLogger.error("Database driver not found. Please ensure the MySQL or H2 driver is included in the classpath."); + OMCLogger.error("Le Driver de la Database n'est pas trouvé. Assurez vous que MYSQL ou H2 driver est dans le classpath."); throw new RuntimeException(e); } @@ -43,45 +44,49 @@ public static void init() { String username = config.getString("database.username"); String password = config.getString("database.password"); connectionSource = new JdbcPooledConnectionSource(databaseUrl, username, password); + } catch (SQLException e) { + OMCLogger.error("Tentative d'initialisation de la base de donnée échouée.", e); + throw new RuntimeException(e); + } catch (ConnectionPendingException e) { + OMCLogger.error("La connection à la base de donnée est en attente. Veuillez vérifier votre configuration de base de données."); + throw new RuntimeException(e); + } + } - OMCPlugin.getInstance().REGISTRY_HOOKS - .forEach(h -> { - try { - h.startDB(connectionSource); - } catch (SQLException e) { - OMCLogger.error("Failed to initialize the database connection.", e); - throw new RuntimeException(e); - } catch (ConnectionPendingException e) { - OMCLogger.error("Database connection is pending. Please check your database configuration."); - throw new RuntimeException(e); - } catch (NoClassDefFoundError e) { - OMCLogger.errorFormatted("Plugin has failed to start feature because {} does not exist.", - e.getMessage()); - } - }); + public static void startFeatureDB(Feature feature) { + if (connectionSource == null) { + OMCLogger.error("Tentative de start la DB d'une feature avant que DatabseManager soit init."); + return; + } + try { + feature.startDB(connectionSource); + } catch (SQLException e) { + OMCLogger.error("Tentative d'initialisation de la base de donnée d'une feature échouée.", e); + throw new RuntimeException(e); + } catch (ConnectionPendingException e) { + OMCLogger.error("La connection à la base de donnée est en attente. Veuillez vérifier votre configuration de base de données."); + throw new RuntimeException(e); + } catch (NoClassDefFoundError e) { + OMCLogger.errorFormatted("Le plugin a tenté de lancer une feature mais {} n'existe pas.", e.getMessage()); + } + } - OMCPlugin.getInstance().REGISTRY_FEATURE - .forEach(f -> { - try { - Feature feature = f.create(); - feature.startDB(connectionSource); - } catch (SQLException e) { - OMCLogger.error("Failed to initialize the database connection.", e); - throw new RuntimeException(e); - } catch (ConnectionPendingException e) { - OMCLogger.error("Database connection is pending. Please check your database configuration."); - throw new RuntimeException(e); - } catch (NoClassDefFoundError e) { - OMCLogger.errorFormatted("Plugin has failed to start feature because {} does not exist.", - e.getMessage()); - } - }); + public static void startHookDB(Hooks hook) { + if (connectionSource == null) { + OMCLogger.error("Tentative de start la DB d'un hook avant que DatabseManager soit init."); + return; + } + try { + hook.startDB(connectionSource); } catch (SQLException e) { - OMCLogger.error("Failed to initialize the database connection.", e); + OMCLogger.error("Tentative d'initialisation de la base de donnée d'un hook échouée.", e); throw new RuntimeException(e); } catch (ConnectionPendingException e) { - OMCLogger.error("Database connection is pending. Please check your database configuration."); + OMCLogger.error("La connection à la base de donnée est en attente. Veuillez vérifier votre configuration de base de données."); throw new RuntimeException(e); + } catch (NoClassDefFoundError e) { + OMCLogger.errorFormatted("Le plugin a tenté de lancer un hook mais {} n'existe pas.", + e.getMessage()); } } diff --git a/src/main/java/fr/openmc/core/bootstrap/integration/DatapackLoader.java b/src/main/java/fr/openmc/core/lifecycle/integration/DatapackLoader.java similarity index 97% rename from src/main/java/fr/openmc/core/bootstrap/integration/DatapackLoader.java rename to src/main/java/fr/openmc/core/lifecycle/integration/DatapackLoader.java index 5e5f23b32..cac83b8c4 100644 --- a/src/main/java/fr/openmc/core/bootstrap/integration/DatapackLoader.java +++ b/src/main/java/fr/openmc/core/lifecycle/integration/DatapackLoader.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.integration; +package fr.openmc.core.lifecycle.integration; import fr.openmc.core.utils.FilesUtils; import io.papermc.paper.plugin.bootstrap.BootstrapContext; diff --git a/src/main/java/fr/openmc/core/bootstrap/integration/ErrorReporter.java b/src/main/java/fr/openmc/core/lifecycle/integration/ErrorReporter.java similarity index 99% rename from src/main/java/fr/openmc/core/bootstrap/integration/ErrorReporter.java rename to src/main/java/fr/openmc/core/lifecycle/integration/ErrorReporter.java index 27d36b562..ea34fce2c 100644 --- a/src/main/java/fr/openmc/core/bootstrap/integration/ErrorReporter.java +++ b/src/main/java/fr/openmc/core/lifecycle/integration/ErrorReporter.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.integration; +package fr.openmc.core.lifecycle.integration; import fr.openmc.core.OMCPlugin; import fr.openmc.core.utils.DiscordWebhookUtils; diff --git a/src/main/java/fr/openmc/core/bootstrap/integration/OMCLogger.java b/src/main/java/fr/openmc/core/lifecycle/integration/OMCLogger.java similarity index 99% rename from src/main/java/fr/openmc/core/bootstrap/integration/OMCLogger.java rename to src/main/java/fr/openmc/core/lifecycle/integration/OMCLogger.java index 1dc80c4f7..3ab785083 100644 --- a/src/main/java/fr/openmc/core/bootstrap/integration/OMCLogger.java +++ b/src/main/java/fr/openmc/core/lifecycle/integration/OMCLogger.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.integration; +package fr.openmc.core.lifecycle.integration; import fr.openmc.core.OMCPlugin; import lombok.Setter; diff --git a/src/main/java/fr/openmc/core/bootstrap/integration/ResourcePacksGenerator.java b/src/main/java/fr/openmc/core/lifecycle/integration/ResourcePacksGenerator.java similarity index 97% rename from src/main/java/fr/openmc/core/bootstrap/integration/ResourcePacksGenerator.java rename to src/main/java/fr/openmc/core/lifecycle/integration/ResourcePacksGenerator.java index fc4104b6f..ab6bcc4c8 100644 --- a/src/main/java/fr/openmc/core/bootstrap/integration/ResourcePacksGenerator.java +++ b/src/main/java/fr/openmc/core/lifecycle/integration/ResourcePacksGenerator.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.integration; +package fr.openmc.core.lifecycle.integration; import fr.openmc.core.utils.FilesUtils; import io.papermc.paper.plugin.bootstrap.BootstrapContext; diff --git a/src/main/java/fr/openmc/core/bootstrap/features/types/HasCommands.java b/src/main/java/fr/openmc/core/lifecycle/interfaces/HasCommands.java similarity index 83% rename from src/main/java/fr/openmc/core/bootstrap/features/types/HasCommands.java rename to src/main/java/fr/openmc/core/lifecycle/interfaces/HasCommands.java index 4c88e004a..6cd9502a3 100644 --- a/src/main/java/fr/openmc/core/bootstrap/features/types/HasCommands.java +++ b/src/main/java/fr/openmc/core/lifecycle/interfaces/HasCommands.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.features.types; +package fr.openmc.core.lifecycle.interfaces; import java.util.Set; diff --git a/src/main/java/fr/openmc/core/bootstrap/features/types/HasDatabase.java b/src/main/java/fr/openmc/core/lifecycle/interfaces/HasDatabase.java similarity index 78% rename from src/main/java/fr/openmc/core/bootstrap/features/types/HasDatabase.java rename to src/main/java/fr/openmc/core/lifecycle/interfaces/HasDatabase.java index 88450c1a7..edfa79761 100644 --- a/src/main/java/fr/openmc/core/bootstrap/features/types/HasDatabase.java +++ b/src/main/java/fr/openmc/core/lifecycle/interfaces/HasDatabase.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.features.types; +package fr.openmc.core.lifecycle.interfaces; import com.j256.ormlite.support.ConnectionSource; @@ -15,4 +15,6 @@ public interface HasDatabase { * @throws SQLException Si l'initialisation DB échoue */ void initDB(ConnectionSource connectionSource) throws SQLException; + + // todo interface qui fait des load et des saves d'un dao dans une type de map choisies? } diff --git a/src/main/java/fr/openmc/core/lifecycle/interfaces/HasFeature.java b/src/main/java/fr/openmc/core/lifecycle/interfaces/HasFeature.java new file mode 100644 index 000000000..0ec7d2aaa --- /dev/null +++ b/src/main/java/fr/openmc/core/lifecycle/interfaces/HasFeature.java @@ -0,0 +1,14 @@ +package fr.openmc.core.lifecycle.interfaces; + +import fr.openmc.core.registry.features.Feature; +import fr.openmc.core.registry.features.loading.FeatureEntry; + +/** + * Interface permettant aux classes d'enregistrer une feature + */ +public interface HasFeature { + /** + * Feature à initialiser + */ + FeatureEntry feature(); +} diff --git a/src/main/java/fr/openmc/core/bootstrap/features/types/HasListeners.java b/src/main/java/fr/openmc/core/lifecycle/interfaces/HasListeners.java similarity index 79% rename from src/main/java/fr/openmc/core/bootstrap/features/types/HasListeners.java rename to src/main/java/fr/openmc/core/lifecycle/interfaces/HasListeners.java index fcd218cd8..928df602e 100644 --- a/src/main/java/fr/openmc/core/bootstrap/features/types/HasListeners.java +++ b/src/main/java/fr/openmc/core/lifecycle/interfaces/HasListeners.java @@ -1,6 +1,6 @@ -package fr.openmc.core.bootstrap.features.types; +package fr.openmc.core.lifecycle.interfaces; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; import java.util.Set; diff --git a/src/main/java/fr/openmc/core/bootstrap/features/types/LoadIfEnable.java b/src/main/java/fr/openmc/core/lifecycle/interfaces/LoadIfEnable.java similarity index 93% rename from src/main/java/fr/openmc/core/bootstrap/features/types/LoadIfEnable.java rename to src/main/java/fr/openmc/core/lifecycle/interfaces/LoadIfEnable.java index b44bb41e4..6037d6d7d 100644 --- a/src/main/java/fr/openmc/core/bootstrap/features/types/LoadIfEnable.java +++ b/src/main/java/fr/openmc/core/lifecycle/interfaces/LoadIfEnable.java @@ -1,7 +1,7 @@ -package fr.openmc.core.bootstrap.features.types; +package fr.openmc.core.lifecycle.interfaces; -import fr.openmc.core.bootstrap.hooks.Hooks; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.registry.hooks.Hooks; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; diff --git a/src/main/java/fr/openmc/core/bootstrap/features/types/NotLoadInUnitTest.java b/src/main/java/fr/openmc/core/lifecycle/interfaces/NotLoadInUnitTest.java similarity index 71% rename from src/main/java/fr/openmc/core/bootstrap/features/types/NotLoadInUnitTest.java rename to src/main/java/fr/openmc/core/lifecycle/interfaces/NotLoadInUnitTest.java index a3024b276..7d45606a3 100644 --- a/src/main/java/fr/openmc/core/bootstrap/features/types/NotLoadInUnitTest.java +++ b/src/main/java/fr/openmc/core/lifecycle/interfaces/NotLoadInUnitTest.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.features.types; +package fr.openmc.core.lifecycle.interfaces; /** * Charge uniquement la feature ou le listener hors des tests unitaires diff --git a/src/main/java/fr/openmc/core/bootstrap/listeners/ListenerFactory.java b/src/main/java/fr/openmc/core/lifecycle/listeners/ListenerFactory.java similarity index 90% rename from src/main/java/fr/openmc/core/bootstrap/listeners/ListenerFactory.java rename to src/main/java/fr/openmc/core/lifecycle/listeners/ListenerFactory.java index 1e3289822..5a7ead498 100644 --- a/src/main/java/fr/openmc/core/bootstrap/listeners/ListenerFactory.java +++ b/src/main/java/fr/openmc/core/lifecycle/listeners/ListenerFactory.java @@ -1,7 +1,7 @@ -package fr.openmc.core.bootstrap.listeners; +package fr.openmc.core.lifecycle.listeners; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.event.Listener; diff --git a/src/main/java/fr/openmc/core/bootstrap/registries/KeyedRegistry.java b/src/main/java/fr/openmc/core/lifecycle/registries/KeyedRegistry.java similarity index 69% rename from src/main/java/fr/openmc/core/bootstrap/registries/KeyedRegistry.java rename to src/main/java/fr/openmc/core/lifecycle/registries/KeyedRegistry.java index 7548dda09..35db42c72 100644 --- a/src/main/java/fr/openmc/core/bootstrap/registries/KeyedRegistry.java +++ b/src/main/java/fr/openmc/core/lifecycle/registries/KeyedRegistry.java @@ -1,12 +1,13 @@ -package fr.openmc.core.bootstrap.registries; +package fr.openmc.core.lifecycle.registries; public interface KeyedRegistry { K key(V registryObject); V register(K key, V value); - default V register(V value) { - return register(key(value), value); + default T register(T value) { + register(key(value), value); + return value; } default void register(V... values) { @@ -20,4 +21,4 @@ default void register(Iterable values) { register(value); } } -} +} \ No newline at end of file diff --git a/src/main/java/fr/openmc/core/bootstrap/registries/LifecycleRegistry.java b/src/main/java/fr/openmc/core/lifecycle/registries/LifecycleRegistry.java similarity index 87% rename from src/main/java/fr/openmc/core/bootstrap/registries/LifecycleRegistry.java rename to src/main/java/fr/openmc/core/lifecycle/registries/LifecycleRegistry.java index 506ca7f96..4b6745488 100644 --- a/src/main/java/fr/openmc/core/bootstrap/registries/LifecycleRegistry.java +++ b/src/main/java/fr/openmc/core/lifecycle/registries/LifecycleRegistry.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.registries; +package fr.openmc.core.lifecycle.registries; import io.papermc.paper.plugin.bootstrap.BootstrapContext; diff --git a/src/main/java/fr/openmc/core/bootstrap/registries/Registry.java b/src/main/java/fr/openmc/core/lifecycle/registries/Registry.java similarity index 81% rename from src/main/java/fr/openmc/core/bootstrap/registries/Registry.java rename to src/main/java/fr/openmc/core/lifecycle/registries/Registry.java index d18b31d38..44de500a4 100644 --- a/src/main/java/fr/openmc/core/bootstrap/registries/Registry.java +++ b/src/main/java/fr/openmc/core/lifecycle/registries/Registry.java @@ -1,13 +1,13 @@ -package fr.openmc.core.bootstrap.registries; +package fr.openmc.core.lifecycle.registries; import java.util.Collection; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; public class Registry implements LifecycleRegistry { - protected final Map entries = new HashMap<>(); + protected final Map entries = new LinkedHashMap<>();; public V register(K key, V value) { entries.put(key, value); diff --git a/src/main/java/fr/openmc/core/bootstrap/registries/RegistryContext.java b/src/main/java/fr/openmc/core/lifecycle/registries/RegistryContext.java similarity index 92% rename from src/main/java/fr/openmc/core/bootstrap/registries/RegistryContext.java rename to src/main/java/fr/openmc/core/lifecycle/registries/RegistryContext.java index 6984ae43d..0587a08a4 100644 --- a/src/main/java/fr/openmc/core/bootstrap/registries/RegistryContext.java +++ b/src/main/java/fr/openmc/core/lifecycle/registries/RegistryContext.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.registries; +package fr.openmc.core.lifecycle.registries; import java.util.function.Supplier; diff --git a/src/main/java/fr/openmc/core/bootstrap/registries/RegistryLoadingType.java b/src/main/java/fr/openmc/core/lifecycle/registries/RegistryLoadingType.java similarity index 91% rename from src/main/java/fr/openmc/core/bootstrap/registries/RegistryLoadingType.java rename to src/main/java/fr/openmc/core/lifecycle/registries/RegistryLoadingType.java index 20f8dfd79..baa57a185 100644 --- a/src/main/java/fr/openmc/core/bootstrap/registries/RegistryLoadingType.java +++ b/src/main/java/fr/openmc/core/lifecycle/registries/RegistryLoadingType.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.registries; +package fr.openmc.core.lifecycle.registries; /** * Les Conditions de Chargement : diff --git a/src/main/java/fr/openmc/core/listeners/AsyncChatListener.java b/src/main/java/fr/openmc/core/listeners/AsyncChatListener.java index 60ff29faa..4aba39b9c 100644 --- a/src/main/java/fr/openmc/core/listeners/AsyncChatListener.java +++ b/src/main/java/fr/openmc/core/listeners/AsyncChatListener.java @@ -1,14 +1,13 @@ package fr.openmc.core.listeners; import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.hooks.LuckPermsHook; import io.papermc.paper.event.player.AsyncChatEvent; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; -import net.luckperms.api.LuckPerms; -import net.luckperms.api.cacheddata.CachedMetaData; import org.bukkit.Bukkit; import org.bukkit.Sound; import org.bukkit.SoundCategory; @@ -22,22 +21,21 @@ public class AsyncChatListener implements Listener { private final OMCPlugin plugin; - private final LuckPerms luckperms; + private final LuckPermsHook luckPermsHook; public AsyncChatListener(OMCPlugin plugin) { this.plugin = plugin; - this.luckperms = LuckPermsHook.getApi(); + this.luckPermsHook = OMCRegistry.HOOKS.LUCK_PERMS; } @EventHandler public void onChat(AsyncChatEvent event) { final Player player = event.getPlayer(); - final CachedMetaData metaData = this.luckperms.getPlayerAdapter(Player.class).getMetaData(player); String message = PlainTextComponentSerializer.plainText().serialize(event.message()); String rawMessage = plugin.getConfig().getString("chat.message", "{prefix}{name}§7: {message}") - .replace("{prefix}", LuckPermsHook.getFormattedPAPIPrefix(player)) - .replace("{suffix}", metaData.getSuffix() != null ? metaData.getSuffix() : "") + .replace("{prefix}", luckPermsHook.getFormattedPAPIPrefix(player)) + .replace("{suffix}", luckPermsHook.getSuffix(player)) .replace("{name}", player.getName()) .replace("{message}", message); diff --git a/src/main/java/fr/openmc/core/listeners/ItemsAddersListener.java b/src/main/java/fr/openmc/core/listeners/ItemsAddersListener.java index e5e7a7ef4..c258d275c 100644 --- a/src/main/java/fr/openmc/core/listeners/ItemsAddersListener.java +++ b/src/main/java/fr/openmc/core/listeners/ItemsAddersListener.java @@ -2,8 +2,8 @@ import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.types.LoadIfEnable; import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.lifecycle.interfaces.LoadIfEnable; import lombok.Setter; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; diff --git a/src/main/java/fr/openmc/core/listeners/JoinQuitMessageListener.java b/src/main/java/fr/openmc/core/listeners/JoinQuitMessageListener.java index e47919b36..0143887db 100644 --- a/src/main/java/fr/openmc/core/listeners/JoinQuitMessageListener.java +++ b/src/main/java/fr/openmc/core/listeners/JoinQuitMessageListener.java @@ -1,7 +1,7 @@ package fr.openmc.core.listeners; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.commands.utils.SpawnManager; import fr.openmc.core.features.displays.TabList; import fr.openmc.core.features.economy.EconomyManager; @@ -11,6 +11,7 @@ import fr.openmc.core.features.tpa.TPAManager; import fr.openmc.core.hooks.LuckPermsHook; import fr.openmc.core.hooks.github.GitHubHook; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.utils.text.messages.MessageType; import fr.openmc.core.utils.text.messages.MessagesManager; import fr.openmc.core.utils.text.messages.Prefix; @@ -30,12 +31,14 @@ public class JoinQuitMessageListener implements Listener { private final double balanceOnJoin; + private final LuckPermsHook luckPermsHook; public static final String JOIN_MESSAGE = "§8[§a§l+§8] §r%s%s"; public static final String QUIT_MESSAGE = "§8[§c§l-§8] §r%s%s"; public JoinQuitMessageListener() { this.balanceOnJoin = OMCPlugin.getInstance().getConfig().getDouble("money-on-first-join", 500D); + this.luckPermsHook = OMCRegistry.HOOKS.LUCK_PERMS; } @EventHandler @@ -52,7 +55,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { if (friend != null && friend.isOnline() && !friend.hasMetadata(OMCPlugin.VANISH_META_KEY)) { MessagesManager.sendMessage(friend, TranslationManager.translation( "core.player.join.friend_online", - Component.text(LuckPermsHook.getFormattedPAPIPrefix(player) + player.getName()).color(NamedTextColor.GREEN) + Component.text(luckPermsHook.getFormattedPAPIPrefix(player) + player.getName()).color(NamedTextColor.GREEN) ), Prefix.FRIEND, MessageType.NONE, true); } } @@ -84,7 +87,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { }); if (!player.hasMetadata(OMCPlugin.VANISH_META_KEY)) - event.joinMessage(Component.text(JOIN_MESSAGE.formatted(LuckPermsHook.getFormattedPAPIPrefix(player), player.getName()))); + event.joinMessage(Component.text(JOIN_MESSAGE.formatted(luckPermsHook.getFormattedPAPIPrefix(player), player.getName()))); // Adjust player's spawn location if (!player.hasPlayedBefore()) { @@ -117,7 +120,7 @@ public void onPlayerQuit(PlayerQuitEvent event) { if (friend != null && friend.isOnline() && !friend.hasMetadata(OMCPlugin.VANISH_META_KEY)) { MessagesManager.sendMessage(friend, TranslationManager.translation( "core.player.quit.friend_offline", - Component.text(LuckPermsHook.getFormattedPAPIPrefix(player) + player.getName()).color(NamedTextColor.YELLOW) + Component.text(luckPermsHook.getFormattedPAPIPrefix(player) + player.getName()).color(NamedTextColor.YELLOW) ), Prefix.FRIEND, MessageType.NONE, true); } } @@ -144,7 +147,7 @@ public void onPlayerQuit(PlayerQuitEvent event) { } if (!player.hasMetadata(OMCPlugin.VANISH_META_KEY)) - event.quitMessage(Component.text(QUIT_MESSAGE.formatted(LuckPermsHook.getFormattedPAPIPrefix(player), player.getName()))); + event.quitMessage(Component.text(QUIT_MESSAGE.formatted(luckPermsHook.getFormattedPAPIPrefix(player), player.getName()))); } } diff --git a/src/main/java/fr/openmc/core/listeners/RegionTrackingListener.java b/src/main/java/fr/openmc/core/listeners/RegionTrackingListener.java index a59e99dee..be6a01321 100644 --- a/src/main/java/fr/openmc/core/listeners/RegionTrackingListener.java +++ b/src/main/java/fr/openmc/core/listeners/RegionTrackingListener.java @@ -6,9 +6,9 @@ import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.RegionContainer; import com.sk89q.worldguard.protection.regions.RegionQuery; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; import fr.openmc.core.events.RegionEnterEvent; import fr.openmc.core.events.RegionLeaveEvent; +import fr.openmc.core.lifecycle.interfaces.NotLoadInUnitTest; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/openmc/core/registry/ambient/CustomAmbientRegistry.java b/src/main/java/fr/openmc/core/registry/ambient/CustomAmbientRegistry.java index 48b026fbc..a1c134270 100644 --- a/src/main/java/fr/openmc/core/registry/ambient/CustomAmbientRegistry.java +++ b/src/main/java/fr/openmc/core/registry/ambient/CustomAmbientRegistry.java @@ -2,14 +2,14 @@ import fr.openmc.api.datapacks.OMCDatapack; import fr.openmc.api.datapacks.injectors.BiomesInjector; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; -import fr.openmc.core.bootstrap.registries.KeyedRegistry; -import fr.openmc.core.bootstrap.registries.Registry; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.contents.ambient.BloodyAmbient; import fr.openmc.core.features.events.contents.dailyevents.contents.goldenharvest.contents.ambient.GoldenAmbient; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.contents.ambient.BlessedAmbient; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.lifecycle.registries.KeyedRegistry; +import fr.openmc.core.lifecycle.registries.Registry; import fr.openmc.core.registry.ambient.contents.DarkAmbient; import fr.openmc.core.registry.ambient.contents.HellAmbient; import fr.openmc.core.registry.ambient.listeners.AmbientFixedTimeListener; diff --git a/src/main/java/fr/openmc/core/registry/ambient/RegistriesLoadConfig.java b/src/main/java/fr/openmc/core/registry/ambient/RegistriesLoadConfig.java index ace14e441..3acf7d04a 100644 --- a/src/main/java/fr/openmc/core/registry/ambient/RegistriesLoadConfig.java +++ b/src/main/java/fr/openmc/core/registry/ambient/RegistriesLoadConfig.java @@ -1,6 +1,6 @@ package fr.openmc.core.registry.ambient; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; import lombok.Getter; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/main/java/fr/openmc/core/registry/ambient/listeners/AmbientFixedTimeListener.java b/src/main/java/fr/openmc/core/registry/ambient/listeners/AmbientFixedTimeListener.java index 144e81755..0db2e9d7a 100644 --- a/src/main/java/fr/openmc/core/registry/ambient/listeners/AmbientFixedTimeListener.java +++ b/src/main/java/fr/openmc/core/registry/ambient/listeners/AmbientFixedTimeListener.java @@ -2,9 +2,9 @@ import fr.openmc.core.OMCPlugin; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; import fr.openmc.core.events.RegionEnterEvent; import fr.openmc.core.events.RegionLeaveEvent; +import fr.openmc.core.lifecycle.interfaces.NotLoadInUnitTest; import fr.openmc.core.registry.ambient.CustomAmbient; import fr.openmc.core.utils.nms.PlayerSetTimeNMS; import org.bukkit.Bukkit; diff --git a/src/main/java/fr/openmc/core/registry/ambient/listeners/AmbientWeatherListener.java b/src/main/java/fr/openmc/core/registry/ambient/listeners/AmbientWeatherListener.java index 2cf6e1467..c46fa634c 100644 --- a/src/main/java/fr/openmc/core/registry/ambient/listeners/AmbientWeatherListener.java +++ b/src/main/java/fr/openmc/core/registry/ambient/listeners/AmbientWeatherListener.java @@ -2,9 +2,9 @@ import fr.openmc.core.OMCPlugin; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; import fr.openmc.core.events.RegionEnterEvent; import fr.openmc.core.events.RegionLeaveEvent; +import fr.openmc.core.lifecycle.interfaces.NotLoadInUnitTest; import fr.openmc.core.registry.ambient.CustomAmbient; import fr.openmc.core.utils.nms.PlayerWeatherNMS; import org.bukkit.Bukkit; diff --git a/src/main/java/fr/openmc/core/registry/ambient/listeners/BiomesOnChunkLoad.java b/src/main/java/fr/openmc/core/registry/ambient/listeners/BiomesOnChunkLoad.java index bdd0fef43..34d6f8233 100644 --- a/src/main/java/fr/openmc/core/registry/ambient/listeners/BiomesOnChunkLoad.java +++ b/src/main/java/fr/openmc/core/registry/ambient/listeners/BiomesOnChunkLoad.java @@ -1,7 +1,7 @@ package fr.openmc.core.registry.ambient.listeners; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; +import fr.openmc.core.lifecycle.interfaces.NotLoadInUnitTest; import fr.openmc.core.registry.ambient.CustomAmbient; import fr.openmc.core.utils.nms.PlayerBiomeNMS; import io.papermc.paper.event.packet.PlayerChunkLoadEvent; diff --git a/src/main/java/fr/openmc/core/registry/enchantments/CustomEnchantment.java b/src/main/java/fr/openmc/core/registry/enchantments/CustomEnchantment.java index 911a43420..28aa69c13 100644 --- a/src/main/java/fr/openmc/core/registry/enchantments/CustomEnchantment.java +++ b/src/main/java/fr/openmc/core/registry/enchantments/CustomEnchantment.java @@ -1,6 +1,6 @@ package fr.openmc.core.registry.enchantments; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; import fr.openmc.core.registry.items.CustomItem; import fr.openmc.core.utils.RandomUtils; import io.papermc.paper.registry.RegistryAccess; diff --git a/src/main/java/fr/openmc/core/registry/enchantments/CustomEnchantmentRegistry.java b/src/main/java/fr/openmc/core/registry/enchantments/CustomEnchantmentRegistry.java index 1b65943c4..5a1107f96 100644 --- a/src/main/java/fr/openmc/core/registry/enchantments/CustomEnchantmentRegistry.java +++ b/src/main/java/fr/openmc/core/registry/enchantments/CustomEnchantmentRegistry.java @@ -2,13 +2,13 @@ import fr.openmc.core.OMCPlugin; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.bootstrap.registries.KeyedRegistry; -import fr.openmc.core.bootstrap.registries.Registry; import fr.openmc.core.features.dream.registries.enchantements.DreamSleeper; import fr.openmc.core.features.dream.registries.enchantements.Experientastic; import fr.openmc.core.features.dream.registries.enchantements.Soulbound; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.contents.enchantments.Vampirism; import fr.openmc.core.features.events.contents.dailyevents.contents.goldenharvest.contents.enchantments.Plantation; +import fr.openmc.core.lifecycle.registries.KeyedRegistry; +import fr.openmc.core.lifecycle.registries.Registry; import io.papermc.paper.plugin.bootstrap.BootstrapContext; import io.papermc.paper.registry.data.EnchantmentRegistryEntry; import io.papermc.paper.registry.event.RegistryComposeEvent; diff --git a/src/main/java/fr/openmc/core/bootstrap/features/DisableFeatureException.java b/src/main/java/fr/openmc/core/registry/features/DisableFeatureException.java similarity index 85% rename from src/main/java/fr/openmc/core/bootstrap/features/DisableFeatureException.java rename to src/main/java/fr/openmc/core/registry/features/DisableFeatureException.java index 5226504b5..3dfba67d1 100644 --- a/src/main/java/fr/openmc/core/bootstrap/features/DisableFeatureException.java +++ b/src/main/java/fr/openmc/core/registry/features/DisableFeatureException.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.features; +package fr.openmc.core.registry.features; public class DisableFeatureException extends RuntimeException { public DisableFeatureException(String message) { diff --git a/src/main/java/fr/openmc/core/bootstrap/features/Feature.java b/src/main/java/fr/openmc/core/registry/features/Feature.java similarity index 76% rename from src/main/java/fr/openmc/core/bootstrap/features/Feature.java rename to src/main/java/fr/openmc/core/registry/features/Feature.java index eca286465..e76291509 100644 --- a/src/main/java/fr/openmc/core/bootstrap/features/Feature.java +++ b/src/main/java/fr/openmc/core/registry/features/Feature.java @@ -1,11 +1,14 @@ -package fr.openmc.core.bootstrap.features; +package fr.openmc.core.registry.features; import com.j256.ormlite.support.ConnectionSource; import fr.openmc.core.CommandsManager; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.types.*; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; +import fr.openmc.core.lifecycle.integration.DatabaseManager; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasCommands; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; import java.sql.SQLException; @@ -20,17 +23,8 @@ public abstract class Feature { * Lance l'initialisation avec des règles en fonction des interfaces mises (NotUnitTest, LoadIfEnable) */ public final void startInit() { - // Condition d'initialisation (si feature ne doit pas être lancée dans les tests ou qu'elle nécessite un hook) - if (this instanceof NotLoadInUnitTest && OMCPlugin.isUnitTestVersion()) { - OMCLogger.errorFormatted("Feature " + this.getClass().getSimpleName() + " non initialisée dans les Unit Tests"); - return; - } - if (this instanceof LoadIfEnable loadIfEnable && !loadIfEnable.shouldLoad()) { - OMCLogger.errorFormatted("Feature " + this.getClass().getSimpleName() + " non initialisée car le hook associé n'est pas activé"); - return; - } - try { + DatabaseManager.startFeatureDB(this); init(); // Enregistre les listeners @@ -67,7 +61,6 @@ public final void startInit() { * @throws SQLException Si l'initialisation DB échoue */ public final void startDB(ConnectionSource connectionSource) throws SQLException { - if (this instanceof NotLoadInUnitTest && OMCPlugin.isUnitTestVersion()) return; if (this instanceof HasDatabase dbF) { dbF.initDB(connectionSource); } @@ -78,7 +71,6 @@ public final void startDB(ConnectionSource connectionSource) throws SQLException */ public final void startSave() { if (!initialize) return; - if (this instanceof NotLoadInUnitTest && OMCPlugin.isUnitTestVersion()) return; try { save(); diff --git a/src/main/java/fr/openmc/core/registry/features/FeaturesRegistry.java b/src/main/java/fr/openmc/core/registry/features/FeaturesRegistry.java new file mode 100644 index 000000000..39104546f --- /dev/null +++ b/src/main/java/fr/openmc/core/registry/features/FeaturesRegistry.java @@ -0,0 +1,214 @@ +package fr.openmc.core.registry.features; + +import com.google.common.base.Supplier; +import fr.openmc.api.cooldown.DynamicCooldownManager; +import fr.openmc.core.OMCPlugin; +import fr.openmc.core.OMCRegistry; +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.bits.BitsManager; +import fr.openmc.core.features.chatanimations.ChatAnimationManager; +import fr.openmc.core.features.city.CityManager; +import fr.openmc.core.features.city.sub.mascots.MascotsManager; +import fr.openmc.core.features.cube.multiblocks.MultiBlockManager; +import fr.openmc.core.features.dimopener.DimensionOpenerManager; +import fr.openmc.core.features.displays.TabList; +import fr.openmc.core.features.displays.bossbar.BossbarManager; +import fr.openmc.core.features.displays.bossbar.contents.HelpConfigManager; +import fr.openmc.core.features.displays.holograms.HologramLoader; +import fr.openmc.core.features.displays.scoreboards.ScoreboardManager; +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.EventsManager; +import fr.openmc.core.features.events.contents.dailyevents.DailyEventsManager; +import fr.openmc.core.features.events.contents.halloween.managers.HalloweenManager; +import fr.openmc.core.features.events.contents.weeklyevents.WeeklyEventsManager; +import fr.openmc.core.features.events.contents.weeklyevents.contents.contest.managers.ContestManager; +import fr.openmc.core.features.friend.FriendManager; +import fr.openmc.core.features.homes.HomesManager; +import fr.openmc.core.features.homes.icons.HomeIconCacheManager; +import fr.openmc.core.features.itemsadder.elevator.ElevatorManager; +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.privatemessage.PrivateMessageManager; +import fr.openmc.core.features.privatemessage.SocialSpyManager; +import fr.openmc.core.features.profile.ProfileManager; +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.shops.managers.ShopManager; +import fr.openmc.core.features.tickets.TicketManager; +import fr.openmc.core.features.toor.DiscordLinkManager; +import fr.openmc.core.features.tpa.TPAManager; +import fr.openmc.core.features.updates.UpdateManager; +import fr.openmc.core.lifecycle.registries.KeyedRegistry; +import fr.openmc.core.lifecycle.registries.Registry; +import fr.openmc.core.registry.features.loading.FeatureEntry; +import fr.openmc.core.registry.features.loading.FeatureFlag; +import fr.openmc.core.registry.features.loading.FeatureLoadingType; +import fr.openmc.core.utils.text.MotdUtils; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class FeaturesRegistry extends Registry + implements KeyedRegistry { + + // * Flags pré enregistrés + public final FeatureFlag NOT_IN_UNIT_TEST = new FeatureFlag.NotInUnitTest(); + public final FeatureFlag NEED_FANCY_NPC = new FeatureFlag.NeedApi(OMCRegistry.HOOKS.FANCY_NPCS::isEnable, "FancyNPC"); + public final FeatureFlag NEED_LUCK_PERMS = new FeatureFlag.NeedApi(OMCRegistry.HOOKS.LUCK_PERMS::isEnable, "LuckPerms"); + public final FeatureFlag NEED_ITEMS_ADDER = new FeatureFlag.NeedApi(OMCRegistry.HOOKS.ITEMS_ADDER::isEnable, "ItemsAdder"); + public final FeatureFlag NEED_PAPI = new FeatureFlag.NeedApi(OMCRegistry.HOOKS.PAPI::isEnable, "PlaceHolderAPI"); + public final FeatureFlag NEED_PROTOCOL_LIB = new FeatureFlag.NeedApi(OMCRegistry.HOOKS.PROTOCOL_LIB::isEnable, "ProtocolLib"); + public final FeatureFlag NEED_WORLD_GUARD = new FeatureFlag.NeedApi(OMCRegistry.HOOKS.WORLD_GUARD::isEnable, "WorldGuard"); + + private final List> declarations = new ArrayList<>(); + + public final FeatureEntry TICKETS = declare(FeatureLoadingType.RUNTIME, + () -> new TicketManager(new File(OMCPlugin.getInstance().getDataFolder(), "data/stats"))); + + public final FeatureEntry PRIVATE_SPY = declare(FeatureLoadingType.RUNTIME, + PrivateMessageManager::new); + public final FeatureEntry SOCIAL_SPY = declare(FeatureLoadingType.RUNTIME, + SocialSpyManager::new); + public final FeatureEntry SPAWN = declare(FeatureLoadingType.RUNTIME, + SpawnManager::new); + public final FeatureEntry UPDATE = declare(FeatureLoadingType.RUNTIME, + UpdateManager::new); + public final FeatureEntry ECONOMY = declare(FeatureLoadingType.RUNTIME, + EconomyManager::new); + public final FeatureEntry BANK = declare(FeatureLoadingType.RUNTIME, + BankManager::new); + public final FeatureEntry BITS = declare(FeatureLoadingType.RUNTIME, + BitsManager::new); + public final FeatureEntry SCOREBOARD = declare(FeatureLoadingType.RUNTIME, + () -> new ScoreboardManager(), NOT_IN_UNIT_TEST, NEED_LUCK_PERMS); + public final FeatureEntry HOMES = declare(FeatureLoadingType.RUNTIME, + HomesManager::new); + public final FeatureEntry TPA = declare(FeatureLoadingType.RUNTIME, + TPAManager::new); + public final FeatureEntry FREEZE = declare(FeatureLoadingType.RUNTIME, + FreezeManager::new); + public final FeatureEntry TRANSACTIONS = declare(FeatureLoadingType.RUNTIME, + TransactionsManager::new); + public final FeatureEntry ANALYTICS = declare(FeatureLoadingType.RUNTIME, + AnalyticsManager::new); + public final FeatureEntry FRIENDS = declare(FeatureLoadingType.RUNTIME, + FriendManager::new); + public final FeatureEntry TAB = declare(FeatureLoadingType.RUNTIME, + () -> new TabList(), NOT_IN_UNIT_TEST, NEED_PROTOCOL_LIB); + public final FeatureEntry ADMIN_SHOP = declare(FeatureLoadingType.RUNTIME, + AdminShopManager::new); + public final FeatureEntry HELP_CONFIG = declare(FeatureLoadingType.RUNTIME, + HelpConfigManager::new); + public final FeatureEntry ANIMATIONS = declare(FeatureLoadingType.RUNTIME, + () -> new AnimationsManager(), NOT_IN_UNIT_TEST, NEED_ITEMS_ADDER); + public final FeatureEntry HALLOWEEN = declare(FeatureLoadingType.RUNTIME, + HalloweenManager::new); + public final FeatureEntry QUEST_PROGRESS = declare(FeatureLoadingType.RUNTIME, + QuestProgressSaveManager::new); + public final FeatureEntry MOTD = declare(FeatureLoadingType.RUNTIME, + MotdUtils::new); + public final FeatureEntry MASCOTS = declare(FeatureLoadingType.RUNTIME, + MascotsManager::new); + public final FeatureEntry PLAYER_SETTINGS = declare(FeatureLoadingType.RUNTIME, + PlayerSettingsManager::new); + public final FeatureEntry MAILBOX = declare(FeatureLoadingType.RUNTIME, + MailboxManager::new); + public final FeatureEntry DISCORD_LINK = declare(FeatureLoadingType.RUNTIME, + DiscordLinkManager::new); + public final FeatureEntry ELEVATOR = declare(FeatureLoadingType.RUNTIME, + () -> new ElevatorManager(), NEED_ITEMS_ADDER); + public final FeatureEntry PROFILE = declare(FeatureLoadingType.AFTER_IA, + ProfileManager::new); + public final FeatureEntry QUESTS = declare(FeatureLoadingType.AFTER_IA, + QuestsManager::new); + public final FeatureEntry CITY = declare(FeatureLoadingType.AFTER_IA, + CityManager::new); + public final FeatureEntry DYNAMIC_COOLDOWN = declare(FeatureLoadingType.AFTER_IA, + DynamicCooldownManager::new); + public final FeatureEntry CONTEST = declare(FeatureLoadingType.AFTER_IA, + ContestManager::new); + public final FeatureEntry WEEKLY_EVENTS = declare(FeatureLoadingType.AFTER_IA, + WeeklyEventsManager::new); + public final FeatureEntry DAILY_EVENTS = declare(FeatureLoadingType.AFTER_IA, + DailyEventsManager::new); + public final FeatureEntry CHAT_ANIMATIONS = declare(FeatureLoadingType.AFTER_IA, + ChatAnimationManager::new); + public final FeatureEntry EVENTS = declare(FeatureLoadingType.AFTER_IA, + EventsManager::new); + public final FeatureEntry DREAM = declare(FeatureLoadingType.AFTER_IA, + DreamManager::new); + public final FeatureEntry MULTIBLOCKS = declare(FeatureLoadingType.AFTER_IA, + () -> new MultiBlockManager(), NOT_IN_UNIT_TEST); + public final FeatureEntry MILESTONES = declare(FeatureLoadingType.AFTER_IA, + MilestonesManager::new); + public final FeatureEntry LEADERBOARD = declare(FeatureLoadingType.AFTER_IA, + () -> new LeaderboardManager(), NOT_IN_UNIT_TEST); + public final FeatureEntry MAIN_MENU = declare(FeatureLoadingType.AFTER_IA, + () -> new MainMenu(), NOT_IN_UNIT_TEST, NEED_PROTOCOL_LIB); + public final FeatureEntry HOLOGRAM_LOADER = declare(FeatureLoadingType.AFTER_IA, + () -> new HologramLoader(), NOT_IN_UNIT_TEST); + public final FeatureEntry BOSSBAR = declare(FeatureLoadingType.AFTER_IA, + BossbarManager::new); + public final FeatureEntry SHOP = declare(FeatureLoadingType.AFTER_IA, + ShopManager::new); + public final FeatureEntry HOME_ICON_CACHE = declare(FeatureLoadingType.AFTER_IA, + HomeIconCacheManager::new); + public final FeatureEntry DIMENSION_OPENER = declare(FeatureLoadingType.AFTER_IA, + DimensionOpenerManager::new); + + private FeatureEntry declare(FeatureLoadingType type, Supplier supplier, FeatureFlag... flags) { + FeatureEntry entry = new FeatureEntry<>(supplier, type, flags); + declarations.add(entry); + return entry; + } + + @Override + public void init() { + load(FeatureLoadingType.RUNTIME); + } + + @Override + public void postInit() { + load(FeatureLoadingType.AFTER_IA); + } + + @Override + public void stop() { + for (Feature feature : values()) { + feature.startSave(); + } + } + + public Optional register(FeatureEntry entry) { + if (!entry.shouldLoad()) return Optional.empty(); + + Feature feature = entry.create(); + feature.startInit(); + register(key(feature), feature); + return Optional.of(feature); + } + + public void load(FeatureLoadingType loadingType) { + for (FeatureEntry entry : declarations) { + if (entry.getLoadingType() != loadingType) continue; + register(entry); + } + } + + @Override + public String key(Feature registryObject) { + return registryObject.getClass().getSimpleName(); + } +} diff --git a/src/main/java/fr/openmc/core/bootstrap/features/annotations/Credit.java b/src/main/java/fr/openmc/core/registry/features/annotations/Credit.java similarity index 86% rename from src/main/java/fr/openmc/core/bootstrap/features/annotations/Credit.java rename to src/main/java/fr/openmc/core/registry/features/annotations/Credit.java index 002798d9a..11d2d7ce2 100644 --- a/src/main/java/fr/openmc/core/bootstrap/features/annotations/Credit.java +++ b/src/main/java/fr/openmc/core/registry/features/annotations/Credit.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.features.annotations; +package fr.openmc.core.registry.features.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/fr/openmc/core/registry/features/loading/FeatureEntry.java b/src/main/java/fr/openmc/core/registry/features/loading/FeatureEntry.java new file mode 100644 index 000000000..0844fd3ea --- /dev/null +++ b/src/main/java/fr/openmc/core/registry/features/loading/FeatureEntry.java @@ -0,0 +1,58 @@ +package fr.openmc.core.registry.features.loading; + +import com.google.common.base.Supplier; +import fr.openmc.core.OMCPlugin; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.registry.features.Feature; +import lombok.Getter; + +import java.util.Set; + +public class FeatureEntry { + private final Supplier supplier; + @Getter + private final FeatureLoadingType loadingType; + private final Set flags; + private F instance; + + public FeatureEntry(Supplier supplier, FeatureLoadingType loadingType, FeatureFlag... flags) { + this.supplier = supplier; + this.loadingType = loadingType; + this.flags = Set.of(flags); + } + + public static FeatureEntry of(FeatureLoadingType loadingType, Supplier supplier, FeatureFlag... flags) { + return new FeatureEntry<>(supplier, loadingType, flags); + } + + public F create() { + if (instance == null) { + instance = supplier.get(); + } + return instance; + } + + public boolean shouldLoad() { + for (FeatureFlag flag : flags) { + if (flag == null) { + OMCLogger.errorFormatted("Un FeatureFlag est nul dans une feature"); + return false; + } + + return !(switch (flag) { + case FeatureFlag.NotInUnitTest _ -> OMCPlugin.isUnitTestVersion(); + case FeatureFlag.NeedApi needApi -> !needApi.isEnabled().get(); + default -> throw new IllegalStateException("FeatureFlag non implémenter dans FeatureEntry#shouldLoad() : " + flag); + }); + } + return true; + } + + public F get() { + if (instance == null) + throw new IllegalStateException("La feature n'est pas encore crée"); + return instance; + } + + public boolean has(FeatureFlag flag) { return flags.contains(flag); } +} diff --git a/src/main/java/fr/openmc/core/registry/features/loading/FeatureFlag.java b/src/main/java/fr/openmc/core/registry/features/loading/FeatureFlag.java new file mode 100644 index 000000000..0e2a605fe --- /dev/null +++ b/src/main/java/fr/openmc/core/registry/features/loading/FeatureFlag.java @@ -0,0 +1,11 @@ +package fr.openmc.core.registry.features.loading; + +import java.util.function.Supplier; + +public interface FeatureFlag { + + record NotInUnitTest() implements FeatureFlag {} + + record NeedApi(Supplier isEnabled, String label) implements FeatureFlag {} + +} diff --git a/src/main/java/fr/openmc/core/bootstrap/features/FeatureLoadingType.java b/src/main/java/fr/openmc/core/registry/features/loading/FeatureLoadingType.java similarity index 55% rename from src/main/java/fr/openmc/core/bootstrap/features/FeatureLoadingType.java rename to src/main/java/fr/openmc/core/registry/features/loading/FeatureLoadingType.java index 8334d55a6..a77eb0b2a 100644 --- a/src/main/java/fr/openmc/core/bootstrap/features/FeatureLoadingType.java +++ b/src/main/java/fr/openmc/core/registry/features/loading/FeatureLoadingType.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.features; +package fr.openmc.core.registry.features.loading; public enum FeatureLoadingType { RUNTIME, diff --git a/src/main/java/fr/openmc/core/bootstrap/hooks/ApiHook.java b/src/main/java/fr/openmc/core/registry/hooks/ApiHook.java similarity index 94% rename from src/main/java/fr/openmc/core/bootstrap/hooks/ApiHook.java rename to src/main/java/fr/openmc/core/registry/hooks/ApiHook.java index 657896ab8..cba01a940 100644 --- a/src/main/java/fr/openmc/core/bootstrap/hooks/ApiHook.java +++ b/src/main/java/fr/openmc/core/registry/hooks/ApiHook.java @@ -1,4 +1,4 @@ -package fr.openmc.core.bootstrap.hooks; +package fr.openmc.core.registry.hooks; import fr.openmc.core.OMCPlugin; diff --git a/src/main/java/fr/openmc/core/bootstrap/hooks/Hooks.java b/src/main/java/fr/openmc/core/registry/hooks/Hooks.java similarity index 94% rename from src/main/java/fr/openmc/core/bootstrap/hooks/Hooks.java rename to src/main/java/fr/openmc/core/registry/hooks/Hooks.java index 9d99c88bf..d6a1a9ca0 100644 --- a/src/main/java/fr/openmc/core/bootstrap/hooks/Hooks.java +++ b/src/main/java/fr/openmc/core/registry/hooks/Hooks.java @@ -1,10 +1,10 @@ -package fr.openmc.core.bootstrap.hooks; +package fr.openmc.core.registry.hooks; import com.j256.ormlite.support.ConnectionSource; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.types.HasDatabase; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.interfaces.HasDatabase; +import fr.openmc.core.lifecycle.interfaces.NotLoadInUnitTest; import org.bukkit.plugin.PluginManager; import java.sql.SQLException; diff --git a/src/main/java/fr/openmc/core/registry/hooks/HooksRegistry.java b/src/main/java/fr/openmc/core/registry/hooks/HooksRegistry.java new file mode 100644 index 000000000..7fcbc35a3 --- /dev/null +++ b/src/main/java/fr/openmc/core/registry/hooks/HooksRegistry.java @@ -0,0 +1,40 @@ +package fr.openmc.core.registry.hooks; + +import fr.openmc.core.hooks.*; +import fr.openmc.core.hooks.github.GitHubHook; +import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.lifecycle.integration.DatabaseManager; +import fr.openmc.core.lifecycle.registries.KeyedRegistry; +import fr.openmc.core.lifecycle.registries.Registry; + +public class HooksRegistry extends Registry + implements KeyedRegistry { + + public final ProtocolLibHook PROTOCOL_LIB = register(new ProtocolLibHook()); + public final PapiHook PAPI = register(new PapiHook()); + public final LuckPermsHook LUCK_PERMS = register(new LuckPermsHook()); + public final WorldGuardHook WORLD_GUARD = register(new WorldGuardHook()); + public final ItemsAdderHook ITEMS_ADDER = register(new ItemsAdderHook()); + public final FancyNpcsHook FANCY_NPCS = register(new FancyNpcsHook()); + public final GitHubHook GITHUB = register(new GitHubHook()); + + @Override + public void init() { + for (Hooks hook : values()) { + DatabaseManager.startHookDB(hook); + hook.startInit(); + } + } + + @Override + public void stop() { + for (Hooks hook : values()) { + hook.startSave(); + } + } + + @Override + public String key(Hooks registryObject) { + return registryObject.getClass().getSimpleName(); + } +} diff --git a/src/main/java/fr/openmc/core/bootstrap/hooks/HttpsHook.java b/src/main/java/fr/openmc/core/registry/hooks/HttpsHook.java similarity index 74% rename from src/main/java/fr/openmc/core/bootstrap/hooks/HttpsHook.java rename to src/main/java/fr/openmc/core/registry/hooks/HttpsHook.java index 14a589e2b..784eff221 100644 --- a/src/main/java/fr/openmc/core/bootstrap/hooks/HttpsHook.java +++ b/src/main/java/fr/openmc/core/registry/hooks/HttpsHook.java @@ -1,9 +1,9 @@ -package fr.openmc.core.bootstrap.hooks; +package fr.openmc.core.registry.hooks; public abstract class HttpsHook extends Hooks { abstract public String getName(); - public static boolean isEnable() { + public boolean isEnable() { return Hooks.isEnabled(HttpsHook.class); } diff --git a/src/main/java/fr/openmc/core/registry/items/CustomItem.java b/src/main/java/fr/openmc/core/registry/items/CustomItem.java index 2f2604927..b11e9db61 100644 --- a/src/main/java/fr/openmc/core/registry/items/CustomItem.java +++ b/src/main/java/fr/openmc/core/registry/items/CustomItem.java @@ -3,7 +3,6 @@ import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomStack; import fr.openmc.core.OMCRegistry; -import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; import fr.openmc.core.utils.bukkit.ItemUtils; import lombok.Getter; import org.bukkit.inventory.ItemStack; @@ -76,7 +75,7 @@ public boolean equals(Object object) { */ public ItemStack getBest() { ItemStack item; - if (!ItemsAdderHook.isEnable() || getItemsAdder() == null) { + if (!OMCRegistry.HOOKS.ITEMS_ADDER.isEnable() || getItemsAdder() == null) { item = getVanilla(); } else { item = getItemsAdder(); diff --git a/src/main/java/fr/openmc/core/registry/items/CustomItemRegistry.java b/src/main/java/fr/openmc/core/registry/items/CustomItemRegistry.java index 597c02ab5..07c481475 100644 --- a/src/main/java/fr/openmc/core/registry/items/CustomItemRegistry.java +++ b/src/main/java/fr/openmc/core/registry/items/CustomItemRegistry.java @@ -3,10 +3,6 @@ import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomStack; import fr.openmc.core.CommandsManager; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; -import fr.openmc.core.bootstrap.registries.KeyedRegistry; -import fr.openmc.core.bootstrap.registries.Registry; import fr.openmc.core.features.bits.contents.items.KitchenBox; import fr.openmc.core.features.bits.contents.items.MedievalBox; import fr.openmc.core.features.bits.contents.items.ModernBox; @@ -18,6 +14,10 @@ import fr.openmc.core.features.itemsadder.elevator.ElevatorBlock; import fr.openmc.core.features.itemsadder.elevator.ElevatorColor; import fr.openmc.core.hooks.itemsadder.ItemsAdderHook; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.lifecycle.registries.KeyedRegistry; +import fr.openmc.core.lifecycle.registries.Registry; import fr.openmc.core.registry.items.contents.AywenCap; import fr.openmc.core.registry.items.contents.Hammer; import fr.openmc.core.registry.items.listeners.BlockBreakListener; diff --git a/src/main/java/fr/openmc/core/registry/lootboxes/CustomLootboxRegistry.java b/src/main/java/fr/openmc/core/registry/lootboxes/CustomLootboxRegistry.java index f41a75b20..59cd96935 100644 --- a/src/main/java/fr/openmc/core/registry/lootboxes/CustomLootboxRegistry.java +++ b/src/main/java/fr/openmc/core/registry/lootboxes/CustomLootboxRegistry.java @@ -1,9 +1,5 @@ package fr.openmc.core.registry.lootboxes; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; -import fr.openmc.core.bootstrap.registries.KeyedRegistry; -import fr.openmc.core.bootstrap.registries.Registry; import fr.openmc.core.features.bits.contents.lootboxes.KitchenLootbox; import fr.openmc.core.features.bits.contents.lootboxes.MedievalLootbox; import fr.openmc.core.features.bits.contents.lootboxes.ModernLootbox; @@ -12,6 +8,10 @@ import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.contents.lootboxes.FishingFurnitureLootbox; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.contents.lootboxes.LegendaryFishingTreasureLootbox; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.contents.lootboxes.RareFishingTreasureLootbox; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.lifecycle.registries.KeyedRegistry; +import fr.openmc.core.lifecycle.registries.Registry; import fr.openmc.core.registry.lootboxes.contents.MachineBallLootbox; import fr.openmc.core.registry.lootboxes.listener.DesactivateFireworkDamageListener; diff --git a/src/main/java/fr/openmc/core/registry/loottable/CustomLootTableRegistry.java b/src/main/java/fr/openmc/core/registry/loottable/CustomLootTableRegistry.java index 5cc2abe7c..5f6724809 100644 --- a/src/main/java/fr/openmc/core/registry/loottable/CustomLootTableRegistry.java +++ b/src/main/java/fr/openmc/core/registry/loottable/CustomLootTableRegistry.java @@ -1,7 +1,5 @@ package fr.openmc.core.registry.loottable; -import fr.openmc.core.bootstrap.registries.KeyedRegistry; -import fr.openmc.core.bootstrap.registries.Registry; import fr.openmc.core.features.bits.contents.loottables.KitchenLootTable; import fr.openmc.core.features.bits.contents.loottables.MedievalLootTable; import fr.openmc.core.features.bits.contents.loottables.ModernLootTable; @@ -21,6 +19,8 @@ import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.contents.loottable.lootbox.FishingFurnitureLootTable; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.contents.loottable.lootbox.LegendaryFishingTreasureLootTable; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.contents.loottable.lootbox.RareFishingTreasureLootTable; +import fr.openmc.core.lifecycle.registries.KeyedRegistry; +import fr.openmc.core.lifecycle.registries.Registry; import fr.openmc.core.registry.loottable.contents.MachineBallLootTable; public class CustomLootTableRegistry extends Registry implements KeyedRegistry { diff --git a/src/main/java/fr/openmc/core/registry/mobs/CustomMobRegistry.java b/src/main/java/fr/openmc/core/registry/mobs/CustomMobRegistry.java index e829f95ff..7194656c5 100644 --- a/src/main/java/fr/openmc/core/registry/mobs/CustomMobRegistry.java +++ b/src/main/java/fr/openmc/core/registry/mobs/CustomMobRegistry.java @@ -1,10 +1,6 @@ package fr.openmc.core.registry.mobs; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.types.HasListeners; -import fr.openmc.core.bootstrap.listeners.ListenerFactory; -import fr.openmc.core.bootstrap.registries.KeyedRegistry; -import fr.openmc.core.bootstrap.registries.Registry; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.contents.mobs.bat.ExplosiveVampireBat; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.contents.mobs.bat.LevitationVampireBat; import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.contents.mobs.bat.PoisonVampireBat; @@ -16,6 +12,10 @@ import fr.openmc.core.features.events.contents.dailyevents.contents.bloodynight.contents.mobs.vampire.VampireSlave; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.contents.mobs.*; import fr.openmc.core.features.events.contents.dailyevents.contents.miraculousfishing.contents.mobs.kraken.Kraken; +import fr.openmc.core.lifecycle.interfaces.HasListeners; +import fr.openmc.core.lifecycle.listeners.ListenerFactory; +import fr.openmc.core.lifecycle.registries.KeyedRegistry; +import fr.openmc.core.lifecycle.registries.Registry; import fr.openmc.core.registry.mobs.listeners.CustomMobBossbarListener; import fr.openmc.core.registry.mobs.listeners.CustomMobDeathListener; import fr.openmc.core.registry.mobs.listeners.CustomMobLoadListener; diff --git a/src/main/java/fr/openmc/core/utils/FilesUtils.java b/src/main/java/fr/openmc/core/utils/FilesUtils.java index 91196c17a..eca22ff90 100644 --- a/src/main/java/fr/openmc/core/utils/FilesUtils.java +++ b/src/main/java/fr/openmc/core/utils/FilesUtils.java @@ -1,7 +1,7 @@ package fr.openmc.core.utils; import fr.openmc.core.OMCBootstrap; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; import java.io.File; import java.io.IOException; diff --git a/src/main/java/fr/openmc/core/utils/nms/PlayerBiomeNMS.java b/src/main/java/fr/openmc/core/utils/nms/PlayerBiomeNMS.java index 46df5530f..77ab1ca11 100644 --- a/src/main/java/fr/openmc/core/utils/nms/PlayerBiomeNMS.java +++ b/src/main/java/fr/openmc/core/utils/nms/PlayerBiomeNMS.java @@ -1,6 +1,6 @@ package fr.openmc.core.utils.nms; -import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.OMCLogger; import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; diff --git a/src/main/java/fr/openmc/core/utils/nms/entity/EntityGlowNMS.java b/src/main/java/fr/openmc/core/utils/nms/entity/EntityGlowNMS.java index 67431b012..5ddd79ff7 100644 --- a/src/main/java/fr/openmc/core/utils/nms/entity/EntityGlowNMS.java +++ b/src/main/java/fr/openmc/core/utils/nms/entity/EntityGlowNMS.java @@ -1,6 +1,6 @@ package fr.openmc.core.utils.nms.entity; -import fr.openmc.core.bootstrap.features.types.NotLoadInUnitTest; +import fr.openmc.core.lifecycle.interfaces.NotLoadInUnitTest; import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket; import net.minecraft.world.scores.PlayerTeam; import net.minecraft.world.scores.Scoreboard; diff --git a/src/main/java/fr/openmc/core/utils/text/InputUtils.java b/src/main/java/fr/openmc/core/utils/text/InputUtils.java index 0ea922c62..d77339435 100644 --- a/src/main/java/fr/openmc/core/utils/text/InputUtils.java +++ b/src/main/java/fr/openmc/core/utils/text/InputUtils.java @@ -1,7 +1,7 @@ package fr.openmc.core.utils.text; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.features.city.City; -import fr.openmc.core.features.city.CityManager; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; @@ -82,7 +82,7 @@ public static boolean isInputCityName(String input) { return false; } - for (City city : CityManager.getCities()) { + for (City city : OMCRegistry.FEATURES.CITY.get().getCities()) { String testCityName = city.getName(); if (testCityName.equalsIgnoreCase(input)) { return false; diff --git a/src/main/java/fr/openmc/core/utils/text/MotdUtils.java b/src/main/java/fr/openmc/core/utils/text/MotdUtils.java index 91493718b..208954e52 100644 --- a/src/main/java/fr/openmc/core/utils/text/MotdUtils.java +++ b/src/main/java/fr/openmc/core/utils/text/MotdUtils.java @@ -1,7 +1,7 @@ package fr.openmc.core.utils.text; import fr.openmc.core.OMCPlugin; -import fr.openmc.core.bootstrap.features.Feature; +import fr.openmc.core.registry.features.Feature; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/main/java/fr/openmc/core/utils/text/messages/TranslationManager.java b/src/main/java/fr/openmc/core/utils/text/messages/TranslationManager.java index fbc199382..6a6ebb1e0 100644 --- a/src/main/java/fr/openmc/core/utils/text/messages/TranslationManager.java +++ b/src/main/java/fr/openmc/core/utils/text/messages/TranslationManager.java @@ -3,8 +3,8 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; -import fr.openmc.core.bootstrap.integration.OMCLogger; -import fr.openmc.core.bootstrap.integration.ResourcePacksGenerator; +import fr.openmc.core.lifecycle.integration.OMCLogger; +import fr.openmc.core.lifecycle.integration.ResourcePacksGenerator; import fr.openmc.core.utils.text.ComponentUtils; import fr.openmc.core.utils.types.MultiResourceBundle; import io.papermc.paper.plugin.bootstrap.BootstrapContext;