8.19.0-SNAPSHOT (API update)

This commit is contained in:
mfnalex 2021-01-02 21:42:34 +01:00
parent 63d21ffb0a
commit 010737db2c
5 changed files with 39 additions and 7 deletions

View File

@ -1,5 +1,8 @@
# Changelog
## 8.19.0
- Improved API for ItemJoin
## 8.18.1
- Improved API

View File

@ -19,7 +19,7 @@ You can use maven to add ChestSort as a dependency to your Spigot-/Bukkit-Plugin
<dependency>
<groupId>de.jeff_media</groupId>
<artifactId>ChestSortAPI</artifactId>
<version>1.0.0</version> <!-- The API version is independent of the ChestSort version -->
<version>1.1.0</version> <!-- The API version is independent of the ChestSort version -->
<scope>compile</scope>
</dependency>
</dependencies>
@ -93,6 +93,31 @@ public void onChestSortEvent(ChestSortEvent event) {
}
```
You can also excempt certain slots / ItemStacks from being sorted using the following methods:
```java
public void setUnmovable(int slot)
public void setUnmovable(ItemStack itemStack)
public void removeUnmovable(int slot)
public void removeUnmovable(ItemStack itemStack)
public boolean isUnmovable(int slot)
public boolean isUnmovable(ItemStack itemStack)
```
For example, to avoid the first item in the player's hotbar from being sorted:
```java
@EventHandler
public void onChestSortEvent(ChestSortEvent event) {
event.setUnmovable(0);
}
```
### Making custom inventories sortable
If you create a new Inventory inside your plugin, you can use the `Sortable` class to tell ChestSort that your custom inventory should be sortable.

View File

@ -9,7 +9,7 @@
<name>ChestSort</name>
<url>https://www.chestsort.de</url>
<description>Automatically sorts your chests!</description>
<version>8.18.1</version>
<version>8.19.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
@ -123,7 +123,7 @@
<dependency>
<groupId>de.jeff_media</groupId>
<artifactId>ChestSortAPI</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -581,11 +581,11 @@ public class ChestSortListener implements Listener {
if (setting.getCurrentDoubleClick(plugin, ChestSortPlayerSetting.DoubleClickType.LEFT_CLICK)
== ChestSortPlayerSetting.DoubleClickType.LEFT_CLICK) {
// Left double click: put everything into destination
plugin.organizer.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory(), false);
plugin.organizer.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory(), false, chestSortEvent);
plugin.organizer.sortInventory(e.getInventory());
} else {
// Left single click: put only matching items into destination
plugin.organizer.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory(), true);
plugin.organizer.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory(), true, chestSortEvent);
}
} else if (e.isRightClick() && setting.rightClick) {

View File

@ -5,6 +5,7 @@ import de.jeff_media.ChestSort.hooks.InventoryPagesHook;
import de.jeff_media.ChestSort.utils.CategoryLinePair;
import de.jeff_media.ChestSort.utils.TypeMatchPositionPair;
import de.jeff_media.ChestSort.utils.Utils;
import de.jeff_media.ChestSortAPI.ChestSortEvent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
@ -520,7 +521,9 @@ public class ChestSortOrganizer {
for (int i = startSlot; i <= endSlot; i++) {
if ((plugin.hookMinepacks && plugin.listener.minepacksHook.isMinepacksBackpack(items[i]))
|| (plugin.hookInventoryPages && inventoryPagesHook.isButton(items[i], i, inv))
|| isOversizedStack(items[i])) {
|| isOversizedStack(items[i])
|| chestSortEvent.isUnmovable(i)
|| chestSortEvent.isUnmovable(items[i])) {
items[i] = null;
unsortableSlots.add(i);
}
@ -669,12 +672,13 @@ public class ChestSortOrganizer {
}
public void stuffPlayerInventoryIntoAnother(PlayerInventory source,
Inventory destination, boolean onlyMatchingStuff) {
Inventory destination, boolean onlyMatchingStuff, ChestSortEvent chestSortEvent) {
boolean destinationIsShulkerBox = destination.getType().name().equalsIgnoreCase("SHULKER_BOX");
Inventory temp = Bukkit.createInventory(null, maxInventorySize);
for (int i = playerInvStartSlot; i <= playerInvEndSlot; i++) {
ItemStack currentItem = source.getItem(i);
if (currentItem == null) continue;
if(chestSortEvent.isUnmovable(i) || chestSortEvent.isUnmovable(currentItem)) continue;
// This prevents Minepacks from being put into Minepacks
/*if(plugin.hookMinepacks && plugin.listener.minepacksHook.isMinepacksBackpack(destination)