io.github.bakedlibs.dough.items.nms.ItemNameAdapter17 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dough-api Show documentation
Show all versions of dough-api Show documentation
This is the complete API of dough.
package io.github.bakedlibs.dough.items.nms;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.inventory.ItemStack;
import io.github.bakedlibs.dough.reflection.ReflectionUtils;
import io.github.bakedlibs.dough.versions.UnknownServerVersionException;
class ItemNameAdapter17 implements ItemNameAdapter {
private final Method getCopy;
private final Method getName;
private final Method toString;
ItemNameAdapter17() throws NoSuchMethodException, SecurityException, ClassNotFoundException, UnknownServerVersionException {
super();
getCopy = ReflectionUtils.getOBCClass("inventory.CraftItemStack").getMethod("asNMSCopy", ItemStack.class);
getName = ReflectionUtils.getMethod(ReflectionUtils.getNetMinecraftClass("world.item.ItemStack"), "getName");
toString = ReflectionUtils.getMethod(ReflectionUtils.getNetMinecraftClass("network.chat.IChatBaseComponent"), "getString");
}
@Override
@ParametersAreNonnullByDefault
public String getName(ItemStack item) throws IllegalAccessException, InvocationTargetException {
Object instance = getCopy.invoke(null, item);
return (String) toString.invoke(getName.invoke(instance));
}
}