Add loading for EssentiaUserSettings

This commit is contained in:
Len 2024-07-28 14:47:49 +02:00
parent fe83919200
commit cf0bcefd06
4 changed files with 42 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package com.alttd.essentia.model;
import com.alttd.essentia.api.model.UserSettings;
import lombok.Getter;
import lombok.Setter;
@Getter
public class EssentiaUserSettings implements UserSettings {
@ -16,6 +17,16 @@ public class EssentiaUserSettings implements UserSettings {
private boolean needsSaving;
private EssentiaUserSettings(Builder builder) {
this.godMode = builder.godMode;;
this.flying = builder.flying;
this.flySpeed = builder.flySpeed;
this.walkSpeed = builder.walkSpeed;
this.pTime = builder.pTime;
this.pWeather = builder.pWeather;
this.allowTeleports = builder.allowTeleports;
}
@Override
public void godMode(boolean godMode) {
this.godMode = godMode;
@ -33,4 +44,22 @@ public class EssentiaUserSettings implements UserSettings {
this.flying = flying;
this.needsSaving = true;
}
@Setter
public static class Builder {
// TODO - defaults?
protected boolean godMode;
protected boolean flying;
protected double flySpeed;
protected double walkSpeed;
protected boolean pTime;
protected boolean pWeather;
protected boolean allowTeleports;
public EssentiaUserSettings build() {
return new EssentiaUserSettings(this);
}
}
}

View File

@ -4,6 +4,7 @@ import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.api.model.Home;
import com.alttd.essentia.model.EssentiaHome;
import com.alttd.essentia.model.EssentiaUserSettings;
import com.alttd.essentia.storage.StorageProvider;
import com.alttd.essentia.user.EssentiaUser;
import org.bukkit.Bukkit;
@ -137,7 +138,10 @@ public class SQLStorageProvider extends StorageProvider {
.backLocation(locationStringToLocation(resultSet.getString("BackLocation")))
.deathLocation(locationStringToLocation(resultSet.getString("DeathLocation")))
.homes(locationMapStringToLocationMap(resultSet.getString("locationMapToString")))
.allowTeleports(resultSet.getBoolean("TeleportToggled"))
.userSettings(new EssentiaUserSettings
.Builder()
//.allowTeleports(resultSet.getBoolean("TeleportToggled")) // FIXME
.build())
.build();
} catch (SQLException e) {

View File

@ -3,6 +3,7 @@ package com.alttd.essentia.storage.yaml;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.model.Home;
import com.alttd.essentia.model.EssentiaHome;
import com.alttd.essentia.model.EssentiaUserSettings;
import com.alttd.essentia.storage.StorageProvider;
import com.alttd.essentia.user.EssentiaUser;
import org.bukkit.Bukkit;
@ -38,7 +39,10 @@ public class YamlStorageProvider extends StorageProvider {
.backLocation(getStoredLocation(config,"teleports.back"))
.deathLocation(getStoredLocation(config,"teleports.death"))
.homes(getHomeData(config))
.allowTeleports(config.getBoolean("allow-teleports", true))
.userSettings(new EssentiaUserSettings
.Builder()
.allowTeleports(config.getBoolean("allow-teleports", true))
.build())
.build();
}

View File

@ -5,7 +5,6 @@ import com.alttd.essentia.api.model.UserSettings;
import com.alttd.essentia.api.request.Request;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.model.EssentiaHome;
import com.alttd.essentia.model.EssentiaUserSettings;
import org.bukkit.Location;
import java.util.*;
@ -133,7 +132,7 @@ public class EssentiaUser implements User {
protected Location backLocation = null;
protected Location deathLocation = null;
protected Map<String, Home> homes = new HashMap<>();
protected EssentiaUserSettings userSettings = new EssentiaUserSettings();
protected UserSettings userSettings = null;
public Builder uuid(UUID uuid) {
this.uuid = uuid;
@ -155,8 +154,8 @@ public class EssentiaUser implements User {
return this;
}
public Builder allowTeleports(boolean allowTeleports) {
this.userSettings.allowTeleports(allowTeleports);
public Builder userSettings(UserSettings userSettings) {
this.userSettings = userSettings;
return this;
}