Skip to content

API Usage

BloodyTim3 edited this page Dec 16, 2024 · 6 revisions

API

Set the provider details from another plugin

Example:

public class MyPlugin extends PluginBase {

    @Override
    public void onLoad() {
        FuturePlots.getInstance().getProvider().setDataClient(new DataClient(
                ClientType.MONGODB, new MongoDBDetails(
                "uri",
                "database"
        )));
    }
}

Custom language handler

Example:

public class MyPlugin extends PluginBase {

    @Override
    public void onLoad() {
        LanguageManager.setHandler(new CustomLanguageHandler());
    }
}
public class CustomLanguageHandler implements LanguageProvider {
    private final Map<String, Map<String, String>> translations = new HashMap<>();

    @Override
    public void init() {
        Map<String, String> enTranslations = new HashMap<>();
        enTranslations.put("greeting", "Hello, %s!");
        
        Map<String, String> deTranslations = new HashMap<>();
        deTranslations.put("greeting", "Hallo, %s!");

        translations.put("en_US", enTranslations);
        translations.put("de_DE", deTranslations);
    }

    @Override
    public String message(String locale, String key, Object... replacements) {
       
        Map<String, String> localeTranslations = translations.getOrDefault(locale, translations.get("en_US"));


        String template = localeTranslations.getOrDefault(key, key);

        return String.format(template, replacements);
    }
}
Clone this wiki locally