Load homes from SQL
This commit is contained in:
parent
a7f14eb573
commit
bbd4610fbe
|
|
@ -137,7 +137,7 @@ public class SQLStorageProvider extends StorageProvider {
|
|||
.uuid(uuid)
|
||||
.backLocation(locationStringToLocation(resultSet.getString("BackLocation")))
|
||||
.deathLocation(locationStringToLocation(resultSet.getString("DeathLocation")))
|
||||
.homes(locationMapStringToLocationMap(resultSet.getString("locationMapToString")))
|
||||
.homes(loadHomes(uuid))
|
||||
.userSettings(new EssentiaUserSettings
|
||||
.Builder()
|
||||
//.allowTeleports(resultSet.getBoolean("TeleportToggled")) // FIXME
|
||||
|
|
@ -150,6 +150,30 @@ public class SQLStorageProvider extends StorageProvider {
|
|||
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
|
||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
||||
// Todo - use reflection to go over the fields to save?
|
||||
|
|
@ -224,13 +248,4 @@ public class SQLStorageProvider extends StorageProvider {
|
|||
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