use of org.spongepowered.api.Game in project LanternServer by LanternPowered.
the class LanternModule method configure.
@Override
protected void configure() {
// Inject into sponge
requestStaticInjection(Sponge.class);
// Injection Points
install(new InjectionPointProvider());
// The logger
bind(Logger.class).toInstance(this.logger);
// Options
install(new OptionModule() {
@Override
protected void configure0() {
// Bind the arguments
bindArguments().toInstance(arguments);
// Bind the parser
bindParser().toInstance(optionParser);
// Expose the Option annotation
exposeOptions();
}
});
// Directories: Plugins, Libraries, Configs, ...
bindAndExposePath(DirectoryKeys.ROOT, DirectoryKeys.DefaultValues.ROOT);
// See below for all the other ones
// Basic Configuration Annotations
bindAndExpose(Path.class, ConfigDirAnnotation.SHARED).toProvider(SharedConfigDirAsPath.class).in(Scopes.SINGLETON);
bindAndExpose(File.class, ConfigDirAnnotation.SHARED).toProvider(SharedConfigDirAsFile.class).in(Scopes.SINGLETON);
// The Game
bindAndExpose(Server.class).to(LanternServer.class);
bindAndExpose(LanternServer.class);
bindAndExpose(Game.class).to(LanternGame.class);
bindAndExpose(MinecraftVersion.class).toInstance(LanternMinecraftVersion.CURRENT);
bindAndExpose(ServiceManager.class).to(LanternServiceManager.class);
bindAndExpose(AssetManager.class).to(LanternAssetManager.class);
bindAndExpose(GameRegistry.class).to(LanternGameRegistry.class);
bindAndExpose(TeleportHelper.class).to(LanternTeleportHelper.class);
bindAndExpose(Scheduler.class).to(LanternScheduler.class);
bindAndExpose(CommandManager.class).to(LanternCommandManager.class);
bindAndExpose(Platform.class).to(LanternPlatform.class);
bindAndExpose(EventManager.class).to(LanternEventManager.class);
bindAndExpose(ChannelRegistrar.class).to(LanternChannelRegistrar.class);
bindAndExpose(GameProfileManager.class).to(LanternGameProfileManager.class);
bindAndExpose(PropertyRegistry.class).to(LanternPropertyRegistry.class);
bindAndExpose(ConfigManager.class).to(LanternConfigManager.class);
bindAndExpose(PluginManager.class).to(LanternPluginManager.class);
bindAndExpose(DataManager.class).to(LanternDataManager.class);
bindAndExpose(PropertyRegistry.class).to(LanternPropertyRegistry.class);
bindAndExpose(CauseStackManager.class).to(LanternCauseStackManager.class);
// Services
bindService(PermissionService.class);
bindService(BanService.class);
bindService(WhitelistService.class);
bindService(UserStorageService.class);
bindService(SqlService.class);
bindService(PaginationService.class);
bindService(RconService.class);
// The Indexed Channel Binding
bindAndExpose(ChannelBinding.IndexedMessageChannel.class).toProvider(ChannelBindingProvider.Indexed.class);
bindAndExpose(ChannelBinding.IndexedMessageChannel.class, Named.class).toProvider(ChannelBindingProvider.Indexed.class);
bindAndExpose(ChannelBinding.IndexedMessageChannel.class, ChannelId.class).toProvider(ChannelBindingProvider.Indexed.class);
// The Raw Channel Binding
bindAndExpose(ChannelBinding.RawDataChannel.class).toProvider(ChannelBindingProvider.Raw.class);
bindAndExpose(ChannelBinding.RawDataChannel.class, Named.class).toProvider(ChannelBindingProvider.Raw.class);
bindAndExpose(ChannelBinding.RawDataChannel.class, ChannelId.class).toProvider(ChannelBindingProvider.Raw.class);
// Assets
bindAndExpose(Asset.class, Named.class).toProvider(PluginAssetProvider.class);
bindAndExpose(Asset.class, AssetId.class).toProvider(PluginAssetProvider.class);
// Internal Plugin Containers
bindAndExpose(PluginContainer.class, Names.named(InternalPluginsInfo.Api.IDENTIFIER)).to(InternalPluginContainer.Api.class);
bindAndExpose(PluginContainer.class, Names.named(InternalPluginsInfo.SpongePlatform.IDENTIFIER)).to(InternalPluginContainer.SpongePlatform.class);
bindAndExpose(PluginContainer.class, Names.named(InternalPluginsInfo.Minecraft.IDENTIFIER)).to(InternalPluginContainer.Minecraft.class);
bindAndExpose(PluginContainer.class, Names.named(InternalPluginsInfo.Implementation.IDENTIFIER)).to(InternalPluginContainer.Implementation.class);
// Loggers
bindAndExpose(Logger.class, Named.class).toProvider(NamedSlf4jLoggerProvider.class);
expose(org.apache.logging.log4j.Logger.class);
bindAndExpose(org.apache.logging.log4j.Logger.class, Named.class).toProvider(NamedLog4jLoggerProvider.class);
// Other Plugin Containers
bindAndExpose(PluginContainer.class, Named.class).toProvider(PluginContainerProvider.class);
// Sponge Executor Services
bindAndExpose(SpongeExecutorService.class, SynchronousExecutor.class).toProvider(SpongeExecutorServiceProvider.Synchronous.class);
bindAndExpose(SpongeExecutorService.class, AsynchronousExecutor.class).toProvider(SpongeExecutorServiceProvider.Asynchronous.class);
}
use of org.spongepowered.api.Game 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();
}
}
Aggregations