Skip to content
viimeinen1Public

About

Small messaging library for plugin use

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

aMsg

Small messaging library to send messages with prefixes for players.

Add as dependency

To use the library in your project, add it as a dependency.

The dependency can be seen at https://central.sonatype.com/artifact/io.github.viimeinen1.amsg/aMsg

build.gradle.kts:

dependencies {
    implementation("io.github.viimeinen1.amsg:aMsg:1.1.2")
}

Usage

/* Default usage */

// set prefix for all messages globally
aMsg.prefix(MiniMessage.minimessage().deserialize("<gold>[prefix] "))

// or use aMsg.mm() {= MiniMessage.minimessage().deserialize()} for deserializing

// send messages
aMsg.send(player, "<green>Hello, world!") // -> [prefix] Hello, world!
aMsg.send(player, "Multiline", "message")
/*
    -> [prefix] Multiline
    -> [prefix] message
*/

// send single message with different prefix
aMsg.send(aMsg.mm("<red>[another prefix] "), player, Component.text("hello"), "<red>hi!");
/*
    -> [another prefix] hello
    -> [another prefix] hi!
*/
/* Multiple prefixes */

// if you require multiple prefixes for different functions, use aMsg.Msg instead of aMsg
Msg defaultMsg = new Msg(aMsg.mm("<green>[default] "));
Msg adminMsg = new Msg(aMsg.mm("<gold>[admin] "));

defaultMsg.send(player, "Hello admins") // -> [default] Hello admins
adminMsg.send(player, "Hello defaults") // -> [admin] Hello defaults
/* Plugin logging */

// set plugin as the plugin used in logging.
public class ExamplePlugin extends JavaPlugin {
    @Override
    public void onEnable() {
        // ...
        aMsg.plugin(this); // set plugin as the context for logging.
        // ...
    }
}

/*
    if the plugin name is "example", the logs will have prefix [example]
    if plugin was not set, server's own context will be used.
    It's recommended to set the context to show what plugin sends the logs.
*/

// after setting the logging plugin, you can use:
aMsg.log("Hello, World!"); // (in console) -> [example] Hello, World!

// with colors
aMsg.log(LOG_COLOR.GREEN, "this text is green"); // -> [example] this text is green

// with multiple lines
aMsg.log(
    LOG_COLOR.RED,
    "line 1",
    "line 2"
);
aMsg.log(
    "line 1",
    "line 2"
);
/*
    both result to:

    -> [example] line 1
    -> [example] line 2

    with the first giving both a green color.
*/

// as LOG_COLOR is an ANSI value, you can use them with text on console.
aMsg.log(LOG_COLOR.RED + "red, " + LOG_COLOR.YELLOW + "yellow, " + LOG_COLOR.RESET + "no-color"); // -> [example] red, yellow, no-color

About

Small messaging library for plugin use

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages