diff --git a/README.md b/README.md index 458622b..c0229ba 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@

CI - API + API Languages Platform

@@ -135,7 +135,7 @@ A C# plugin is a `net8.0` class library that references `Falcon.PluginAPI` and s - + ``` @@ -191,7 +191,7 @@ A Java plugin is a Java 22 jar that depends on `falcon-plugin-api` with the `pro io.github.falcon-mc falcon-plugin-api - 1.3.3 + 1.4.0 provided ``` @@ -220,7 +220,7 @@ full class name and `jar` defaults to `.jar`: { "name": "MyPlugin", "version": "1.0.0", - "api-version": "1.3.3", + "api-version": "1.4.0", "main": "myplugin.MyPlugin", "runtime": "java", "jar": "MyPlugin.jar" diff --git a/dotnet/Falcon.PluginAPI/Entities/Player.cs b/dotnet/Falcon.PluginAPI/Entities/Player.cs index 7a2c788..1ac1e74 100644 --- a/dotnet/Falcon.PluginAPI/Entities/Player.cs +++ b/dotnet/Falcon.PluginAPI/Entities/Player.cs @@ -207,6 +207,32 @@ public void SendTitle(string title, string subtitle = "") } } + /// + /// Shows a boss bar and returns its id. The newest bar of a player is displayed, the others wait behind it, and + /// a raid bar replaces them all while it is up. Percent goes from 0 to 1. Colors: 0 pink, 1 blue, 2 red, + /// 3 green, 4 yellow, 5 purple, 6 rebecca purple, 7 white. + /// + public uint AddBossBar(string title, float percent = 1.0f, uint color = 5) + { + fixed (byte* text = NativeApi.Utf8(title)) + { + return NativeApi.Table->playerAddBossBar(_handle, text, percent, color); + } + } + + public bool UpdateBossBar(uint bar, string title, float percent, uint color = 5) + { + fixed (byte* text = NativeApi.Utf8(title)) + { + return NativeApi.Table->playerUpdateBossBar(_handle, bar, text, percent, color) != 0; + } + } + + public bool RemoveBossBar(uint bar) + { + return NativeApi.Table->playerRemoveBossBar(_handle, bar) != 0; + } + public void SendActionBar(string message) { fixed (byte* text = NativeApi.Utf8(message)) diff --git a/examples/java/HelloPlugin/plugin.json b/examples/java/HelloPlugin/plugin.json index aa6ccd7..3d2e7de 100644 --- a/examples/java/HelloPlugin/plugin.json +++ b/examples/java/HelloPlugin/plugin.json @@ -1,7 +1,7 @@ { "name": "HelloPlugin", "version": "1.0.0", - "api-version": "1.3.3", + "api-version": "1.4.0", "main": "falcon.examples.hello.HelloPlugin", "runtime": "java", "jar": "HelloPlugin.jar", diff --git a/examples/java/HelloPlugin/pom.xml b/examples/java/HelloPlugin/pom.xml index d660bd3..b8215b3 100644 --- a/examples/java/HelloPlugin/pom.xml +++ b/examples/java/HelloPlugin/pom.xml @@ -15,7 +15,7 @@ 22 UTF-8 - 1.3.3 + 1.4.0 diff --git a/java/pom.xml b/java/pom.xml index 0111256..99ad6b5 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -6,7 +6,7 @@ io.github.falcon-mc falcon-plugin-api - 1.3.3 + 1.4.0 jar Falcon Plugin API diff --git a/java/src/main/java/falcon/api/Player.java b/java/src/main/java/falcon/api/Player.java index 81d0b22..5f5fb53 100644 --- a/java/src/main/java/falcon/api/Player.java +++ b/java/src/main/java/falcon/api/Player.java @@ -110,6 +110,27 @@ public void sendTitle(String title, String subtitle) { } } + /** + * Shows a boss bar and returns its id. The newest bar of a player is displayed, the others wait behind it, and a + * raid bar replaces them all while it is up. Percent goes from 0 to 1. Colors: 0 pink, 1 blue, 2 red, 3 green, + * 4 yellow, 5 purple, 6 rebecca purple, 7 white. + */ + public int addBossBar(String title, float percent, int color) { + try (Arena arena = Arena.ofConfined()) { + return api().playerAddBossBar(mHandle, Interop.text(arena, title), percent, color); + } + } + + public boolean updateBossBar(int bar, String title, float percent, int color) { + try (Arena arena = Arena.ofConfined()) { + return api().playerUpdateBossBar(mHandle, bar, Interop.text(arena, title), percent, color) != 0; + } + } + + public boolean removeBossBar(int bar) { + return api().playerRemoveBossBar(mHandle, bar) != 0; + } + public void sendActionBar(String message) { try (Arena arena = Arena.ofConfined()) { api().playerSendActionBar(mHandle, Interop.text(arena, message)); diff --git a/native/include/falcon/Player.hpp b/native/include/falcon/Player.hpp index a0b19e7..35c44b7 100644 --- a/native/include/falcon/Player.hpp +++ b/native/include/falcon/Player.hpp @@ -97,6 +97,23 @@ namespace falcon { detail::api().playerSendTitle(mHandle, title.c_str(), subtitle.c_str()); } + /** + * Shows a boss bar and returns its id. The newest bar of a player is displayed, the others wait behind it, and + * a raid bar replaces them all while it is up. Percent goes from 0 to 1. Colors: 0 pink, 1 blue, 2 red, + * 3 green, 4 yellow, 5 purple, 6 rebecca purple, 7 white. + */ + uint32_t addBossBar(const std::string &title, float percent = 1.0f, uint32_t color = 5) const { + return detail::api().playerAddBossBar(mHandle, title.c_str(), percent, color); + } + + bool updateBossBar(uint32_t bar, const std::string &title, float percent, uint32_t color = 5) const { + return detail::api().playerUpdateBossBar(mHandle, bar, title.c_str(), percent, color) != 0; + } + + bool removeBossBar(uint32_t bar) const { + return detail::api().playerRemoveBossBar(mHandle, bar) != 0; + } + void sendActionBar(const std::string &message) const { detail::api().playerSendActionBar(mHandle, message.c_str()); } diff --git a/native/include/falcon/falcon_api.h b/native/include/falcon/falcon_api.h index 721dc48..0282c5c 100644 --- a/native/include/falcon/falcon_api.h +++ b/native/include/falcon/falcon_api.h @@ -14,8 +14,8 @@ extern "C" { #endif #define FALCON_API_VERSION_MAJOR 1 -#define FALCON_API_VERSION_MINOR 3 -#define FALCON_API_VERSION_PATCH 3 +#define FALCON_API_VERSION_MINOR 4 +#define FALCON_API_VERSION_PATCH 0 #define FALCON_PLUGIN_ENTRY_NAME "falcon_plugin_entry" typedef struct FalconPlugin FalconPlugin; @@ -433,6 +433,10 @@ typedef struct FalconServerApi { void (*entitySetInvisible)(FalconEntity *entity, int invisible); int32_t (*playerProtocolVersion)(FalconPlayer *player); + + uint32_t (*playerAddBossBar)(FalconPlayer *player, const char *title, float percent, uint32_t color); + int (*playerUpdateBossBar)(FalconPlayer *player, uint32_t bar, const char *title, float percent, uint32_t color); + int (*playerRemoveBossBar)(FalconPlayer *player, uint32_t bar); } FalconServerApi; typedef int (*FalconPluginEntry)(const FalconServerApi *api, FalconPlugin *plugin, FalconPluginCallbacks *callbacks); diff --git a/wasm/falcon.wit b/wasm/falcon.wit index dfe833d..4f7f928 100644 --- a/wasm/falcon.wit +++ b/wasm/falcon.wit @@ -114,6 +114,9 @@ interface players { player-address: func(player: player) -> string; player-send-title: func(player: player, title: string, subtitle: string); player-send-action-bar: func(player: player, message: string); + player-add-boss-bar: func(player: player, title: string, percent: f32, color: u32) -> u32; + player-update-boss-bar: func(player: player, bar: u32, title: string, percent: f32, color: u32) -> bool; + player-remove-boss-bar: func(player: player, bar: u32) -> bool; player-food: func(player: player) -> f32; player-set-food: func(player: player, food: f32); player-xp-level: func(player: player) -> s32;