https://github.com/tgross03/interaction-api
A Spigot API for managing interactions with items.
https://github.com/tgross03/interaction-api
api framework java minecraft spigot
Last synced: about 2 months ago
JSON representation
A Spigot API for managing interactions with items.
- Host: GitHub
- URL: https://github.com/tgross03/interaction-api
- Owner: tgross03
- License: mit
- Created: 2024-10-01T00:30:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-03T23:57:08.000Z (over 1 year ago)
- Last Synced: 2025-04-09T22:45:12.400Z (12 months ago)
- Topics: api, framework, java, minecraft, spigot
- Language: Java
- Homepage: https://central.sonatype.com/artifact/dev.edgetom/interaction-api
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README


# Interaction-API
A Spigot API for managing interactions with items.
> [!WARNING]
> At the moment the API is designed and tested for Spigot version `1.19.4`!
> Other versions will be usable in the future.
## Include the API in your project
### Maven (Recommended)
You can include the package as a dependency in Maven.
For that you have to include the following entry in your `pom.xml` in the surrounding
` ... `:
```xml
dev.edgetom
interaction-api
VERSION
```
Replace the placeholder `VERSION` with the version you want to use. You can find the all versions of
the API in the [Maven Central Repository](https://central.sonatype.com/artifact/dev.edgetom/interaction-api).
### Gradle
Alternatively you can include the API via Gradle:
```Gradle
implementation group: 'dev.edgetom', name: 'interaction-api', version: 'VERSION'
```
Replace the placeholder `VERSION` with the version you want to use. You can find the all versions of
the API in the [Maven Central Repository](https://central.sonatype.com/artifact/dev.edgetom/interaction-api).
## Basic usage example
1. You will need to create an `InteractionManager` which will handle the calls to the Interactions.
There should only be one `InteractionManager` for your project.
Initialize it like this:
```java
InteractionManager interactionManager = new InteractionManager(plugin);
```
2. Create your own Interaction by inheriting from the class `InteractionExecutor `.
For example like this:
```java
// Create a new class with an arbitrary name extending the class InteractionExecutor
public class TestInteraction extends InteractionExecutor {
// Create an constructor for the interaction fitting the use case
public TestInteraction(@NotNull InteractionManager interactionManager, String interactionKey, boolean placeable, ActionClass actionClass) {
super(interactionManager, interactionKey, placeable, actionClass);
}
// Override the execute method, which will be called if a player interacts with an item referencing this interaction
@Override
public void execute(PlayerInteractEvent event, Player player) {
// Send a message to the player who caused the interaction
event.getPlayer().sendMessage("Click!");
}
}
```
3. Initialize the `InteractionExecutor`, create an `ItemStack` and "connect" it to the `InteractionExecutor`.
The following example assumes the usage of an ItemBuilder
```java
TestInteraction testInteraction = new TestInteraction(plugin.getInteractionManager(), "test_interaction", false, ActionClass.RIGHT_CLICK);
// Creating a stick
ItemStack itemStack = new ItemStack(Material.STICK);
// Adding the InteractionExecutor key to the ItemStack. This will make sure that the ItemStack is being assigned to the executor if someone interacts with it
itemStack = testInteraction.addToItem(itemStack);
```
Voilà, the item you just created will now trigger the `TestInteraction#execute()` method and will inform the user of the item of the fact he just clicked with your item.
> [!NOTE]
> Your `ItemStack` has to have a valid `ItemMeta` in order to be connected to the `InteractionExecutor`.
> It is recommended to use a kind of ItemBuilder (like for example [this one](https://github.com/Acquized/ItemBuilder)) to ensure the
> existence of an `ItemMeta`.