database debug

This commit is contained in:
NK 2022-11-27 18:40:02 +00:00
parent 605a82dc4b
commit 07af2596d8
4 changed files with 10 additions and 24 deletions

View file

@ -31,7 +31,7 @@ public final class Main extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new DamageEffectEvents(this), this);
Bukkit.getPluginManager().registerEvents(new NPCEvents(), this);
new DiscordClientManager();
new DatabaseManager(this);
new DatabaseManager();
NPCManager.reloadNPC();
}
}

View file

@ -1,8 +1,5 @@
package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.database.DatabaseManager;
import me.night.nullvalkyrie.npc.NPCManager;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -17,9 +14,6 @@ public class BetaCommand extends Command {
@Override
public void onCommand(CommandSender sender, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
NPCManager.createNPC(player, "&a&lNK");
DatabaseManager.getUser("Kaly15");
}
}
@Override

View file

@ -3,7 +3,6 @@ package me.night.nullvalkyrie.database;
import com.mongodb.client.*;
import com.mongodb.client.model.Filters;
import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.database.ranks.RankManager;
import org.bson.Document;
import org.bson.conversions.Bson;
@ -15,9 +14,8 @@ public class DatabaseManager {
public static MongoCollection<Document> ranks;
public MongoClient client;
public static MongoDatabase database;
private Main main;
public DatabaseManager(Main main) {
this.main = main;
public DatabaseManager() {
this.client = MongoClients.create(Main.env.get("MONGODB_URI"));
database = client.getDatabase("NullValkyrie");
users = database.getCollection("users");
@ -42,13 +40,10 @@ public class DatabaseManager {
try (MongoCursor<Document> cursor = users.find(Filters.eq("Username", username)).cursor()) {
while (cursor.hasNext()) {
Document doc = cursor.next();
for (String a : doc.keySet()) {
if (!a.equals("_id")) {
HashMap<String, Object> details = new HashMap<>();
details.put(a, doc.get(a));
return details;
}
}
HashMap<String, Object> map = new HashMap<>();
for (String key : doc.keySet()) map.put(key, doc.get(key));
map.remove("_id");
return map;
}
}
return null;

View file

@ -1,10 +1,7 @@
package me.night.nullvalkyrie.database.ranks;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.model.Filters;
import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.database.DatabaseManager;
import me.night.nullvalkyrie.ui.Rank;
import org.bson.Document;
@ -40,9 +37,9 @@ public class RankManager {
try (MongoCursor<Document> cursor = DatabaseManager.ranks.find(Filters.eq("UUID", uuid.toString())).cursor()) {
while (cursor.hasNext()) {
Document doc = cursor.next();
for (String a : doc.keySet()) {
if (a.equals("Rank")) {
return Rank.valueOf((String) doc.get(a));
for (String key : doc.keySet()) {
if (key.equals("Rank")) {
return Rank.valueOf((String) doc.get(key));
}
}
}