Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.58 KB | None | 0 0
  1. package fr.savannagames.hub.player;
  2.  
  3. import fr.savannagames.hub.Hub;
  4. import fr.savannagames.hub.database.DatabaseManager;
  5.  
  6. import java.sql.Connection;
  7. import java.sql.PreparedStatement;
  8. import java.sql.SQLException;
  9. import java.util.UUID;
  10.  
  11. public class Profile {
  12.  
  13.     private int id;
  14.     private UUID uuid;
  15.     private long coins;
  16.     private long credits;
  17.     private int power;
  18.  
  19.  
  20.     public Profile(int id, UUID uuid, long coins, long credits, int power) {
  21.         this.id = id;
  22.         this.uuid = uuid;
  23.         this.coins = coins;
  24.         this.credits = credits;
  25.         this.power = power;
  26.     }
  27.  
  28.     public void updateData(UUID player) {
  29.         Profile profile = Hub.get().getPlayerManager().getPlayerProfile(player);
  30.         try {
  31.             final Connection connection = DatabaseManager.SavannaGames.getDatabaseAccess().getConnection();
  32.             String query = "UPDATE players SET coins= ?, credits= ?, power= ? WHERE uuid= ?";
  33.  
  34.             final PreparedStatement preparedStatement = connection.prepareStatement(query);
  35.             preparedStatement.setLong(1, coins);
  36.             preparedStatement.setLong(2, credits);
  37.             preparedStatement.setInt(3, power);
  38.             preparedStatement.setString(4, uuid.toString());
  39.             preparedStatement.executeUpdate();
  40.             preparedStatement.close();
  41.             connection.close();
  42.         } catch (SQLException e) {
  43.             e.printStackTrace();
  44.         }
  45.  
  46.  
  47.     }
  48.  
  49.     public int getId() {
  50.         return id;
  51.     }
  52.  
  53.     public void setId(int id) {
  54.         this.id = id;
  55.     }
  56.  
  57.     public UUID getUuid() {
  58.         return uuid;
  59.     }
  60.  
  61.     public void setUuid(UUID uuid) {
  62.         this.uuid = uuid;
  63.     }
  64.  
  65.     public long getCoins() {
  66.         return coins;
  67.     }
  68.  
  69.     public void setCoins(long coins) {
  70.         this.coins = coins;
  71.     }
  72.  
  73.     public long getCredits() {
  74.         return credits;
  75.     }
  76.  
  77.     public void setCredits(long credits) {
  78.         this.credits = credits;
  79.     }
  80.  
  81.     public int getPower() {
  82.         return power;
  83.     }
  84.  
  85.     public void setPower(int power) {
  86.         this.power = power;
  87.     }
  88.  
  89.     public boolean hasEnough(int type, long price) {
  90.         if (type == 0) {
  91.             return getCoins() >= price;
  92.         } else {
  93.             return getCredits() >= price;
  94.         }
  95.     }
  96.  
  97.     public boolean equals(Object o){
  98.         if(o == null){
  99.             return false;
  100.  
  101.         }
  102.         if(!(o instanceof Profile)){
  103.             return false;
  104.         } else {
  105.             return ((Profile)o).getId() == this.id;
  106.         }
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement