removed crackshot dependency, fixes #152

This commit is contained in:
mfnalex 2022-03-21 10:47:44 +01:00
parent 31cc62774b
commit 1afec3b34e
3 changed files with 42 additions and 35 deletions

View File

@ -9,7 +9,7 @@
<name>ChestSort</name>
<url>https://www.chestsort.de</url>
<description>Allows automatic chest sorting!</description>
<version>13.0.2</version>
<version>13.0.3</version>
<packaging>jar</packaging>
<properties>
@ -234,13 +234,6 @@
<scope>compile</scope>
</dependency>
<!--<dependency>
<groupId>de.jeff_media.thirdparty</groupId>
<artifactId>CrackShot</artifactId>
<version>0.98.11</version>
<scope>provided</scope>
</dependency>--> <!-- not needed anymore, using reflection since crackshot is dead -->
<dependency>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>Minepacks-API</artifactId>

View File

@ -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;

View File

@ -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;
}
}
}