[Tutorial] [NMS] Yet another NMS tutorial!

Discussion in 'Resources' started by DevilMental, Aug 3, 2014.

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

    DevilMental

    ~
    NMS Tutorial
    ~

    Heeeeeeeeeeeeey my dear friends (have I got any ?),

    I'm DevilMental, 13yrs old and new to this community (I've been here fore like 2weeks).
    And yes, this is another NMS tutorial where everything will be explained from A to Z (french expression, sorry...).

    1. Reflection
    To start with, do you know about Reflection ? If not, I'll explain it to you:
    Let's imagine a class :
    Code:java
    1. public class MyClass{
    2. public String myName;
    3. private String myPassword;
    4.  
    5. public MyClass(String name, String pass){
    6. this.myName = name;
    7. this.myPassword = pass;
    8. }
    9. }
    10.  

    Do you think the "myPassword" is safe, private and accessible only by the class ? PA-THE-TIC! If you want to get a private field, use what the Java developers call "Reflection". Example :
    Code:java
    1. // Import Reflection
    2. // Get the MyClass instance
    3. // -> myClassInstance [I](Is that a simple name ? naaaaaaay)[/I]
    4. try {
    5. Field f = myClassInstance.getClass().getDeclaredField("myPassword");
    6. // Get the myClassInstance's field
    7. f.setAccessible(true);
    8. // Set it accessible
    9. String password = f.get(myClassInstance);
    10. } catch (Exception e) {
    11. e.printStackTrace();
    12. }

    Be careful with reflection, because private field are private for a reason!

    2. NMS, what the heck is that ?
    Let's get back at the NMS thingy; NMS stands for the package net.minecraft.server
    You won't be able to import NMS if you don't include the craftbukkit jar into your project. If your plugin contains, even a line of NMS, will break every version, that's why there are plenty of tutorials/utils/libs about "how not to make your plugin break with NMS through every update" (is that a correct english sentence ?) NMS is like fire : it's dangerous to play with it (sorry, french expression again :D) You can use it on the good side : fireworks, virtual mobs, cool effects, or you can use it on the bad side : crash player, make his minecraft freeze, lag the server, etc... On this tutorial I won't be covering the bad side : it's dangerous and I think prohibited on thie forum.

    See you next time, with the first tutorial on how to disguise a player into a mob.
    Hope you like it, if yes, leave a comment or like my post, and tell me if something is wrong ;)

    ~DevilMental

    RESERVED

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    xTrollxDudex

    A bit brief. Seems like you read the top and suddenly you are at the end without really seeing the body, the content.

    Good work on the good and bad side. It's great to know someone is doing his/her research on the topics.

    Also, general NMS is very difficult to document in a single resource, split it up. It's too broad and there's no single way to use it, therefore, you can't umbrella the subject like that.

    Don't post reflection tutorials, I mean it's great and all, but leave that for a blog post or an offsite Java specific, you should be focusing on features of the API, not on a Java feature.

    I don't think your snippet of code will compile, don't you have to cast it to String? .get(...) returns an Object.

    Otherwise, it seems good so far, I like the voice an enthusiasm. Oh, and welcome to the community, I hope to see you around on the forums more often.
     
    rbrick and Phasesaber like this.
Thread Status:
Not open for further replies.

Share This Page