#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

View File

@ -129,7 +129,7 @@ public class AuthMeApi {
PlayerAuth auth = playerCache.getAuth(player.getName()); PlayerAuth auth = playerCache.getAuth(player.getName());
if (auth != null) { if (auth != null) {
return new Location(Bukkit.getWorld(auth.getWorld()), 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; return null;
} }

View File

@ -26,6 +26,8 @@ public class PlayerAuth {
private double y; private double y;
private double z; private double z;
private String world; private String world;
private float yaw;
private float pitch;
/** /**
* @param serialized String * @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 * @see #builder()
* @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
*/ */
private PlayerAuth(String nickname, HashedPassword password, int groupId, String ip, long lastLogin, private PlayerAuth() {
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;
} }
@ -124,6 +104,14 @@ public class PlayerAuth {
this.world = world; this.world = world;
} }
public float getYaw() {
return yaw;
}
public float getPitch() {
return pitch;
}
public String getIp() { public String getIp() {
return ip; return ip;
} }
@ -235,26 +223,34 @@ public class PlayerAuth {
private String realName; private String realName;
private HashedPassword password; private HashedPassword password;
private String ip; private String ip;
private String world;
private String email; private String email;
private int groupId = -1; 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 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() { public PlayerAuth build() {
return new PlayerAuth( PlayerAuth auth = new PlayerAuth();
checkNotNull(name), auth.nickname = checkNotNull(name).toLowerCase();
firstNonNull(password, new HashedPassword("")), auth.realName = firstNonNull(realName, "Player");
groupId, auth.password = firstNonNull(password, new HashedPassword(""));
firstNonNull(ip, "127.0.0.1"), auth.email = firstNonNull(email, "your@email.com");
lastLogin, auth.ip = firstNonNull(ip, "127.0.0.1");
x, y, z, auth.groupId = groupId;
firstNonNull(world, "world"), auth.lastLogin = lastLogin;
firstNonNull(email, "your@email.com"),
firstNonNull(realName, "Player") 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) { public Builder name(String name) {
@ -286,11 +282,8 @@ public class PlayerAuth {
this.y = location.getY(); this.y = location.getY();
this.z = location.getZ(); this.z = location.getZ();
this.world = location.getWorld().getName(); this.world = location.getWorld().getName();
return this; this.yaw = location.getYaw();
} this.pitch = location.getPitch();
public Builder locWorld(String world) {
this.world = world;
return this; return this;
} }
@ -309,6 +302,21 @@ public class PlayerAuth {
return this; 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) { public Builder lastLogin(long lastLogin) {
this.lastLogin = lastLogin; this.lastLogin = lastLogin;
return this; return this;

View File

@ -21,6 +21,8 @@ public final class Columns {
public final String LASTLOC_Y; public final String LASTLOC_Y;
public final String LASTLOC_Z; public final String LASTLOC_Z;
public final String LASTLOC_WORLD; public final String LASTLOC_WORLD;
public final String LASTLOC_YAW;
public final String LASTLOC_PITCH;
public final String EMAIL; public final String EMAIL;
public final String ID; public final String ID;
public final String IS_LOGGED; public final String IS_LOGGED;
@ -37,6 +39,8 @@ public final class Columns {
LASTLOC_Y = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Y); LASTLOC_Y = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Y);
LASTLOC_Z = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Z); LASTLOC_Z = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Z);
LASTLOC_WORLD = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_WORLD); 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); EMAIL = settings.getProperty(DatabaseSettings.MYSQL_COL_EMAIL);
ID = settings.getProperty(DatabaseSettings.MYSQL_COL_ID); ID = settings.getProperty(DatabaseSettings.MYSQL_COL_ID);
IS_LOGGED = settings.getProperty(DatabaseSettings.MYSQL_COL_ISLOGGED); IS_LOGGED = settings.getProperty(DatabaseSettings.MYSQL_COL_ISLOGGED);

View File

@ -218,6 +218,16 @@ public class MySQL implements DataSource {
+ col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + col.LASTLOC_Z); + 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)) { if (isColumnMissing(md, col.EMAIL)) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com' AFTER " + col.LASTLOC_WORLD); + col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com' AFTER " + col.LASTLOC_WORLD);
@ -714,14 +724,17 @@ public class MySQL implements DataSource {
@Override @Override
public boolean updateQuitLoc(PlayerAuth auth) { public boolean updateQuitLoc(PlayerAuth auth) {
String sql = "UPDATE " + tableName 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 + "=?;"; + " WHERE " + col.NAME + "=?;";
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
pst.setDouble(1, auth.getQuitLocX()); pst.setDouble(1, auth.getQuitLocX());
pst.setDouble(2, auth.getQuitLocY()); pst.setDouble(2, auth.getQuitLocY());
pst.setDouble(3, auth.getQuitLocZ()); pst.setDouble(3, auth.getQuitLocZ());
pst.setString(4, auth.getWorld()); 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(); pst.executeUpdate();
return true; return true;
} catch (SQLException ex) { } catch (SQLException ex) {
@ -959,6 +972,8 @@ public class MySQL implements DataSource {
.locX(row.getDouble(col.LASTLOC_X)) .locX(row.getDouble(col.LASTLOC_X))
.locY(row.getDouble(col.LASTLOC_Y)) .locY(row.getDouble(col.LASTLOC_Y))
.locZ(row.getDouble(col.LASTLOC_Z)) .locZ(row.getDouble(col.LASTLOC_Z))
.locYaw(row.getFloat(col.LASTLOC_YAW))
.locPitch(row.getFloat(col.LASTLOC_PITCH))
.email(row.getString(col.EMAIL)) .email(row.getString(col.EMAIL))
.groupId(group) .groupId(group)
.build(); .build();

View File

@ -21,10 +21,10 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import static fr.xephi.authme.datasource.SqlDataSourceUtils.close;
import static fr.xephi.authme.datasource.SqlDataSourceUtils.logSqlException; import static fr.xephi.authme.datasource.SqlDataSourceUtils.logSqlException;
/** /**
* SQLite data source.
*/ */
public class SQLite implements DataSource { 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';"); + " 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)) { if (isColumnMissing(md, col.EMAIL)) {
st.executeUpdate("ALTER TABLE " + tableName st.executeUpdate("ALTER TABLE " + tableName
+ " ADD COLUMN " + col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com';"); + " ADD COLUMN " + col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com';");
@ -352,12 +362,17 @@ public class SQLite implements DataSource {
public boolean updateQuitLoc(PlayerAuth auth) { public boolean updateQuitLoc(PlayerAuth auth) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { 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(1, auth.getQuitLocX());
pst.setDouble(2, auth.getQuitLocY()); pst.setDouble(2, auth.getQuitLocY());
pst.setDouble(3, auth.getQuitLocZ()); pst.setDouble(3, auth.getQuitLocZ());
pst.setString(4, auth.getWorld()); 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(); pst.executeUpdate();
return true; return true;
} catch (SQLException ex) { } catch (SQLException ex) {
@ -586,7 +601,9 @@ public class SQLite implements DataSource {
.locX(row.getDouble(col.LASTLOC_X)) .locX(row.getDouble(col.LASTLOC_X))
.locY(row.getDouble(col.LASTLOC_Y)) .locY(row.getDouble(col.LASTLOC_Y))
.locZ(row.getDouble(col.LASTLOC_Z)) .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); String ip = row.getString(col.IP);
if (!ip.isEmpty()) { if (!ip.isEmpty()) {
@ -594,4 +611,35 @@ public class SQLite implements DataSource {
} }
return authBuilder.build(); 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);
}
}
}
} }

View File

@ -134,7 +134,8 @@ public class TeleportationService implements Reloadable {
if (world == null) { if (world == null) {
world = player.getWorld(); 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) { private void teleportBackFromSpawn(final Player player, final Location location) {

View File

@ -98,6 +98,14 @@ public final class DatabaseSettings implements SettingsHolder {
public static final Property<String> MYSQL_COL_LASTLOC_WORLD = public static final Property<String> MYSQL_COL_LASTLOC_WORLD =
newProperty("DataSource.mySQLlastlocWorld", "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") @Comment("Column for storing players groups")
public static final Property<String> MYSQL_COL_GROUP = public static final Property<String> MYSQL_COL_GROUP =
newProperty("ExternalBoardOptions.mySQLColumnGroup", ""); newProperty("ExternalBoardOptions.mySQLColumnGroup", "");

View File

@ -16,15 +16,15 @@ public final class AuthMeMatchers {
private AuthMeMatchers() { private AuthMeMatchers() {
} }
public static Matcher<? super HashedPassword> equalToHash(final String hash) { public static Matcher<? super HashedPassword> equalToHash(String hash) {
return equalToHash(new HashedPassword(hash)); return equalToHash(new HashedPassword(hash));
} }
public static Matcher<? super HashedPassword> equalToHash(final String hash, final String salt) { public static Matcher<? super HashedPassword> equalToHash(String hash, String salt) {
return equalToHash(new HashedPassword(hash, salt)); return equalToHash(new HashedPassword(hash, salt));
} }
public static Matcher<? super HashedPassword> equalToHash(final HashedPassword hash) { public static Matcher<? super HashedPassword> equalToHash(HashedPassword hash) {
return new TypeSafeMatcher<HashedPassword>() { return new TypeSafeMatcher<HashedPassword>() {
@Override @Override
public boolean matchesSafely(HashedPassword item) { public boolean matchesSafely(HashedPassword item) {
@ -43,8 +43,8 @@ public final class AuthMeMatchers {
}; };
} }
public static Matcher<? super PlayerAuth> hasAuthBasicData(final String name, final String realName, public static Matcher<? super PlayerAuth> hasAuthBasicData(String name, String realName,
final String email, final String ip) { String email, String ip) {
return new TypeSafeMatcher<PlayerAuth>() { return new TypeSafeMatcher<PlayerAuth>() {
@Override @Override
public boolean matchesSafely(PlayerAuth item) { public boolean matchesSafely(PlayerAuth item) {
@ -59,29 +59,43 @@ public final class AuthMeMatchers {
description.appendValue(String.format("PlayerAuth with name %s, realname %s, email %s, ip %s", description.appendValue(String.format("PlayerAuth with name %s, realname %s, email %s, ip %s",
name, realName, email, ip)); name, realName, email, ip));
} }
@Override
public void describeMismatchSafely(PlayerAuth item, Description description) {
description.appendValue(String.format("PlayerAuth with name %s, realname %s, email %s, ip %s",
item.getNickname(), item.getRealName(), item.getEmail(), item.getIp()));
}
}; };
} }
public static Matcher<? super PlayerAuth> hasAuthLocation(final double x, final double y, final double z, public static Matcher<? super PlayerAuth> hasAuthLocation(PlayerAuth auth) {
final String world) { return hasAuthLocation(auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(),
auth.getYaw(), auth.getPitch());
}
public static Matcher<? super PlayerAuth> hasAuthLocation(double x, double y, double z,
String world, float yaw, float pitch) {
return new TypeSafeMatcher<PlayerAuth>() { return new TypeSafeMatcher<PlayerAuth>() {
@Override @Override
public boolean matchesSafely(PlayerAuth item) { public boolean matchesSafely(PlayerAuth item) {
return Objects.equals(x, item.getQuitLocX()) return Objects.equals(x, item.getQuitLocX())
&& Objects.equals(y, item.getQuitLocY()) && Objects.equals(y, item.getQuitLocY())
&& Objects.equals(z, item.getQuitLocZ()) && Objects.equals(z, item.getQuitLocZ())
&& Objects.equals(world, item.getWorld()); && Objects.equals(world, item.getWorld())
&& Objects.equals(yaw, item.getYaw())
&& Objects.equals(pitch, item.getPitch());
} }
@Override @Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendValue(String.format("PlayerAuth with quit location (x: %f, y: %f, z: %f, world: %s)", description.appendValue(
x, y, z, world)); String.format("PlayerAuth with quit location (x: %f, y: %f, z: %f, world: %s, yaw: %f, pitch: %f)",
x, y, z, world, yaw, pitch));
} }
}; };
} }
public static Matcher<String> stringWithLength(final int length) { public static Matcher<String> stringWithLength(int length) {
return new TypeSafeMatcher<String>() { return new TypeSafeMatcher<String>() {
@Override @Override
protected boolean matchesSafely(String item) { protected boolean matchesSafely(String item) {

View File

@ -1,13 +1,12 @@
package fr.xephi.authme.api.v3; package fr.xephi.authme.api.v3;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ReflectionTestUtils; import fr.xephi.authme.ReflectionTestUtils;
import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.process.Management; import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.service.ValidationService; import fr.xephi.authme.service.ValidationService;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -43,8 +42,6 @@ public class AuthMeApiTest {
@InjectMocks @InjectMocks
private AuthMeApi api; private AuthMeApi api;
@Mock
private AuthMe authMe;
@Mock @Mock
private PluginHookService pluginHookService; private PluginHookService pluginHookService;
@Mock @Mock
@ -120,6 +117,8 @@ public class AuthMeApiTest {
.locX(12.4) .locX(12.4)
.locY(24.6) .locY(24.6)
.locZ(-438.2) .locZ(-438.2)
.locYaw(3.41f)
.locPitch(0.29f)
.build(); .build();
given(playerCache.getAuth(name)).willReturn(auth); given(playerCache.getAuth(name)).willReturn(auth);
Server server = mock(Server.class); Server server = mock(Server.class);
@ -136,6 +135,8 @@ public class AuthMeApiTest {
assertThat(result.getY(), equalTo(auth.getQuitLocY())); assertThat(result.getY(), equalTo(auth.getQuitLocY()));
assertThat(result.getZ(), equalTo(auth.getQuitLocZ())); assertThat(result.getZ(), equalTo(auth.getQuitLocZ()));
assertThat(result.getWorld(), equalTo(world)); assertThat(result.getWorld(), equalTo(world));
assertThat(result.getYaw(), equalTo(auth.getYaw()));
assertThat(result.getPitch(), equalTo(auth.getPitch()));
} }
@Test @Test

View File

@ -96,12 +96,12 @@ public abstract class AbstractDataSourceIntegrationTest {
assertThat(invalidAuth, nullValue()); assertThat(invalidAuth, nullValue());
assertThat(bobbyAuth, hasAuthBasicData("bobby", "Bobby", "your@email.com", "123.45.67.89")); assertThat(bobbyAuth, hasAuthBasicData("bobby", "Bobby", "your@email.com", "123.45.67.89"));
assertThat(bobbyAuth, hasAuthLocation(1.05, 2.1, 4.2, "world")); assertThat(bobbyAuth, hasAuthLocation(1.05, 2.1, 4.2, "world", -0.44f, 2.77f));
assertThat(bobbyAuth.getLastLogin(), equalTo(1449136800L)); assertThat(bobbyAuth.getLastLogin(), equalTo(1449136800L));
assertThat(bobbyAuth.getPassword(), equalToHash("$SHA$11aa0706173d7272$dbba966")); assertThat(bobbyAuth.getPassword(), equalToHash("$SHA$11aa0706173d7272$dbba966"));
assertThat(userAuth, hasAuthBasicData("user", "user", "user@example.org", "34.56.78.90")); assertThat(userAuth, hasAuthBasicData("user", "user", "user@example.org", "34.56.78.90"));
assertThat(userAuth, hasAuthLocation(124.1, 76.3, -127.8, "nether")); assertThat(userAuth, hasAuthLocation(124.1, 76.3, -127.8, "nether", 0.23f, 4.88f));
assertThat(userAuth.getLastLogin(), equalTo(1453242857L)); assertThat(userAuth.getLastLogin(), equalTo(1453242857L));
assertThat(userAuth.getPassword(), equalToHash("b28c32f624a4eb161d6adc9acb5bfc5b", "f750ba32")); assertThat(userAuth.getPassword(), equalToHash("b28c32f624a4eb161d6adc9acb5bfc5b", "f750ba32"));
} }
@ -229,14 +229,14 @@ public abstract class AbstractDataSourceIntegrationTest {
DataSource dataSource = getDataSource(); DataSource dataSource = getDataSource();
PlayerAuth user = PlayerAuth.builder() PlayerAuth user = PlayerAuth.builder()
.name("user").locX(143).locY(-42.12).locZ(29.47) .name("user").locX(143).locY(-42.12).locZ(29.47)
.locWorld("the_end").build(); .locWorld("the_end").locYaw(2.2f).locPitch(0.45f).build();
// when // when
boolean response = dataSource.updateQuitLoc(user); boolean response = dataSource.updateQuitLoc(user);
// then // then
assertThat(response, equalTo(true)); assertThat(response, equalTo(true));
assertThat(dataSource.getAuth("user"), hasAuthLocation(143, -42.12, 29.47, "the_end")); assertThat(dataSource.getAuth("user"), hasAuthLocation(user));
} }
@Test @Test

View File

@ -62,15 +62,15 @@ public class FlatFileIntegrationTest {
// then // then
assertThat(authList, hasSize(7)); assertThat(authList, hasSize(7));
assertThat(getName("bobby", authList), hasAuthBasicData("bobby", "bobby", "your@email.com", "123.45.67.89")); assertThat(getName("bobby", authList), hasAuthBasicData("bobby", "bobby", "your@email.com", "123.45.67.89"));
assertThat(getName("bobby", authList), hasAuthLocation(1.05, 2.1, 4.2, "world")); assertThat(getName("bobby", authList), hasAuthLocation(1.05, 2.1, 4.2, "world", 0, 0));
assertThat(getName("bobby", authList).getPassword(), equalToHash("$SHA$11aa0706173d7272$dbba966")); assertThat(getName("bobby", authList).getPassword(), equalToHash("$SHA$11aa0706173d7272$dbba966"));
assertThat(getName("twofields", authList), hasAuthBasicData("twofields", "twofields", "your@email.com", "127.0.0.1")); assertThat(getName("twofields", authList), hasAuthBasicData("twofields", "twofields", "your@email.com", "127.0.0.1"));
assertThat(getName("twofields", authList).getPassword(), equalToHash("hash1234")); assertThat(getName("twofields", authList).getPassword(), equalToHash("hash1234"));
assertThat(getName("threefields", authList), hasAuthBasicData("threefields", "threefields", "your@email.com", "33.33.33.33")); assertThat(getName("threefields", authList), hasAuthBasicData("threefields", "threefields", "your@email.com", "33.33.33.33"));
assertThat(getName("fourfields", authList), hasAuthBasicData("fourfields", "fourfields", "your@email.com", "4.4.4.4")); assertThat(getName("fourfields", authList), hasAuthBasicData("fourfields", "fourfields", "your@email.com", "4.4.4.4"));
assertThat(getName("fourfields", authList).getLastLogin(), equalTo(404040404L)); assertThat(getName("fourfields", authList).getLastLogin(), equalTo(404040404L));
assertThat(getName("sevenfields", authList), hasAuthLocation(7.7, 14.14, 21.21, "world")); assertThat(getName("sevenfields", authList), hasAuthLocation(7.7, 14.14, 21.21, "world", 0, 0));
assertThat(getName("eightfields", authList), hasAuthLocation(8.8, 17.6, 26.4, "eightworld")); assertThat(getName("eightfields", authList), hasAuthLocation(8.8, 17.6, 26.4, "eightworld", 0, 0));
assertThat(getName("eightfields", authList).getLastLogin(), equalTo(1234567888L)); assertThat(getName("eightfields", authList).getLastLogin(), equalTo(1234567888L));
assertThat(getName("eightfields", authList).getPassword(), equalToHash("hash8168")); assertThat(getName("eightfields", authList).getPassword(), equalToHash("hash8168"));
} }

View File

@ -1,9 +1,6 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import fr.xephi.authme.datasource.AbstractResourceClosingTest;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.MySQL;
import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;

View File

@ -1,8 +1,5 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import fr.xephi.authme.datasource.AbstractResourceClosingTest;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.SQLite;
import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;

View File

@ -64,11 +64,11 @@ public class ForceFlatToSqliteTest {
verify(dataSource, times(7)).saveAuth(authCaptor.capture()); verify(dataSource, times(7)).saveAuth(authCaptor.capture());
List<PlayerAuth> auths = authCaptor.getAllValues(); List<PlayerAuth> auths = authCaptor.getAllValues();
assertThat(auths, hasItem(hasAuthBasicData("bobby", "Player", "your@email.com", "123.45.67.89"))); assertThat(auths, hasItem(hasAuthBasicData("bobby", "Player", "your@email.com", "123.45.67.89")));
assertThat(auths, hasItem(hasAuthLocation(1.05, 2.1, 4.2, "world"))); assertThat(auths, hasItem(hasAuthLocation(1.05, 2.1, 4.2, "world", 0, 0)));
assertThat(auths, hasItem(hasAuthBasicData("user", "Player", "user@example.org", "34.56.78.90"))); assertThat(auths, hasItem(hasAuthBasicData("user", "Player", "user@example.org", "34.56.78.90")));
assertThat(auths, hasItem(hasAuthLocation(124.1, 76.3, -127.8, "nether"))); assertThat(auths, hasItem(hasAuthLocation(124.1, 76.3, -127.8, "nether", 0, 0)));
assertThat(auths, hasItem(hasAuthBasicData("eightfields", "Player", "your@email.com", "6.6.6.66"))); assertThat(auths, hasItem(hasAuthBasicData("eightfields", "Player", "your@email.com", "6.6.6.66")));
assertThat(auths, hasItem(hasAuthLocation(8.8, 17.6, 26.4, "eightworld"))); assertThat(auths, hasItem(hasAuthLocation(8.8, 17.6, 26.4, "eightworld", 0, 0)));
} }
} }

View File

@ -126,7 +126,7 @@ public class EmailRegisterExecutorProviderTest {
// then // then
assertThat(auth, hasAuthBasicData("veronica", "Veronica", "test@example.com", "123.45.67.89")); assertThat(auth, hasAuthBasicData("veronica", "Veronica", "test@example.com", "123.45.67.89"));
assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld")); assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 0, 0));
assertThat(auth.getPassword().getHash(), stringWithLength(12)); assertThat(auth.getPassword().getHash(), stringWithLength(12));
} }

View File

@ -100,7 +100,7 @@ public class PasswordRegisterExecutorTest {
TestHelper.mockPlayerIp(player, "123.45.67.89"); TestHelper.mockPlayerIp(player, "123.45.67.89");
World world = mock(World.class); World world = mock(World.class);
given(world.getName()).willReturn("someWorld"); given(world.getName()).willReturn("someWorld");
given(player.getLocation()).willReturn(new Location(world, 48, 96, 144)); given(player.getLocation()).willReturn(new Location(world, 48, 96, 144, 1.1f, 0.28f));
PasswordRegisterParams params = PasswordRegisterParams.of(player, "pass", "mail@example.org"); PasswordRegisterParams params = PasswordRegisterParams.of(player, "pass", "mail@example.org");
// when // when
@ -108,7 +108,7 @@ public class PasswordRegisterExecutorTest {
// then // then
assertThat(auth, hasAuthBasicData("s1m0n", "S1m0N", "mail@example.org", "123.45.67.89")); assertThat(auth, hasAuthBasicData("s1m0n", "S1m0N", "mail@example.org", "123.45.67.89"));
assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld")); assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 1.1f, 0.28f));
assertThat(auth.getPassword(), equalToHash("pass")); assertThat(auth.getPassword(), equalToHash("pass"));
} }

View File

@ -28,7 +28,7 @@ public class PlayerAuthBuilderHelperTest {
TestHelper.mockPlayerIp(player, ip); TestHelper.mockPlayerIp(player, ip);
World world = mock(World.class); World world = mock(World.class);
given(world.getName()).willReturn("worldName"); given(world.getName()).willReturn("worldName");
Location location = new Location(world, 123, 80, -99); Location location = new Location(world, 123, 80, -99, 2.45f, 7.61f);
given(player.getLocation()).willReturn(location); given(player.getLocation()).willReturn(location);
HashedPassword hashedPassword = new HashedPassword("myHash0001"); HashedPassword hashedPassword = new HashedPassword("myHash0001");
String email = "test@example.org"; String email = "test@example.org";
@ -38,7 +38,7 @@ public class PlayerAuthBuilderHelperTest {
// then // then
assertThat(auth, hasAuthBasicData("noah", "Noah", email, ip)); assertThat(auth, hasAuthBasicData("noah", "Noah", email, ip));
assertThat(auth, hasAuthLocation(123, 80, -99, "worldName")); assertThat(auth, hasAuthLocation(123, 80, -99, "worldName", 2.45f, 7.61f));
} }
@Test @Test

View File

@ -10,6 +10,8 @@ CREATE TABLE authme (
y DOUBLE NOT NULL DEFAULT '0.0', y DOUBLE NOT NULL DEFAULT '0.0',
z DOUBLE NOT NULL DEFAULT '0.0', z DOUBLE NOT NULL DEFAULT '0.0',
world VARCHAR(255) NOT NULL DEFAULT 'world', world VARCHAR(255) NOT NULL DEFAULT 'world',
yaw FLOAT,
pitch FLOAT,
email VARCHAR(255) DEFAULT 'your@email.com', email VARCHAR(255) DEFAULT 'your@email.com',
isLogged INT DEFAULT '0', realname VARCHAR(255) NOT NULL DEFAULT 'Player', isLogged INT DEFAULT '0', realname VARCHAR(255) NOT NULL DEFAULT 'Player',
salt varchar(255), salt varchar(255),
@ -18,7 +20,7 @@ CREATE TABLE authme (
CONSTRAINT table_const_prim PRIMARY KEY (id) CONSTRAINT table_const_prim PRIMARY KEY (id)
); );
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, email, isLogged, realname, salt) INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, yaw, pitch, email, isLogged, realname, salt)
VALUES (1,'bobby','$SHA$11aa0706173d7272$dbba966','123.45.67.89',1449136800,1.05,2.1,4.2,'world','your@email.com',0,'Bobby',NULL); VALUES (1,'bobby','$SHA$11aa0706173d7272$dbba966','123.45.67.89',1449136800,1.05,2.1,4.2,'world',-0.44,2.77,'your@email.com',0,'Bobby',NULL);
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, email, isLogged, realname, salt) INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, yaw, pitch, email, isLogged, realname, salt)
VALUES (NULL,'user','b28c32f624a4eb161d6adc9acb5bfc5b','34.56.78.90',1453242857,124.1,76.3,-127.8,'nether','user@example.org',0,'user','f750ba32'); VALUES (NULL,'user','b28c32f624a4eb161d6adc9acb5bfc5b','34.56.78.90',1453242857,124.1,76.3,-127.8,'nether',0.23,4.88,'user@example.org',0,'user','f750ba32');