use of org.spongepowered.api.asset.Asset in project LanternServer by LanternPowered.
the class GeneratorTypeRegistryModule method postInit.
/**
* Post initialize the {@link GeneratorType}s. All the default world generators
* here be selected by scanning for 'default-world-gen.json' files.
*/
@CustomCatalogRegistration
@DelayedRegistration(RegistrationPhase.POST_INIT)
public void postInit() {
final Multimap<String, DefaultEntry> entries = HashMultimap.create();
final Gson gson = new Gson();
// Scan every plugin
for (PluginContainer pluginContainer : Sponge.getPluginManager().getPlugins()) {
final Optional<Asset> optAsset = pluginContainer.getAsset("default-world-gen.json");
if (optAsset.isPresent()) {
try {
final InputStream is = optAsset.get().getUrl().openStream();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
final JsonObject json = gson.fromJson(reader, JsonObject.class);
for (Map.Entry<String, JsonElement> entry : json.entrySet()) {
entries.put(entry.getKey(), new DefaultEntry(pluginContainer, entry.getValue().getAsString()));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
for (Map.Entry<String, Collection<DefaultEntry>> entry : entries.asMap().entrySet()) {
final String id = entry.getKey();
if (!getById(id).map(type -> type instanceof DelegateGeneratorType).orElse(false)) {
Lantern.getLogger().warn("The plugin(s) ({}) attempted to map an unknown id: {}", Arrays.toString(entry.getValue().stream().map(e -> e.pluginContainer.getId()).toArray()), id);
continue;
}
final List<DefaultEntry> possibleEntries = new ArrayList<>();
for (DefaultEntry entry1 : entry.getValue()) {
final Optional<GeneratorType> generatorType = getById(entry1.type);
if (generatorType.isPresent()) {
possibleEntries.add(entry1);
} else {
Lantern.getLogger().warn("The plugin {} attempted to map a missing generator type {} for {}", entry1.pluginContainer.getId(), entry1.type, id);
}
}
if (!possibleEntries.isEmpty()) {
final DefaultEntry defaultEntry = possibleEntries.get(0);
if (possibleEntries.size() > 1) {
Lantern.getLogger().warn("Multiple plugins are mapping {}: {}", id, Arrays.toString(entry.getValue().stream().map(e -> "\n" + e.pluginContainer.getId() + ": " + e.type).toArray()));
Lantern.getLogger().warn("The first one will be used.");
}
((DelegateGeneratorType) getById(id).get()).setGeneratorType(getById(defaultEntry.type).get());
Lantern.getLogger().warn("Successfully registered a generator type mapping: {} from {} for {}", defaultEntry.type, defaultEntry.pluginContainer.getId(), id);
}
}
}
use of org.spongepowered.api.asset.Asset in project LanternServer by LanternPowered.
the class LanternScriptGameRegistry method compile.
@Override
public Script<Object> compile(Object plugin, String asset) {
final AssetRepository assetRepository = Lantern.getAssetRepository();
final Asset theAsset = assetRepository.get(plugin, asset).orElseThrow(() -> new IllegalArgumentException("There is no asset with the specified id: " + asset + " for the specified plugin:" + plugin));
return this.compile(theAsset);
}
use of org.spongepowered.api.asset.Asset in project TotalEconomy by Erigitic.
the class MessageManager method setupConfig.
/**
* Setup the messages_[lang].conf file
*/
private void setupConfig(Locale locale) {
File messagesFile = new File(totalEconomy.getConfigDir(), "messages_" + locale.getLanguage() + ".conf");
ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setFile(messagesFile).build();
try {
if (!messagesFile.exists()) {
Asset defaultMessagesAsset = totalEconomy.getPluginContainer().getAsset("messages_en.conf").get();
Optional<Asset> optMessagesAsset = totalEconomy.getPluginContainer().getAsset("messages_" + locale.getLanguage() + ".conf");
optMessagesAsset.orElse(defaultMessagesAsset).copyToFile(messagesFile.toPath());
}
messagesConfig = loader.load();
} catch (IOException e) {
logger.warn("[TE] Error loading/creating the messages configuration file!");
}
}
use of org.spongepowered.api.asset.Asset in project core by CubeEngine.
the class I18n method enable.
public void enable() {
LanguageLoader languageLoader = service.getLanguageLoader();
Asset langs = getAssetManager().getAsset(plugin, "languages/languages.yml").get();
try {
List<URL> urls = new ArrayList<>();
for (String lang : langs.readLines()) {
Optional<Asset> langAsset = getAssetManager().getAsset(plugin, "languages/" + lang + ".yml");
if (langAsset.isPresent()) {
urls.add(langAsset.get().getUrl());
} else {
log.warn("Could not find language definition for: " + lang);
}
}
if (urls.size() != 0) {
log.info("Loading {} language definitions", urls.size());
}
((I18nLanguageLoader) languageLoader).loadLanguages(urls);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
use of org.spongepowered.api.asset.Asset in project core by CubeEngine.
the class I18n method registerPlugin.
public void registerPlugin(PluginContainer plugin) {
String name = plugin.getName();
for (Language language : getLanguages()) {
String lang = language.getLocale().getLanguage();
String full = lang + "_ " + language.getLocale().getCountry();
Optional<Asset> asset = getAssetManager().getAsset(plugin, "translations/" + lang + "_" + name + ".po");
asset.map(Asset::getUrl).ifPresent(poFiles::add);
asset = getAssetManager().getAsset(plugin, "translations/" + full + "_" + name + ".po");
asset.map(Asset::getUrl).ifPresent(poFiles::add);
}
}
Aggregations