#815 Save yaw & pitch for last login in SQL data sources
This commit is contained in:
@@ -129,7 +129,7 @@ public class AuthMeApi {
|
||||
PlayerAuth auth = playerCache.getAuth(player.getName());
|
||||
if (auth != null) {
|
||||
return new Location(Bukkit.getWorld(auth.getWorld()),
|
||||
auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
|
||||
auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getYaw(), auth.getPitch());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ public class PlayerAuth {
|
||||
private double y;
|
||||
private double z;
|
||||
private String world;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
|
||||
/**
|
||||
* @param serialized String
|
||||
@@ -35,33 +37,11 @@ public class PlayerAuth {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor. Instantiate objects with the {@link #builder() builder}.
|
||||
* Hidden constructor.
|
||||
*
|
||||
* @param nickname all lowercase name of the player
|
||||
* @param password password
|
||||
* @param groupId the group id
|
||||
* @param ip the associated ip address
|
||||
* @param lastLogin player's last login (timestamp)
|
||||
* @param x quit location: x coordinate
|
||||
* @param y quit location: y coordinate
|
||||
* @param z quit location: z coordinate
|
||||
* @param world quit location: world name
|
||||
* @param email the associated email
|
||||
* @param realName the player's name with proper casing
|
||||
* @see #builder()
|
||||
*/
|
||||
private PlayerAuth(String nickname, HashedPassword password, int groupId, String ip, long lastLogin,
|
||||
double x, double y, double z, String world, String email, String realName) {
|
||||
this.nickname = nickname.toLowerCase();
|
||||
this.password = password;
|
||||
this.ip = ip;
|
||||
this.lastLogin = lastLogin;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.world = world;
|
||||
this.groupId = groupId;
|
||||
this.email = email;
|
||||
this.realName = realName;
|
||||
private PlayerAuth() {
|
||||
}
|
||||
|
||||
|
||||
@@ -124,6 +104,14 @@ public class PlayerAuth {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
@@ -235,26 +223,34 @@ public class PlayerAuth {
|
||||
private String realName;
|
||||
private HashedPassword password;
|
||||
private String ip;
|
||||
private String world;
|
||||
private String email;
|
||||
private int groupId = -1;
|
||||
private double x = 0.0f;
|
||||
private double y = 0.0f;
|
||||
private double z = 0.0f;
|
||||
private long lastLogin = System.currentTimeMillis();
|
||||
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private String world;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
|
||||
public PlayerAuth build() {
|
||||
return new PlayerAuth(
|
||||
checkNotNull(name),
|
||||
firstNonNull(password, new HashedPassword("")),
|
||||
groupId,
|
||||
firstNonNull(ip, "127.0.0.1"),
|
||||
lastLogin,
|
||||
x, y, z,
|
||||
firstNonNull(world, "world"),
|
||||
firstNonNull(email, "your@email.com"),
|
||||
firstNonNull(realName, "Player")
|
||||
);
|
||||
PlayerAuth auth = new PlayerAuth();
|
||||
auth.nickname = checkNotNull(name).toLowerCase();
|
||||
auth.realName = firstNonNull(realName, "Player");
|
||||
auth.password = firstNonNull(password, new HashedPassword(""));
|
||||
auth.email = firstNonNull(email, "your@email.com");
|
||||
auth.ip = firstNonNull(ip, "127.0.0.1");
|
||||
auth.groupId = groupId;
|
||||
auth.lastLogin = lastLogin;
|
||||
|
||||
auth.x = x;
|
||||
auth.y = y;
|
||||
auth.z = z;
|
||||
auth.world = firstNonNull(world, "world");
|
||||
auth.yaw = yaw;
|
||||
auth.pitch = pitch;
|
||||
return auth;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
@@ -286,11 +282,8 @@ public class PlayerAuth {
|
||||
this.y = location.getY();
|
||||
this.z = location.getZ();
|
||||
this.world = location.getWorld().getName();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder locWorld(String world) {
|
||||
this.world = world;
|
||||
this.yaw = location.getYaw();
|
||||
this.pitch = location.getPitch();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -309,6 +302,21 @@ public class PlayerAuth {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder locWorld(String world) {
|
||||
this.world = world;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder locYaw(float yaw) {
|
||||
this.yaw = yaw;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder locPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder lastLogin(long lastLogin) {
|
||||
this.lastLogin = lastLogin;
|
||||
return this;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,8 @@ public class TeleportationService implements Reloadable {
|
||||
if (world == null) {
|
||||
world = player.getWorld();
|
||||
}
|
||||
return new Location(world, auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
|
||||
return new Location(world, auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(),
|
||||
auth.getYaw(), auth.getPitch());
|
||||
}
|
||||
|
||||
private void teleportBackFromSpawn(final Player player, final Location location) {
|
||||
|
||||
@@ -98,6 +98,14 @@ public final class DatabaseSettings implements SettingsHolder {
|
||||
public static final Property<String> MYSQL_COL_LASTLOC_WORLD =
|
||||
newProperty("DataSource.mySQLlastlocWorld", "world");
|
||||
|
||||
@Comment("Column for storing player LastLocation - Yaw")
|
||||
public static final Property<String> MYSQL_COL_LASTLOC_YAW =
|
||||
newProperty("DataSource.mySQLlastlocYaw", "yaw");
|
||||
|
||||
@Comment("Column for storing player LastLocation - Pitch")
|
||||
public static final Property<String> MYSQL_COL_LASTLOC_PITCH =
|
||||
newProperty("DataSource.mySQLlastlocPitch", "pitch");
|
||||
|
||||
@Comment("Column for storing players groups")
|
||||
public static final Property<String> MYSQL_COL_GROUP =
|
||||
newProperty("ExternalBoardOptions.mySQLColumnGroup", "");
|
||||
|
||||
Reference in New Issue
Block a user