Reflection

Discussion in 'Plugin Development' started by ZodiacTheories, Jul 29, 2014.

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

    ZodiacTheories

    Hi, so I am looking to work with NMS to do something with my plugin. I haven't really learnt reflection, and I can't seem to find the oracle documentation on it, so if you have any helpful links, can you post them please?

    -Zodiac
     
  2. Offline

    raGan.

  3. Offline

    werter318

    Watch this video, and try doing different things with the things he shows.

    Video
     
  4. Offline

    AoH_Ruthless

  5. Offline

    ZodiacTheories

    AoH_Ruthless werter318 raGan.

    For some reason that wouldn't come up on google.... I will go and read that, before trying to work with NMS, sounds good?
     
  6. Offline

    xTrollxDudex

    Yes. Also, go in slowly, the obfuscation hits you like a fist in the face the first time.
     
  7. Offline

    Double0negative

    Reflection isn't needed to work with NMS and I wouldn't recommend arbitrarily using reflection either.
     
    NathanWolf likes this.
  8. Offline

    Garris0n

    I wish it was only the first time...
     
    Chlorek and xTigerRebornx like this.
  9. Offline

    ZodiacTheories

    Double0negative

    Well, looking at tutorials they seem to use Reflection
     
  10. Offline

    NathanWolf


    I'm going to super-2nd this statement.

    Don't jump into reflection right away- learn NMS first, just build against CB and make your plugin specific to a CB build version.

    Calling NMS or CB methods via reflection will make all your code 10x more complex, and 10x more dangerous. Save this for later, if ever!
     
  11. Offline

    ZodiacTheories

    NathanWolf

    Oh. I thought that reflection and nms was a bit like Bukkit and Java. Seems not. Got any good NMS tutorials?
     
  12. Offline

    Gater12

  13. Offline

    ZodiacTheories

  14. Offline

    xTigerRebornx

  15. Offline

    NathanWolf

    EDIT: What ^^^ he ^^^ said :D


    Ha- nope.... to both, I'm afraid :)

    In a nutshell, "Reflection" means the ability to interrogate and manipulate objects dynamically- meaning you can look at an object at runtime, see what Class it is an instance of, look at that Class to see all of its Fields and Methods- and then access/call those Fields and Methods. It's a very cool feature of Java that those of us with a background in C or other "old school" languages can really appreciate- it just doesn't exist there, at all.

    Most people here use Reflection as a way to, shall we say, sidestep Bukkit's protection layer against calling NMS and Craftbukkit code directly without having to have 5 different versions of their plugins. It can also be useful for calling methods in another plugin if you don't want to statically build against it (I do this for my Factions integration, for instance, because Factions doesn't have a Maven repo and I refuse to statically link).

    Reflection is not a requirement, however, for calling CB or NMS methods.

    If you add CraftBukkit to your build path, you should see that you can now access CraftBukkit classes and some NMS classes (the ones that have been modified and now live in the CraftBukkit source - it's not everything). I think there is some Maven shading "trick" you then have to do so that your code calls the correct methods at runtime, since Bukkit renames everything with a version identifier.

    I'm afraid I'm not going to be much more help here as I don't do this myself- but I think that's the general idea, and maybe someone else can point you in the right direction or provide a tutorial.
     
Thread Status:
Not open for further replies.

Share This Page