Skip to content
Open
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
6 changes: 3 additions & 3 deletions src/main/java/fr/openmc/api/menulib/template/ConfirmMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import fr.openmc.api.menulib.Menu;
import fr.openmc.api.menulib.utils.InventorySize;
import fr.openmc.api.menulib.utils.ItemBuilder;
import fr.openmc.core.registry.items.CustomItemRegistry;
import fr.openmc.core.OMCRegistry;
import fr.openmc.core.utils.text.messages.MessageType;
import fr.openmc.core.utils.text.messages.MessagesManager;
import fr.openmc.core.utils.text.messages.Prefix;
Expand Down Expand Up @@ -110,8 +110,8 @@ public void onClose(InventoryCloseEvent event) {

loreDeny.add(Component.text("§e§lCLIQUEZ ICI POUR REFUSER"));

ItemStack refuseBtn = CustomItemRegistry.getByName("omc_menus:refuse_btn").getBest();
ItemStack acceptBtn = CustomItemRegistry.getByName("omc_menus:accept_btn").getBest();
ItemStack refuseBtn = OMCRegistry.CUSTOM_ITEMS.get("omc_menus:refuse_btn").getBest();
ItemStack acceptBtn = OMCRegistry.CUSTOM_ITEMS.get("omc_menus:accept_btn").getBest();

inventory.put(posDenyBtn, new ItemBuilder(this, refuseBtn, itemMeta -> {
itemMeta.displayName(Component.text("§cRefuser"));
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/fr/openmc/core/OMCBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import fr.openmc.core.bootstrap.integration.OMCLogger;
import fr.openmc.core.hooks.itemsadder.ItemsAdderHook;
import fr.openmc.core.registry.enchantments.CustomEnchantmentRegistry;
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.plugin.lifecycle.event.types.LifecycleEvents;
import io.papermc.paper.registry.event.RegistryEvents;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

Expand All @@ -24,7 +22,6 @@
*/
@SuppressWarnings("UnstableApiUsage")
public class OMCBootstrap implements PluginBootstrap {

/**
* Configure les handlers de cycle de vie necessaires avant l'activation du plugin.
*
Expand All @@ -51,11 +48,12 @@ public void bootstrap(@NotNull BootstrapContext context) {
// ** LOAD ITEMS ADDER NAMESPACES **
ItemsAdderHook.copyContentsToItemsAdder(context, "contents");

// ** ENCHANTMENT IMPL **
CustomEnchantmentRegistry.init();
context.getLifecycleManager().registerEventHandler(RegistryEvents.ENCHANTMENT.compose()
.newHandler(CustomEnchantmentRegistry::loadEnchantmentInBootstrap)
);
// ** REGISTRY MANAGER **
OMCRegistry.bootstrapAll(context);

// context.getLifecycleManager().registerEventHandler(RegistryEvents.ENCHANTMENT.compose()
// .newHandler(CustomEnchantmentRegistry::loadEnchantmentInBootstrap)
// );

// ** LOAD TRANSLATION **
// this creates resource pack who is needed for item adder
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/fr/openmc/core/OMCPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
import fr.openmc.core.features.updates.UpdateManager;
import fr.openmc.core.hooks.*;
import fr.openmc.core.hooks.itemsadder.ItemsAdderHook;
import fr.openmc.core.registry.enchantments.CustomEnchantmentRegistry;
import fr.openmc.core.registry.items.CustomItemRegistry;
import fr.openmc.core.registry.loottable.CustomLootTableRegistry;
import fr.openmc.core.utils.bukkit.ParticleUtils;
import fr.openmc.core.utils.text.MotdUtils;
import io.papermc.paper.datapack.Datapack;
Expand Down Expand Up @@ -175,6 +172,9 @@ public void onEnable() {
CommandsManager.init();
ListenersManager.init();

/* REGISTRIES */
OMCRegistry.initAll();

/* FEATURES */
REGISTRY_FEATURE.stream()
.filter(f -> !(f instanceof LoadAfterItemsAdder))
Expand All @@ -190,15 +190,13 @@ public void onEnable() {
* Charge les registres et features qui doivent être lancé apres ItemsAdder
*/
public void loadAfterItemsAdder() {
// ** LOAD ITEMS ADDER CONTENTS **
/* LOAD ITEMS ADDER CONTENTS */
ItemsAdderHook.loadContents();

// ** REGISTRIES **
CustomItemRegistry.init();
CustomEnchantmentRegistry.postInit();
CustomLootTableRegistry.init();
/* REGISTRIES */
OMCRegistry.postInitAll();

// ** FEATURES **
/* FEATURES */
REGISTRY_FEATURE.stream()
.filter(f -> f instanceof LoadAfterItemsAdder)
.forEachOrdered(Feature::startInit);
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/fr/openmc/core/OMCRegistry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package fr.openmc.core;

import fr.openmc.core.bootstrap.integration.OMCLogger;
import fr.openmc.core.bootstrap.registries.LifecycleRegistry;
import fr.openmc.core.registry.enchantments.CustomEnchantmentRegistry;
import fr.openmc.core.registry.items.CustomItemRegistry;
import fr.openmc.core.registry.loottable.CustomLootTableRegistry;
import fr.openmc.core.registry.mobs.CustomMobRegistry;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;

import java.util.List;

@SuppressWarnings("UnstableApiUsage")
public final class OMCRegistry {

public static final CustomItemRegistry CUSTOM_ITEMS = new CustomItemRegistry();
public static final CustomMobRegistry CUSTOM_MOBS = new CustomMobRegistry();
public static final CustomEnchantmentRegistry CUSTOM_ENCHANTS = new CustomEnchantmentRegistry();
public static final CustomLootTableRegistry CUSTOM_LOOT_TABLES = new CustomLootTableRegistry();

private static final List<LifecycleRegistry> ALL = List.of(
CUSTOM_ITEMS,
CUSTOM_MOBS,
CUSTOM_ENCHANTS,
CUSTOM_LOOT_TABLES
);

private OMCRegistry() {}

public static void bootstrapAll(BootstrapContext context) {
for (LifecycleRegistry r : OMCRegistry.ALL) {
if (isOverridden(r, "bootstrap", BootstrapContext.class)) {
r.bootstrap(context);
OMCLogger.successFormatted("Registre {} chargée pendant le bootstrap", r.getClass().getSimpleName());
}
}
}

public static void initAll() {
for (LifecycleRegistry r : OMCRegistry.ALL) {
if (isOverridden(r, "init")) {
r.init();
OMCLogger.successFormatted("Registre {} chargée pendant le runtime", r.getClass().getSimpleName());
}
}
}

public static void postInitAll() {
for (LifecycleRegistry r : OMCRegistry.ALL) {
if (isOverridden(r, "postInit")) {
r.postInit();
OMCLogger.successFormatted("Registre {} chargée après ItemsAdder", r.getClass().getSimpleName());
}
}
}

private static boolean isOverridden(LifecycleRegistry r, String methodName, Class<?>... args) {
try {
return !r.getClass()
.getMethod(methodName, args)
.getDeclaringClass()
.equals(LifecycleRegistry.class);
} catch (NoSuchMethodException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fr.openmc.core.bootstrap.registries;

import io.papermc.paper.plugin.bootstrap.BootstrapContext;

@SuppressWarnings("UnstableApiUsage")
public interface LifecycleRegistry {
default void bootstrap(BootstrapContext context) {}

default void init() {}

default void postInit() {}
}
26 changes: 26 additions & 0 deletions src/main/java/fr/openmc/core/bootstrap/registries/Registry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package fr.openmc.core.bootstrap.registries;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class Registry<K, V> implements LifecycleRegistry {

protected final Map<K, V> entries = new HashMap<>();

public void register(K key, V value) {
entries.put(key, value);
}

public V get(K key) {
return entries.get(key);
}

public Collection<K> keys() {
return entries.keySet();
}

public Collection<V> values() {
return entries.values();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.openmc.core.commands.autocomplete;

import fr.openmc.core.registry.items.CustomItemRegistry;
import fr.openmc.core.OMCRegistry;
import fr.openmc.core.registry.items.CustomItem;
import org.jetbrains.annotations.NotNull;
import revxrsal.commands.autocomplete.SuggestionProvider;
import revxrsal.commands.bukkit.actor.BukkitCommandActor;
Expand All @@ -12,10 +13,11 @@ public class CustomItemAutoComplete implements SuggestionProvider<BukkitCommandA

@Override
public @NotNull List<String> getSuggestions(@NotNull ExecutionContext<BukkitCommandActor> context) {
return CustomItemRegistry.getNames()
return OMCRegistry.CUSTOM_ITEMS.values()
.stream()
.filter(name -> !name.startsWith("omc_dream:"))
.map(name -> name.replace("omc_dream:", ""))
.map(CustomItem::getId)
.filter(id -> !id.startsWith("omc_dream:"))
.map(id -> id.split(":")[1])
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package fr.openmc.core.commands.debug;

import fr.openmc.core.OMCRegistry;
import fr.openmc.core.commands.autocomplete.CustomItemAutoComplete;
import fr.openmc.core.registry.items.CustomItem;
import fr.openmc.core.registry.items.CustomItemRegistry;
import fr.openmc.core.utils.text.messages.MessageType;
import fr.openmc.core.utils.text.messages.MessagesManager;
import fr.openmc.core.utils.text.messages.Prefix;
Expand All @@ -25,7 +25,7 @@ public void get(
@SuggestWith(CustomItemAutoComplete.class) String name,
@Optional Integer amount
) {
CustomItem item = CustomItemRegistry.getByName(name);
CustomItem item = OMCRegistry.CUSTOM_ITEMS.get(name);

if (item == null) {
MessagesManager.sendMessage(player, Component.text("Cet item n'existe pas"), Prefix.STAFF, MessageType.ERROR, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ public class CompanyBankTransactionsMenu extends PaginatedMenu {
@Override
public Map<Integer, ItemBuilder> getButtons() {
Map<Integer, ItemBuilder> buttons = new HashMap<>();
buttons.put(49, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_cancel").getBest(), itemMeta -> itemMeta.setDisplayName("§7Fermer"))
buttons.put(49, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_cancel").getBest(), itemMeta -> itemMeta.setDisplayName("§7Fermer"))
.setCloseButton());
ItemBuilder nextPageButton = new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_next_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§aPage suivante"));
ItemBuilder nextPageButton = new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_next_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§aPage suivante"));
if ((getPage() == 0 && isLastPage()) || company.getShops().isEmpty()) {
buttons.put(48, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cRetour"))
buttons.put(48, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cRetour"))
.setOnClick(inventoryClickEvent -> new CompanyMenu(getOwner(), company, false).open()));
buttons.put(50, nextPageButton);
} else {
buttons.put(48, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cPage précédente"))
buttons.put(48, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cPage précédente"))
.setPreviousPageButton());
buttons.put(50, nextPageButton.setNextPageButton());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ public class CompanyMenu extends PaginatedMenu {
public Map<Integer, ItemBuilder> getButtons() {
Map<Integer, ItemBuilder> buttons = new HashMap<>();

ItemBuilder closeButton = new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_cancel").getBest(), itemMeta -> itemMeta.setDisplayName("§7Fermer")).setCloseButton();
ItemBuilder backButton = new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§7Retour"), true);
ItemBuilder closeButton = new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_cancel").getBest(), itemMeta -> itemMeta.setDisplayName("§7Fermer")).setCloseButton();
ItemBuilder backButton = new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§7Retour"), true);

buttons.put(49, isBackButton ? backButton : closeButton);

buttons.put(48, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cPage précédente"))
buttons.put(48, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cPage précédente"))
.setPreviousPageButton());

buttons.put(50, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_next_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§aPage suivante"))
buttons.put(50, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_next_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§aPage suivante"))
.setNextPageButton());

ItemBuilder ownerItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public class CompanySearchMenu extends PaginatedMenu {
@Override
public Map<Integer, ItemBuilder> getButtons() {
Map<Integer, ItemBuilder> map = new HashMap<>();
map.put(49, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_cancel").getBest(), itemMeta -> itemMeta.setDisplayName("§7Fermer"))
map.put(49, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_cancel").getBest(), itemMeta -> itemMeta.setDisplayName("§7Fermer"))
.setCloseButton());
map.put(48, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cPage précédente"))
map.put(48, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cPage précédente"))
.setPreviousPageButton());
map.put(50, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_next_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§aPage suivante"))
map.put(50, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_next_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§aPage suivante"))
.setNextPageButton());
if (CompanyManager.isInCompany(getOwner().getUniqueId())) {
map.put(4, new ItemBuilder(this, CompanyManager.getCompany(getOwner().getUniqueId()).getHead(), itemMeta -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ public class ShopManageMenu extends PaginatedMenu {
@Override
public Map<Integer, ItemBuilder> getButtons() {
Map<Integer, ItemBuilder> buttons = new HashMap<>();
buttons.put(49, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_cancel").getBest(), itemMeta -> itemMeta.setDisplayName("§7Fermer"))
buttons.put(49, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_cancel").getBest(), itemMeta -> itemMeta.setDisplayName("§7Fermer"))
.setCloseButton());
ItemBuilder nextPageButton = new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_next_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§aPage suivante"));
ItemBuilder nextPageButton = new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_next_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§aPage suivante"));
if ((getPage() == 0 && isLastPage()) || company.getShops().isEmpty()) {
buttons.put(48, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cRetour"))
buttons.put(48, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cRetour"))
.setOnClick(inventoryClickEvent -> new CompanyMenu(getOwner(), company, false).open()));
buttons.put(50, nextPageButton);
} else {
buttons.put(48, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cPage précédente"))
buttons.put(48, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cPage précédente"))
.setPreviousPageButton());
buttons.put(50, nextPageButton.setNextPageButton());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ public class ShopCatalogueMenu extends PaginatedMenu {
@Override
public Map<Integer, ItemBuilder> getButtons() {
Map<Integer, ItemBuilder> buttons = new HashMap<>();
buttons.put(49, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_cancel").getBest(), itemMeta -> itemMeta.setDisplayName("§7Fermer"))
buttons.put(49, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_cancel").getBest(), itemMeta -> itemMeta.setDisplayName("§7Fermer"))
.setCloseButton());
ItemBuilder nextPageButton = new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_next_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§aPage suivante"));
ItemBuilder nextPageButton = new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_next_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§aPage suivante"));
if ((getPage() == 0 && isLastPage()) || shop.getItems().isEmpty()) {
buttons.put(48, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cRetour"))
buttons.put(48, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cRetour"))
.setOnClick(inventoryClickEvent -> new ShopMenu(getOwner(), shop, itemIndex).open()));
buttons.put(50, nextPageButton);
} else {
buttons.put(48, new ItemBuilder(this, CustomItemRegistry.getByName("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cPage précédente"))
buttons.put(48, new ItemBuilder(this, OMCRegistry.CUSTOM_ITEMS.get("_iainternal:icon_back_orange").getBest(), itemMeta -> itemMeta.setDisplayName("§cPage précédente"))
.setPreviousPageButton());
buttons.put(50, nextPageButton.setNextPageButton());
}
Expand Down
Loading
Loading