An open API service indexing awesome lists of open source software.

https://github.com/rchomczyk/honey

A message library, which focuses on being extensible and flexible.
https://github.com/rchomczyk/honey

adventure bukkit bukkit-api dispatcher java kyori message minecraft minimessage notification paper papermc placeholders spigot spigot-api

Last synced: 6 months ago
JSON representation

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

Awesome Lists containing this project

README

          

## 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
You can build dependency and append it to your local .m2 directory, by using:
`./gradlew publishToMavenLocal`

![test-plugin showcase](assets/image.png)

### Use case (honey)

A showcase of how to use *honey*, can be found in [honey-test-plugin](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.

```java
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.

```java
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)
```kotlin
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](https://github.com/rchomczyk/honey/tree/main/honey-common/src/dev/shiza/honey/message/dispatcher/MessageBaseDispatcher.java#L71)
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](https://github.com/rchomczyk/honey/tree/main/honey-common/src/dev/shiza/honey/message/dispatcher/MessageBaseDispatcher.java#L76)
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.