Some more questions...

Discussion in 'Plugin Development' started by bigbeno37, Jul 14, 2012.

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

    bigbeno37

    Hey there!

    I am trying to run a plugin and when it loads up, it is fine. However, whenever a player joins, it fails to execute the method which has the PlayerJoinEvent with a NullPointerException. Next, I try to type in /shlocko, and it results in once again a NullPointerException. Could someone please look over my code and tell me what is wrong? I have all the info below:

    ShlockoCraftCore:
    com.shlockocraft.bigbeno37.ShlockoCraftCore:
    ShlockoCraftCore.java: http://pastie.org/4254628

    com.shlockocraft.bigbeno37.ShlockoCraftCore.Data:
    ShlockoCraftAPI: http://pastie.org/4254631
    ShlockoCraftVAR: http://pastie.org/4254632

    com.shlockocraft.bigbeno37.ShlockoCraftCore.Listener:
    ShlockoCraftListener: http://pastie.org/4254636
    ShlockoCraftExecutor: http://pastie.org/4254635

    server.log: http://pastie.org/4254641

    Also, could someone please tell me if it is possible to convert a String to a Material? Because I want this plugin to be configurable and thus in the config.yml file I want to include 'MaterialName'. I then want to read the name off of the config.yml file and then put it in the 'onBlockTouchProtect' method at line 66 in ShlockoCraftListener.
     
  2. Inside ShlockoCraftExecutor add:
    var = new ShlockoCraftVAR();

    Inside ShlockoCraftListener you're creating an entirely new ShlockCraftVAR and this MOTD is null.
    To fix this add a getter to your ShlockoCraftCore to get the ShlockCraftVAR inside that class.

    EDIT: You're constantly making new ShlockoCraftVAR's. But I suspect you want a single ShlockoCraftVAR to use in your entire project. You can do this by making the variables inside the ShlockoCraftVAR static.
     
  3. Offline

    bigbeno37

    Okay, so, two questions.

    1) What is a getter and how do I use it?

    2) By making the variables inside VAR static, what will that accomplish?

    Sorry if these questions seem noobish, but I really don't understand what static means, and I have watched several videos about it. Please answer

    I fixed the errors by making all the variables static. Thanks for that.

    Still, I have some questions:
    1) Does static mean that whenever it changes, EVERYTHING connected to it changes to its new value? Or that when it changes, it changes globally?

    2) What is a getter and what is a setter?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  4. Offline

    EnvisionRed

    Static means that there is one instance of the variable in existence. So you can call it in other classes, etc. etc.
     
    -_Husky_- likes this.
  5. A static variable is a variable that is the same for every single instance of the object, so even though you make several ShlockoCraftVAR objects named var, they all share the same static variables, so changing it in one var changes it in all the var's.

    a getter and a setter is convention used in Java to get variables inside a class. Because the convention says that you should keep most if not all the variables in a certain class private, but that means you can't directly call them, that's why you make methods to get them, these are mostly named getters and setters. getters most of the times just return the variable and setters set the variable.
     
Thread Status:
Not open for further replies.

Share This Page