forked from ServerOpenMC/PluginV2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOMCRegistry.java
More file actions
89 lines (76 loc) · 3.74 KB
/
Copy pathOMCRegistry.java
File metadata and controls
89 lines (76 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package fr.openmc.core;
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.registry.ambient.CustomAmbientRegistry;
import fr.openmc.core.registry.enchantments.CustomEnchantmentRegistry;
import fr.openmc.core.registry.items.CustomItemRegistry;
import fr.openmc.core.registry.lootboxes.CustomLootboxRegistry;
import fr.openmc.core.registry.loottable.CustomLootTableRegistry;
import fr.openmc.core.registry.mobs.CustomMobRegistry;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings("UnstableApiUsage")
public final class OMCRegistry {
public static CustomItemRegistry CUSTOM_ITEMS;
public static CustomMobRegistry CUSTOM_MOBS;
public static CustomEnchantmentRegistry CUSTOM_ENCHANTS;
public static CustomLootTableRegistry CUSTOM_LOOT_TABLES;
public static CustomAmbientRegistry CUSTOM_AMBIENTS;
public static CustomLootboxRegistry CUSTOM_LOOTBOXES;
private static final List<RegistryContext> ALL = List.of(
new RegistryContext(
() -> CUSTOM_ITEMS = new CustomItemRegistry(),
RegistryLoadingType.AFTER_IA),
new RegistryContext(() -> CUSTOM_MOBS = new CustomMobRegistry(),
RegistryLoadingType.AFTER_IA),
new RegistryContext(
() -> CUSTOM_ENCHANTS = new CustomEnchantmentRegistry(),
RegistryLoadingType.BOOTSTRAP, RegistryLoadingType.AFTER_IA),
new RegistryContext(
() -> CUSTOM_LOOT_TABLES = new CustomLootTableRegistry(),
RegistryLoadingType.AFTER_IA),
new RegistryContext(
() -> CUSTOM_AMBIENTS = new CustomAmbientRegistry(),
RegistryLoadingType.BOOTSTRAP),
new RegistryContext(
() -> CUSTOM_LOOTBOXES = new CustomLootboxRegistry(),
RegistryLoadingType.AFTER_IA)
);
private OMCRegistry() {}
public static void bootstrapAll(BootstrapContext context) {
for (RegistryContext ctx : OMCRegistry.ALL) {
if (Arrays.stream(ctx.loadingTypes())
.noneMatch(t -> t == RegistryLoadingType.BOOTSTRAP)) continue;
LifecycleRegistry r = ctx.registry().get();
try {
r.bootstrap(context);
} catch (IOException e) {
OMCLogger.errorFormatted("Erreur lors du chargement du registre '{}' lors du bootstrap", r.getClass().getSimpleName());
OMCLogger.error(e.getMessage());
}
OMCLogger.successFormatted("Registre {} chargé pendant le bootstrap", r.getClass().getSimpleName());
}
}
public static void initAll() {
for (RegistryContext ctx : OMCRegistry.ALL) {
if (Arrays.stream(ctx.loadingTypes())
.noneMatch(t -> t == RegistryLoadingType.RUNTIME)) continue;
LifecycleRegistry r = ctx.registry().get();
r.init();
OMCLogger.successFormatted("Registre {} chargé pendant le runtime", r.getClass().getSimpleName());
}
}
public static void postInitAll() {
for (RegistryContext ctx : OMCRegistry.ALL) {
if (Arrays.stream(ctx.loadingTypes())
.noneMatch(t -> t == RegistryLoadingType.AFTER_IA)) continue;
LifecycleRegistry r = ctx.registry().get();
r.postInit();
OMCLogger.successFormatted("Registre {} chargé après ItemsAdder", r.getClass().getSimpleName());
}
}
}