From d7328dda506cd14cdb3e181cbc09c42eb94163fe Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Wed, 20 Apr 2022 21:11:57 -0400 Subject: [PATCH 1/5] Update Morphia to 2.x --- build.gradle | 11 +- .../grasscutter/database/DatabaseCounter.java | 2 +- .../grasscutter/database/DatabaseHelper.java | 117 +++++++----------- .../grasscutter/database/DatabaseManager.java | 42 +++---- .../java/emu/grasscutter/game/Account.java | 2 +- .../emu/grasscutter/game/GenshinPlayer.java | 2 +- .../game/avatar/GenshinAvatar.java | 2 +- .../grasscutter/game/friends/Friendship.java | 2 +- .../game/inventory/GenshinItem.java | 2 +- 9 files changed, 73 insertions(+), 109 deletions(-) diff --git a/build.gradle b/build.gradle index 97477456a..bfd5be045 100644 --- a/build.gradle +++ b/build.gradle @@ -14,17 +14,16 @@ plugins { id 'application' } -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 17 +targetCompatibility = 17 repositories { mavenCentral() - jcenter() } dependencies { implementation fileTree(dir: 'lib', include: ['*.jar']) - + implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.32' implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.6' implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.6' @@ -33,9 +32,9 @@ dependencies { implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.8' implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.18.1' - implementation group: 'org.reflections', name: 'reflections', version: '0.9.12' + implementation group: 'org.reflections', name: 'reflections', version: '0.10.2' - implementation group: 'dev.morphia.morphia', name: 'core', version: '1.6.1' + implementation group: 'dev.morphia.morphia', name: 'morphia-core', version: '2.2.6' implementation group: 'org.greenrobot', name: 'eventbus-java', version: '3.3.1' } diff --git a/src/main/java/emu/grasscutter/database/DatabaseCounter.java b/src/main/java/emu/grasscutter/database/DatabaseCounter.java index 37fa59d7c..a70fe518a 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseCounter.java +++ b/src/main/java/emu/grasscutter/database/DatabaseCounter.java @@ -3,7 +3,7 @@ package emu.grasscutter.database; import dev.morphia.annotations.Entity; import dev.morphia.annotations.Id; -@Entity(value = "counters", noClassnameStored = true) +@Entity(value = "counters", useDiscriminator = false) public class DatabaseCounter { @Id private String id; diff --git a/src/main/java/emu/grasscutter/database/DatabaseHelper.java b/src/main/java/emu/grasscutter/database/DatabaseHelper.java index 0289c3e71..27a20159f 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseHelper.java +++ b/src/main/java/emu/grasscutter/database/DatabaseHelper.java @@ -2,41 +2,33 @@ package emu.grasscutter.database; import java.util.List; -import com.mongodb.WriteResult; - -import dev.morphia.query.FindOptions; -import dev.morphia.query.Query; -import dev.morphia.query.internal.MorphiaCursor; +import com.mongodb.client.result.DeleteResult; +import dev.morphia.query.experimental.filters.Filters; import emu.grasscutter.GenshinConstants; -import emu.grasscutter.Grasscutter; import emu.grasscutter.game.Account; import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.friends.Friendship; import emu.grasscutter.game.inventory.GenshinItem; -public class DatabaseHelper { - - protected static FindOptions FIND_ONE = new FindOptions().limit(1); - +public final class DatabaseHelper { public static Account createAccount(String username) { return createAccountWithId(username, 0); } - + public static Account createAccountWithId(String username, int reservedId) { // Unique names only Account exists = DatabaseHelper.getAccountByName(username); if (exists != null) { return null; } - + // Make sure there are no id collisions if (reservedId > 0) { // Cannot make account with the same uid as the server console if (reservedId == GenshinConstants.SERVER_CONSOLE_UID) { return null; } - exists = DatabaseHelper.getAccountByPlayerId(reservedId); if (exists != null) { return null; @@ -47,10 +39,10 @@ public class DatabaseHelper { Account account = new Account(); account.setUsername(username); account.setId(Integer.toString(DatabaseManager.getNextId(account))); - + if (reservedId > 0) { account.setPlayerId(reservedId); - } + } DatabaseHelper.saveAccount(account); return account; @@ -63,65 +55,52 @@ public class DatabaseHelper { if (exists != null) { return null; } - + // Account Account account = new Account(); account.setId(Integer.toString(DatabaseManager.getNextId(account))); account.setUsername(username); account.setPassword(password); - DatabaseHelper.saveAccount(account); + DatabaseHelper.saveAccount(account); return account; } public static void saveAccount(Account account) { DatabaseManager.getDatastore().save(account); } - + public static Account getAccountByName(String username) { - MorphiaCursor cursor = DatabaseManager.getDatastore().createQuery(Account.class).field("username").equalIgnoreCase(username).find(FIND_ONE); - if (!cursor.hasNext()) return null; - return cursor.next(); + return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("username", username)).first(); } - + public static Account getAccountByToken(String token) { - if (token == null) return null; - MorphiaCursor cursor = DatabaseManager.getDatastore().createQuery(Account.class).field("token").equal(token).find(FIND_ONE); - if (!cursor.hasNext()) return null; - return cursor.next(); + if(token == null) return null; + return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("token", token)).first(); } - + public static Account getAccountById(String uid) { - MorphiaCursor cursor = DatabaseManager.getDatastore().createQuery(Account.class).field("_id").equal(uid).find(FIND_ONE); - if (!cursor.hasNext()) return null; - return cursor.next(); + return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("_id", uid)).first(); } - + public static Account getAccountByPlayerId(int playerId) { - MorphiaCursor cursor = DatabaseManager.getDatastore().createQuery(Account.class).field("playerId").equal(playerId).find(FIND_ONE); - if (!cursor.hasNext()) return null; - return cursor.next(); + return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("playerId", playerId)).first(); } - + public static boolean deleteAccount(String username) { - Query q = DatabaseManager.getDatastore().createQuery(Account.class).field("username").equalIgnoreCase(username); - return DatabaseManager.getDatastore().findAndDelete(q) != null; + return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("username", username)).delete().getDeletedCount() > 0; } - + public static GenshinPlayer getPlayerById(int id) { - Query query = DatabaseManager.getDatastore().createQuery(GenshinPlayer.class).field("_id").equal(id); - MorphiaCursor cursor = query.find(FIND_ONE); - if (!cursor.hasNext()) return null; - return cursor.next(); + return DatabaseManager.getDatastore().find(GenshinPlayer.class).filter(Filters.eq("_id", id)).first(); } - + public static boolean checkPlayerExists(int id) { - MorphiaCursor query = DatabaseManager.getDatastore().createQuery(GenshinPlayer.class).field("_id").equal(id).find(FIND_ONE); - return query.hasNext(); + return DatabaseManager.getDatastore().find(GenshinPlayer.class).filter(Filters.eq("_id", id)).first() != null; } - + public static synchronized GenshinPlayer createPlayer(GenshinPlayer character, int reservedId) { // Check if reserved id - int id = 0; + int id; if (reservedId > 0 && !checkPlayerExists(reservedId)) { id = reservedId; character.setUid(id); @@ -136,10 +115,10 @@ public class DatabaseHelper { DatabaseManager.getDatastore().save(character); return character; } - + public static synchronized int getNextPlayerId(int reservedId) { // Check if reserved id - int id = 0; + int id; if (reservedId > 0 && !checkPlayerExists(reservedId)) { id = reservedId; } else { @@ -150,41 +129,37 @@ public class DatabaseHelper { } return id; } - + public static void savePlayer(GenshinPlayer character) { DatabaseManager.getDatastore().save(character); } - + public static void saveAvatar(GenshinAvatar avatar) { DatabaseManager.getDatastore().save(avatar); } - + public static List getAvatars(GenshinPlayer player) { - Query query = DatabaseManager.getDatastore().createQuery(GenshinAvatar.class).filter("ownerId", player.getUid()); - return query.find().toList(); + return DatabaseManager.getDatastore().find(GenshinAvatar.class).filter(Filters.eq("playerId", player.getUid())).stream().toList(); } - + public static void saveItem(GenshinItem item) { DatabaseManager.getDatastore().save(item); } - + public static boolean deleteItem(GenshinItem item) { - WriteResult result = DatabaseManager.getDatastore().delete(item); + DeleteResult result = DatabaseManager.getDatastore().delete(item); return result.wasAcknowledged(); } - + public static List getInventoryItems(GenshinPlayer player) { - Query query = DatabaseManager.getDatastore().createQuery(GenshinItem.class).filter("ownerId", player.getUid()); - return query.find().toList(); + return DatabaseManager.getDatastore().find(GenshinItem.class).filter(Filters.eq("ownerId", player.getUid())).stream().toList(); } public static List getFriends(GenshinPlayer player) { - Query query = DatabaseManager.getDatastore().createQuery(Friendship.class).filter("ownerId", player.getUid()); - return query.find().toList(); + return DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("playerId", player.getUid())).stream().toList(); } - + public static List getReverseFriends(GenshinPlayer player) { - Query query = DatabaseManager.getDatastore().createQuery(Friendship.class).filter("friendId", player.getUid()); - return query.find().toList(); + return DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("friendId", player.getUid())).stream().toList(); } public static void saveFriendship(Friendship friendship) { @@ -196,13 +171,9 @@ public class DatabaseHelper { } public static Friendship getReverseFriendship(Friendship friendship) { - Query query = DatabaseManager.getDatastore().createQuery(Friendship.class); - query.and( - query.criteria("ownerId").equal(friendship.getFriendId()), - query.criteria("friendId").equal(friendship.getOwnerId()) - ); - MorphiaCursor reverseFriendship = query.find(FIND_ONE); - if (!reverseFriendship.hasNext()) return null; - return reverseFriendship.next(); + return DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.and( + Filters.eq("ownerId", friendship.getFriendId()), + Filters.eq("friendId", friendship.getOwnerId()) + )).first(); } } diff --git a/src/main/java/emu/grasscutter/database/DatabaseManager.java b/src/main/java/emu/grasscutter/database/DatabaseManager.java index 97e27a81a..3dccbcc0e 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseManager.java +++ b/src/main/java/emu/grasscutter/database/DatabaseManager.java @@ -1,13 +1,15 @@ package emu.grasscutter.database; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientURI; import com.mongodb.MongoCommandException; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; import com.mongodb.client.MongoDatabase; import com.mongodb.client.MongoIterable; import dev.morphia.Datastore; import dev.morphia.Morphia; +import dev.morphia.mapping.MapperOptions; +import dev.morphia.query.experimental.filters.Filters; import emu.grasscutter.Grasscutter; import emu.grasscutter.game.Account; import emu.grasscutter.game.GenshinPlayer; @@ -23,10 +25,6 @@ public final class DatabaseManager { DatabaseCounter.class, Account.class, GenshinPlayer.class, GenshinAvatar.class, GenshinItem.class, Friendship.class }; - public static MongoClient getMongoClient() { - return mongoClient; - } - public static Datastore getDatastore() { return datastore; } @@ -37,27 +35,23 @@ public final class DatabaseManager { public static void initialize() { // Initialize - mongoClient = new MongoClient(new MongoClientURI(Grasscutter.getConfig().DatabaseUrl)); - Morphia morphia = new Morphia(); + mongoClient = MongoClients.create(Grasscutter.getConfig().DatabaseUrl); - // TODO Update when migrating to Morphia 2.0 - morphia.getMapper().getOptions().setStoreEmpties(true); - morphia.getMapper().getOptions().setStoreNulls(false); - morphia.getMapper().getOptions().setDisableEmbeddedIndexes(true); - - // Map - morphia.map(mappedClasses); - - // Build datastore - datastore = morphia.createDatastore(mongoClient, Grasscutter.getConfig().DatabaseCollection); + // Set mapper options. + MapperOptions mapperOptions = MapperOptions.builder() + .storeEmpties(true).storeNulls(false).build(); + // Create data store. + datastore = Morphia.createDatastore(mongoClient, Grasscutter.getConfig().DatabaseCollection, mapperOptions); + // Map classes. + datastore.getMapper().map(mappedClasses); // Ensure indexes try { datastore.ensureIndexes(); - } catch (MongoCommandException e) { - Grasscutter.getLogger().info("Mongo index error: ", e); + } catch (MongoCommandException exception) { + Grasscutter.getLogger().info("Mongo index error: ", exception); // Duplicate index error - if (e.getCode() == 85) { + if (exception.getCode() == 85) { // Drop all indexes and re add them MongoIterable collections = datastore.getDatabase().listCollectionNames(); for (String name : collections) { @@ -68,9 +62,9 @@ public final class DatabaseManager { } } } - + public static synchronized int getNextId(Class c) { - DatabaseCounter counter = getDatastore().createQuery(DatabaseCounter.class).field("_id").equal(c.getSimpleName()).find().tryNext(); + DatabaseCounter counter = getDatastore().find(DatabaseCounter.class).filter(Filters.eq("_id", c.getName())).first(); if (counter == null) { counter = new DatabaseCounter(c.getSimpleName()); } @@ -80,7 +74,7 @@ public final class DatabaseManager { getDatastore().save(counter); } } - + public static synchronized int getNextId(Object o) { return getNextId(o.getClass()); } diff --git a/src/main/java/emu/grasscutter/game/Account.java b/src/main/java/emu/grasscutter/game/Account.java index 2eeeed3b1..3eff38cf9 100644 --- a/src/main/java/emu/grasscutter/game/Account.java +++ b/src/main/java/emu/grasscutter/game/Account.java @@ -15,7 +15,7 @@ import java.util.List; import com.mongodb.DBObject; -@Entity(value = "accounts", noClassnameStored = true) +@Entity(value = "accounts", useDiscriminator = false) public class Account { @Id private String id; diff --git a/src/main/java/emu/grasscutter/game/GenshinPlayer.java b/src/main/java/emu/grasscutter/game/GenshinPlayer.java index 1d8650e54..535ef06d9 100644 --- a/src/main/java/emu/grasscutter/game/GenshinPlayer.java +++ b/src/main/java/emu/grasscutter/game/GenshinPlayer.java @@ -58,7 +58,7 @@ import emu.grasscutter.utils.Position; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -@Entity(value = "players", noClassnameStored = true) +@Entity(value = "players", useDiscriminator = false) public class GenshinPlayer { @Id private int id; @Indexed(options = @IndexOptions(unique = true)) private String accountId; diff --git a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java index a5dcb3ee8..d16208047 100644 --- a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java @@ -50,7 +50,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -@Entity(value = "avatars", noClassnameStored = true) +@Entity(value = "avatars", useDiscriminator = false) public class GenshinAvatar { @Id private ObjectId id; @Indexed private int ownerId; // Id of player that this avatar belongs to diff --git a/src/main/java/emu/grasscutter/game/friends/Friendship.java b/src/main/java/emu/grasscutter/game/friends/Friendship.java index 2be7d1fce..7ac147b6a 100644 --- a/src/main/java/emu/grasscutter/game/friends/Friendship.java +++ b/src/main/java/emu/grasscutter/game/friends/Friendship.java @@ -9,7 +9,7 @@ import emu.grasscutter.net.proto.FriendBriefOuterClass.FriendBrief; import emu.grasscutter.net.proto.FriendOnlineStateOuterClass.FriendOnlineState; import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage; -@Entity(value = "friendships", noClassnameStored = true) +@Entity(value = "friendships", useDiscriminator = false) public class Friendship { @Id private ObjectId id; diff --git a/src/main/java/emu/grasscutter/game/inventory/GenshinItem.java b/src/main/java/emu/grasscutter/game/inventory/GenshinItem.java index 0b0db49c4..a395825da 100644 --- a/src/main/java/emu/grasscutter/game/inventory/GenshinItem.java +++ b/src/main/java/emu/grasscutter/game/inventory/GenshinItem.java @@ -34,7 +34,7 @@ import emu.grasscutter.net.proto.SceneWeaponInfoOuterClass.SceneWeaponInfo; import emu.grasscutter.net.proto.WeaponOuterClass.Weapon; import emu.grasscutter.utils.WeightedList; -@Entity(value = "items", noClassnameStored = true) +@Entity(value = "items", useDiscriminator = false) public class GenshinItem { @Id private ObjectId id; @Indexed private int ownerId; From b902fa6f48300f9daefec6d1a666b5a908d44b15 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Wed, 20 Apr 2022 23:56:27 -0400 Subject: [PATCH 2/5] Fix command detection --- src/main/java/emu/grasscutter/Grasscutter.java | 2 +- src/main/java/emu/grasscutter/command/CommandMap.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/Grasscutter.java b/src/main/java/emu/grasscutter/Grasscutter.java index 0e34c120d..a66c71254 100644 --- a/src/main/java/emu/grasscutter/Grasscutter.java +++ b/src/main/java/emu/grasscutter/Grasscutter.java @@ -34,7 +34,7 @@ public final class Grasscutter { private static DispatchServer dispatchServer; private static GameServer gameServer; - public static final Reflections reflector = new Reflections(); + public static final Reflections reflector = new Reflections("emu.grasscutter"); static { // Declare logback configuration. diff --git a/src/main/java/emu/grasscutter/command/CommandMap.java b/src/main/java/emu/grasscutter/command/CommandMap.java index 007fafe17..f735bc642 100644 --- a/src/main/java/emu/grasscutter/command/CommandMap.java +++ b/src/main/java/emu/grasscutter/command/CommandMap.java @@ -11,6 +11,7 @@ import java.util.*; public final class CommandMap { private final Map commands = new HashMap<>(); private final Map annotations = new HashMap<>(); + public CommandMap() { this(false); } From 0a96012f2c128c5217ec6a1344d3906ffa06016a Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Thu, 21 Apr 2022 02:07:05 -0400 Subject: [PATCH 3/5] why is `Account#onLoad` THE DAMN REASON FOR HOURS OF TESTING --- build.gradle | 4 +-- .../grasscutter/database/DatabaseManager.java | 3 +- .../java/emu/grasscutter/game/Account.java | 28 ++++++++----------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index bfd5be045..dcc109d0e 100644 --- a/build.gradle +++ b/build.gradle @@ -14,8 +14,8 @@ plugins { id 'application' } -sourceCompatibility = 17 -targetCompatibility = 17 +sourceCompatibility = 16 +targetCompatibility = 16 repositories { mavenCentral() diff --git a/src/main/java/emu/grasscutter/database/DatabaseManager.java b/src/main/java/emu/grasscutter/database/DatabaseManager.java index 3dccbcc0e..004f6ba80 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseManager.java +++ b/src/main/java/emu/grasscutter/database/DatabaseManager.java @@ -18,7 +18,6 @@ import emu.grasscutter.game.friends.Friendship; import emu.grasscutter.game.inventory.GenshinItem; public final class DatabaseManager { - private static MongoClient mongoClient; private static Datastore datastore; private static final Class[] mappedClasses = new Class[] { @@ -35,7 +34,7 @@ public final class DatabaseManager { public static void initialize() { // Initialize - mongoClient = MongoClients.create(Grasscutter.getConfig().DatabaseUrl); + MongoClient mongoClient = MongoClients.create(Grasscutter.getConfig().DatabaseUrl); // Set mapper options. MapperOptions mapperOptions = MapperOptions.builder() diff --git a/src/main/java/emu/grasscutter/game/Account.java b/src/main/java/emu/grasscutter/game/Account.java index 3eff38cf9..073bf10fd 100644 --- a/src/main/java/emu/grasscutter/game/Account.java +++ b/src/main/java/emu/grasscutter/game/Account.java @@ -1,20 +1,13 @@ package emu.grasscutter.game; -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 dev.morphia.annotations.*; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.utils.Crypto; import emu.grasscutter.utils.Utils; -import dev.morphia.annotations.IndexOptions; import java.util.ArrayList; import java.util.List; -import com.mongodb.DBObject; - @Entity(value = "accounts", useDiscriminator = false) public class Account { @Id private String id; @@ -30,7 +23,7 @@ public class Account { private String token; private String sessionKey; // Session token for dispatch server private List permissions; - + @Deprecated public Account() { this.permissions = new ArrayList<>(); @@ -121,15 +114,16 @@ 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); } + +// 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("*"); +// } +// } } From 06101f1b9c85e472158f7384bede4b21f2347d74 Mon Sep 17 00:00:00 2001 From: fumbling <104180076+fumbling644o@users.noreply.github.com> Date: Thu, 21 Apr 2022 22:19:47 -0400 Subject: [PATCH 4/5] Morphia call fixes; add `@Entity` to more classes 1. During the conversion of Morphia calls to the new API, some of the `Filter.eq()` calls had their `field` set to `playerId` due to a copy/paste typo. 2. Morphia 2 switches to the codec system, so anything that will be serialized in the pipeline requires the `@Entity` annotation. --- src/main/java/emu/grasscutter/database/DatabaseHelper.java | 4 ++-- src/main/java/emu/grasscutter/game/TeamInfo.java | 2 ++ src/main/java/emu/grasscutter/game/TeamManager.java | 2 ++ .../java/emu/grasscutter/game/avatar/AvatarProfileData.java | 3 +++ src/main/java/emu/grasscutter/game/friends/PlayerProfile.java | 1 + .../emu/grasscutter/game/gacha/PlayerGachaBannerInfo.java | 3 +++ src/main/java/emu/grasscutter/game/gacha/PlayerGachaInfo.java | 3 +++ src/main/java/emu/grasscutter/utils/Position.java | 2 ++ 8 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/database/DatabaseHelper.java b/src/main/java/emu/grasscutter/database/DatabaseHelper.java index 27a20159f..b70365225 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseHelper.java +++ b/src/main/java/emu/grasscutter/database/DatabaseHelper.java @@ -139,7 +139,7 @@ public final class DatabaseHelper { } public static List getAvatars(GenshinPlayer player) { - return DatabaseManager.getDatastore().find(GenshinAvatar.class).filter(Filters.eq("playerId", player.getUid())).stream().toList(); + return DatabaseManager.getDatastore().find(GenshinAvatar.class).filter(Filters.eq("ownerId", player.getUid())).stream().toList(); } public static void saveItem(GenshinItem item) { @@ -155,7 +155,7 @@ public final class DatabaseHelper { return DatabaseManager.getDatastore().find(GenshinItem.class).filter(Filters.eq("ownerId", player.getUid())).stream().toList(); } public static List getFriends(GenshinPlayer player) { - return DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("playerId", player.getUid())).stream().toList(); + return DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("ownerId", player.getUid())).stream().toList(); } public static List getReverseFriends(GenshinPlayer player) { diff --git a/src/main/java/emu/grasscutter/game/TeamInfo.java b/src/main/java/emu/grasscutter/game/TeamInfo.java index 0a12b1d2c..83220a7e5 100644 --- a/src/main/java/emu/grasscutter/game/TeamInfo.java +++ b/src/main/java/emu/grasscutter/game/TeamInfo.java @@ -3,10 +3,12 @@ package emu.grasscutter.game; import java.util.ArrayList; import java.util.List; +import dev.morphia.annotations.Entity; import emu.grasscutter.GenshinConstants; import emu.grasscutter.Grasscutter; import emu.grasscutter.game.avatar.GenshinAvatar; +@Entity public class TeamInfo { private String name; private List avatars; diff --git a/src/main/java/emu/grasscutter/game/TeamManager.java b/src/main/java/emu/grasscutter/game/TeamManager.java index 4cd7bfcdf..2ab9639c2 100644 --- a/src/main/java/emu/grasscutter/game/TeamManager.java +++ b/src/main/java/emu/grasscutter/game/TeamManager.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import dev.morphia.annotations.Entity; import dev.morphia.annotations.Transient; import emu.grasscutter.GenshinConstants; import emu.grasscutter.Grasscutter; @@ -41,6 +42,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntSet; +@Entity public class TeamManager { @Transient private GenshinPlayer player; diff --git a/src/main/java/emu/grasscutter/game/avatar/AvatarProfileData.java b/src/main/java/emu/grasscutter/game/avatar/AvatarProfileData.java index 5458c1752..d04c9d326 100644 --- a/src/main/java/emu/grasscutter/game/avatar/AvatarProfileData.java +++ b/src/main/java/emu/grasscutter/game/avatar/AvatarProfileData.java @@ -1,5 +1,8 @@ package emu.grasscutter.game.avatar; +import dev.morphia.annotations.Entity; + +@Entity public class AvatarProfileData { private int avatarId; private int level; diff --git a/src/main/java/emu/grasscutter/game/friends/PlayerProfile.java b/src/main/java/emu/grasscutter/game/friends/PlayerProfile.java index cc7408aa6..50889ad0c 100644 --- a/src/main/java/emu/grasscutter/game/friends/PlayerProfile.java +++ b/src/main/java/emu/grasscutter/game/friends/PlayerProfile.java @@ -4,6 +4,7 @@ import dev.morphia.annotations.*; import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.utils.Utils; +@Entity public class PlayerProfile { @Transient private GenshinPlayer player; diff --git a/src/main/java/emu/grasscutter/game/gacha/PlayerGachaBannerInfo.java b/src/main/java/emu/grasscutter/game/gacha/PlayerGachaBannerInfo.java index 2e144226e..b0c85d355 100644 --- a/src/main/java/emu/grasscutter/game/gacha/PlayerGachaBannerInfo.java +++ b/src/main/java/emu/grasscutter/game/gacha/PlayerGachaBannerInfo.java @@ -1,5 +1,8 @@ package emu.grasscutter.game.gacha; +import dev.morphia.annotations.Entity; + +@Entity public class PlayerGachaBannerInfo { private int pity5 = 0; private int pity4 = 0; diff --git a/src/main/java/emu/grasscutter/game/gacha/PlayerGachaInfo.java b/src/main/java/emu/grasscutter/game/gacha/PlayerGachaInfo.java index c3aabcb76..8dd0e380e 100644 --- a/src/main/java/emu/grasscutter/game/gacha/PlayerGachaInfo.java +++ b/src/main/java/emu/grasscutter/game/gacha/PlayerGachaInfo.java @@ -1,5 +1,8 @@ package emu.grasscutter.game.gacha; +import dev.morphia.annotations.Entity; + +@Entity public class PlayerGachaInfo { private PlayerGachaBannerInfo standardBanner; private PlayerGachaBannerInfo eventCharacterBanner; diff --git a/src/main/java/emu/grasscutter/utils/Position.java b/src/main/java/emu/grasscutter/utils/Position.java index 6a02dacba..f2ecb6915 100644 --- a/src/main/java/emu/grasscutter/utils/Position.java +++ b/src/main/java/emu/grasscutter/utils/Position.java @@ -2,8 +2,10 @@ package emu.grasscutter.utils; import java.io.Serializable; +import dev.morphia.annotations.Entity; import emu.grasscutter.net.proto.VectorOuterClass.Vector; +@Entity public class Position implements Serializable { private static final long serialVersionUID = -2001232313615923575L; From 7b9447602b29a81e9eb17a95fac6c31eb6a3a62b Mon Sep 17 00:00:00 2001 From: Melledy <52122272+Melledy@users.noreply.github.com> Date: Fri, 22 Apr 2022 19:26:48 -0700 Subject: [PATCH 5/5] Change java version requirement in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 853c37ae3..e6843b116 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ A WIP server reimplementation for *some anime game* 2.3-2.6 * If you update from an older version, delete `config.json` for regeneration ### Prerequisites -* JDK-8u202 ([mirror link](https://mirrors.huaweicloud.com/java/jdk/8u202-b08/) since Oracle required an account to download old builds) +* Java 16 * Mongodb (recommended 4.0+) * Proxy daemon: mitmproxy (mitmdump, recommended), Fiddler Classic, etc.