Skip to content

Commit

Permalink
Update version and improve formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMicky-FR committed Apr 25, 2021
1 parent 99ef96d commit 693b73e
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 164 deletions.
26 changes: 0 additions & 26 deletions CHANGELOG.md

This file was deleted.

82 changes: 48 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@
[![JitPack](https://jitpack.io/v/fr.mrmicky/FastInv.svg)](https://jitpack.io/#fr.mrmicky/FastInv)
[![Discord](https://img.shields.io/discord/390919659874156560.svg?colorB=7289da&label=discord&logo=discord&logoColor=white)](https://discord.gg/q9UwaBT)

Small and easy Bukkit inventory API with 1.7 to 1.16 support.
Lightweight and easy-to-use inventory API for Bukkit plugins.

## Features
* Really small (only 2 class with less than 400 lines with the JavaDoc).
* Very small (less than 400 lines of code with the JavaDoc) and no dependencies
* Works with all Bukkit versions from 1.7.10 to 1.16.
* Support custom inventories (size, title and type).
* Easy to use.
* Supports custom inventories (size, title and type).
* Easy to use
* Option to prevent a player from closing the inventory
* You can still access the Bukkit inventory without any problem
* The Bukkit inventory can still be directly used

## How to use
## Installation

### Add FastInv in your plugin

#### Maven
### Maven
```xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
Expand All @@ -36,7 +34,7 @@ Small and easy Bukkit inventory API with 1.7 to 1.16 support.
<relocations>
<relocation>
<pattern>fr.mrmicky.fastinv</pattern>
<!-- Replace with the package of your plugin ! -->
<!-- Replace 'com.yourpackae' with the package of your plugin ! -->
<shadedPattern>com.yourpackage.fastinv</shadedPattern>
</relocation>
</relocations>
Expand All @@ -58,44 +56,57 @@ Small and easy Bukkit inventory API with 1.7 to 1.16 support.
<dependency>
<groupId>fr.mrmicky</groupId>
<artifactId>FastInv</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
<version>3.0.3</version>
</dependency>
</dependencies>
```

#### Gradle
### Gradle
```groovy
plugins {
id 'com.github.johnrengelman.shadow' version '6.1.0'
}
```
```groovy
repositories {
maven { url 'https://jitpack.io' }
}
```
```groovy
dependencies {
compile 'fr.mrmicky:FastInv:3.0.2'
implementation 'fr.mrmicky:FastInv:3.0.3'
}
```
```groovy
shadowJar {
// Replace 'com.yourpackage' with the package of your plugin
relocate 'fr.mrmicky.fastinv', 'com.yourpackage.fastinv'
}
```

#### Manual
### Manual

Just copy `FastInv.java` and `FastInvManager.java` in your plugin. You can also add `ItemBuilder.java`
Just copy `FastInv.java` and `FastInvManager.java` in your plugin.
You can also add `ItemBuilder.java` if you need.

### Use FastInv
## Usage

#### Register FastInv
Before creating inventories, you just need to register your plugin by adding `FastInvManager.register(this);` in your `onEnable` method of your plugin like this:
### Register FastInv
Before creating inventories, you just need to register your plugin by adding `FastInvManager.register(this);` in the `onEnable()` method of your plugin:
```java
@Override
public void onEnable() {
FastInvManager.register(this);
}
```

#### Create an inventory class
### Creating an inventory class

Now you can create an inventory by make a class that extends `FastInv`, and add items in the constructor.
You can also override `onClick`, `onClose` and `onOpen` if you need

Small example inventory:

```java
package fr.mrmicky.fastinv.test;

Expand Down Expand Up @@ -123,11 +134,11 @@ public class ExampleInventory extends FastInv {

// Add a simple item to prevent closing the inventory
setItem(34, new ItemBuilder(Material.BARRIER).name(ChatColor.RED + "Prevent close").build(), e -> {
preventClose = !preventClose;
this.preventClose = !this.preventClose;
});

// Prevent from closing when preventClose is to true
setCloseFilter(p -> preventClose);
setCloseFilter(p -> this.preventClose);
}

@Override
Expand All @@ -152,19 +163,22 @@ Now you can open the inventory:
new ExampleInventory().open(player);
```

#### Create a 'compact' inventory

If you prefer you can create a 'compact' inventory that don't need a full class, but this is not recommended.
### Creating a 'compact' inventory
If you prefer you can create a 'compact' inventory that doesn't require an entire class, but this is not recommended.

```java
FastInv inv = new FastInv(InventoryType.DISPENSER, "Example compact inventory");
FastInv inv = new FastInv(InventoryType.DISPENSER, "Example compact inventory");

inv.setItem(4, new ItemStack(Material.NAME_TAG), e -> e.getWhoClicked().sendMessage("You clicked on the name tag"));
inv.addClickHandler(e -> player.sendMessage("You clicked on slot " + e.getSlot()));
inv.addCloseHandler(e -> player.sendMessage(ChatColor.YELLOW + "Inventory closed"));
inv.open(player);
inv.setItem(4, new ItemStack(Material.NAME_TAG), e -> e.getWhoClicked().sendMessage("You clicked on the name tag"));
inv.addClickHandler(e -> player.sendMessage("You clicked on slot " + e.getSlot()));
inv.addCloseHandler(e -> player.sendMessage(ChatColor.YELLOW + "Inventory closed"));
inv.open(player);
```

## Changelog

[Changelog](CHANGELOG.md)
### Get the FastInv instance
You can easily get the FastInv instance from a Bukkit inventory with the holder:
```java
if (inventory.getHolder() instanceof FastInv) {
FastInv fastInv = (FastInv) inventory.getHolder();
}
```
38 changes: 19 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,38 @@

<groupId>fr.mrmicky</groupId>
<artifactId>fastinv</artifactId>
<version>3.0.2</version>
<version>3.0.3</version>

<name>FastInv</name>
<description>Lightweight and easy-to-use inventory API for Bukkit plugins.</description>
<url>https://github.com/MrMicky-FR/FastInv</url>
<description>Small and easy Bukkit inventory API with 1.7 to 1.16 support</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -30,20 +46,4 @@
</plugins>
</build>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit 693b73e

Please sign in to comment.