Reflection is giving me attitude.

Discussion in 'Plugin Development' started by pie_flavor, Dec 21, 2015.

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

    pie_flavor

    So I am using reflection to make a way to run any Java method from a Minecraft command. I am running into trouble however. Even though my /constructor command functions virtually identically to my /method command, it keeps giving me a NoSuchMethodException even though a method that has the exact same arguments doesn't. Here is my code. Pls halp.
    Also, don't tell me my code is stupid. I know my code is stupid.
     
  2. Offline

    WolfMage1

    Can I just ask, what is the purpose of this? xD, (I ask because I understand things better when I know what it's for)
     
  3. Offline

    pie_flavor

    @WolfMage1 The end goal of this is to have a plugin where you can do anything at all. Basically everything doable with Bukkit, controllable by commands.
     
  4. Offline

    WolfMage1

    Are you sure you entered the method name correctly?
     
  5. Offline

    pie_flavor

    Actually, it was the /constructor command that was giving me attitude. I said /classname ItemStack org.bukkit.inventory.ItemStack, /classname Material org.bukkit.Material, /enum sword Material DIAMOND_SWORD, and then /constructor stack ItemStack sword, at which point it give me a NoSuchMethodException. I also tried the constructor for PotionEffect.
     
  6. Offline

    WolfMage1

    Your String classname returns null, thats the problem
     
    Last edited: Dec 21, 2015
  7. Offline

    pie_flavor

    @WolfMage1 Except it doesn't. I definitely put something there.
     
  8. Offline

    WolfMage1

    yeah ignore that post, I did something wrong xD

    http://prntscr.com/9gy5kd perhaps this might help?
     
  9. Offline

    Tecno_Wizard

    @pie_flavor, can you print out the get methods array to yourself and find out why it isn't matching? I've used reflection with specific method names before and everything must be perfect in order for it to work.

    PS. This is why you are always supposed to avoid reflection unless absolutely necessary. It works perfectly, but can be confusing.
     
    WolfMage1 likes this.
Thread Status:
Not open for further replies.

Share This Page