#815 Save yaw & pitch for last login in SQL data sources

This commit is contained in:
ljacqu
2017-04-22 13:30:03 +02:00
parent 70298a830b
commit e56a3c0ab6
18 changed files with 188 additions and 93 deletions
@@ -21,6 +21,8 @@ public final class Columns {
public final String LASTLOC_Y;
public final String LASTLOC_Z;
public final String LASTLOC_WORLD;
public final String LASTLOC_YAW;
public final String LASTLOC_PITCH;
public final String EMAIL;
public final String ID;
public final String IS_LOGGED;
@@ -37,6 +39,8 @@ public final class Columns {
LASTLOC_Y = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Y);
LASTLOC_Z = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Z);
LASTLOC_WORLD = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_WORLD);
LASTLOC_YAW = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_YAW);
LASTLOC_PITCH = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_PITCH);
EMAIL = settings.getProperty(DatabaseSettings.MYSQL_COL_EMAIL);
ID = settings.getProperty(DatabaseSettings.MYSQL_COL_ID);
IS_LOGGED = settings.getProperty(DatabaseSettings.MYSQL_COL_ISLOGGED);
@@ -218,6 +218,16 @@ public class MySQL implements DataSource {
+ col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + col.LASTLOC_Z);
}
if (isColumnMissing(md, col.LASTLOC_YAW)) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ col.LASTLOC_YAW + " FLOAT;");
}
if (isColumnMissing(md, col.LASTLOC_PITCH)) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ col.LASTLOC_PITCH + " FLOAT;");
}
if (isColumnMissing(md, col.EMAIL)) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com' AFTER " + col.LASTLOC_WORLD);
@@ -714,14 +724,17 @@ public class MySQL implements DataSource {
@Override
public boolean updateQuitLoc(PlayerAuth auth) {
String sql = "UPDATE " + tableName
+ " SET " + col.LASTLOC_X + " =?, " + col.LASTLOC_Y + "=?, " + col.LASTLOC_Z + "=?, " + col.LASTLOC_WORLD + "=?"
+ " SET " + col.LASTLOC_X + " =?, " + col.LASTLOC_Y + "=?, " + col.LASTLOC_Z + "=?, " + col.LASTLOC_WORLD + "=?, "
+ col.LASTLOC_YAW + "=?, " + col.LASTLOC_PITCH + "=?"
+ " WHERE " + col.NAME + "=?;";
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
pst.setDouble(1, auth.getQuitLocX());
pst.setDouble(2, auth.getQuitLocY());
pst.setDouble(3, auth.getQuitLocZ());
pst.setString(4, auth.getWorld());
pst.setString(5, auth.getNickname());
pst.setFloat(5, auth.getYaw());
pst.setFloat(6, auth.getPitch());
pst.setString(7, auth.getNickname());
pst.executeUpdate();
return true;
} catch (SQLException ex) {
@@ -959,6 +972,8 @@ public class MySQL implements DataSource {
.locX(row.getDouble(col.LASTLOC_X))
.locY(row.getDouble(col.LASTLOC_Y))
.locZ(row.getDouble(col.LASTLOC_Z))
.locYaw(row.getFloat(col.LASTLOC_YAW))
.locPitch(row.getFloat(col.LASTLOC_PITCH))
.email(row.getString(col.EMAIL))
.groupId(group)
.build();
@@ -21,10 +21,10 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static fr.xephi.authme.datasource.SqlDataSourceUtils.close;
import static fr.xephi.authme.datasource.SqlDataSourceUtils.logSqlException;
/**
* SQLite data source.
*/
public class SQLite implements DataSource {
@@ -118,6 +118,16 @@ public class SQLite implements DataSource {
+ " ADD COLUMN " + col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT 'world';");
}
if (isColumnMissing(md, col.LASTLOC_YAW)) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ col.LASTLOC_YAW + " FLOAT;");
}
if (isColumnMissing(md, col.LASTLOC_PITCH)) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ col.LASTLOC_PITCH + " FLOAT;");
}
if (isColumnMissing(md, col.EMAIL)) {
st.executeUpdate("ALTER TABLE " + tableName
+ " ADD COLUMN " + col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com';");
@@ -352,12 +362,17 @@ public class SQLite implements DataSource {
public boolean updateQuitLoc(PlayerAuth auth) {
PreparedStatement pst = null;
try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + col.LASTLOC_X + "=?, " + col.LASTLOC_Y + "=?, " + col.LASTLOC_Z + "=?, " + col.LASTLOC_WORLD + "=? WHERE " + col.NAME + "=?;");
pst = con.prepareStatement("UPDATE " + tableName + " SET "
+ col.LASTLOC_X + "=?, " + col.LASTLOC_Y + "=?, " + col.LASTLOC_Z + "=?, "
+ col.LASTLOC_WORLD + "=?, " + col.LASTLOC_YAW + "=?, " + col.LASTLOC_PITCH + "=? "
+ "WHERE " + col.NAME + "=?;");
pst.setDouble(1, auth.getQuitLocX());
pst.setDouble(2, auth.getQuitLocY());
pst.setDouble(3, auth.getQuitLocZ());
pst.setString(4, auth.getWorld());
pst.setString(5, auth.getNickname());
pst.setFloat(5, auth.getYaw());
pst.setFloat(6, auth.getPitch());
pst.setString(7, auth.getNickname());
pst.executeUpdate();
return true;
} catch (SQLException ex) {
@@ -586,7 +601,9 @@ public class SQLite implements DataSource {
.locX(row.getDouble(col.LASTLOC_X))
.locY(row.getDouble(col.LASTLOC_Y))
.locZ(row.getDouble(col.LASTLOC_Z))
.locWorld(row.getString(col.LASTLOC_WORLD));
.locWorld(row.getString(col.LASTLOC_WORLD))
.locYaw(row.getFloat(col.LASTLOC_YAW))
.locPitch(row.getFloat(col.LASTLOC_PITCH));
String ip = row.getString(col.IP);
if (!ip.isEmpty()) {
@@ -594,4 +611,35 @@ public class SQLite implements DataSource {
}
return authBuilder.build();
}
private static void close(Statement st) {
if (st != null) {
try {
st.close();
} catch (SQLException ex) {
logSqlException(ex);
}
}
}
private static void close(Connection con) {
if (con != null) {
try {
con.close();
} catch (SQLException ex) {
logSqlException(ex);
}
}
}
private static void close(ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException ex) {
logSqlException(ex);
}
}
}
}