Tool
A Tool class is an abstraction introduced by the library to represent an item in a toolbar. A tool could represent
many things. For example:
- A moderation tool: banning/kicking/muting/warning a certain individual upon an entity interaction.
- A builder tool: replacing/selecting a collection of blocks, or to undo/redo a set of actions.
- A gameplay tool: opening a quest/shop/auction menu interface.
The tool abstraction accepts three arguments:
- A unique string - to identify the tool (the uniqueness is on a per-toolbar basis, so it is not global)
- An item (
ItemStack) - to place the tool at the player’s hotbar. - A slot (
ItemSlot) - to identify where the tool will be placed at the player’s hotbar.
Creation
Section titled “Creation”A Tool could be constructed in two ways, depending on your model and preference: directly or a mutable builder.
Directly
Section titled “Directly”If all the data is available upfront, this approach could be used to construct a Tool.
public Tool constructGunTool() { return Tool.of( "gun", new ItemStack(Material.STICK), ToolAction.of( PlayerInteractEvent.class, (toolbar, event) -> event.getPlayer().sendMessage("You shot with a gun!") ), ItemSlot.undefined() // the library will place the tool at the most suitable slot (e.g. at index 0) );}Builder
Section titled “Builder”If the data are gathered iteratively or across different parts of your application, then the builder approach could be
used to construct a Tool.
public Tool constructGunTool() { return Tool.newBuilder("gun") .setToolAction( ToolAction.of( PlayerInteractEvent.class, (toolbar, event) -> event.getPlayer().sendMessage("You shot with a gun!") ) ) .build(new ItemStack(Material.STICK));}