60 lines
1.4 KiB
Java
60 lines
1.4 KiB
Java
package eu.univento.core.api.player;
|
|
|
|
import eu.univento.core.Core;
|
|
import eu.univento.core.api.database.MySQL;
|
|
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
|
|
/**
|
|
* experience management
|
|
* @author joethei
|
|
* @version 1.0
|
|
*/
|
|
public class Experience{
|
|
|
|
/**
|
|
* gets experience from player
|
|
* @param p CustomPlayer
|
|
* @return experience as integer
|
|
*/
|
|
static int getExperience(CustomPlayer p) {
|
|
int id = 0;
|
|
MySQL sql = Core.returnSQL();
|
|
try {
|
|
sql.openConnection();
|
|
PreparedStatement st = sql.getConnection().prepareStatement("SELECT Experience FROM users WHERE ID='" + id + "';");
|
|
ResultSet rs = st.executeQuery();
|
|
if(rs.next()) {
|
|
int coins = rs.getInt("Experience");
|
|
sql.closeConnection();
|
|
return coins;
|
|
}
|
|
return 0;
|
|
} catch (ClassNotFoundException | SQLException e) {
|
|
e.printStackTrace();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* sets experience of player
|
|
* @param p CustomPlayer
|
|
* @param experience experience to set
|
|
*/
|
|
static void setExperience(CustomPlayer p, int experience) {
|
|
int id = 0;
|
|
MySQL sql = Core.returnSQL();
|
|
try {
|
|
sql.openConnection();
|
|
PreparedStatement st = sql.getConnection().prepareStatement("UPDATE users SET Experience='" + experience + "' WHERE ID='" + id + "';");
|
|
st.execute();
|
|
sql.closeConnection();
|
|
} catch (ClassNotFoundException | SQLException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
} |