Object problems

Discussion in 'Plugin Development' started by Ati_444, Jun 25, 2014.

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

    Ati_444

    So I have a SignManager class :
    Code:java
    1. package me.ati.signsplus;
    2.  
    3. import java.lang.reflect.Array;
    4.  
    5. public class SignManager {
    6.  
    7. private String signType;
    8. private String signPermission;
    9. private String signIdentifier; //E.G. [HEAL] top line of sign
    10. private Array[] lines = new Array[2];
    11.  
    12. /* Getters and Setters */
    13.  
    14. public String getSign1() {
    15. return signType;
    16. }
    17. public void setSign(String sign) {
    18. this.signType = sign;
    19. }
    20. public String getPermission() {
    21. return signPermission;
    22. }
    23. public void setPermission(String permission) {
    24. this.signPermission = permission;
    25. }
    26. public String getIdentifier() {
    27. return signIdentifier;
    28. }
    29. public void setIdentifier(String identifier) {
    30. this.signIdentifier = identifier;
    31. }
    32. public Array[] getLines() {
    33. return lines;
    34. }
    35. public void setLines(Array[] lines) {
    36. this.lines = lines;
    37. }
    38.  
    39. public SignManager(String signType, String identifier, String permission) {
    40. this.signType = signType;
    41. this.signPermission = permission;
    42. this.signIdentifier = identifier;
    43. }
    44. }
    45.  


    And a Heal Class:
    Code:java
    1. package me.ati.signsplus.signs;
    2.  
    3. import me.ati.signsplus.SignManager;
    4.  
    5.  
    6. public class Heal {
    7.  
    8. public SignManager heal = new SignManager("Heal", "#heal", "signsplus.use.heal");
    9. // heal.getIdentifier(); this doesn't work
    10.  
    11. }
    12.  


    I cant access the get methods for the Heal sign in the Heal class. I've looked on Google an YouTube and cant find a solution.

    Thanks in advance.
     
  2. Offline

    felixfritz

    The methods can only be used in other methods or when initializing a variable.

    Code:java
    1. public class Heal {
    2.  
    3. public SignManager heal = new SignManager("Heal", "#heal", "signsplus.use.heal");
    4. String myString = heal.getIdentifier();
    5.  
    6. public void myMethod() {
    7. heal.getIdentifier();
    8. }
    9. }
     
  3. Offline

    mythbusterma

    Learning Java is generally a good first step before starting to program in Bukkit.
     
    Zupsub likes this.
  4. Offline

    Ati_444

    @felizfritz How would I use the setters then, is there a way to do it without the method?

    mythbusterma I am trying to learn Java by using the Bukkit API to make it more enjoyable. I have tried to find a solution to this with Google and YouTube but had no luck. Also bear in mind I don't have a good source to learn Java since I cant buy books on the language.
     
  5. Offline

    mythbusterma

    Ati_444 Perhaps using the Java Trail is a good idea: http://docs.oracle.com/javase/tutorial/java/

    We strongly recommend against using Bukkit to learn Java, as it will only cause you grief. Using Bukkit is something you should do only after you feel comfortable with the language.
     
  6. Offline

    xTrollxDudex

    Ati_444
    The library was made for a reason. It won't be enjoyable to learn java and a 3rd party at the same time once you figure out you weren't able to learn anything. Java is a separate entity from its API and to use an API you need to learn how to use the language it was written in first.
     
Thread Status:
Not open for further replies.

Share This Page