Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.savannagames.hub.player;
- import fr.savannagames.hub.Hub;
- import fr.savannagames.hub.database.DatabaseManager;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import java.util.UUID;
- public class Profile {
- private int id;
- private UUID uuid;
- private long coins;
- private long credits;
- private int power;
- public Profile(int id, UUID uuid, long coins, long credits, int power) {
- this.id = id;
- this.uuid = uuid;
- this.coins = coins;
- this.credits = credits;
- this.power = power;
- }
- public void updateData(UUID player) {
- Profile profile = Hub.get().getPlayerManager().getPlayerProfile(player);
- try {
- final Connection connection = DatabaseManager.SavannaGames.getDatabaseAccess().getConnection();
- String query = "UPDATE players SET coins= ?, credits= ?, power= ? WHERE uuid= ?";
- final PreparedStatement preparedStatement = connection.prepareStatement(query);
- preparedStatement.setLong(1, coins);
- preparedStatement.setLong(2, credits);
- preparedStatement.setInt(3, power);
- preparedStatement.setString(4, uuid.toString());
- preparedStatement.executeUpdate();
- preparedStatement.close();
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public UUID getUuid() {
- return uuid;
- }
- public void setUuid(UUID uuid) {
- this.uuid = uuid;
- }
- public long getCoins() {
- return coins;
- }
- public void setCoins(long coins) {
- this.coins = coins;
- }
- public long getCredits() {
- return credits;
- }
- public void setCredits(long credits) {
- this.credits = credits;
- }
- public int getPower() {
- return power;
- }
- public void setPower(int power) {
- this.power = power;
- }
- public boolean hasEnough(int type, long price) {
- if (type == 0) {
- return getCoins() >= price;
- } else {
- return getCredits() >= price;
- }
- }
- public boolean equals(Object o){
- if(o == null){
- return false;
- }
- if(!(o instanceof Profile)){
- return false;
- } else {
- return ((Profile)o).getId() == this.id;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement