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> <name>ChestSort</name>
<url>https://www.chestsort.de</url> <url>https://www.chestsort.de</url>
<description>Allows automatic chest sorting!</description> <description>Allows automatic chest sorting!</description>
<version>13.0.2</version> <version>13.0.3</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
@ -234,13 +234,6 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </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> <dependency>
<groupId>at.pcgamingfreaks</groupId> <groupId>at.pcgamingfreaks</groupId>
<artifactId>Minepacks-API</artifactId> <artifactId>Minepacks-API</artifactId>

View File

@ -28,6 +28,7 @@
package de.jeff_media.chestsort; package de.jeff_media.chestsort;
import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin; 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.AdminCommand;
import de.jeff_media.chestsort.commands.ChestSortCommand; import de.jeff_media.chestsort.commands.ChestSortCommand;
import de.jeff_media.chestsort.commands.InvSortCommand; 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.JeffLib;
import de.jeff_media.jefflib.McVersion; import de.jeff_media.jefflib.McVersion;
import de.jeff_media.jefflib.NBTAPI; import de.jeff_media.jefflib.NBTAPI;
import de.jeff_media.updatechecker.UpdateChecker;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;

View File

@ -2,32 +2,46 @@ package de.jeff_media.chestsort.hooks;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.shampaggon.crackshot.CSUtility;
import de.jeff_media.chestsort.ChestSortPlugin; import de.jeff_media.chestsort.ChestSortPlugin;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class CrackShotHook { public class CrackShotHook {
final ChestSortPlugin plugin; final ChestSortPlugin plugin;
CSUtility crackShotUtility = null; Class<?> csUtilityClass = null;
Object crackShotUtility = null;
Method getWeaponTitle = null;
public CrackShotHook(ChestSortPlugin plugin) { public CrackShotHook(ChestSortPlugin plugin) {
this.plugin=plugin; this.plugin=plugin;
if(plugin.isHookCrackShot()) { if(plugin.isHookCrackShot()) {
crackShotUtility = new CSUtility(); 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"); plugin.getLogger().info("Successfully hooked into CrackShot");
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ignored) {
}
} }
} }
// Will return when not a weapon // Will return when not a weapon
public String getCrackShotWeaponName(ItemStack item) { public String getCrackShotWeaponName(ItemStack item) {
if(crackShotUtility == null || !plugin.isHookCrackShot()) { if(getWeaponTitle == null || !plugin.isHookCrackShot()) {
return null; return null;
} }
// Will be null if not a weapon // Will be null if not a weapon
return crackShotUtility.getWeaponTitle(item); try {
return (String) getWeaponTitle.invoke(crackShotUtility,item);
} catch (InvocationTargetException | IllegalAccessException ignored) {
return null;
}
} }
} }