API
As you may already know, there is an official LabyMod Server API. So why create another one? It seems that the original does not work with current Versions of minecraft and is also made to work with LabyMod 3 (it should still work with Laby 4 tho). As far as i can tell, there is another third-party LabyMod Server API, but this one still does not seem to work with 1.20.2. I do hope that LabyMod creates a new Server Plugin for their new API and keeps it up to date, until then, my go-to solution will be this repository.
To use this API you need the plugin jar File on your Server. You can download the latest file here.
To use this API in your Plugin, you need to add it as a dependency.
<repository>
<id>joshicodes-de-releases</id>
<name>JoshiCodes Repository</name>
<url>https://repo.joshicodes.de/releases</url>
</repository>
<dependency>
<groupId>de.joshicodes</groupId>
<artifactId>NewLabyAPI</artifactId>
<version>1.2.5</version>
<scope>provided</scope>
</dependency>
The Protocol Util Class, mentioned in the LabyMod Documentation, is already implemented and can be used standalone.
final String key = "some_key_here";
final JsonElement data = new JsonObject();
LabyModProtocol.sendLabyMessage(player, key, data);
Alternative, you can use the provided classes to send data to the client.
You can send every LabyProtocolObject
to the client, via LabyModAPI.sendObject(Player, String, LabyProtocolObject)
, where the String is the key of the object.
Some classes, like InputPrompt
have their own Methods to send them to the client:
LabyModAPI.sendPrompt(Player, InputPrompt)
Some objects even have their own method in the LabyModPlayer
class.
You can get a LabyModPlayer using LabyModAPI.getLabyModPlayer(Player)
or LabyModAPI.getLabyModPlayer(UUID)
.
This API provides some events, which listen to LabyMod specific events. You can listen to those events exactly like every other Bukkit Event. At the moment there are the following events:
LabyModPlayerJoinEvent
for when a LabyMod player joins the serverInputPromptEvent
for when a player answers an InputPrompt
You can send an InputPrompt to the client, which will ask the player for an input.
More Information on the LabyMod Docs
// ID (int, unique for each player), Message (String, shown to the player), Value (String, default value), Placeholder (String, placeholder)
final InputPrompt prompt = new InputPrompt(1234, "What is your name?", "<Name>", "<Name>");
LabyModAPI.sendPrompt(player, prompt);
// Or use LabyModPlayer
LabyModPlayer labyPlayer = ...
labyPlayer.sendInputPrompt(prompt);
Modify the Middle Click Menu of the player.
More Information on the LabyMod Docs
MouseMenuActionList menu = new MouseMenuActionList();
menu.addAction(
"Report player",
MouseMenuActionType.SUGGEST_COMMAND,
"/report {name}"
);
// Send to player
labyPlayer.sendActionMenu(menu);
Sends a Server Banner to the client.
More Information on the LabyMod Docs
The Banner has to have a ratio of 5:1, recommended size is 1280x256px.
labyPlayer.sendServerBanner("https://example.com/banner.png");
LabyMod Docs
Allows or Denies certain permissions.
labyPlayer.sendPermissions(HashMap<LabyModPermission, Boolean>);
// or
labyPlayer.sendPermission(List<LabyModPermission> allow, List<LabyModPermission> deny);
There is already a way implemented to send those permissions on player join.
To use them, just set permissions.use
to true
in the config.yml.
After that, you can enable or disable the permissions in the config.yml.
LabyMod Docs
Displays a Subtitle to everyone or just a specific player.
labyPlayer.sendSubtitle(LabyModPlayerSubtitle...); // Sends the Subtitles to just this player
labyPlayer.setSubtitle(LabyModPlayerSubtitle); // Sets the subtitle of the player. This updates the subtitle for everyone.
labyPlayer.clearSubtitle(); // Clears the subtitle of the player. This updates the subtitle for everyone.
Labymod Docs
Displays the current playing gamemode to the player.
labyPlayer.setCurrentPlayingGamemode("Gamemode");
Feel free to contribute in any way you like, just create a pull request or just create an issue. I will try to keep an eye on everything, but may take some time to respond.