Load homes from SQL
This commit is contained in:
parent
a7f14eb573
commit
e2a32c1ebd
|
|
@ -137,7 +137,7 @@ public class SQLStorageProvider extends StorageProvider {
|
||||||
.uuid(uuid)
|
.uuid(uuid)
|
||||||
.backLocation(locationStringToLocation(resultSet.getString("BackLocation")))
|
.backLocation(locationStringToLocation(resultSet.getString("BackLocation")))
|
||||||
.deathLocation(locationStringToLocation(resultSet.getString("DeathLocation")))
|
.deathLocation(locationStringToLocation(resultSet.getString("DeathLocation")))
|
||||||
.homes(locationMapStringToLocationMap(resultSet.getString("locationMapToString")))
|
.homes(loadHomes(uuid))
|
||||||
.userSettings(new EssentiaUserSettings
|
.userSettings(new EssentiaUserSettings
|
||||||
.Builder()
|
.Builder()
|
||||||
//.allowTeleports(resultSet.getBoolean("TeleportToggled")) // FIXME
|
//.allowTeleports(resultSet.getBoolean("TeleportToggled")) // FIXME
|
||||||
|
|
@ -150,8 +150,33 @@ public class SQLStorageProvider extends StorageProvider {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, Home> loadHomes(UUID uuid) {
|
||||||
|
String sql = "SELECT * FROM homes WHERE uuid = ?";
|
||||||
|
Map<String, Home> locationMap = new HashMap<>();
|
||||||
|
DatabaseQuery databaseQuery = new DatabaseQuery(sql, ps -> ps.setString(1, uuid.toString()));
|
||||||
|
try (ResultSet resultSet = databaseQuery.executeQuery(getDatabaseConnection().get())) {
|
||||||
|
if (!resultSet.next()) {
|
||||||
|
return locationMap;
|
||||||
|
}
|
||||||
|
String homeName = resultSet.getString("Name");
|
||||||
|
while (resultSet.next()) {
|
||||||
|
locationMap.put(
|
||||||
|
homeName,
|
||||||
|
new EssentiaHome(
|
||||||
|
homeName,
|
||||||
|
locationStringToLocation(resultSet.getString("HomeLocation"))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// catch this nicely
|
||||||
|
}
|
||||||
|
return locationMap;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
public void save(@NotNull EssentiaUser user) throws Exception {
|
||||||
|
// TODO - convert to json object and save that in sql!
|
||||||
// Todo - use reflection to go over the fields to save?
|
// Todo - use reflection to go over the fields to save?
|
||||||
// might not be the best way if new fields are added...
|
// might not be the best way if new fields are added...
|
||||||
// split into multiple tables - users, userdata, userhomes, ... ?
|
// split into multiple tables - users, userdata, userhomes, ... ?
|
||||||
|
|
@ -169,6 +194,11 @@ public class SQLStorageProvider extends StorageProvider {
|
||||||
}
|
}
|
||||||
}), true
|
}), true
|
||||||
);
|
);
|
||||||
|
saveHomes(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveHomes(EssentiaUser essentiaUser) {
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -224,13 +254,4 @@ public class SQLStorageProvider extends StorageProvider {
|
||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Home> locationMapStringToLocationMap(String locationMapString) {
|
|
||||||
Map<String, Home> locationMap = new HashMap<>();
|
|
||||||
String[] entries = locationMapString.split(";");
|
|
||||||
for (String entry : entries) {
|
|
||||||
String[] data = entry.split("%");
|
|
||||||
locationMap.put(data[0], new EssentiaHome(data[0], locationStringToLocation(data[1])));
|
|
||||||
}
|
|
||||||
return locationMap;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user