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 DamageEffectEvents(this), this);
Bukkit.getPluginManager().registerEvents(new NPCEvents(), this); Bukkit.getPluginManager().registerEvents(new NPCEvents(), this);
new DiscordClientManager(); new DiscordClientManager();
new DatabaseManager(this); new DatabaseManager();
NPCManager.reloadNPC(); NPCManager.reloadNPC();
} }
} }

View file

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

View file

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

View file

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