mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-26 23:32:43 +00:00
why is Account#onLoad
THE DAMN REASON FOR HOURS OF TESTING
This commit is contained in:
parent
c3da897e01
commit
cc231b812d
@ -14,8 +14,8 @@ plugins {
|
|||||||
id 'application'
|
id 'application'
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceCompatibility = 17
|
sourceCompatibility = 16
|
||||||
targetCompatibility = 17
|
targetCompatibility = 16
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
@ -18,7 +18,6 @@ import emu.grasscutter.game.friends.Friendship;
|
|||||||
import emu.grasscutter.game.inventory.GenshinItem;
|
import emu.grasscutter.game.inventory.GenshinItem;
|
||||||
|
|
||||||
public final class DatabaseManager {
|
public final class DatabaseManager {
|
||||||
private static MongoClient mongoClient;
|
|
||||||
private static Datastore datastore;
|
private static Datastore datastore;
|
||||||
|
|
||||||
private static final Class<?>[] mappedClasses = new Class<?>[] {
|
private static final Class<?>[] mappedClasses = new Class<?>[] {
|
||||||
@ -35,7 +34,7 @@ public final class DatabaseManager {
|
|||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
// Initialize
|
// Initialize
|
||||||
mongoClient = MongoClients.create(Grasscutter.getConfig().DatabaseUrl);
|
MongoClient mongoClient = MongoClients.create(Grasscutter.getConfig().DatabaseUrl);
|
||||||
|
|
||||||
// Set mapper options.
|
// Set mapper options.
|
||||||
MapperOptions mapperOptions = MapperOptions.builder()
|
MapperOptions mapperOptions = MapperOptions.builder()
|
||||||
|
@ -1,20 +1,13 @@
|
|||||||
package emu.grasscutter.game;
|
package emu.grasscutter.game;
|
||||||
|
|
||||||
import dev.morphia.annotations.Collation;
|
import dev.morphia.annotations.*;
|
||||||
import dev.morphia.annotations.Entity;
|
|
||||||
import dev.morphia.annotations.Id;
|
|
||||||
import dev.morphia.annotations.Indexed;
|
|
||||||
import dev.morphia.annotations.PreLoad;
|
|
||||||
import emu.grasscutter.database.DatabaseHelper;
|
import emu.grasscutter.database.DatabaseHelper;
|
||||||
import emu.grasscutter.utils.Crypto;
|
import emu.grasscutter.utils.Crypto;
|
||||||
import emu.grasscutter.utils.Utils;
|
import emu.grasscutter.utils.Utils;
|
||||||
import dev.morphia.annotations.IndexOptions;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
|
|
||||||
@Entity(value = "accounts", useDiscriminator = false)
|
@Entity(value = "accounts", useDiscriminator = false)
|
||||||
public class Account {
|
public class Account {
|
||||||
@Id private String id;
|
@Id private String id;
|
||||||
@ -30,7 +23,7 @@ public class Account {
|
|||||||
private String token;
|
private String token;
|
||||||
private String sessionKey; // Session token for dispatch server
|
private String sessionKey; // Session token for dispatch server
|
||||||
private List<String> permissions;
|
private List<String> permissions;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Account() {
|
public Account() {
|
||||||
this.permissions = new ArrayList<>();
|
this.permissions = new ArrayList<>();
|
||||||
@ -121,15 +114,16 @@ public class Account {
|
|||||||
return this.token;
|
return this.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreLoad
|
|
||||||
public void onLoad(DBObject dbObj) {
|
|
||||||
// Grant the superuser permissions to accounts created before the permissions update
|
|
||||||
if (!dbObj.containsField("permissions")) {
|
|
||||||
this.addPermission("*");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
DatabaseHelper.saveAccount(this);
|
DatabaseHelper.saveAccount(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Find an implementation for this. Morphia 2.0 breaks this method for some reason?
|
||||||
|
// @PreLoad
|
||||||
|
// public void onLoad(DBObject object) {
|
||||||
|
// // Grant the superuser permissions to accounts created before the permissions update
|
||||||
|
// if (!object.containsField("permissions")) {
|
||||||
|
// this.addPermission("*");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user