Sample plugin provides a basic configuration for plugin usage in the SerenityJS software.
npm install chest-formchest-form plugin to your SerenityJS server's plugins directory.
chest-form features in your own plugins!
bash
#npm
npm install chest-form
#yarn
yarn add chest-form
#bun
bun add chest-form
`
3. Import the Plugin Typings: In your plugin's main file, import the ChestFormPlugin class.
`typescript
import type { ChestFormPlugin } from "chest-form";
`
4. Resolve the Plugin Instance: Once your plugin is initialized, resolve the ChestFormPlugin instance to use its features.
`typescript
import { Plugin } from "@serenityjs/plugins";
import type { ChestFormPlugin } from "chest-form";
class MyPlugin extends Plugin {
public onInitialize(): void {
// The resolve method fetches the ChestFormPlugin instance
// And we use the ChestFormPlugin type to ensure type safety
const { ChestForm } = this.resolve("chest-form")!; // Notice the use of ! can be unsafe if the plugin is not loaded correctly
}
}
`
API Reference
$3
The ChestForm class provides methods to create and manage forms similar to the FormUI system, but using the single or double chest UI.
> Example Usage
`typescript
// Create a new ChestForm instance
const form = new ChestForm("Chest Form");
// Create a new ItemStack, and add it to a button
form.button(11, new ItemStack("minecraft:diamond"));
form.button(13, new ItemStack("minecraft:gold_ingot"));
form.button(15, new ItemStack("minecraft:iron_ingot"));
// Show the form to the player
form.show(origin, (index) => {
// Handle the button click
origin.sendMessage(You clicked button at index: ${index});
});
``