mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-22 10:15:56 +01:00
Remove CLI API dependency to fix build failures
This commit is contained in:
parent
7dd229eee9
commit
e04f39ad48
7
pom.xml
7
pom.xml
@ -175,12 +175,5 @@
|
||||
<version>2.20.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>CMI-API</groupId>
|
||||
<artifactId>CMI-API</artifactId>
|
||||
<version>9.7.4.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -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<String, ConversionKit> getKits() {
|
||||
Map<String, ConversionKit> kits = new LinkedHashMap<>();
|
||||
for (String kitName : this.cmi.getKitsManager().getKitMap().keySet()) {
|
||||
Set<ItemStack> 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<String, Object> kitMap = (Map<String, Object>) this.getKitMapMethod.invoke(kitsManager);
|
||||
for (String kitName : kitMap.keySet()) {
|
||||
Set<ItemStack> stacks = new HashSet<>();
|
||||
try {
|
||||
Object kit = this.getKitMethod.invoke(kitsManager, kitName, true);
|
||||
List<ItemStack> items = (List<ItemStack>) this.getItemsMethod.invoke(kit);
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
stacks.add(item);
|
||||
}
|
||||
}
|
||||
List<String> commands = (List<String>) 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user