### Clone Bukkit View Template Source: https://github.com/typst-io/view/blob/main/README.md This command clones the bukkit-view template repository from GitHub, providing a quick start for new projects using the library. ```shell git clone https://github.com/typst-io/bukkit-view-template ``` -------------------------------- ### ViewControl Construction with Just ItemStack Source: https://github.com/typst-io/view/blob/main/README.md This Java example shows the simplest way to create a `ViewControl` using only an `ItemStack`. This creates a static item in the view. ```java `ViewControl.just(ItemStack)` > ItemStack -> ViewControl ``` -------------------------------- ### Java ViewAction Examples: Opening, Updating, and Closing Views Source: https://context7.com/typst-io/view/llms.txt This Java code demonstrates how to use various ViewAction types to manage user interactions within a chest view. It includes actions for opening new views (synchronously and asynchronously), updating view contents (synchronously and asynchronously), closing the view, and performing no-operation actions. It relies on the io.typst.view package and Bukkit API for inventory management. ```java import io.typst.view.*; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; public class ViewActionExamples { public static ChestView createTargetView() { return ChestView.builder() .title("Target View") .row(1) .contents(ViewContents.ofControls(new HashMap<>())) .build(); } public static void demonstrateActions() { Map> controls = new HashMap<>(); // Open another view immediately controls.put(0, ViewControl.of( new ItemStack(Material.COMPASS), e -> new ViewAction.Open<>(createTargetView()) )); // Open a view asynchronously (e.g., load from database) controls.put(1, ViewControl.of( new ItemStack(Material.ENDER_PEARL), e -> { Future> futureView = CompletableFuture.supplyAsync(() -> { // Simulate async operation try { Thread.sleep(1000); } catch (InterruptedException ex) {} return createTargetView(); }); return new ViewAction.OpenAsync<>(futureView); } )); // Update current view contents without reopening controls.put(2, ViewControl.of( new ItemStack(Material.WRITABLE_BOOK), e -> { Map> newControls = new HashMap<>(); newControls.put(10, ViewControl.just(new ItemStack(Material.DIAMOND))); ViewContents newContents = ViewContents.ofControls(newControls); return new ViewAction.Update<>(newContents); } )); // Update contents asynchronously controls.put(3, ViewControl.of( new ItemStack(Material.HOPPER), e -> { Future> futureContents = CompletableFuture.supplyAsync(() -> { // Load updated contents Map> newControls = new HashMap<>(); return ViewContents.ofControls(newControls); }); return new ViewAction.UpdateAsync<>(futureContents); } )); // Close the view and give back player items controls.put(4, ViewControl.of( new ItemStack(Material.BARRIER), e -> new ViewAction.Close<>(true) )); // Reopen the current view (refresh) controls.put(5, ViewControl.of( new ItemStack(Material.CLOCK), e -> ViewAction.reopen() )); // Do nothing controls.put(6, ViewControl.of( new ItemStack(Material.GRAY_STAINED_GLASS_PANE), e -> ViewAction.nothing() )); } } ``` -------------------------------- ### Closing ChestView with Actions Source: https://github.com/typst-io/view/blob/main/README.md This Java example demonstrates how to handle the close event of a ChestView. You can specify actions to perform upon closing, such as returning `ViewAction.NOTHING` or `ViewAction.REOPEN`. ```java ChestView.of(title, row, map, closeEvent -> { return ViewAction.NOTHING; // or ViewAction.REOPEN }) ``` -------------------------------- ### Test Pure View Construction with JUnit 5 Source: https://github.com/typst-io/view/blob/main/CLAUDE.md Demonstrates how to test pure view construction using JUnit 5. This example focuses on creating a ChestView and verifying its properties directly, leveraging the immutability provided by @Value and @With annotations. ```java ```java // Good: Test pure view construction ChestView view = ChestView.builder() .title("Test") .row(3) .contents(ViewContents.ofControls(controls)) .build(); // Verify view properties directly assertEquals("Test", view.getTitle()); ``` ``` -------------------------------- ### Create Interactive ViewControls with Factory Methods (Java) Source: https://context7.com/typst-io/view/llms.txt Provides examples of creating ViewControls using factory methods like 'of', 'just', and 'consumer'. These controls handle item display and player interactions, with different methods for defining click actions, side effects, or purely visual elements. Dependencies include Typst view and Bukkit APIs. ```java import io.typst.view.*; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public class ViewControlExamples { public static ViewControl createActionControl() { // Full control with item and action function return ViewControl.of( new ItemStack(Material.COMPASS), clickEvent -> { Player player = clickEvent.getPlayer(); String clickType = clickEvent.getClick(); // "LEFT", "RIGHT", etc. String action = clickEvent.getAction(); // "PICKUP_ALL", etc. if (clickType.equals("LEFT")) { return new ViewAction.Close<>(false); // close without returning items } else { return ViewAction.nothing(); // no action } } ); } public static ViewControl createDisplayControl() { // Display-only control (no click action) return ViewControl.just(new ItemStack(Material.BARRIER)); } public static ViewControl createConsumerControl() { // Consumer-style for side effects without returning actions return ViewControl.consumer( new ItemStack(Material.BELL), clickEvent -> { clickEvent.getPlayer().playSound( clickEvent.getPlayer().getLocation(), "block.note_block.bell", 1.0f, 1.0f ); } ); } public static ViewControl createDynamicItemControl() { // Dynamic item based on OpenEvent context return ViewControl.of( openEvent -> { Player player = openEvent.getPlayer(); ItemStack item = new ItemStack(Material.PLAYER_HEAD); // Customize item based on player return item; }, clickEvent -> ViewAction.nothing() ); } } ``` -------------------------------- ### Create and Open ChestView in Java Source: https://github.com/typst-io/view/blob/main/README.md This Java code demonstrates how to build and open a custom ChestView. It includes setting the title, rows, and defining interactive controls for items. It also shows how to handle click events and return different ViewActions like opening another view or nothing. ```java ChestView subView = ...; String title = "title"; int row = 1; Map controls = new HashMap<>(); controls.put(3, ViewControl.of( new ItemStack(Material.DIAMOND), e -> { // this view item don't -- also shouldn't -- know how to open view, // just tell what view want to open. return new ViewAction.Open(subView); } )); ChestView view = ChestView.builder() .title(title) .row(row) .contents(ViewContents.ofControls(controls)) .build(); BukkitView.openView(view, player, plugin); ``` -------------------------------- ### Create and Open a Simple ChestView Source: https://context7.com/typst-io/view/llms.txt Demonstrates how to build and open a basic chest inventory GUI with clickable controls that trigger specific actions upon interaction. ```APIDOC ## Create and Open a Simple ChestView ### Description Build an interactive chest inventory with clickable controls that trigger actions. This example shows how to define items, their associated actions, and how to present the view to a player. ### Method `BukkitView.openView(ChestView view, P player, Plugin plugin)` ### Endpoint N/A (Static method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java import io.typst.view.*; import io.typst.view.bukkit.BukkitView; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import java.util.HashMap; import java.util.Map; public class SimpleViewExample { public static void openSimpleView(Player player, Plugin plugin) { // Create controls with items and click handlers Map> controls = new HashMap<>(); // Slot 0: Diamond that closes the view controls.put(0, ViewControl.of( new ItemStack(Material.DIAMOND), clickEvent -> new ViewAction.Close<>(true) // give back items on close )); // Slot 1: Emerald that does nothing (display only) controls.put(1, ViewControl.just(new ItemStack(Material.EMERALD))); // Slot 2: Gold ingot with consumer-style handler controls.put(2, ViewControl.consumer( new ItemStack(Material.GOLD_INGOT), clickEvent -> { clickEvent.getPlayer().sendMessage("You clicked gold!"); // Consumer version automatically returns ViewAction.nothing() } )); // Build the view ChestView view = ChestView.builder() .title("Simple Chest") .row(3) // 3 rows = 27 slots .contents(ViewContents.ofControls(controls)) .build(); // Open the view for the player BukkitView.openView(view, player, plugin); } } ``` ### Response None (This method opens a GUI for the player) #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### Evaluate and Open PageView Source: https://github.com/typst-io/view/blob/main/README.md This Java code demonstrates how to evaluate a specific page from a `PageViewLayout` and then open it as a `ChestView` for a player. ```java int page = 1; ChestView view = layout.toView(page); BukkitView.openView(view, player, plugin); ``` -------------------------------- ### Publish Modules to Maven Central via Gradle Source: https://github.com/typst-io/view/blob/main/CLAUDE.md Shows the command to publish modules to Maven Central using Gradle, including specifying Sonatype credentials for username and password. This process is configured in the root build.gradle file. ```bash ./gradlew publish -PossrhUsername=... -PossrhPassword=... ``` -------------------------------- ### Initialize Bukkit View Plugin Source: https://github.com/typst-io/view/blob/main/README.md This Java code snippet shows how to initialize the BukkitView within your plugin's onEnable method. It is essential for the library to function correctly. ```java public class MyPlugin extends JavaPlugin { @Override public void onEnable() { BukkitView.register(this); } } ``` -------------------------------- ### Full PageViewLayout Construction Source: https://github.com/typst-io/view/blob/main/README.md This Java snippet illustrates the full construction of a `PageViewLayout`, allowing for custom item slots and fixed control items in addition to the paginated items. ```java // Paging elements List> items = ...; // Paging elements will be put in this slots. List slots = ...; // Control means fixed view-item, won't affected by view paging. Map> controls = ...; String title = "title"; int row = 6; PageViewLayout layout = PageViewLayout.of(title, row, items, slots, controls); ``` -------------------------------- ### ViewControl Construction with Consumer Source: https://github.com/typst-io/view/blob/main/README.md This Java snippet demonstrates creating a `ViewControl` with an `ItemStack` and a `Consumer` that accepts a `ViewAction`. This is useful for items that trigger actions without returning a new view. ```java `ViewControl.consumer(ItemStack, Consumer)` > (ItemStack, ClickEvent -> Unit) -> ViewControl ``` -------------------------------- ### Asynchronous ChestView Opening Source: https://github.com/typst-io/view/blob/main/README.md This Java snippet illustrates how to open a ChestView asynchronously using `ViewAction.OpenAsync`. This is useful for operations that might take time, such as loading data for the view. ```java ViewControl.of( bukkitItemStack, e -> { Future myChestViewFuture; return new ViewAction.OpenAsync(myChestViewFuture); } ) ``` -------------------------------- ### ViewControl Construction with ItemStack and Click Handler Source: https://github.com/typst-io/view/blob/main/README.md This Java snippet shows one way to construct a `ViewControl` by providing an `ItemStack` and a function that handles click events, returning a `ViewAction`. ```java `ViewControl.of(ItemStack, Function)` > (ItemStack, ClickEvent -> ViewAction) -> ViewControl ``` -------------------------------- ### Default PageViewLayout Construction Source: https://github.com/typst-io/view/blob/main/README.md This Java code shows the default construction of a `PageViewLayout` using `ofDefault()`. It takes a title, number of rows, a default item material, and a list of lazy item controls. ```java // Lazy `Function` not just `ViewControl` List> items = ...; PageViewLayout layout = PageViewLayout.ofDefault( "title", 6, Material.STONE_BUTTON, items ); ``` -------------------------------- ### Create and Open a Simple ChestView in Java Source: https://context7.com/typst-io/view/llms.txt Demonstrates building and opening a simple chest inventory with clickable controls. Items can be configured with click handlers that trigger specific actions, like closing the view or displaying messages. ```java import io.typst.view.*; import io.typst.view.bukkit.BukkitView; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import java.util.HashMap; import java.util.Map; public class SimpleViewExample { public static void openSimpleView(Player player, Plugin plugin) { // Create controls with items and click handlers Map> controls = new HashMap<>(); // Slot 0: Diamond that closes the view controls.put(0, ViewControl.of( new ItemStack(Material.DIAMOND), clickEvent -> new ViewAction.Close<>(true) // give back items on close )); // Slot 1: Emerald that does nothing (display only) controls.put(1, ViewControl.just(new ItemStack(Material.EMERALD))); // Slot 2: Gold ingot with consumer-style handler controls.put(2, ViewControl.consumer( new ItemStack(Material.GOLD_INGOT), clickEvent -> { clickEvent.getPlayer().sendMessage("You clicked gold!"); // Consumer version automatically returns ViewAction.nothing() } )); // Build the view ChestView view = ChestView.builder() .title("Simple Chest") .row(3) // 3 rows = 27 slots .contents(ViewContents.ofControls(controls)) .build(); // Open the view for the player BukkitView.openView(view, player, plugin); } } ``` -------------------------------- ### Initialize BukkitView Source: https://context7.com/typst-io/view/llms.txt Registers the view system in your Bukkit plugin to enable event handling for chest GUIs. This is a mandatory step before using any other bukkit-view features. ```APIDOC ## Initialize BukkitView ### Description Register the view system in your Bukkit plugin to enable event handling for chest GUIs. ### Method `BukkitView.register(JavaPlugin plugin)` or `BukkitView.register(ItemStackOps itemOps, JavaPlugin plugin)` ### Endpoint N/A (Static method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java import io.typst.view.bukkit.BukkitView; import org.bukkit.plugin.java.JavaPlugin; public class MyPlugin extends JavaPlugin { @Override public void onEnable() { // Register with default Bukkit ItemStack operations BukkitView.register(this); // Or register with custom ItemStackOps implementation // BukkitView.register(customItemOps, this); } } ``` ### Response None (This method performs registration) #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### Create Inventory Views with Kotlin Type Aliases (Kotlin) Source: https://context7.com/typst-io/view/llms.txt Illustrates how to leverage Kotlin type aliases to simplify the declaration of inventory views. This makes the code more readable and concise by reducing the verbosity of generic type parameters. It shows the creation of basic view controls and page layouts. ```kotlin import io.typst.view.bukkit.kotlin.* import io.typst.view.ViewAction import org.bukkit.Material import org.bukkit.inventory.ItemStack fun createKotlinView(): BukkitChestView { val controls = mutableMapOf() // Using type aliases instead of full generic types controls[0] = ViewControl.of( ItemStack(Material.DIAMOND) ) { clickEvent -> clickEvent.player.sendMessage("Clicked!") ViewAction.nothing() } val contents: BukkitViewContents = ViewContents.ofControls(controls) return ChestView.builder() .title("Kotlin View") .row(3) .contents(contents) .build() } fun createPageLayout(elements: List<(BukkitPageContext) -> BukkitViewControl>): BukkitPageViewLayout { return PageViewLayout.ofDefault( io.typst.inventory.bukkit.BukkitItemStackOps.INSTANCE, "Page", 6, Material.STONE_BUTTON.keyOrThrow.toString(), elements ) } ``` -------------------------------- ### Gradle Dependency for Bukkit View Source: https://github.com/typst-io/view/blob/main/README.md This snippet shows how to add the bukkit-view-core dependency to your project using Gradle. It specifies the Maven repository and the dependency coordinates. ```groovy repositories { mavenCentral() } dependencies { implementation("io.typst:bukkit-view-core:8.1.0") } ``` -------------------------------- ### Opening a Bukkit-View Source: https://context7.com/typst-io/view/llms.txt Opens a Bukkit-View for a specific player. This method handles the underlying inventory creation and event registration. It requires the `view` object, the target `player`, and the `plugin` object. ```java BukkitView.openView(view, player, plugin); ``` -------------------------------- ### Open Custom Paginated View with Navigation Controls (Java) Source: https://context7.com/typst-io/view/llms.txt This Java code illustrates creating a custom paginated view with user-defined navigation controls. It specifies content slots, defines sample elements, and implements custom 'Previous', 'Next', and 'Current Page' buttons using specific Bukkit materials. The view is then constructed and opened. ```java import io.typst.view.*; import io.typst.view.page.*; import io.typst.view.bukkit.BukkitView; import io.typst.inventory.bukkit.BukkitItemStackOps; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import java.util.Arrays; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; import java.util.Map; public class PageViewExample { // ... openMaterialBrowser method ... public static void openCustomPaginatedView(Player player, Plugin plugin) { // Define which slots contain paginated content List contentSlots = Arrays.asList( 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34 ); // 21 slots for content // Create sample elements List, ViewControl>> elements = Arrays.stream(new Material[]{ Material.DIAMOND, Material.EMERALD, Material.GOLD_INGOT, Material.IRON_INGOT, Material.COAL, Material.REDSTONE }) .map(mat -> (Function, ViewControl>) ctx -> ViewControl.just(new ItemStack(mat))) .collect(Collectors.toList()); // Define custom page navigation controls Map, ViewControl>> controls = new java.util.HashMap<>(); // Previous page button at slot 48 controls.put(48, ctx -> ViewControl.of( new ItemStack(Material.ARROW), clickEvent -> { if (ctx.canPrev()) { return new ViewAction.Update<>( ctx.getLayout().toView(ctx.getPage() - 1).getContents() ); } return ViewAction.nothing(); } )); // Next page button at slot 50 controls.put(50, ctx -> ViewControl.of( new ItemStack(Material.ARROW), clickEvent -> { if (ctx.canNext()) { return new ViewAction.Update<>( ctx.getLayout().toView(ctx.getPage() + 1).getContents() ); } return ViewAction.nothing(); } )); // Current page indicator at slot 49 controls.put(49, ctx -> { ItemStack pageItem = new ItemStack(Material.PAPER); pageItem.setAmount(Math.max(1, ctx.getPage())); return ViewControl.just(pageItem); }); // Build layout PageViewLayout layout = PageViewLayout.of( "Custom Pages", 6, // rows elements, contentSlots, controls, pageCtx -> closeEvent -> new ViewAction.Close<>(true), BukkitItemStackOps.INSTANCE ); ChestView view = layout.toView(1); BukkitView.openView(view, player, plugin); } } ``` -------------------------------- ### Maven Dependency for Bukkit View Source: https://github.com/typst-io/view/blob/main/README.md This snippet demonstrates how to include the bukkit-view-core dependency in your project's pom.xml file using Maven. It specifies the group ID, artifact ID, and version. ```xml io.typst bukkit-view-core 8.1.0 ``` -------------------------------- ### Open Material Browser with Default Pagination (Java) Source: https://context7.com/typst-io/view/llms.txt This Java code demonstrates how to open a paginated 'Material Browser' view for a player. It creates a list of item elements from Bukkit materials and uses PageViewLayout.ofDefault to automatically generate pagination controls. The view is then opened using BukkitView. ```java import io.typst.view.*; import io.typst.view.page.*; import io.typst.view.bukkit.BukkitView; import io.typst.inventory.bukkit.BukkitItemStackOps; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import java.util.Arrays; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; public class PageViewExample { public static void openMaterialBrowser(Player player, Plugin plugin) { // Create elements as lazy functions for performance List, ViewControl>> elements = Arrays.stream(Material.values()) .filter(mat -> mat.isItem() && !mat.isAir()) .map(material -> // Lazy function - only evaluated when page is viewed (Function, ViewControl>) ctx -> ViewControl.of( new ItemStack(material), clickEvent -> { clickEvent.getPlayer().sendMessage("Clicked: " + material.name()); return ViewAction.nothing(); } ) ) .collect(Collectors.toList()); // Create layout with default pagination controls PageViewLayout layout = PageViewLayout.ofDefault( BukkitItemStackOps.INSTANCE, "Material Browser", 6, // 6 rows total (5 for items + 1 for controls) Material.STONE_BUTTON.getKeyOrThrow().toString(), // navigation button material elements ); // Open first page ChestView view = layout.toView(1); BukkitView.openView(view, player, plugin); } // ... openCustomPaginatedView method follows ... } ``` -------------------------------- ### Updating ChestView Contents Asynchronously Source: https://github.com/typst-io/view/blob/main/README.md This Java code shows how to update the contents of an existing ChestView asynchronously using `ViewAction.UpdateAsync`. This allows for dynamic updates without blocking the main thread. ```java ViewControl.of( bukkitItemStack, e -> new ViewAction.Update(newContents) // UpdateAsync if needed ) ``` -------------------------------- ### Registering Bukkit-View Plugin Source: https://context7.com/typst-io/view/llms.txt Registers the Bukkit-View plugin during the server's enable phase. This is a prerequisite for using any Bukkit-View functionalities. It requires the `plugin` object as input. ```java BukkitView.register(plugin); ``` -------------------------------- ### Create Nested Views with Modal Behavior in Java Source: https://context7.com/typst-io/view/llms.txt Demonstrates how to create nested views where a child view opens from a parent and automatically returns to the parent when closed. This utilizes the `parent` property of `ChestView` for modal behavior. It requires `io.typst.view`, `io.typst.view.bukkit`, and `io.typst.inventory.bukkit`. ```java import io.typst.view.*; import io.typst.view.bukkit.BukkitView; import io.typst.inventory.bukkit.BukkitItem; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import java.util.HashMap; import java.util.Map; public class NestedViewExample { public static void openMainView(Player player, Plugin plugin) { ChestView mainView = createMainView(player); BukkitView.openView(mainView, player, plugin); } private static ChestView createMainView(Player player) { Map> controls = new HashMap<>(); // Open equipment view as child controls.put(10, ViewControl.of( BukkitItem.builder() .material(Material.IRON_CHESTPLATE) .displayName("View Equipment") .build().create(), e -> new ViewAction.Open<>(createEquipmentView(player, e.getView())) )); // Exit button controls.put(8, ViewControl.of( new ItemStack(Material.BARRIER), e -> new ViewAction.Close<>(true) )); return ChestView.builder() .title("Main Menu") .row(3) .contents(ViewContents.ofControls(controls)) .build(); } private static ChestView createEquipmentView( Player player, ChestView parentView ) { Map> controls = new HashMap<>(); // Display player's armor int slot = 9; for (ItemStack armorPiece : player.getInventory().getArmorContents()) { if (armorPiece != null) { controls.put(slot++, ViewControl.just(armorPiece)); } } // Back button (explicit navigation) controls.put(0, ViewControl.of( BukkitItem.builder() .material(Material.ARROW) .displayName("Back to Main") .build().create(), e -> new ViewAction.Open<>(parentView) )); return ChestView.builder() .title("Equipment") .row(3) .contents(ViewContents.ofControls(controls)) .parent(parentView) // Modal behavior: closing returns to parent .build(); } } ``` -------------------------------- ### Creating a Default Paginated View Source: https://context7.com/typst-io/view/llms.txt Quickly creates a scrollable view with default navigation buttons for pagination. This is useful for displaying lists of items. ```java PageViewLayout.ofDefault() ``` -------------------------------- ### Creating a Custom Paginated View Source: https://context7.com/typst-io/view/llms.txt Provides full control over slot positions and navigation behavior for creating custom paginated views. Use this when the default layout is insufficient. ```java PageViewLayout.of() ``` -------------------------------- ### Java: Create Mixed Chest View with Controls and Player Slots Source: https://context7.com/typst-io/view/llms.txt Creates a `ChestView` where specific slots are predefined controls (like a black stained glass border, an access button, and a barrier for closing) and other slots are available for the player to store their items. It uses `ViewControl` for interactive elements and `ViewContents` to manage both controls and player-managed items, with logic to save player items when the view is closed. ```java import io.typst.view.*; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.HashMap; import java.util.Map; public class MixedContentsExample { public static ChestView createStorageView(Player player) { Map> controls = new HashMap<>(); // Border of non-interactive glass panes (slots 0-8) for (int i = 0; i < 9; i++) { controls.put(i, ViewControl.just( new ItemStack(Material.BLACK_STAINED_GLASS_PANE) )); } // Action button at slot 4 controls.put(4, ViewControl.of( new ItemStack(Material.CHEST), e -> { e.getPlayer().sendMessage("Storage accessed!"); return ViewAction.nothing(); } )); // Exit button at slot 8 controls.put(8, ViewControl.of( new ItemStack(Material.BARRIER), e -> new ViewAction.Close<>(true) )); // Player items from their previous session Map playerItems = new HashMap<>(); // Slots 9-35 are accessible to the player for storage // These could be loaded from a database playerItems.put(10, new ItemStack(Material.DIAMOND, 5)); playerItems.put(15, new ItemStack(Material.GOLDEN_APPLE, 2)); // Create contents with both controls and player items ViewContents contents = ViewContents.of(controls, playerItems); return ChestView.builder() .title(player.getName() + "'s Storage") .row(4) .contents(contents) .onClose(closeEvent -> { // Save player's items when closing ViewContents finalContents = closeEvent.getView().getContents(); Map items = finalContents.getItems(); // Here you would save 'items' to database closeEvent.getPlayer().sendMessage("Storage saved!"); return new ViewAction.Close<>(false); // items already handled }) .build(); } } ``` -------------------------------- ### Initialize BukkitView in Bukkit Plugin Source: https://context7.com/typst-io/view/llms.txt Registers the bukkit-view system with your Bukkit plugin to enable event handling for chest GUIs. It can use default ItemStack operations or a custom implementation. ```java import io.typst.view.bukkit.BukkitView; import org.bukkit.plugin.java.JavaPlugin; public class MyPlugin extends JavaPlugin { @Override public void onEnable() { // Register with default Bukkit ItemStack operations BukkitView.register(this); // Or register with custom ItemStackOps implementation // BukkitView.register(customItemOps, this); } } ``` -------------------------------- ### Handle View Close Events in Java Source: https://context7.com/typst-io/view/llms.txt Shows how to define custom actions when a view is closed using the `onClose` callback. This allows for executing specific logic, such as sending messages, reopening the view, or preventing item drops. Dependencies include `io.typst.view`. ```java import io.typst.view.*; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.HashMap; import java.util.Map; public class CloseEventExample { public static ChestView createViewWithCloseHandler() { Map> controls = new HashMap<>(); controls.put(0, ViewControl.just(new ItemStack(Material.DIAMOND))); return ChestView.builder() .title("Close Handler Demo") .row(1) .contents(ViewContents.ofControls(controls)) .onClose(closeEvent -> { Player player = closeEvent.getPlayer(); ChestView view = closeEvent.getView(); // Perform actions on close player.sendMessage("View closed!"); // Return nothing to allow normal close return ViewAction.nothing(); // Or reopen the view to prevent closing // return ViewAction.reopen(); // Or open a different view // return new ViewAction.Open<>(anotherView); // Or control item return behavior // return new ViewAction.Close<>(false); // don't give back items }) .build(); } } ``` -------------------------------- ### Update Inventory View Dynamically (Java) Source: https://context7.com/typst-io/view/llms.txt Demonstrates how to dynamically update the contents of an inventory view without closing it for the player. This involves creating new view controls and using ViewAction.Update or ViewAction.UpdateAsync to refresh the displayed items. It leverages BukkitView.updateView to apply changes. ```java import io.typst.view.*; import io.typst.view.bukkit.BukkitView; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletableFuture; public class UpdateViewExample { public static ChestView createDynamicView() { Map> controls = new HashMap<>(); // Counter display controls.put(4, ViewControl.of( openEvent -> { ItemStack paper = new ItemStack(Material.PAPER); // Initial count paper.setAmount(1); return paper; }, clickEvent -> ViewAction.nothing() )); // Increment button controls.put(3, ViewControl.of( new ItemStack(Material.LIME_WOOL), clickEvent -> { ChestView currentView = clickEvent.getView(); ViewControl counter = currentView.getContents().getControls().get(4); // Create updated counter Map> newControls = new HashMap<>(currentView.getContents().getControls()); ViewControl updatedCounter = ViewControl.of( openEvent -> { ItemStack paper = new ItemStack(Material.PAPER); ItemStack current = counter.getItem(openEvent); paper.setAmount(Math.min(64, current.getAmount() + 1)); return paper; }, e -> ViewAction.nothing() ); newControls.put(4, updatedCounter); return new ViewAction.Update<>( ViewContents.ofControls(newControls) ); } )); // Async update button (simulate loading from database) controls.put(5, ViewControl.of( new ItemStack(Material.ENDER_PEARL), clickEvent -> { clickEvent.getPlayer().sendMessage("Loading..."); CompletableFuture> future = CompletableFuture.supplyAsync(() -> { try { Thread.sleep(2000); // Simulate delay } catch (InterruptedException e) { Thread.currentThread().interrupt(); } Map> loaded = new HashMap<>(); loaded.put(10, ViewControl.just(new ItemStack(Material.DIAMOND, 64))); loaded.put(11, ViewControl.just(new ItemStack(Material.EMERALD, 32))); return ViewContents.ofControls(loaded); }); return new ViewAction.UpdateAsync<>(future); } )); return ChestView.builder() .title("Dynamic View") .row(3) .contents(ViewContents.ofControls(controls)) .build(); } public static boolean updateExistingView(Player player, ChestView newView) { // Update view without closing/reopening // Returns false if player isn't viewing a compatible view return BukkitView.updateView(newView, player); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.