Skip to content

A message library, which focuses on being extensible and flexible.

License

Notifications You must be signed in to change notification settings

rchomczyk/honey

Repository files navigation

honey (miód)

A message library, which focuses on simplicity and flexibility.

Intent

honey was created to allow for developers to create easily customizable messages for end users, by giving them flexibility with placeholders.

Get started

Gradle DSL (kts) || std

Add repository
maven("https://repo.shiza.dev/releases")
maven { url 'https://repo.shiza.dev/releases' }
Add dependency
implementation("dev.shiza:honey:2.2.2")
implementation 'dev.shiza:honey:2.2.2'

Maven

Add repository
<repository>
  <id>shiza-releases</id>
  <url>https://repo.shiza.dev/releases</url>
</repository>
Add dependency
<dependency>
  <groupId>dev.shiza</groupId>
  <artifactId>honey</artifactId>
  <version>2.2.2</version>
</dependency>

test-plugin showcase

Use case (honey)

A showcase of how to use honey, can be found in honey-test-plugin module.

With use of formatter

MessageFormatter provides all functionality that honey offers, it comes with reflective placeholder evaluation and sanitization to make them harmless, while used with minimessage without any additional hasle on developer side.

AdventureMessageDispatcher.createTitle()
    .viewer(event.getPlayer())
    .title(it -> it.template(formatter, "Hello!"))
    .subtitle(it -> it.template(formatter, "It is a pleasure to see you there {{player.getName}}"))
    .variable("player", event.getPlayer())
    .times(2, 4, 2)
    .dispatch();

AdventureMessageDispatcher.createChat()
    .viewer(Bukkit.getServer())
    .template(formatter, "{{player.getName}} has joined the server!")
    .variable("player", event.getPlayer())
    .dispatch();

AdventureMessageDispatcher.createActionBar()
    .viewer(event.getPlayer())
    .template(formatter, "Honey is great, isn't it?")
    .dispatch();

Without formatter

MessageDispatcher provides a way to send messages without the need of using placeholders.

AdventureMessageDispatcher.createChat()
    .viewer(Bukkit.getServer())
    .template(Component.text("Somebody joined to the server!").color(NamedTextColor.RED))
    .dispatch();

AdventureMessageDispatcher.createActionBar()
    .viewer(event.getPlayer())
    .template(Component.text("Honey is great, isn't it?"))
    .dispatch();

Use case (honey-kt-extesion)

AdventureMessageDispatcher.createChat()
    .viewer(event.player)
    .template(Component.text("Hello!"))
    .dispatch()

AdventureMessageDispatcher.createActionBar()
    .viewer(event.player)
    .template(Component.text("This is an action bar message!"))
    .dispatch()

player.createChat()
    .template(Component.text("A custom chat message"))
    .dispatch()

player.createActionBar()
    .template(Component.text("This is a custom action bar"))
    .dispatch()

AdventureMessageDispatcher.createTitle()
    .viewer(event.player)
    .title { it.template(Component.text("Hello!")) }
    .subtitle { it.template(Component.text("It's great to see you!")) }
    .times(2, 4, 2)
    .dispatch()

Synchronous vs asynchronous message dispatching

  • dispatch This method immediately delivers the message synchronously. It calls the deliver function with the rendered message and the viewer, and the action is completed immediately.

  • dispatchAsync This method delivers the message asynchronously. It returns a CompletableFuture that performs the message rendering in the background and then delivers the result once it's ready. It allows non-blocking behavior and handles exceptions asynchronously.