Search in sources :

Example 1 with TextParsingUtils

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

the class NucleusPlugin method onPreInit.

@Listener
public void onPreInit(GamePreInitializationEvent preInitializationEvent) {
    // Setup object mapper.
    MessageReceiver s;
    if (Sponge.getGame().isServerAvailable()) {
        s = Sponge.getServer().getConsole();
    } else {
        s = new ClientMessageReciever();
    }
    if (this.versionFail != null) {
        s.sendMessage(messageProvider.getTextMessageWithFormat("startup.nostart.compat", PluginInfo.NAME, Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getName(), Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getVersion().orElse("unknown")));
        s.sendMessage(messageProvider.getTextMessageWithFormat("startup.nostart.compat2", this.versionFail));
        s.sendMessage(messageProvider.getTextMessageWithFormat("startup.nostart.compat3", this.versionFail));
        disable();
        return;
    }
    s.sendMessage(Text.of(TextColors.WHITE, "--------------------------"));
    s.sendMessage(messageProvider.getTextMessageWithFormat("startup.welcome", PluginInfo.NAME, PluginInfo.VERSION, Sponge.getPlatform().getContainer(Platform.Component.API).getVersion().orElse("unknown")));
    s.sendMessage(messageProvider.getTextMessageWithFormat("startup.welcome2"));
    s.sendMessage(messageProvider.getTextMessageWithFormat("startup.welcome3"));
    s.sendMessage(messageProvider.getTextMessageWithFormat("startup.welcome4"));
    s.sendMessage(Text.of(TextColors.WHITE, "--------------------------"));
    logger.info(messageProvider.getMessageWithFormat("startup.preinit", PluginInfo.NAME));
    Game game = Sponge.getGame();
    NucleusAPITokens.onPreInit(this);
    // Startup tasks, for the migrations I need to do.
    PreloadTasks.getPreloadTasks().forEach(x -> x.accept(this));
    // Get the mandatory config files.
    try {
        Files.createDirectories(this.configDir);
        if (this.isServer) {
            Files.createDirectories(this.dataDir.get());
        }
        this.commandsConfig = new CommandsConfig(Paths.get(configDir.toString(), "commands.conf"));
        DataProviders d = new DataProviders(this);
        this.generalService = new ModularGeneralService(d.getGeneralDataProvider());
        this.itemDataService = new ItemDataService(d.getItemDataProvider());
        this.itemDataService.loadInternal();
        this.userDataManager = new UserDataManager(d::getUserFileDataProviders, d::doesUserFileExist);
        this.worldDataManager = new WorldDataManager(d::getWorldFileDataProvider, d::doesWorldFileExist);
        this.kitService = new KitService(d.getKitsDataProvider());
        this.nameBanService = new NameBanService(d.getNameBanDataProvider());
        this.userCacheService = new UserCacheService(d.getUserCacheDataProvider());
        this.warmupManager = new WarmupManager();
        this.textParsingUtils = new TextParsingUtils(this);
        this.nameUtil = new NameUtil(this);
        if (this.isServer) {
            allChange();
        }
    } catch (Exception e) {
        this.isErrored = e;
        disable();
        e.printStackTrace();
        return;
    }
    PreloadTasks.getPreloadTasks2().forEach(x -> x.accept(this));
    // We register the ModuleService NOW so that others can hook into it.
    game.getServiceManager().setProvider(this, NucleusModuleService.class, new ModuleRegistrationProxyService(this));
    game.getServiceManager().setProvider(this, NucleusWarmupManagerService.class, warmupManager);
    serviceManager.registerService(WarmupManager.class, warmupManager);
    nucleusChatService = new NucleusTokenServiceImpl(this);
    serviceManager.registerService(NucleusTokenServiceImpl.class, nucleusChatService);
    Sponge.getServiceManager().setProvider(this, NucleusMessageTokenService.class, nucleusChatService);
    try {
        final String he = this.messageProvider.getMessageWithFormat("config.main-header", PluginInfo.VERSION);
        HoconConfigurationLoader.Builder builder = HoconConfigurationLoader.builder();
        Optional<Asset> optionalAsset = Sponge.getAssetManager().getAsset(Nucleus.getNucleus(), "classes.json");
        DiscoveryModuleContainer.Builder db = DiscoveryModuleContainer.builder();
        if (optionalAsset.isPresent()) {
            Map<String, Map<String, List<String>>> m = new Gson().fromJson(optionalAsset.get().readString(), new TypeToken<Map<String, Map<String, List<String>>>>() {
            }.getType());
            Set<Class<?>> sc = Sets.newHashSet();
            for (String classString : m.keySet()) {
                sc.add(Class.forName(classString));
            }
            db.setStrategy((string, classloader) -> sc).setConstructor(new QuickStartModuleConstructor(m));
        } else {
            db.setConstructor(new QuickStartModuleConstructor(null)).setStrategy(Strategy.DEFAULT);
        }
        this.moduleContainer = db.setConfigurationLoader(builder.setDefaultOptions(ConfigurateHelper.setOptions(builder.getDefaultOptions()).setHeader(he)).setPath(Paths.get(configDir.toString(), "main.conf")).build()).setPackageToScan(getClass().getPackage().getName() + ".modules").setLoggerProxy(new NucleusLoggerProxy(logger)).setConfigurationOptionsTransformer(x -> ConfigurateHelper.setOptions(x).setHeader(he)).setOnPreEnable(() -> {
            initDocGenIfApplicable();
            Sponge.getEventManager().post(new BaseModuleEvent.AboutToEnable(this));
        }).setOnEnable(() -> {
            Sponge.getEventManager().post(new BaseModuleEvent.PreEnable(this));
        }).setOnPostEnable(() -> Sponge.getEventManager().post(new BaseModuleEvent.Enabled(this))).setRequireModuleDataAnnotation(true).setNoMergeIfPresent(true).setModuleConfigurationHeader(m -> {
            StringBuilder ssb = new StringBuilder().append(divider).append("\n");
            String name = m.getClass().getAnnotation(ModuleData.class).name();
            int nameLength = name.length() + 2;
            int dashes = (length - nameLength) / 2;
            ssb.append("|");
            for (int i = 0; i < dashes; i++) {
                ssb.append(" ");
            }
            ssb.append(" ").append(name).append(" ");
            for (int i = 0; i < dashes; i++) {
                ssb.append(" ");
            }
            if (length > dashes * 2 + nameLength) {
                ssb.append(" ");
            }
            return ssb.append("|").append("\n").append(divider).toString();
        }).setModuleConfigSectionName("-modules").setModuleConfigSectionDescription(this.messageProvider.getMessageWithFormat("config.module-desc")).setModuleDescriptionHandler(m -> this.messageProvider.getMessageWithFormat("config.module." + m.getAnnotation(ModuleData.class).id().toLowerCase() + ".desc")).build();
        moduleContainer.startDiscover();
    } catch (Exception e) {
        isErrored = e;
        disable();
        e.printStackTrace();
    }
}
Also used : NameBanService(io.github.nucleuspowered.nucleus.dataservices.NameBanService) GameStoppedServerEvent(org.spongepowered.api.event.game.state.GameStoppedServerEvent) CatalogTypeFinalStaticProcessor(io.github.nucleuspowered.nucleus.internal.CatalogTypeFinalStaticProcessor) TypeToken(com.google.gson.reflect.TypeToken) GameInitializationEvent(org.spongepowered.api.event.game.state.GameInitializationEvent) VERSION(io.github.nucleuspowered.nucleus.PluginInfo.VERSION) PermissionService(org.spongepowered.api.service.permission.PermissionService) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) Path(java.nio.file.Path) PrintWriter(java.io.PrintWriter) CommandPermissionHandler(io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler) NameBanService(io.github.nucleuspowered.nucleus.dataservices.NameBanService) Set(java.util.Set) ResourceMessageProvider(io.github.nucleuspowered.nucleus.internal.messages.ResourceMessageProvider) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) BaseModuleEvent(io.github.nucleuspowered.nucleus.internal.qsml.event.BaseModuleEvent) ConfigException(com.typesafe.config.ConfigException) KitService(io.github.nucleuspowered.nucleus.dataservices.KitService) ConfigurateHelper(io.github.nucleuspowered.nucleus.configurate.ConfigurateHelper) ModularGeneralService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularGeneralService) PermissionInformation(io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation) GamePostInitializationEvent(org.spongepowered.api.event.game.state.GamePostInitializationEvent) TextParsingUtils(io.github.nucleuspowered.nucleus.internal.text.TextParsingUtils) Supplier(java.util.function.Supplier) ID(io.github.nucleuspowered.nucleus.PluginInfo.ID) Lists(com.google.common.collect.Lists) Text(org.spongepowered.api.text.Text) WorldDataManager(io.github.nucleuspowered.nucleus.dataservices.loaders.WorldDataManager) NucleusLoggerProxy(io.github.nucleuspowered.nucleus.internal.qsml.NucleusLoggerProxy) QuickStartModuleConstructor(io.github.nucleuspowered.nucleus.internal.qsml.QuickStartModuleConstructor) NucleusTeleportHandler(io.github.nucleuspowered.nucleus.internal.teleport.NucleusTeleportHandler) NucleusModuleService(io.github.nucleuspowered.nucleus.api.service.NucleusModuleService) QuickStartModuleLoaderException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleLoaderException) ModuleData(uk.co.drnaylor.quickstart.annotations.ModuleData) PluginContainer(org.spongepowered.api.plugin.PluginContainer) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) WarmupConfig(io.github.nucleuspowered.nucleus.modules.core.config.WarmupConfig) NucleusAPITokens(io.github.nucleuspowered.nucleus.api.NucleusAPITokens) UserCacheService(io.github.nucleuspowered.nucleus.dataservices.UserCacheService) UserDataManager(io.github.nucleuspowered.nucleus.dataservices.loaders.UserDataManager) Files(java.nio.file.Files) CommandsConfig(io.github.nucleuspowered.nucleus.config.CommandsConfig) StringWriter(java.io.StringWriter) TextFileController(io.github.nucleuspowered.nucleus.internal.TextFileController) IOException(java.io.IOException) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) QuickStartModuleDiscoveryException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException) PreloadTasks(io.github.nucleuspowered.nucleus.internal.PreloadTasks) NucleusTokenServiceImpl(io.github.nucleuspowered.nucleus.internal.text.NucleusTokenServiceImpl) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) Paths(java.nio.file.Paths) MessageReceiver(org.spongepowered.api.text.channel.MessageReceiver) ConsoleSource(org.spongepowered.api.command.source.ConsoleSource) Game(org.spongepowered.api.Game) NoModuleException(uk.co.drnaylor.quickstart.exceptions.NoModuleException) EconHelper(io.github.nucleuspowered.nucleus.internal.EconHelper) Strategy(uk.co.drnaylor.quickstart.modulecontainers.discoverystrategies.Strategy) DESCRIPTION(io.github.nucleuspowered.nucleus.PluginInfo.DESCRIPTION) CoreModule(io.github.nucleuspowered.nucleus.modules.core.CoreModule) CoreConfigAdapter(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter) NucleusWarmupManagerService(io.github.nucleuspowered.nucleus.api.service.NucleusWarmupManagerService) ItemDataService(io.github.nucleuspowered.nucleus.dataservices.ItemDataService) Order(org.spongepowered.api.event.Order) Gson(com.google.gson.Gson) CoreConfig(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig) NucleusMessageTokenService(io.github.nucleuspowered.nucleus.api.service.NucleusMessageTokenService) WorldCorrector(io.github.nucleuspowered.nucleus.internal.WorldCorrector) EconomyService(org.spongepowered.api.service.economy.EconomyService) ClientMessageReciever(io.github.nucleuspowered.nucleus.internal.client.ClientMessageReciever) GamePreInitializationEvent(org.spongepowered.api.event.game.state.GamePreInitializationEvent) UniqueUserCountTransientModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.UniqueUserCountTransientModule) Sponge(org.spongepowered.api.Sponge) Instant(java.time.Instant) Sets(com.google.common.collect.Sets) DataProviders(io.github.nucleuspowered.nucleus.dataservices.dataproviders.DataProviders) List(java.util.List) NAME(io.github.nucleuspowered.nucleus.PluginInfo.NAME) GameStartedServerEvent(org.spongepowered.api.event.game.state.GameStartedServerEvent) Optional(java.util.Optional) ConfigMessageProvider(io.github.nucleuspowered.nucleus.internal.messages.ConfigMessageProvider) Asset(org.spongepowered.api.asset.Asset) DocGenCache(io.github.nucleuspowered.nucleus.internal.docgen.DocGenCache) PermissionDescription(org.spongepowered.api.service.permission.PermissionDescription) GameStartingServerEvent(org.spongepowered.api.event.game.state.GameStartingServerEvent) Platform(org.spongepowered.api.Platform) Inject(javax.inject.Inject) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) ModuleRegistrationProxyService(io.github.nucleuspowered.nucleus.internal.qsml.ModuleRegistrationProxyService) NucleusConfigAdapter(io.github.nucleuspowered.nucleus.internal.qsml.NucleusConfigAdapter) Task(org.spongepowered.api.scheduler.Task) GameState(org.spongepowered.api.GameState) IncorrectAdapterTypeException(uk.co.drnaylor.quickstart.exceptions.IncorrectAdapterTypeException) WarmupManager(io.github.nucleuspowered.nucleus.internal.services.WarmupManager) Logger(org.slf4j.Logger) HoconConfigurationLoader(ninja.leaping.configurate.hocon.HoconConfigurationLoader) InternalServiceManager(io.github.nucleuspowered.nucleus.internal.InternalServiceManager) ConstructionPhase(uk.co.drnaylor.quickstart.enums.ConstructionPhase) ConfigDir(org.spongepowered.api.config.ConfigDir) Maps(com.google.common.collect.Maps) Plugin(org.spongepowered.api.plugin.Plugin) UUIDChangeService(io.github.nucleuspowered.nucleus.modules.core.service.UUIDChangeService) Listener(org.spongepowered.api.event.Listener) DiscoveryModuleContainer(uk.co.drnaylor.quickstart.modulecontainers.DiscoveryModuleContainer) DebugLogger(io.github.nucleuspowered.nucleus.logging.DebugLogger) Collections(java.util.Collections) QuickStartModuleConstructor(io.github.nucleuspowered.nucleus.internal.qsml.QuickStartModuleConstructor) DiscoveryModuleContainer(uk.co.drnaylor.quickstart.modulecontainers.DiscoveryModuleContainer) KitService(io.github.nucleuspowered.nucleus.dataservices.KitService) NucleusTokenServiceImpl(io.github.nucleuspowered.nucleus.internal.text.NucleusTokenServiceImpl) Gson(com.google.gson.Gson) UserDataManager(io.github.nucleuspowered.nucleus.dataservices.loaders.UserDataManager) BaseModuleEvent(io.github.nucleuspowered.nucleus.internal.qsml.event.BaseModuleEvent) HoconConfigurationLoader(ninja.leaping.configurate.hocon.HoconConfigurationLoader) NucleusLoggerProxy(io.github.nucleuspowered.nucleus.internal.qsml.NucleusLoggerProxy) DataProviders(io.github.nucleuspowered.nucleus.dataservices.dataproviders.DataProviders) ModularGeneralService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularGeneralService) Asset(org.spongepowered.api.asset.Asset) UserCacheService(io.github.nucleuspowered.nucleus.dataservices.UserCacheService) WorldDataManager(io.github.nucleuspowered.nucleus.dataservices.loaders.WorldDataManager) TextParsingUtils(io.github.nucleuspowered.nucleus.internal.text.TextParsingUtils) CommandsConfig(io.github.nucleuspowered.nucleus.config.CommandsConfig) 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) ModuleRegistrationProxyService(io.github.nucleuspowered.nucleus.internal.qsml.ModuleRegistrationProxyService) ItemDataService(io.github.nucleuspowered.nucleus.dataservices.ItemDataService) WarmupManager(io.github.nucleuspowered.nucleus.internal.services.WarmupManager) Game(org.spongepowered.api.Game) MessageReceiver(org.spongepowered.api.text.channel.MessageReceiver) TypeToken(com.google.gson.reflect.TypeToken) ClientMessageReciever(io.github.nucleuspowered.nucleus.internal.client.ClientMessageReciever) Map(java.util.Map) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) Listener(org.spongepowered.api.event.Listener)

Example 2 with TextParsingUtils

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

the class ChatUtilTests method setup.

@BeforeClass
public static void setup() throws Exception {
    TestBase.testSetup();
    NucleusPlugin plugin = Guice.createInjector(new TestModule()).getInstance(NucleusPlugin.class);
    Field parserToTest = TextParsingUtils.class.getDeclaredField("urlParser");
    parserToTest.setAccessible(true);
    patternToTest = (Pattern) parserToTest.get(new TextParsingUtils(plugin));
}
Also used : Field(java.lang.reflect.Field) NucleusPlugin(io.github.nucleuspowered.nucleus.NucleusPlugin) TestModule(io.github.nucleuspowered.nucleus.tests.util.TestModule) TextParsingUtils(io.github.nucleuspowered.nucleus.internal.text.TextParsingUtils) BeforeClass(org.junit.BeforeClass)

Aggregations

TextParsingUtils (io.github.nucleuspowered.nucleus.internal.text.TextParsingUtils)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 ConfigException (com.typesafe.config.ConfigException)1 NucleusPlugin (io.github.nucleuspowered.nucleus.NucleusPlugin)1 DESCRIPTION (io.github.nucleuspowered.nucleus.PluginInfo.DESCRIPTION)1 ID (io.github.nucleuspowered.nucleus.PluginInfo.ID)1 NAME (io.github.nucleuspowered.nucleus.PluginInfo.NAME)1 VERSION (io.github.nucleuspowered.nucleus.PluginInfo.VERSION)1 NucleusAPITokens (io.github.nucleuspowered.nucleus.api.NucleusAPITokens)1 NucleusMessageTokenService (io.github.nucleuspowered.nucleus.api.service.NucleusMessageTokenService)1 NucleusModuleService (io.github.nucleuspowered.nucleus.api.service.NucleusModuleService)1 NucleusWarmupManagerService (io.github.nucleuspowered.nucleus.api.service.NucleusWarmupManagerService)1 CommandsConfig (io.github.nucleuspowered.nucleus.config.CommandsConfig)1 ConfigurateHelper (io.github.nucleuspowered.nucleus.configurate.ConfigurateHelper)1 ItemDataService (io.github.nucleuspowered.nucleus.dataservices.ItemDataService)1 KitService (io.github.nucleuspowered.nucleus.dataservices.KitService)1