Refactored UserInfo to have Server UUID in it

This commit is contained in:
Rsl1122 2019-02-01 11:06:33 +02:00
parent f7e28346e9
commit d5adc7f428
10 changed files with 38 additions and 40 deletions

View File

@ -19,6 +19,7 @@ package com.djrapitops.plan.system.importing.importers;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.data.container.BaseUser;
import com.djrapitops.plan.data.container.GeoInfo;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.container.UserInfo;
@ -186,14 +187,22 @@ public abstract class BukkitImporter implements Importer {
helper.submit(service);
}
private UserInfo toUserInfo(UserImportData userImportData) {
// TODO Refactor parts to use the base user
private BaseUser toBaseUser(UserImportData userImportData) {
UUID uuid = userImportData.getUuid();
String name = userImportData.getName();
long registered = userImportData.getRegistered();
int timesKicked = userImportData.getTimesKicked();
return new BaseUser(uuid, name, registered, timesKicked);
}
private UserInfo toUserInfo(UserImportData userImportData) {
UUID uuid = userImportData.getUuid();
long registered = userImportData.getRegistered();
boolean op = userImportData.isOp();
boolean banned = userImportData.isBanned();
return new UserInfo(uuid, name, registered, op, banned);
return new UserInfo(uuid, serverUUID.get(), registered, op, banned);
}
private Session toSession(UserImportData userImportData) {

View File

@ -26,28 +26,31 @@ import java.util.UUID;
*/
public class UserInfo {
private final UUID uuid;
@Deprecated
private String name;
private final UUID playerUUID;
private final UUID serverUUID;
private long registered;
private boolean banned;
private boolean opped;
public UserInfo(UUID uuid, String name, long registered, boolean opped, boolean banned) {
this.uuid = uuid;
this.name = name;
public UserInfo(UUID playerUUID, UUID serverUUID, long registered, boolean opped, boolean banned) {
this.playerUUID = playerUUID;
this.serverUUID = serverUUID;
this.registered = registered;
this.opped = opped;
this.banned = banned;
}
public UUID getUuid() {
return uuid;
public UUID getPlayerUuid() {
return playerUUID;
}
public UUID getServerUUID() {
return serverUUID;
}
@Deprecated
public String getName() {
return name;
return null;
}
public long getRegistered() {
@ -65,25 +68,25 @@ public class UserInfo {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!(o instanceof UserInfo)) return false;
UserInfo userInfo = (UserInfo) o;
return registered == userInfo.registered &&
banned == userInfo.banned &&
opped == userInfo.opped &&
Objects.equals(uuid, userInfo.uuid) &&
Objects.equals(name, userInfo.name);
playerUUID.equals(userInfo.playerUUID) &&
serverUUID.equals(userInfo.serverUUID);
}
@Override
public int hashCode() {
return Objects.hash(uuid, name, registered, banned, opped);
return Objects.hash(playerUUID, serverUUID, registered, banned, opped);
}
@Override
public String toString() {
return "UserInfo{" +
"uuid=" + uuid +
", name='" + name + '\'' +
"playerUUID=" + playerUUID +
", serverUUID=" + serverUUID +
", registered=" + registered +
", banned=" + banned +
", opped=" + opped +

View File

@ -474,7 +474,7 @@ public class LargeFetchQueries {
boolean banned = set.getBoolean(UserInfoTable.BANNED);
boolean op = set.getBoolean(UserInfoTable.OP);
userInfos.add(new UserInfo(uuid, "", registered, op, banned));
userInfos.add(new UserInfo(uuid, serverUUID, registered, op, banned));
serverMap.put(serverUUID, userInfos);
}

View File

@ -263,7 +263,7 @@ public class LargeStoreQueries {
UUID serverUUID = entry.getKey();
// Every User
for (UserInfo user : entry.getValue()) {
statement.setString(1, user.getUuid().toString());
statement.setString(1, user.getPlayerUuid().toString());
statement.setLong(2, user.getRegistered());
statement.setString(3, serverUUID.toString());
statement.setBoolean(4, user.isBanned());

View File

@ -56,7 +56,7 @@ public class AllPlayerContainersQuery implements Query<List<PlayerContainer>> {
List<UserInfo> serverUserInfo = entry.getValue();
for (UserInfo userInfo : serverUserInfo) {
UUID uuid = userInfo.getUuid();
UUID uuid = userInfo.getPlayerUuid();
if (uuid == null) {
continue;
}

View File

@ -77,7 +77,7 @@ public class ServerPlayerContainersQuery implements Query<List<PlayerContainer>>
for (UserInfo userInfo : serverUserInfo) {
PlayerContainer container = new PlayerContainer();
UUID uuid = userInfo.getUuid();
UUID uuid = userInfo.getPlayerUuid();
container.putRawData(PlayerKeys.UUID, uuid);
container.putRawData(PlayerKeys.REGISTERED, userInfo.getRegistered());

View File

@ -144,17 +144,12 @@ public class UserInfoTable extends Table {
}
public Map<UUID, UserInfo> getAllUserInfo(UUID uuid) {
String usersUUIDColumn = UsersTable.TABLE_NAME + "." + UsersTable.USER_UUID;
String usersNameColumn = UsersTable.TABLE_NAME + "." + UsersTable.USER_NAME + " as name";
String sql = "SELECT " +
TABLE_NAME + "." + REGISTERED + ", " +
BANNED + ", " +
OP + ", " +
usersNameColumn + ", " +
SERVER_UUID +
" FROM " + TABLE_NAME +
" INNER JOIN " + UsersTable.TABLE_NAME + " on " + usersUUIDColumn + "=" + TABLE_NAME + "." + USER_UUID +
" WHERE " + TABLE_NAME + "." + USER_UUID + "=?";
return query(new QueryStatement<Map<UUID, UserInfo>>(sql) {
@ -170,10 +165,8 @@ public class UserInfoTable extends Table {
long registered = set.getLong(REGISTERED);
boolean op = set.getBoolean(OP);
boolean banned = set.getBoolean(BANNED);
String name = set.getString("name");
UUID serverUUID = UUID.fromString(set.getString(SERVER_UUID));
map.put(serverUUID, new UserInfo(uuid, name, registered, op, banned));
map.put(serverUUID, new UserInfo(uuid, serverUUID, registered, op, banned));
}
return map;
}
@ -181,17 +174,12 @@ public class UserInfoTable extends Table {
}
public List<UserInfo> getServerUserInfo(UUID serverUUID) {
String usersUUIDColumn = UsersTable.TABLE_NAME + "." + UsersTable.USER_UUID;
String usersNameColumn = UsersTable.TABLE_NAME + "." + UsersTable.USER_NAME + " as name";
String sql = "SELECT " +
TABLE_NAME + "." + REGISTERED + ", " +
BANNED + ", " +
OP + ", " +
usersNameColumn + ", " +
TABLE_NAME + "." + USER_UUID +
" FROM " + TABLE_NAME +
" INNER JOIN " + UsersTable.TABLE_NAME + " on " + usersUUIDColumn + "=" + TABLE_NAME + "." + USER_UUID +
" WHERE " + SERVER_UUID + "=?";
return query(new QueryStatement<List<UserInfo>>(sql, 20000) {
@ -205,12 +193,11 @@ public class UserInfoTable extends Table {
List<UserInfo> userInfo = new ArrayList<>();
while (set.next()) {
UUID uuid = UUID.fromString(set.getString(USER_UUID));
String name = set.getString("name");
long registered = set.getLong(REGISTERED);
boolean op = set.getBoolean(OP);
boolean banned = set.getBoolean(BANNED);
UserInfo info = new UserInfo(uuid, name, registered, op, banned);
UserInfo info = new UserInfo(uuid, serverUUID, registered, op, banned);
if (!userInfo.contains(info)) {
userInfo.add(info);
}

View File

@ -70,7 +70,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
@Override
protected void performOperations() {
Collection<BaseUser> users = ofUsers.values().stream()
.map(user -> new BaseUser(user.getUuid(), user.getName(), user.getRegistered(), 0))
.map(user -> new BaseUser(user.getPlayerUuid(), user.getName(), user.getRegistered(), 0))
.collect(Collectors.toSet());
execute(LargeStoreQueries.storeAllCommonUserInformation(users));
}

View File

@ -413,10 +413,9 @@ public abstract class CommonDBTest {
assertTrue(userInfoTable.isRegistered(playerUUID));
UserInfo userInfo = userInfoTable.getAllUserInfo(playerUUID).get(serverUUID);
assertEquals(playerUUID, userInfo.getUuid());
assertEquals(playerUUID, userInfo.getPlayerUuid());
assertEquals(123456789L, (long) usersTable.getRegisterDates().get(0));
assertEquals(223456789L, userInfo.getRegistered());
assertEquals("Test", userInfo.getName());
assertFalse(userInfo.isBanned());
assertFalse(userInfo.isOperator());

View File

@ -89,7 +89,7 @@ public class RandomData {
public static List<UserInfo> randomUserData() {
List<UserInfo> test = new ArrayList<>();
for (int i = 0; i < 20; i++) {
UserInfo info = new UserInfo(UUID.randomUUID(), randomString(10), r.nextLong(), r.nextBoolean(), r.nextBoolean());
UserInfo info = new UserInfo(UUID.randomUUID(), UUID.randomUUID(), r.nextLong(), r.nextBoolean(), r.nextBoolean());
test.add(info);
}
return test;