make npc property registry accessible during onLoad
This commit is contained in:
parent
d48de6382a
commit
06889a221e
2 changed files with 59 additions and 3 deletions
|
@ -0,0 +1,46 @@
|
|||
package lol.pyr.znpcsplus.api;
|
||||
|
||||
import lol.pyr.znpcsplus.api.entity.EntityPropertyRegistry;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* Provider for the registered entity property registry instance
|
||||
*/
|
||||
public class NpcPropertyRegistryProvider {
|
||||
private static EntityPropertyRegistry registry = null;
|
||||
|
||||
private NpcPropertyRegistryProvider() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Static method that returns the entity property registry instance of the plugin
|
||||
*
|
||||
* @return The instance of the entity property registry for the ZNPCsPlus plugin
|
||||
*/
|
||||
public static EntityPropertyRegistry get() {
|
||||
if (registry == null) throw new IllegalStateException(
|
||||
"ZNPCsPlus plugin isn't enabled yet!\n" +
|
||||
"Please add it to your plugin.yml as a depend or softdepend."
|
||||
);
|
||||
return registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method used to register the main instance of the plugin as the entity property registry provider
|
||||
* You probably shouldn't call this method under any circumstances
|
||||
*
|
||||
* @param api Instance of the ZNPCsPlus entity property registry
|
||||
*/
|
||||
public static void register(EntityPropertyRegistry api) {
|
||||
NpcPropertyRegistryProvider.registry = api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method used to unregister the plugin from the provider when the plugin shuts down
|
||||
* You probably shouldn't call this method under any circumstances
|
||||
*/
|
||||
public static void unregister() {
|
||||
Bukkit.getServicesManager().unregister(registry);
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ import lol.pyr.director.adventure.parse.primitive.FloatParser;
|
|||
import lol.pyr.director.adventure.parse.primitive.IntegerParser;
|
||||
import lol.pyr.director.common.message.Message;
|
||||
import lol.pyr.znpcsplus.api.NpcApiProvider;
|
||||
import lol.pyr.znpcsplus.api.NpcPropertyRegistryProvider;
|
||||
import lol.pyr.znpcsplus.api.interaction.InteractionType;
|
||||
import lol.pyr.znpcsplus.commands.*;
|
||||
import lol.pyr.znpcsplus.commands.action.*;
|
||||
|
@ -78,12 +79,23 @@ public class ZNpcsPlus {
|
|||
private final PacketEventsAPI<Plugin> packetEvents;
|
||||
private final ZNpcsPlusBootstrap bootstrap;
|
||||
|
||||
private final ConfigManager configManager;
|
||||
private final MojangSkinCache skinCache;
|
||||
private final EntityPropertyRegistryImpl propertyRegistry;
|
||||
|
||||
public ZNpcsPlus(ZNpcsPlusBootstrap bootstrap) {
|
||||
this.bootstrap = bootstrap;
|
||||
packetEvents = SpigotPacketEventsBuilder.build(bootstrap);
|
||||
PacketEvents.setAPI(packetEvents);
|
||||
packetEvents.getSettings().checkForUpdates(false);
|
||||
packetEvents.load();
|
||||
|
||||
configManager = new ConfigManager(getDataFolder());
|
||||
skinCache = new MojangSkinCache(configManager);
|
||||
propertyRegistry = new EntityPropertyRegistryImpl(skinCache, configManager);
|
||||
|
||||
NpcPropertyRegistryProvider.register(propertyRegistry);
|
||||
shutdownTasks.add(NpcPropertyRegistryProvider::unregister);
|
||||
}
|
||||
|
||||
private void log(String str) {
|
||||
|
@ -113,9 +125,7 @@ public class ZNpcsPlus {
|
|||
TaskScheduler scheduler = FoliaUtil.isFolia() ? new FoliaScheduler(bootstrap) : new SpigotScheduler(bootstrap);
|
||||
shutdownTasks.add(scheduler::cancelAll);
|
||||
|
||||
ConfigManager configManager = new ConfigManager(getDataFolder());
|
||||
MojangSkinCache skinCache = new MojangSkinCache(configManager);
|
||||
EntityPropertyRegistryImpl propertyRegistry = new EntityPropertyRegistryImpl(skinCache, configManager);
|
||||
|
||||
PacketFactory packetFactory = setupPacketFactory(scheduler, propertyRegistry, configManager);
|
||||
propertyRegistry.registerTypes(bootstrap, packetFactory, textSerializer);
|
||||
|
||||
|
|
Loading…
Reference in a new issue