use of net.minecraftforge.server.permission.handler.IPermissionHandlerFactory in project MinecraftForge by MinecraftForge.
the class PermissionAPI method initializePermissionAPI.
/**
* <p>Helper method for internal use only!</p>
* <p>Initializes the active permission handler based on the users config.</p>
*/
public static void initializePermissionAPI() {
Class callerClass = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass();
if (callerClass != ServerLifecycleHooks.class) {
LOGGER.warn("{} tried to initialize the PermissionAPI, this call will be ignored.", callerClass.getName());
return;
}
PermissionAPI.activeHandler = null;
PermissionGatherEvent.Handler handlerEvent = new PermissionGatherEvent.Handler();
MinecraftForge.EVENT_BUS.post(handlerEvent);
Map<ResourceLocation, IPermissionHandlerFactory> availableHandlers = handlerEvent.getAvailablePermissionHandlerFactories();
try {
ResourceLocation selectedPermissionHandler = new ResourceLocation(ForgeConfig.SERVER.permissionHandler.get());
if (!availableHandlers.containsKey(selectedPermissionHandler)) {
LOGGER.error("Unable to find configured permission handler {}, will use {}", selectedPermissionHandler, DefaultPermissionHandler.IDENTIFIER);
selectedPermissionHandler = DefaultPermissionHandler.IDENTIFIER;
}
IPermissionHandlerFactory factory = availableHandlers.get(selectedPermissionHandler);
PermissionGatherEvent.Nodes nodesEvent = new PermissionGatherEvent.Nodes();
MinecraftForge.EVENT_BUS.post(nodesEvent);
PermissionAPI.activeHandler = factory.create(nodesEvent.getNodes());
if (!selectedPermissionHandler.equals(activeHandler.getIdentifier()))
LOGGER.warn("Identifier for permission handler {} does not match registered one {}", activeHandler.getIdentifier(), selectedPermissionHandler);
LOGGER.info("Successfully initialized permission handler {}", PermissionAPI.activeHandler.getIdentifier());
} catch (ResourceLocationException e) {
LOGGER.error("Error parsing config value 'permissionHandler'", e);
}
}
Aggregations