From 1afec3b34e504587afe569546caf5291f004eac1 Mon Sep 17 00:00:00 2001
From: mfnalex <1122571+mfnalex@users.noreply.github.com>
Date: Mon, 21 Mar 2022 10:47:44 +0100
Subject: [PATCH] removed crackshot dependency, fixes #152
---
pom.xml | 9 +--
.../jeff_media/chestsort/ChestSortPlugin.java | 2 +-
.../chestsort/hooks/CrackShotHook.java | 66 +++++++++++--------
3 files changed, 42 insertions(+), 35 deletions(-)
diff --git a/pom.xml b/pom.xml
index 0e83094..e83db70 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
ChestSort
https://www.chestsort.de
Allows automatic chest sorting!
- 13.0.2
+ 13.0.3
jar
@@ -234,13 +234,6 @@
compile
-
-
at.pcgamingfreaks
Minepacks-API
diff --git a/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java b/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java
index 7367a1d..0defd13 100644
--- a/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java
+++ b/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java
@@ -28,6 +28,7 @@
package de.jeff_media.chestsort;
import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin;
+import com.jeff_media.updatechecker.UpdateChecker;
import de.jeff_media.chestsort.commands.AdminCommand;
import de.jeff_media.chestsort.commands.ChestSortCommand;
import de.jeff_media.chestsort.commands.InvSortCommand;
@@ -53,7 +54,6 @@ import de.jeff_media.chestsort.utils.Utils;
import de.jeff_media.jefflib.JeffLib;
import de.jeff_media.jefflib.McVersion;
import de.jeff_media.jefflib.NBTAPI;
-import de.jeff_media.updatechecker.UpdateChecker;
import io.papermc.lib.PaperLib;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
diff --git a/src/main/java/de/jeff_media/chestsort/hooks/CrackShotHook.java b/src/main/java/de/jeff_media/chestsort/hooks/CrackShotHook.java
index 5ddf2aa..c0488b0 100644
--- a/src/main/java/de/jeff_media/chestsort/hooks/CrackShotHook.java
+++ b/src/main/java/de/jeff_media/chestsort/hooks/CrackShotHook.java
@@ -2,32 +2,46 @@ package de.jeff_media.chestsort.hooks;
import org.bukkit.inventory.ItemStack;
-import com.shampaggon.crackshot.CSUtility;
-
import de.jeff_media.chestsort.ChestSortPlugin;
-public class CrackShotHook {
-
- final ChestSortPlugin plugin;
- CSUtility crackShotUtility = null;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
- public CrackShotHook(ChestSortPlugin plugin) {
- this.plugin=plugin;
-
- if(plugin.isHookCrackShot()) {
- crackShotUtility = new CSUtility();
- plugin.getLogger().info("Successfully hooked into CrackShot");
- }
- }
-
- // Will return when not a weapon
- public String getCrackShotWeaponName(ItemStack item) {
- if(crackShotUtility == null || !plugin.isHookCrackShot()) {
- return null;
- }
-
- // Will be null if not a weapon
- return crackShotUtility.getWeaponTitle(item);
- }
-
-}
+public class CrackShotHook {
+
+ final ChestSortPlugin plugin;
+ Class> csUtilityClass = null;
+ Object crackShotUtility = null;
+ Method getWeaponTitle = null;
+
+ public CrackShotHook(ChestSortPlugin plugin) {
+ this.plugin=plugin;
+
+ if(plugin.isHookCrackShot()) {
+ try {
+ csUtilityClass = Class.forName("com.shampaggon.crackshot.CSUtility");
+ crackShotUtility = csUtilityClass.getConstructor().newInstance();
+ getWeaponTitle = csUtilityClass.getMethod("getWeaponTitle", ItemStack.class);
+ plugin.getLogger().info("Successfully hooked into CrackShot");
+ } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ignored) {
+
+ }
+
+ }
+ }
+
+ // Will return when not a weapon
+ public String getCrackShotWeaponName(ItemStack item) {
+ if(getWeaponTitle == null || !plugin.isHookCrackShot()) {
+ return null;
+ }
+
+ // Will be null if not a weapon
+ try {
+ return (String) getWeaponTitle.invoke(crackShotUtility,item);
+ } catch (InvocationTargetException | IllegalAccessException ignored) {
+ return null;
+ }
+ }
+
+}
\ No newline at end of file