mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-24 17:39:30 +00:00
@@ -1,20 +1,19 @@
|
||||
package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class EnchantmentUtils {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, Integer> toMap(Object itemEnchantments) throws ReflectiveOperationException {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
for (Object2IntMap.Entry<Object> entry : (Set<Object2IntMap.Entry<Object>>) Reflections.method$ItemEnchantments$entrySet.invoke(itemEnchantments)) {
|
||||
Map<Object, Integer> enchantments = (Map<Object, Integer>) Reflections.field$ItemEnchantments$enchantments.get(itemEnchantments);
|
||||
|
||||
for (Map.Entry<Object, Integer> entry : enchantments.entrySet()) {
|
||||
Object holder = entry.getKey();
|
||||
String name = (String) Reflections.method$Holder$getRegisteredName.invoke(holder);
|
||||
int level = entry.getIntValue();
|
||||
int level = entry.getValue();
|
||||
map.put(name, level);
|
||||
}
|
||||
return map;
|
||||
|
||||
@@ -2995,16 +2995,11 @@ public class Reflections {
|
||||
|
||||
public static final Class<?> clazz$ItemEnchantments =
|
||||
ReflectionUtils.getClazz(
|
||||
"world.item.enchantment.ItemEnchantments"
|
||||
BukkitReflectionUtils.assembleMCClass( "world.item.enchantment.ItemEnchantments")
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$Enchantment =
|
||||
ReflectionUtils.getClazz(
|
||||
"world.item.enchantment.Enchantment"
|
||||
);
|
||||
|
||||
public static final Method method$ItemEnchantments$entrySet = Optional.ofNullable(clazz$ItemEnchantments)
|
||||
.map(it -> ReflectionUtils.getMethod(it, new String[] {"entrySet"}))
|
||||
public static final Field field$ItemEnchantments$enchantments = Optional.ofNullable(clazz$ItemEnchantments)
|
||||
.map(it -> ReflectionUtils.getInstanceDeclaredField(it, 0))
|
||||
.orElse(null);
|
||||
|
||||
public static final Field field$Direction$data3d = requireNonNull(
|
||||
|
||||
Reference in New Issue
Block a user