From efc9a4b3e5f58511b7d3a2d2f1a525a9780c77bd Mon Sep 17 00:00:00 2001 From: Melledy <52122272+Melledy@users.noreply.github.com> Date: Mon, 18 Apr 2022 22:00:01 -0700 Subject: [PATCH] Grant superuser permissions to accounts created before the permissions update --- src/main/java/emu/grasscutter/game/Account.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/emu/grasscutter/game/Account.java b/src/main/java/emu/grasscutter/game/Account.java index 0d206dda1..dffbb0d86 100644 --- a/src/main/java/emu/grasscutter/game/Account.java +++ b/src/main/java/emu/grasscutter/game/Account.java @@ -4,6 +4,7 @@ import dev.morphia.annotations.Collation; 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.utils.Crypto; import emu.grasscutter.utils.Utils; @@ -12,6 +13,8 @@ import dev.morphia.annotations.IndexOptions; import java.util.ArrayList; import java.util.List; +import com.mongodb.DBObject; + @Entity(value = "accounts", noClassnameStored = true) public class Account { @Id private String id; @@ -114,6 +117,14 @@ public class Account { 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() { DatabaseHelper.saveAccount(this); }