From e04f39ad48baadc80b29bd6c873426c5f2fa5b92 Mon Sep 17 00:00:00 2001 From: ceze88 Date: Wed, 17 Jul 2024 17:39:13 +0200 Subject: [PATCH] Remove CLI API dependency to fix build failures --- pom.xml | 7 -- .../conversion/hooks/CMIHook.java | 64 +++++++++++++------ 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/pom.xml b/pom.xml index 8df2250..a619b12 100644 --- a/pom.xml +++ b/pom.xml @@ -175,12 +175,5 @@ 2.20.1 provided - - - CMI-API - CMI-API - 9.7.4.1 - provided - diff --git a/src/main/java/com/craftaro/ultimatekits/conversion/hooks/CMIHook.java b/src/main/java/com/craftaro/ultimatekits/conversion/hooks/CMIHook.java index b44ea60..8c03f6b 100644 --- a/src/main/java/com/craftaro/ultimatekits/conversion/hooks/CMIHook.java +++ b/src/main/java/com/craftaro/ultimatekits/conversion/hooks/CMIHook.java @@ -1,44 +1,70 @@ package com.craftaro.ultimatekits.conversion.hooks; -import com.Zrips.CMI.CMI; -import com.Zrips.CMI.Modules.Kits.Kit; import com.craftaro.ultimatekits.conversion.ConversionKit; import com.craftaro.ultimatekits.conversion.Hook; import com.craftaro.ultimatekits.kit.type.KitContentCommand; import org.bukkit.Bukkit; import org.bukkit.inventory.ItemStack; +import java.lang.reflect.Method; import java.util.*; public class CMIHook implements Hook { - private final CMI cmi; + private Object cmi; + private Method getKitsManagerMethod; + private Method getKitMapMethod; + private Method getKitMethod; + private Method getItemsMethod; + private Method getCommandsMethod; + private Method getDelayMethod; public CMIHook() { - this.cmi = (CMI) Bukkit.getPluginManager().getPlugin("CMI"); + try { + Class cmiClass = Class.forName("com.Zrips.CMI.CMI"); + this.cmi = Bukkit.getPluginManager().getPlugin("CMI"); + Class kitsManagerClass = Class.forName("com.Zrips.CMI.Modules.Kits.KitsManager"); + this.getKitsManagerMethod = cmiClass.getMethod("getKitsManager"); + Object kitsManager = this.getKitsManagerMethod.invoke(this.cmi); + this.getKitMapMethod = kitsManagerClass.getMethod("getKitMap"); + Class kitClass = Class.forName("com.Zrips.CMI.Modules.Kits.Kit"); + this.getKitMethod = kitsManagerClass.getMethod("getKit", String.class, boolean.class); + this.getItemsMethod = kitClass.getMethod("getItems"); + this.getCommandsMethod = kitClass.getMethod("getCommands"); + this.getDelayMethod = kitClass.getMethod("getDelay"); + } catch (Exception e) { + e.printStackTrace(); + } } @Override public Map getKits() { Map kits = new LinkedHashMap<>(); - for (String kitName : this.cmi.getKitsManager().getKitMap().keySet()) { - Set stacks = new HashSet<>(); - try { - Kit kit = this.cmi.getKitsManager().getKit(kitName, true); - - for (ItemStack item : kit.getItems()) { - if (item != null) { - stacks.add(item); + try { + Object kitsManager = this.getKitsManagerMethod.invoke(this.cmi); + Map kitMap = (Map) this.getKitMapMethod.invoke(kitsManager); + for (String kitName : kitMap.keySet()) { + Set stacks = new HashSet<>(); + try { + Object kit = this.getKitMethod.invoke(kitsManager, kitName, true); + List items = (List) this.getItemsMethod.invoke(kit); + for (ItemStack item : items) { + if (item != null) { + stacks.add(item); + } } + List commands = (List) this.getCommandsMethod.invoke(kit); + for (String command : commands) { + stacks.add(new KitContentCommand(command).getItemForDisplay()); + } + long delay = (long) this.getDelayMethod.invoke(kit); + kits.put(kitName, new ConversionKit(stacks, delay)); + } catch (Exception ex) { + ex.printStackTrace(); } - - for (String command : kit.getCommands()) { - stacks.add(new KitContentCommand(command).getItemForDisplay()); - } - } catch (Exception ex) { - ex.printStackTrace(); } - kits.put(kitName, new ConversionKit(stacks, this.cmi.getKitsManager().getKit(kitName, true).getDelay())); + } catch (Exception e) { + e.printStackTrace(); } return kits; }