From 73f361651fb77cc8b74d274b240bfca4c975a084 Mon Sep 17 00:00:00 2001
From: mfnalex <1122571+mfnalex@users.noreply.github.com>
Date: Sun, 14 Jun 2020 20:02:24 +0200
Subject: [PATCH] 8.10.4 release
---
CHANGELOG.md | 3 +++
pom.xml | 2 +-
.../ChestSort/ChestSortOrganizer.java | 23 +++++++++++++------
src/main/resources/plugin.yml | 2 +-
4 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ff473ff..32d2647 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,7 @@
# Changelog
+## 8.10.4
+- Fixed exception when sorting inventories in 1.8 because Inventory.getLocation() did not exist yet
+
## 8.10.3
- Fixed exception when using the left-/right-click hotkey while using PaperMC instead of Spigot
diff --git a/pom.xml b/pom.xml
index 52624af..d05c990 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
JeffChestSort
https://www.chestsort.de
Automatically sorts your chests!
- 8.10.3
+ 8.10.4
jar
diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortOrganizer.java b/src/main/java/de/jeff_media/ChestSort/ChestSortOrganizer.java
index 9eb2a15..361153e 100644
--- a/src/main/java/de/jeff_media/ChestSort/ChestSortOrganizer.java
+++ b/src/main/java/de/jeff_media/ChestSort/ChestSortOrganizer.java
@@ -387,16 +387,25 @@ public class ChestSortOrganizer {
// Sort an inventory only between startSlot and endSlot
void sortInventory(Inventory inv, int startSlot, int endSlot) {
-
- if(inv.getLocation() != null) {
- ChestSortEvent chestSortEvent = new ChestSortEvent(inv);
- chestSortEvent.loc = inv.getLocation();
- Bukkit.getPluginManager().callEvent(chestSortEvent);
- if (chestSortEvent.isCancelled()) {
- return;
+ Class extends Inventory> invClass = inv.getClass();
+ try {
+ if(invClass.getMethod("getLocation", null) != null) {
+ // This whole try/catch fixes MethodNotFoundException when using inv.getLocation in Spigot 1.8.
}
+ if(inv.getLocation() != null) {
+ ChestSortEvent chestSortEvent = new ChestSortEvent(inv);
+ chestSortEvent.loc = inv.getLocation();
+ Bukkit.getPluginManager().callEvent(chestSortEvent);
+ if (chestSortEvent.isCancelled()) {
+ return;
+ }
+ }
+ } catch (NoSuchMethodException | SecurityException | IllegalStateException e) {
+ // TODO Auto-generated catch block
+
}
+
if (plugin.debug) {
System.out.println(" ");
System.out.println(" ");
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 09f78f8..6f9673e 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,6 +1,6 @@
main: de.jeff_media.ChestSort.ChestSortPlugin
name: ChestSort
-version: 8.10.3
+version: 8.10.4
api-version: 1.13
description: Allows automatic chest sorting
author: mfnalex