This commit is contained in:
NK 2022-11-28 22:27:00 +00:00
parent 0ba5074c30
commit df59f95c7b
2 changed files with 7 additions and 2 deletions

View file

@ -13,6 +13,7 @@ public class DatabaseManager {
private static MongoCollection<Document> custom_weapons; private static MongoCollection<Document> custom_weapons;
public static MongoCollection<Document> ranks; public static MongoCollection<Document> ranks;
public static MongoCollection<Document> npcs; public static MongoCollection<Document> npcs;
public static MongoCollection<Document> miners;
public MongoClient client; public MongoClient client;
public static MongoDatabase database; public static MongoDatabase database;
@ -23,13 +24,16 @@ public class DatabaseManager {
custom_weapons = database.getCollection("custom_weapons"); custom_weapons = database.getCollection("custom_weapons");
ranks = database.getCollection("ranks"); ranks = database.getCollection("ranks");
npcs = database.getCollection("npcs"); npcs = database.getCollection("npcs");
miners = database.getCollection("miners");
} }
public static void createUserSchema(String username) { public static void createUserSchema(String username) {
Document document = new Document(); Document document = new Document();
document.put("Username", username); document.put("Username", username);
document.put("Bank", 0); document.put("Bank", 0);
users.insertOne(document); users.insertOne(document);
} }
public void updateUserBank(String username, Number coins) { public void updateUserBank(String username, Number coins) {
Document document = users.find(new Document("Username", username)).first(); Document document = users.find(new Document("Username", username)).first();
if (document != null) { if (document != null) {
@ -38,6 +42,7 @@ public class DatabaseManager {
users.updateOne(document, update); users.updateOne(document, update);
} }
} }
public static HashMap<String, Object> getUser(String username) { public static HashMap<String, Object> getUser(String username) {
try (MongoCursor<Document> cursor = users.find(Filters.eq("Username", username)).cursor()) { try (MongoCursor<Document> cursor = users.find(Filters.eq("Username", username)).cursor()) {
while (cursor.hasNext()) { while (cursor.hasNext()) {