mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-24 17:39:30 +00:00
refactor(bukkit): 优化物品操作反射机制
- 使用 Reflections 类中已有的 method$NonNullList$set 方法替代动态获取的 set 方法 - 移除冗余的异常捕获 NoSuchMethodException- 新增 NonNullList 相关的类和方法引用
This commit is contained in:
@@ -25,10 +25,9 @@ public class ItemUtils {
|
||||
.get(nmsInventory$getInventory);
|
||||
Object nmsItemStack = Reflections.method$CraftItemStack$asNMSCopy
|
||||
.invoke(null, itemStack);
|
||||
nmsInventory$items.getClass()
|
||||
.getMethod("set", int.class, Object.class)
|
||||
Reflections.method$NonNullList$set
|
||||
.invoke(nmsInventory$items, slot, nmsItemStack);
|
||||
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||
} catch (InvocationTargetException | IllegalAccessException e) {
|
||||
CraftEngine.instance().logger().warn("Failed to set item", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3916,4 +3916,19 @@ public class Reflections {
|
||||
INVENTORY$ITEMS
|
||||
)
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$NonNullList = requireNonNull(
|
||||
ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass("core.NonNullList")
|
||||
)
|
||||
);
|
||||
|
||||
public static final Method method$NonNullList$set = requireNonNull(
|
||||
ReflectionUtils.getMethod(
|
||||
clazz$NonNullList,
|
||||
Object.class,
|
||||
int.class,
|
||||
Object.class
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user