Skip to content

An API to consistently format messages being sent to players.

Notifications You must be signed in to change notification settings

Pickaria/Messager

Repository files navigation

Pickaria Messager API

An API making use of the Adventure to consistently format messages being sent to players.

Usage

Add dependency

repositories {
    mavenLocal()
}

dependencies {
    implementation("fr.pickaria:messager:1.0-SNAPSHOT")
}

Register translations

Since this API requires messages to be defined in a Bundle.properties file, you must first register the Bundle in the TranslationRegistry.

This is well explain on the Internationalization documentation of Paper.

# src/main/resources/your/plugin/Bundle_en_US.properties
hello.player=Hello {0}!

Usage with Spigot

import fr.pickaria.messager.Messager;

public class ExamplePlugin extends JavaPlugin implements Listener {
    @Override
    public void onEnable() {
        // Register translations
        TranslationRegistry registry = TranslationRegistry.create(Key.key("namespace:value"));

        ResourceBundle bundle = ResourceBundle.getBundle("your.plugin.Bundle", Locale.US, UTF8ResourceBundleControl.get());
        registry.registerAll(Locale.US, bundle, true);
        GlobalTranslator.translator().addSource(registry);
        
        // Register events
        Bukkit.getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Messager messager = Messager();
        messager.info(event.getPlayer(), "hello.player", Text(event.getPlayer().getName()));
    }
}

About

An API to consistently format messages being sent to players.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages