Search in sources :

Example 1 with ResourceLocationException

use of net.minecraft.ResourceLocationException in project SpongeCommon by SpongePowered.

the class SpongeResourceKeyBuilder method build.

@Override
public ResourceKey build() throws IllegalStateException {
    checkState(this.namespace != null, "Namespace cannot be empty");
    checkState(this.value != null, "Value cannot be empty");
    try {
        final ResourceLocation resourceLocation = new ResourceLocation(this.namespace, this.value);
        return (ResourceKey) (Object) resourceLocation;
    } catch (ResourceLocationException e) {
        throw new IllegalStateException(e);
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) ResourceLocationException(net.minecraft.ResourceLocationException) ResourceKey(org.spongepowered.api.ResourceKey)

Example 2 with ResourceLocationException

use of net.minecraft.ResourceLocationException 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);
    }
}
Also used : PermissionGatherEvent(net.minecraftforge.server.permission.events.PermissionGatherEvent) IPermissionHandlerFactory(net.minecraftforge.server.permission.handler.IPermissionHandlerFactory) ResourceLocation(net.minecraft.resources.ResourceLocation) ResourceLocationException(net.minecraft.ResourceLocationException) IPermissionHandler(net.minecraftforge.server.permission.handler.IPermissionHandler) DefaultPermissionHandler(net.minecraftforge.server.permission.handler.DefaultPermissionHandler)

Aggregations

ResourceLocationException (net.minecraft.ResourceLocationException)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 PermissionGatherEvent (net.minecraftforge.server.permission.events.PermissionGatherEvent)1 DefaultPermissionHandler (net.minecraftforge.server.permission.handler.DefaultPermissionHandler)1 IPermissionHandler (net.minecraftforge.server.permission.handler.IPermissionHandler)1 IPermissionHandlerFactory (net.minecraftforge.server.permission.handler.IPermissionHandlerFactory)1 ResourceKey (org.spongepowered.api.ResourceKey)1