Search in sources :

Example 1 with CommandPermissionHandler

use of io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler in project Nucleus by NucleusPowered.

the class NucleusPlugin method onPostInit.

@Listener(order = Order.FIRST)
public void onPostInit(GamePostInitializationEvent event) {
    if (isErrored != null) {
        return;
    }
    logger.info(messageProvider.getMessageWithFormat("startup.postinit", PluginInfo.NAME));
    // Load up the general data files now, mods should have registered items by now.
    try {
        // Reloadable so that we can update the serialisers.
        moduleContainer.reloadSystemConfig();
    } catch (Exception e) {
        isErrored = e;
        disable();
        e.printStackTrace();
        return;
    }
    try {
        Sponge.getEventManager().post(new BaseModuleEvent.AboutToConstructEvent(this));
        logger.info(messageProvider.getMessageWithFormat("startup.moduleloading", PluginInfo.NAME));
        moduleContainer.loadModules(true);
        CoreConfig coreConfig = moduleContainer.getConfigAdapterForModule(CoreModule.ID, CoreConfigAdapter.class).getNodeOrDefault();
        if (coreConfig.isErrorOnStartup()) {
            throw new IllegalStateException("In main.conf, core.simulate-error-on-startup is set to TRUE. Remove this config entry to allow Nucleus to start. Simulating error and disabling Nucleus.");
        }
        this.isDebugMode = coreConfig.isDebugmode();
        this.isTraceUserCreations = coreConfig.traceUserCreations();
        this.savesandloads = coreConfig.isPrintSaveLoad();
    } catch (Throwable construction) {
        logger.info(messageProvider.getMessageWithFormat("startup.modulenotloaded", PluginInfo.NAME));
        construction.printStackTrace();
        disable();
        isErrored = construction;
        return;
    }
    // Register a reloadable.
    CommandPermissionHandler.onReload();
    registerReloadable(CommandPermissionHandler::onReload);
    getDocGenCache().ifPresent(x -> x.addTokenDocs(nucleusChatService.getNucleusTokenParser().getTokenNames()));
    logger.info(messageProvider.getMessageWithFormat("startup.moduleloaded", PluginInfo.NAME));
    registerPermissions();
    Sponge.getEventManager().post(new BaseModuleEvent.Complete(this));
    logger.info(messageProvider.getMessageWithFormat("startup.completeinit", PluginInfo.NAME));
}
Also used : CoreConfig(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig) BaseModuleEvent(io.github.nucleuspowered.nucleus.internal.qsml.event.BaseModuleEvent) CoreConfigAdapter(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter) CommandPermissionHandler(io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler) ConfigException(com.typesafe.config.ConfigException) QuickStartModuleLoaderException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleLoaderException) IOException(java.io.IOException) QuickStartModuleDiscoveryException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) NoModuleException(uk.co.drnaylor.quickstart.exceptions.NoModuleException) IncorrectAdapterTypeException(uk.co.drnaylor.quickstart.exceptions.IncorrectAdapterTypeException) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) Listener(org.spongepowered.api.event.Listener)

Example 2 with CommandPermissionHandler

use of io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler in project Nucleus by NucleusPowered.

the class StandardModule method createSeenModule.

protected final void createSeenModule(@Nullable Class<? extends AbstractCommand> permissionClass, BiFunction<CommandSource, User, Collection<Text>> function) {
    // Register seen information.
    CommandPermissionHandler permissionHandler = plugin.getPermissionRegistry().getPermissionsForNucleusCommand(permissionClass);
    createSeenModule(permissionHandler == null ? null : permissionHandler.getBase(), function);
}
Also used : CommandPermissionHandler(io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler)

Example 3 with CommandPermissionHandler

use of io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler in project Nucleus by NucleusPowered.

the class NicknameService method register.

public void register() {
    if (this.registered) {
        return;
    }
    MessageProvider mp = Nucleus.getNucleus().getMessageProvider();
    CommandPermissionHandler permissions = Nucleus.getNucleus().getPermissionRegistry().getPermissionsForNucleusCommand(NicknameCommand.class);
    String colPerm = permissions.getPermissionWithSuffix("colour.");
    String colPerm2 = permissions.getPermissionWithSuffix("color.");
    NameUtil.getColours().forEach((key, value) -> replacements.put(new String[] { colPerm + value.getName(), colPerm2 + value.getName() }, Tuple.of(Pattern.compile("[&]+" + key.toString().toLowerCase(), Pattern.CASE_INSENSITIVE).matcher(""), mp.getTextMessageWithFormat("command.nick.colour.nopermswith", value.getName()))));
    String stylePerm = permissions.getPermissionWithSuffix("style.");
    NameUtil.getStyleKeys().entrySet().stream().filter(x -> x.getKey() != 'k').forEach((k) -> replacements.put(new String[] { stylePerm + k.getValue().toLowerCase() }, Tuple.of(Pattern.compile("[&]+" + k.getKey().toString().toLowerCase(), Pattern.CASE_INSENSITIVE).matcher(""), mp.getTextMessageWithFormat("command.nick.style.nopermswith", k.getValue().toLowerCase()))));
    this.replacements.put(new String[] { permissions.getPermissionWithSuffix("magic") }, Tuple.of(Pattern.compile("[&]+k", Pattern.CASE_INSENSITIVE).matcher(""), mp.getTextMessageWithFormat("command.nick.style.nopermswith", "magic")));
    this.registered = true;
}
Also used : Arrays(java.util.Arrays) NameUtil(io.github.nucleuspowered.nucleus.NameUtil) NucleusNicknameService(io.github.nucleuspowered.nucleus.api.service.NucleusNicknameService) NicknameConfigAdapter(io.github.nucleuspowered.nucleus.modules.nickname.config.NicknameConfigAdapter) NicknameException(io.github.nucleuspowered.nucleus.api.exceptions.NicknameException) UserStorageService(org.spongepowered.api.service.user.UserStorageService) Matcher(java.util.regex.Matcher) Text(org.spongepowered.api.text.Text) Map(java.util.Map) NicknameCommand(io.github.nucleuspowered.nucleus.modules.nickname.commands.NicknameCommand) NicknameModule(io.github.nucleuspowered.nucleus.modules.nickname.NicknameModule) Subject(org.spongepowered.api.service.permission.Subject) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) NicknameUserDataModule(io.github.nucleuspowered.nucleus.modules.nickname.datamodules.NicknameUserDataModule) CommandPermissionHandler(io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) User(org.spongepowered.api.entity.living.player.User) NicknameConfig(io.github.nucleuspowered.nucleus.modules.nickname.config.NicknameConfig) CommandSource(org.spongepowered.api.command.CommandSource) CauseStackHelper(io.github.nucleuspowered.nucleus.util.CauseStackHelper) Sponge(org.spongepowered.api.Sponge) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) Tuple(org.spongepowered.api.util.Tuple) Maps(com.google.common.collect.Maps) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) TextSerializers(org.spongepowered.api.text.serializer.TextSerializers) Cause(org.spongepowered.api.event.cause.Cause) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) ChangeNicknameEvent(io.github.nucleuspowered.nucleus.modules.nickname.events.ChangeNicknameEvent) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) CommandPermissionHandler(io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler)

Aggregations

CommandPermissionHandler (io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler)3 Maps (com.google.common.collect.Maps)1 ConfigException (com.typesafe.config.ConfigException)1 NameUtil (io.github.nucleuspowered.nucleus.NameUtil)1 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)1 NicknameException (io.github.nucleuspowered.nucleus.api.exceptions.NicknameException)1 NucleusNicknameService (io.github.nucleuspowered.nucleus.api.service.NucleusNicknameService)1 ModularUserService (io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService)1 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)1 MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)1 ServiceChangeListener (io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener)1 BaseModuleEvent (io.github.nucleuspowered.nucleus.internal.qsml.event.BaseModuleEvent)1 CoreConfig (io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig)1 CoreConfigAdapter (io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter)1 NicknameModule (io.github.nucleuspowered.nucleus.modules.nickname.NicknameModule)1 NicknameCommand (io.github.nucleuspowered.nucleus.modules.nickname.commands.NicknameCommand)1 NicknameConfig (io.github.nucleuspowered.nucleus.modules.nickname.config.NicknameConfig)1 NicknameConfigAdapter (io.github.nucleuspowered.nucleus.modules.nickname.config.NicknameConfigAdapter)1 NicknameUserDataModule (io.github.nucleuspowered.nucleus.modules.nickname.datamodules.NicknameUserDataModule)1 ChangeNicknameEvent (io.github.nucleuspowered.nucleus.modules.nickname.events.ChangeNicknameEvent)1