help with MySQL database

Discussion in 'Plugin Development' started by Sabersamus, Apr 18, 2012.

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

    Sabersamus

    I have a class for a table, and its working well except for one small problem,

    Code:java
    1. @Table(name="bytecraft_homes")
    2. public class HomesDatabase
    3. {
    4.  
    5. @Id
    6. private int id;
    7.  
    8. @NotNull
    9. private String playerName;
    10.  
    11. @NotNull
    12. private double x;
    13.  
    14. @NotNull
    15. private double y;
    16.  
    17. @NotNull
    18. private double z;
    19.  
    20. @NotNull
    21. private float pitch;
    22.  
    23. @NotNull
    24. private float yaw;
    25.  
    26. private String worldName;
    27.  
    28. public void setId(int id) {
    29. this.id = id;
    30. }
    31.  
    32. public int getId() {
    33. return id;
    34. }
    35. public Player getPlayer() {
    36. return Bukkit.getServer().getPlayer(playerName);
    37. }
    38.  
    39. public void setPlayer(Player player) {
    40. this.playerName = player.getName();
    41. }
    42.  
    43. public String getWorldName() {
    44. return worldName;
    45. }
    46.  
    47. public void setWorldName(String worldName) {
    48. this.worldName = worldName;
    49. }
    50.  
    51. public double getX() {
    52. return x;
    53. }
    54.  
    55. public void setX(double x) {
    56. this.x = x;
    57. }
    58.  
    59. public double getY() {
    60. return y;
    61. }
    62.  
    63. public void setY(double y) {
    64. this.y = y;
    65. }
    66.  
    67. public double getZ() {
    68. return z;
    69. }
    70.  
    71. public void setZ(double z) {
    72. this.z = z;
    73. }
    74.  
    75. public float getPitch() {
    76. return pitch;
    77. }
    78.  
    79. public void setPitch(float pitch) {
    80. this.pitch = pitch;
    81. }
    82.  
    83. public float getYaw() {
    84. return yaw;
    85. }
    86.  
    87. public void setYaw(float yaw) {
    88. this.yaw = yaw;
    89. }
    90.  
    91. public void setLocation(Location location){
    92. this.worldName = location.getWorld().getName();
    93. this.x = location.getX();
    94. this.y = location.getY();
    95. this.z = location.getZ();
    96. this.pitch = location.getPitch();
    97. this.yaw = location.getYaw();
    98. }
    99.  
    100. public Location getLocation() {
    101. World world = Bukkit.getServer().getWorld(worldName);
    102. return new Location(world, x, y, z, yaw, pitch);
    103. }


    when i do /home save, it doesnt update the existing home that i have saved for myself, :/

    heres how i do it:
    Code:java
    1. HomesDatabase home = plugin.getDatabase().find(HomesDatabase.class).where().ieq("name", player.getName()).ieq("playerName", player.getName()).findUnique();
    2.  
    3. if (home == null) {
    4. home = new HomesDatabase();
    5. home.setPlayer(player);
    6. home.setName(player.getName());
    7. home.setLocation(player.getLocation());
    8. plugin.getDatabase().save(home);
    9. }else{
    10. home.setLocation(player.getLocation());
    11. plugin.getDatabase().update(home);
    12. }


    im not sure what im doing wrong, do you have any clue? D:
     
Thread Status:
Not open for further replies.

Share This Page