From df59f95c7b6a74739e5ebde547099e1074dcb610 Mon Sep 17 00:00:00 2001 From: NK Date: Mon, 28 Nov 2022 22:27:00 +0000 Subject: [PATCH] miners --- .../me/night/nullvalkyrie/database/DatabaseManager.java | 9 +++++++-- src/main/resources/npcs.yml | 0 2 files changed, 7 insertions(+), 2 deletions(-) delete mode 100644 src/main/resources/npcs.yml diff --git a/src/main/java/me/night/nullvalkyrie/database/DatabaseManager.java b/src/main/java/me/night/nullvalkyrie/database/DatabaseManager.java index eb435b9..30caf7c 100644 --- a/src/main/java/me/night/nullvalkyrie/database/DatabaseManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/DatabaseManager.java @@ -13,6 +13,7 @@ public class DatabaseManager { private static MongoCollection custom_weapons; public static MongoCollection ranks; public static MongoCollection npcs; + public static MongoCollection miners; public MongoClient client; public static MongoDatabase database; @@ -23,27 +24,31 @@ public class DatabaseManager { custom_weapons = database.getCollection("custom_weapons"); ranks = database.getCollection("ranks"); npcs = database.getCollection("npcs"); + miners = database.getCollection("miners"); } + public static void createUserSchema(String username) { Document document = new Document(); document.put("Username", username); document.put("Bank", 0); users.insertOne(document); } + public void updateUserBank(String username, Number coins) { Document document = users.find(new Document("Username", username)).first(); - if(document != null) { + if (document != null) { Bson updated = new Document("Bank", coins); Bson update = new Document("$set", updated); users.updateOne(document, update); } } + public static HashMap getUser(String username) { try (MongoCursor cursor = users.find(Filters.eq("Username", username)).cursor()) { while (cursor.hasNext()) { Document doc = cursor.next(); HashMap map = new HashMap<>(); - for (String key : doc.keySet()) map.put(key, doc.get(key)); + for (String key : doc.keySet()) map.put(key, doc.get(key)); map.remove("_id"); return map; } diff --git a/src/main/resources/npcs.yml b/src/main/resources/npcs.yml deleted file mode 100644 index e69de29..0000000