mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-22 18:26:12 +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>
|
<version>2.20.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>CMI-API</groupId>
|
|
||||||
<artifactId>CMI-API</artifactId>
|
|
||||||
<version>9.7.4.1</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,44 +1,70 @@
|
|||||||
package com.craftaro.ultimatekits.conversion.hooks;
|
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.ConversionKit;
|
||||||
import com.craftaro.ultimatekits.conversion.Hook;
|
import com.craftaro.ultimatekits.conversion.Hook;
|
||||||
import com.craftaro.ultimatekits.kit.type.KitContentCommand;
|
import com.craftaro.ultimatekits.kit.type.KitContentCommand;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class CMIHook implements Hook {
|
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() {
|
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
|
@Override
|
||||||
public Map<String, ConversionKit> getKits() {
|
public Map<String, ConversionKit> getKits() {
|
||||||
Map<String, ConversionKit> kits = new LinkedHashMap<>();
|
Map<String, ConversionKit> kits = new LinkedHashMap<>();
|
||||||
for (String kitName : this.cmi.getKitsManager().getKitMap().keySet()) {
|
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<>();
|
Set<ItemStack> stacks = new HashSet<>();
|
||||||
try {
|
try {
|
||||||
Kit kit = this.cmi.getKitsManager().getKit(kitName, true);
|
Object kit = this.getKitMethod.invoke(kitsManager, kitName, true);
|
||||||
|
List<ItemStack> items = (List<ItemStack>) this.getItemsMethod.invoke(kit);
|
||||||
for (ItemStack item : kit.getItems()) {
|
for (ItemStack item : items) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
stacks.add(item);
|
stacks.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
List<String> commands = (List<String>) this.getCommandsMethod.invoke(kit);
|
||||||
for (String command : kit.getCommands()) {
|
for (String command : commands) {
|
||||||
stacks.add(new KitContentCommand(command).getItemForDisplay());
|
stacks.add(new KitContentCommand(command).getItemForDisplay());
|
||||||
}
|
}
|
||||||
|
long delay = (long) this.getDelayMethod.invoke(kit);
|
||||||
|
kits.put(kitName, new ConversionKit(stacks, delay));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
kits.put(kitName, new ConversionKit(stacks, this.cmi.getKitsManager().getKit(kitName, true).getDelay()));
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return kits;
|
return kits;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user