[LIB] Kit 1.0 - "NMS without the stupid!"

Discussion in 'Resources' started by user_43347, May 24, 2013.

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

    user_43347

    What's Kit?
    Kit is the outcome of me having nothing to do on a Friday night. Kit uses Reflection (so it's a bit clunky, but works fine) to access NMS classes and variables, giving you access to NMS abilities not yet adopted by Bukkit. Instead you get easy to use built in classes which will either have a cleaner version of the API, or built in reflection methods to mess around with the NMS variables. It also doesn't break per Bukkit build, unless the variable names changes.

    "I Don't See the Use"
    Want to change the name of a chest? Too bad! Bukkit can't do that, so to do it you would have to use CraftBukkit and import that NMS mess and worry updates and changes. Instead of that, just import Kit and find the correct class. Maybe Kit doesn't have an API for it? Use the built in reflection methods to work around it and the versioning mess.

    Current Classes:
    This list is a bit short, because I've only spent an hour or two on it, it will expand over time and move into areas Bukkit refuses to support.
    1. EntityPlayer
      1. Set/Get Ping
      2. Set/Get Viewing Credits
    2. NBTBase
      1. Byte, byte array, compound, double, end, float, int, int array, list, long, short, and string.
      2. Optimized and cleaned version of Vanilla NBT tag system.
    3. PlayerConnection
      1. Get Connected
      2. Get Disconnected
      3. Get Last Packet
    4. TileEntityBeacon
      1. Set/Get Primary Effect
      2. Set/Get Secondary Effect
      3. Set/Get Levels
    5. TileEntityBeacon & TileEntityBrewingStand & TileEntityChest & TileEntityDispenser & TileEntityFurance
      1. Set/Get Name
    Story Time!
    Code:
    TileEntityChest chest = new TileEntityChest(chestBlock);
    System.out.println("Old Name: " + chest.getName());
    chest.setName("Fabulous!");
    System.out.println("New Name: " + chest.getName());
    Now with Free Shipping!
    The source code is available on Github right here. It only needs Bukkit to compile. I would be thrilled for anyone to do some pull requests and help me expand it, the base is pretty simple but could use some work. If anybody could make a better package matcher, please do (I'll love you forever).

    Added a really horrible version finder that consists of a few for loops, if anybody knows a better way, please tell me!
    On the brighter side, it doesn't break per update (unless obfuscation changes)!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
    JWhy, skipperguy12 and chasechocolate like this.
  2. Which actually does and is the exact reason why versioning was implemented in the first place, to force devs to re-check those stuff and prevent very bad behaviour that could even break the game world.
     
  3. How about using
    Code:java
    1. World get = Bukkit.getWorlds().get(0);
    2. get.getClass().getDeclaredMethod("getHandle", new Class[0]).invoke(get, new Object[0]).getClass().getPackage();

    (Yes you have to put the statement in try{} with catch(){} or finally{})
     
  4. Offline

    user_43347

    So because a few developers refused to pay attention to changes, they decided to version it and cause problems for everyone? Including those who payed attention and made sure the NMS didn't break anything?

    The obfuscation map/Kit will remain updated. And it provides a safer way for developers to use NMS without breaking everything and worrying about versioned packages.
     
  5. I think he meant if you keep it updated you don't need to be flexible about the package naming, because you update it every time that happens anyways and that wouldn't allow running outdated versions.
     
  6. Offline

    FrozenBrain


    Code:
    String pack = Bukkit.getServer().getClass().getPackage().getName();
    String version = pack.substring(pack.lastIndexOf('.') + 1);
     
  7. Nope thats the OBC package not the NMS package, see method provided by me for NMS.
     
  8. Offline

    lol768

    Have you considered submitting pull requests to address these shortcomings you describe in your post?
     
  9. Offline

    user_43347

    Ironically, people have submitted pull requests for allowing renames in the past. They were rejected due to their 16 character limit if I remember correctly.
     
  10. Offline

    lol768

    It'd be great if you could link me to some of these PRs
     
  11. Offline

    user_43347

    I'm trying to find the one that was rejected due to the character limit, but here's another that died off due to bad implementation: https://github.com/Bukkit/Bukkit/pull/754
     
  12. Offline

    lol768

    Would you rather that bad code was present in Bukkit/CraftBukiit, affecting the stability and efficiency of the project?
     
  13. Offline

    Jogy34

    Since there is a method in TileEntityChest for setting the inventory title I am curious as to why you don't just allow the calling of that through CraftChest and possibly the Chest interface in the actual Bukkit API.
     
  14. Offline

    user_43347

    I never said I wanted his to be implemented? I simply was stating why that PR died...
     
Thread Status:
Not open for further replies.

Share This Page