Libb 图标

Libb

作者:rebot | 分类:模组

价格:0 墨喵币 下载量:0 点赞:0 版本 1.2.3
本资源为搬运资源,原资源地址: https://modrinth.com/mod/libb
资源信息

Minecraft 版本: 1.20 1.20.1 1.20.2 1.20.3 1.20.4 1.20.5 1.20.6 1.21 1.21.1 1.21.2 1.21.3 1.21.4 1.21.5 1.21.6 1.21.7 1.21.8 1.21.9 1.21.10 1.21.11 26.1 26.1.1 26.1.2 26.2

平台: bukkit paper spigot

标签: utility

资源介绍

Libb

A library for convenient and easy creation of Minecraft plugins.



Dependencies
PlaceholderAPI
Java 21 or higher
Paper or forks
Minecraft Version 1.20 or higher

GUI ### Example ```java public class GuiTest extends AdvancedGui { public GuiTest() { super("Gui title"); setItem("example", ItemWrapper.builder(Material.STONE) .slots(1, 5, 7) .displayName(Component.text("This is the name dude")) .onClick(event -> { event.setCancelled(true); player.sendMessage("Clicked on slot: " + event.getSlot()); }) .build()); } } ``` To open a GUI for a player, call `open()`: ```java new GuiTest().open(player); ```
ParsedGui — Config-driven GUIs `ParsedGui` lets you define an entire inventory GUI in a YAML config file — items, slots, click actions, open/close hooks, and placeholders — with no boilerplate code. --- ### YAML structure ```yaml id: my_gui title: "My Shop" size: 54 # must be a multiple of 9 on_open: # optional — action list to run when GUI opens - "[sound] UI_BUTTON_CLICK;1;1" on_close: # optional — action list to run when GUI closes - "[message] Closed the shop." Items: my_item: material: DIAMOND slot: 13 # single slot display_name: "Buy Diamond" lore: - "" - " Click to purchase" - "" on_click: any: # fires on every click type - "[sound] UI_BUTTON_CLICK;1;1" - "[player] buy diamond" left: # fires only on left click - "[message] Left clicked!" shift_left: - "[message] Shift+Left!" ``` **Supported click types:** `any`, `left`, `shift_left`, `right`, `shift_right`, `middle`, `drop`, `control_drop`, `double` **Slot formats:** ```yaml slot: 13 # single slot slots: - '0-8' # range - '45-53' # another range - '27' # single inside a list ``` --- ### Opening from code ```java // From a FileConfiguration: FileConfiguration config = YamlConfiguration.loadConfiguration(file); new ParsedGui(player, config, myPlugin).open(player); // From a pre-parsed Gui record (more efficient for many players): Gui gui = ...; // parsed once at startup new ParsedGui(player, gui, myPlugin).open(player); ``` --- ### Runtime placeholders Use `setReplace()` to inject values into display names, lore, and action lines at runtime. Call it **before** `open()` — items are built on open. ```java ParsedGui gui = new ParsedGui(player, config, myPlugin); gui.setReplace("%price%", "500") .setReplace("%item_name%", "Diamond Sword"); gui.open(player); ``` In YAML: ```yaml display_name: "Price: $%price%" lore: - " Item: %item_name%" ``` PlaceholderAPI placeholders (`%papi_placeholder%`) are applied automatically — no extra setup needed. --- ### Click handlers from code Register Java-side click logic for items by their YAML section key. Runs **in addition** to whatever `on_click` is defined in YAML. ```java ParsedGui gui = new ParsedGui(player, config, myPlugin); gui.addClickHandler("my_item", event -> { Player clicker = (Player) event.getWhoClicked(); clicker.sendMessage("You clicked my_item!"); gui.refresh(); }); gui.open(player); ``` --- ### Passing the GUI into actions via ActionContext When a player clicks an item, `ParsedGui` puts itself into the `ActionContext` automatically. Inside a custom action you can retrieve it: ```java ActionRegistry.register("myplugin", "my_action", (ctx, text) -> { ParsedGui gui = ctx.get(ParsedGui.class); if (gui == null) return; // do something, then refresh gui.refresh(); }); ``` In config: ```yaml on_click: any: - "[myplugin:my_action]" ``` --- ### Slot priority & view_requirements Multiple items can target the same slot. The one with the lowest `priority` value whose `view_requirements` all pass wins. This is useful for conditional items — e.g. show a locked version until the player has enough money. ```yaml Items: buy_locked: material: RED_STAINED_GLASS_PANE slot: 13 priority: 1 display_name: "Not enough money" view_requirements: - "%vault_eco_balance% Buy" ``` `view_requirements` supports `==`, `!=`, `>=`, ``, ` { toggleSomething(player); gui.refresh(); }); ``` --- ### Extending ParsedGui You can subclass `ParsedGui` to add custom inventory slots, override rendering logic, etc. > ⚠️ `super(viewer, config, plugin)` calls `buildItems()` internally during construction — before your subclass fields are initialized. Override `buildItems()` with a null-check guard: ```java public class MyGui extends ParsedGui { private final MyPlugin plugin; public MyGui(Player viewer, FileConfiguration config, MyPlugin plugin) { super(viewer, config, plugin); this.plugin = plugin; // your init here } @Override public void buildItems(List items) { if (plugin == null) { // guard: called from super() before our fields exist super.buildItems(items); return; } // your custom logic, then: super.buildItems(items); } @Override public void refresh() { // update your replacements before items are rebuilt setReplace("%score%", String.valueOf(getScore())); super.refresh(); } } ```
Actions Actions are config-driven commands executed on a player. Each action is a string in the format `[key] text`. ### Built-in actions | Key | Description | |-----|-------------| | `[message]` | Send a message to the player | | `[broadcast_message]` | Broadcast a message to all players | | `[console]` | Run a command from console | | `[player]` | Run a command as the player | | `[effect]` | Apply a potion effect | | `[action_bar]` | Send an action bar message | | `[broadcast_action_bar]` | Broadcast an action bar to all players | | `[title]` | Send a title to the player | | `[broadcast_title]` | Broadcast a title to all players | | `[sound]` | Play a sound for the player | | `[broadcast_sound]` | Play a sound for all players | | `[open]` | Open a GUI | ### Usage **Simple run:** ```java ActionExecute.run(ActionContext.of(player), "[message] Hello!"); ``` **With extra objects in context:** ```java ActionExecute.run( ActionContext.of(player).with(entity), "[myplugin:give_diamond] 64" ); ``` > Extra objects added via `.with()` can be retrieved inside the handler using `ctx.get(YourClass.class)`. --- ### Registering a custom action Custom actions are registered in `onEnable` and unregistered in `onDisable`. Actions from different plugins can share the same key without conflict — the full key is `namespace:command`: ```yaml # config.yml actions: - "[plugina:spawn] text" # resolves plugina's spawn - "[pluginb:spawn] text" # resolves pluginb's spawn — no conflict - "[spawn] text" # resolves whichever was registered first ``` #### Lambda (simple cases) ```java @Override public void onEnable() { ActionRegistry.register("myplugin", "give_diamond", (ctx, text) -> { Player player = ctx.getPlayer(); if (player == null || text == null) return; int amount = Integer.parseInt(text); player.getInventory().addItem(new ItemStack(Material.DIAMOND, amount)); player.sendMessage("You got " + amount + " diamonds!"); }); } @Override public void onDisable() { ActionRegistry.unregisterAll("myplugin"); } ``` #### Class (recommended for complex logic) Register in `onEnable`: ```java @Override public void onEnable() { ActionRegistry.register("myplugin", "give_diamond", new GiveDiamondAction()); } @Override public void onDisable() { ActionRegistry.unregisterAll("myplugin"); } ``` Implement `Action`: ```java public class GiveDiamondAction implements Action { @Override public void execute(@NotNull ActionContext ctx, @Nullable String text) { Player player = ctx.getPlayer(); if (player == null || text == null) return; // Parse text argument int amount = Integer.parseInt(text); player.getInventory().addItem(new ItemStack(Material.DIAMOND, amount)); player.sendMessage("You got " + amount + " diamonds!"); // Retrieve a custom object from context — null if not provided Entity entity = ctx.get(Entity.class); if (entity == null) return; entity.teleport(player.getLocation()); ActionExecute.run( ActionContext.of(player), "[message] Entity has been teleported to you" ); } } ``` #### ActionContext `ActionContext` is a type-safe container for objects passed into an action. Objects are stored and retrieved by class — no string keys needed. ```java // Put objects in ActionContext ctx = ActionContext.of(player) .with(entity) // store by entity.getClass() .with(myGui); // store by myGui.getClass() // Get objects out (inside a handler) Entity entity = ctx.get(Entity.class); // null if not provided Entity entity = ctx.require(Entity.class); // throws if not provided ``` If you want to store an object under an interface rather than its concrete class: ```java ctx.with(MyInterface.class, myObject); // retrieve as: ctx.get(MyInterface.class); ```

API

MAVEN ```xml JetbyMC https://api.jetby.org/ ``` ```xml me.jetby.libb api VERSION provided ``` GRADLE ```gradle repositories { maven { url "https://api.jetby.org/" name "JetbyMC" } } ``` ```gradle dependencies { compileOnly "me.jetby.libb:api:VERSION" } ```
下载太慢?试试 墨喵加速站,支持 Modrinth 和外网直链高速下载! 用的人越多,下载的越快!
下载与版本
评论(0)
登录 后发表评论。

暂无评论,抢个沙发吧~

举报此资源

请登录后举报

🔥 相关推荐
Reei's Easy NPCs

价格:0 墨喵币
下载量:0

查看详情
Dyed Books

价格:0 墨喵币
下载量:0

查看详情
Universal Shops

价格:0 墨喵币
下载量:0

查看详情
Some Tweaks

价格:0 墨喵币
下载量:0

查看详情