Solved Sethome bug

Discussion in 'Plugin Development' started by Aragone, Jun 7, 2019.

  1. Online

    Aragone

    Hello,

    I don't know why but I have some errors with this plugin when I want to execute /sethome command... It's a home plugin with a MySql database, to keep players home's locations.

    Thanks for your help !

    Just for you :
    La commande est /sethome = Unknow command.
    Votre home a bien été posé = Your home is now set.
     

    Attached Files:

  2. Offline

    KarimAKL

    @Aragone 'sql' is null in your 'CommandHome' class.
     
  3. Online

    Aragone

    How can I resolve this problem ? Sorry I'm a beginner
     
  4. Offline

    KarimAKL

    @Aragone Give it an instance of your 'SqlHomePlugin' class.
     
  5. Online

    Aragone

    I'm sorry I don't know how... I don't know the syntax for this
     
  6. Offline

    KarimAKL

    @Aragone
    Change this:
    Code:Java
    1. public SqlHomePlugin sql;

    to something like this:
    Code:Java
    1. public SqlHomePlugin sql = /*SqlHomePlugin instance*/;

    EDIT: I also recommend you make the MySQL table have a yaw and a pitch so you can choose where the player is looking when using '/home'
     
  7. Online

    Aragone

    I try but... What's SqlHomePlugin instance ?

    I tried public SqlHomePlugin sql = new SqlHomePlugin(connection()) but it doesn't work

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

    KarimAKL

    @Aragone Make a constructor for your CommandHome where you pass the instance of SqlHomePlugin.
     
  9. Online

    Aragone

    And what can I put in it ?
     

    Attached Files:

  10. Offline

    KarimAKL

    Don't make a constructor for your SqlHomePlugin.
     
  11. Online

    Aragone

    Can you just show me what are you thinking ? Because I'm really stuck.

    I think I understand the problem but I don't know the syntax to resolve it.
     
  12. Offline

    KarimAKL

    @Aragone
    Code:Java
    1. private SqlHomePlugin sql;
    2.  
    3. // This is a CommandHome constructor
    4. // It has a parameter of type SqlHomePlugin
    5. // We give it the SqlHomePlugin instance
    6. // when we initialize CommandHome
    7. public CommandHome(SqlHomePlugin sql) {
    8. // We now set our variable to the
    9. // instance that was passed to this object
    10. this.sql = sql;
    11. }
     
  13. Online

    Aragone

    Thanks for your answer. I have now this error : Implicit super constructor commandHome is undefined in my SqlHomePlugin class. I had too to add 'sql' in my main class in the getCommand instruction.
     

    Attached Files:

  14. Offline

    KarimAKL

    @Aragone Why does SqlHomePlugin extend CommandHome? Also, don't create two instances of your CommandHome class when you register the commands, make a variable with an instance and pass the variable when you register the commands.
     
  15. Online

    Aragone

    SqlHomePlugin extend CommandHome because of the public static double x, y and z. I put them into the method 'createAccount' 'addX' 'addY' and 'addZ'

    How can I do what you said ?
     
  16. Offline

    KarimAKL

    @Aragone If they are static you can just do 'CommandHome.x' etc, no need to extend CommandHome.
     
  17. Online

    Aragone

    Ok now I have a problem with my database. There is a problem with sql.createAccount(player).

    EDIT : Erreur de synthaxe = Syntax error
     

    Attached Files:

  18. Offline

    KarimAKL

    @Aragone I would guess that has to do with your SQL Statement. It's been a while since i've worked with SQL, so i can't really help you there.
     
  19. Online

    Aragone

    I understood the problem.

    Thank you very much man !
     
    KarimAKL likes this.

Share This Page