[NOW WORKING] Using NMS and OBC Without Your Plugins Breaking [No Reflection Involved]

Discussion in 'Resources' started by BungeeTheCookie, Apr 18, 2014.

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

    BungeeTheCookie

    Code:
    if(VerisonHandler.is1_7_2()){
    //1.7.2 NMS
    }else if(VersionHandler.is1_7_5()){
    //1.7.5 NMS
    }
    
    In order for this to be any use you have to use reflection or have multiple craftbukkits in your build path. bigteddy98
     
  2. Offline

    bigteddy98

    Yeah, I know.
     
  3. Offline

    TigerHix

    BungeeTheCookie The problem is, I can have multiple CraftBukkit, but users won't..

    Like if you imported 1.7.2 NMS class, and the plugin is loaded by CraftBukkit 1.6.4, no matter are you using an if/else statement, the plugin simply crashed because you CraftBukkit will return a NoClassDefFoundError!..
     
  4. Offline

    Deleted user

    TigerHix
    I thought something like that would happen, because as soon as the class loads, it would try to do that.
    A (possible?) solution would be to have all Versioned NMS in their own classes, and initialize classes (no static methods) when needed.
    It'd be very clunky, though. Reflection ftw
     
    TigerHix likes this.
  5. Offline

    BungeeTheCookie

    Why would you get the NoClassDefFoundError even if you decide to not use an import and use net.minecraft.server.v1_7_1R.Class?
     
  6. Offline

    ccrama

    BungeeTheCookie if the class you call contains any mention of a not found class, it will automatically fail. The way I worked around this was make three classes for each of the versions I was working with, and put the if statement before I call the classes, then call the one that matches the version.
     
    TigerHix likes this.
  7. Offline

    TigerHix

    BungeeTheCookie I beg u haven't tried yourself. Refers to ccrama's explanation.
    In conclusion, this class doesn't really does what you stated in the title..
     
    ccrama likes this.
  8. Offline

    ccrama

    BungeeTheCookie Also the class won't work with every 1.7 version, as there are three different versions of NMS for 1.7. I edited the code as so so it would work:
    Code:java
    1. public static boolean isR1(){
    2. if(Bukkit.getServer().getClass().getPackage().getName().contains("R1")){
    3. return true;
    4. }
    5. return false;
    6. }
    7.  


    That way you can have support for each version of NMS. Using your class won't work if you directly refer to NMS on different versions of 1.7.
     
  9. Offline

    BungeeTheCookie

    ccrama
    Ok thanks! Could you provide me an example of using three different classes for the initilization so I can put it in my thread and not mislead people?

    TigerHix
    I have failed your mission. Don't worry, I will find a solution! COOKIE POWA
     
    TigerHix likes this.
  10. Offline

    bigteddy98

    As we have all seen now this code is not going to work without reflection, maybe you should change the title and remove the [No Reflection Involved] part ;)
     
  11. Offline

    BungeeTheCookie

  12. Offline

    au2001

    BungeeTheCookie
    Instead of :
    Code:java
    1. public static boolean is1_2_5(){
    2. if(Bukkit.getVersion().contains("1.2.5")){
    3. return true;
    4. }
    5. return false;
    6. }

    You should do :
    Code:java
    1. public static boolean is1_2_5(){
    2. return Bukkit.getVersion().contains("1.2.5");
    3. }
     
  13. Offline

    raGan.

    What exactly are the benefits of using this over reflection?
     
  14. Offline

    BungeeTheCookie

    1. People who are not experts at reflection, like me, would actually find this beneficial. It saves them the time from learning all of the things about reflection. People would use this for making private plugins mostly, and if they are smart enough to use NMS, they are smart enough to update it when a new CraftBukkit version comes out.

    2. Reflection reflects light, which can darken your room, making it hard to code because you are thinking Mini Godzilla has teamed up with The Boogie Man and are going to come and destroy you in the dark. Thus, reflection should be abolished for all of Eternity.
     
  15. Offline

    raGan.

    Thanks for enlightenment. (hue)
     
  16. Offline

    RawCode

    [NOW WORKING]

    thx god you understood that, only 30 more posts was required for this...
     
  17. Offline

    BungeeTheCookie

    @ranGan.
    Any time.

    RawCode
    Lolz
     
Thread Status:
Not open for further replies.

Share This Page