31 lines
927 B
Java
31 lines
927 B
Java
package me.konsolas.aac.util.general;
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Method;
|
|
import org.bukkit.entity.Player;
|
|
|
|
public class ItemUseUtil {
|
|
private static Method getHandleMethod;
|
|
private static Field activeItemField;
|
|
|
|
public static boolean isUsingItem(Player player) {
|
|
try {
|
|
if (getHandleMethod == null) {
|
|
getHandleMethod = player.getClass().getDeclaredMethod("getHandle");
|
|
getHandleMethod.setAccessible(true);
|
|
}
|
|
|
|
Object entityPlayer = getHandleMethod.invoke(player);
|
|
if (activeItemField == null) {
|
|
activeItemField = entityPlayer.getClass().getSuperclass().getSuperclass().getDeclaredField("bo");
|
|
activeItemField.setAccessible(true);
|
|
}
|
|
|
|
return activeItemField.get(entityPlayer) != null;
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return false;
|
|
}
|
|
}
|
|
}
|