Solved Help with Reflection!

Discussion in 'Plugin Development' started by Tim_M, Aug 6, 2021.

Thread Status:
Not open for further replies.
  1. Offline

    Tim_M

    I want my plugin to work with all minecraft version from 1.8.9 to 1.17. I have "Reflected" all of my code. But there's one bit where the code changes between versions. Can someone either give a documentation, or help me?

    The code I need to reflect.
    Code:
    NBTTagCompound item = initiliaze.blabla...;
    CraftItemStack.getBukkitCopy(net.minecraft.server.ItemStack.createStack(item));
    
    The code that works in 1.8-1.10.
    Code:
    Reflect.CraftItemStack.getMethod("asBukkitCopy", Reflect.ItemStack).invoke(item.getClass(), Reflect.ItemStack.getMethod("createStack", Reflect.NBTTagCompound).invoke(item, item));
    
    The code that works in 1.11-1.12.
    Code:
    Constructor<?> createStack = Reflect.ItemStack.getConstructor(Reflect.NBTTagCompound);
    Reflect.CraftItemStack.getMethod("asBukkitCopy", Reflect.ItemStack).invoke(createStack.newInstance(item));
    
    Edit: The issue is to now to get it to work in 1.13 and onwards.
     
  2. Online

    timtower Administrator Administrator Moderator

    @Tim_M Do a version check?
     
  3. Offline

    Tim_M

    Yes I do:
    Code:
    if(version.contains("1.8")||version.contains("1.9")||version.contains("1.10"))
    
    Code:
    else if(version.contains("1.11")||version.contains("1.12"))
    
    The problem is finding a way to make an ItemStack from an NBTTagCompound in 1.13 (the code in 1.11 and 1.12 has been changed in 1.13 and doesn't work)

    EDIT: Issue solved! Turns out the constructor was just made invisible for some reason... Setting it accessible fixed the issue! Marking solved.
     
    Last edited: Aug 8, 2021
Thread Status:
Not open for further replies.

Share This Page