Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/main/java/fr/openmc/api/cooldown/DynamicCooldownManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fr/openmc/api/menulib/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/openmc/api/menulib/MenuLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/openmc/core/ListenersManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/fr/openmc/core/OMCBootstrap.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
176 changes: 9 additions & 167 deletions src/main/java/fr/openmc/core/OMCPlugin.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand All @@ -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<FeatureFactory> 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<Feature> loadedFeature = new ArrayList<>();

// ** Registry of OMC Plugin Hooks
public final List<Hooks> 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);
Expand All @@ -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");
Expand All @@ -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();
}
}
Expand All @@ -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);
}
}
Expand All @@ -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();

Expand Down Expand Up @@ -282,18 +136,6 @@ public static void registerEvents(Collection<ListenerFactory> 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.
*
Expand Down
Loading